Class: Parser::Lexer::StackState
- Inherits:
-
Object
- Object
- Parser::Lexer::StackState
- Defined in:
- lib/parser/lexer/stack_state.rb
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#initialize(name) ⇒ StackState
constructor
A new instance of StackState.
- #lexpop ⇒ Object
- #pop ⇒ Object
- #push(bit) ⇒ Object
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(name) ⇒ StackState
Returns a new instance of StackState.
4 5 6 7 |
# File 'lib/parser/lexer/stack_state.rb', line 4 def initialize(name) @name = name.freeze @stack = 0 end |
Instance Method Details
#active? ⇒ Boolean
27 28 29 |
# File 'lib/parser/lexer/stack_state.rb', line 27 def active? @stack[0] == 1 end |
#lexpop ⇒ Object
23 24 25 |
# File 'lib/parser/lexer/stack_state.rb', line 23 def lexpop push(pop || pop) end |
#pop ⇒ Object
16 17 18 19 20 21 |
# File 'lib/parser/lexer/stack_state.rb', line 16 def pop bit_value = @stack & 1 @stack >>= 1 bit_value == 1 end |
#push(bit) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/parser/lexer/stack_state.rb', line 9 def push(bit) bit_value = bit ? 1 : 0 @stack = (@stack << 1) | bit_value bit end |
#to_s ⇒ Object Also known as: inspect
31 32 33 |
# File 'lib/parser/lexer/stack_state.rb', line 31 def to_s "[#{@stack.to_s(2)} <= #{@name}]" end |