123456789_123456789_123456789_123456789_123456789_

Class: IRB::Color::SymbolState

Relationships & Source Files
Inherits: Object
Defined in: lib/irb/color.rb

Overview

A class to manage a state to know whether the current token is for Symbol or not.

Class Method Summary

Instance Method Summary

Constructor Details

.newSymbolState

[ GitHub ]

  
# File 'lib/irb/color.rb', line 214

def initialize
  # Push `true` to detect Symbol. `false` to increase the nest level for non-Symbol.
  @stack = []
end

Instance Method Details

#scan_token(token)

Return true if the token is a part of Symbol.

[ GitHub ]

  
# File 'lib/irb/color.rb', line 220

def scan_token(token)
  prev_state = @stack.last
  case token
  when :on_symbeg, :on_symbols_beg, :on_qsymbols_beg
    @stack << true
  when :on_ident, :on_op, :on_const, :on_ivar, :on_cvar, :on_gvar, :on_kw
    if @stack.last # Pop only when it's Symbol
      @stack.pop
      return prev_state
    end
  when :on_tstring_beg
    @stack << false
  when :on_embexpr_beg
    @stack << false
    return prev_state
  when :on_tstring_end # :on_tstring_end may close Symbol
    @stack.pop
    return prev_state
  when :on_embexpr_end
    @stack.pop
  end
  @stack.last
end