Class: Parser::Lexer::StackState
- Inherits:
-
Object
- Object
- Parser::Lexer::StackState
- Defined in:
- lib/parser/lexer/stack_state.rb
Instance Method Summary collapse
- #active? ⇒ Boolean
- #clear ⇒ Object
- #empty? ⇒ 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.
6 7 8 9 |
# File 'lib/parser/lexer/stack_state.rb', line 6 def initialize(name) @name = name.freeze clear end |
Instance Method Details
#active? ⇒ Boolean
34 35 36 |
# File 'lib/parser/lexer/stack_state.rb', line 34 def active? @stack[0] == 1 end |
#clear ⇒ Object
11 12 13 |
# File 'lib/parser/lexer/stack_state.rb', line 11 def clear @stack = 0 end |
#empty? ⇒ Boolean
38 39 40 |
# File 'lib/parser/lexer/stack_state.rb', line 38 def empty? @stack == 0 end |
#lexpop ⇒ Object
29 30 31 32 |
# File 'lib/parser/lexer/stack_state.rb', line 29 def lexpop @stack = ((@stack >> 1) | (@stack & 1)) @stack[0] == 1 end |
#pop ⇒ Object
22 23 24 25 26 27 |
# File 'lib/parser/lexer/stack_state.rb', line 22 def pop bit_value = @stack & 1 @stack >>= 1 bit_value == 1 end |
#push(bit) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/parser/lexer/stack_state.rb', line 15 def push(bit) bit_value = bit ? 1 : 0 @stack = (@stack << 1) | bit_value bit end |
#to_s ⇒ Object Also known as: inspect
42 43 44 |
# File 'lib/parser/lexer/stack_state.rb', line 42 def to_s "[#{@stack.to_s(2)} <= #{@name}]" end |