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
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/parser-2.4.0.2/lib/parser/lexer/stack_state.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/parser-2.4.0.2/lib/parser/lexer/stack_state.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/parser-2.4.0.2/lib/parser/lexer/stack_state.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/parser-2.4.0.2/lib/parser/lexer/stack_state.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/parser-2.4.0.2/lib/parser/lexer/stack_state.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/parser-2.4.0.2/lib/parser/lexer/stack_state.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/parser-2.4.0.0/lib/parser/lexer/stack_state.rb
parser-2.4.0.2 lib/parser/lexer/stack_state.rb
parser-2.4.0.1 lib/parser/lexer/stack_state.rb
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/parser-2.4.0.0/lib/parser/lexer/stack_state.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/parser-2.4.0.0/lib/parser/lexer/stack_state.rb
parser-2.4.0.0 lib/parser/lexer/stack_state.rb
parser-2.3.3.1 lib/parser/lexer/stack_state.rb
parser-2.3.3.0 lib/parser/lexer/stack_state.rb
parser-2.3.2.0 lib/parser/lexer/stack_state.rb
parser-2.3.1.4 lib/parser/lexer/stack_state.rb
parser-2.3.1.3 lib/parser/lexer/stack_state.rb
erruby_parser-2.3.1.2 lib/parser/lexer/stack_state.rb
parser-2.3.1.2 lib/parser/lexer/stack_state.rb
parser-2.3.1.1 lib/parser/lexer/stack_state.rb