Sha256: 9a839ee45e263990f639fab63d6b4abdac52f32340c386543dee38d25849c6e2

Contents?: true

Size: 544 Bytes

Versions: 101

Compression:

Stored size: 544 Bytes

Contents

module Parser

  class Lexer::StackState
    def initialize(name)
      @name  = name.freeze
      clear
    end

    def clear
      @stack = 0
    end

    def push(bit)
      bit_value = bit ? 1 : 0
      @stack = (@stack << 1) | bit_value

      bit
    end

    def pop
      bit_value = @stack & 1
      @stack  >>= 1

      bit_value == 1
    end

    def lexpop
      push(pop || pop)
    end

    def active?
      @stack[0] == 1
    end

    def to_s
      "[#{@stack.to_s(2)} <= #{@name}]"
    end

    alias inspect to_s
  end

end

Version data entries

101 entries across 101 versions & 5 rubygems

Version Path
parser-2.2.2.3 lib/parser/lexer/stack_state.rb
parser-2.2.2.2 lib/parser/lexer/stack_state.rb
parser-2.2.2.1 lib/parser/lexer/stack_state.rb
parser-2.2.2.0 lib/parser/lexer/stack_state.rb
parser-2.2.0.4 lib/parser/lexer/stack_state.rb
parser-2.2.0.3 lib/parser/lexer/stack_state.rb
parser-2.2.0.2 lib/parser/lexer/stack_state.rb
parser-2.2.0.1 lib/parser/lexer/stack_state.rb
parser-2.2.0 lib/parser/lexer/stack_state.rb
parser-2.2.0.pre.8 lib/parser/lexer/stack_state.rb
parser-2.2.0.pre.7 lib/parser/lexer/stack_state.rb
parser-2.2.0.pre.6 lib/parser/lexer/stack_state.rb
parser-2.2.0.pre.5 lib/parser/lexer/stack_state.rb
parser-2.2.0.pre.4 lib/parser/lexer/stack_state.rb
parser-2.2.0.pre.3 lib/parser/lexer/stack_state.rb
parser-2.2.0.pre.2 lib/parser/lexer/stack_state.rb
parser-2.2.0.pre.1 lib/parser/lexer/stack_state.rb
parser-2.1.9 lib/parser/lexer/stack_state.rb
parser-2.1.8 lib/parser/lexer/stack_state.rb
parser-2.1.7 lib/parser/lexer/stack_state.rb