Sha256: 6c4b455a2961afcfa57e2508d2d2f927d9f1b509c6bf3b6796a2de9b9bcdde59

Contents?: true

Size: 661 Bytes

Versions: 7011

Compression:

Stored size: 661 Bytes

Contents

# frozen_string_literal: true

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
      @stack = ((@stack >> 1) | (@stack & 1))
      @stack[0] == 1
    end

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

    def empty?
      @stack == 0
    end

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

    alias inspect to_s
  end

end

Version data entries

7,011 entries across 6,988 versions & 50 rubygems

Version Path
parser-2.6.2.1 lib/parser/lexer/stack_state.rb
parser-2.6.2.0 lib/parser/lexer/stack_state.rb
parser-2.6.0.0 lib/parser/lexer/stack_state.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/parser-2.5.3.0/lib/parser/lexer/stack_state.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/parser-2.5.3.0/lib/parser/lexer/stack_state.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/parser-2.5.3.0/lib/parser/lexer/stack_state.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/parser-2.5.3.0/lib/parser/lexer/stack_state.rb
parser-2.5.3.0 lib/parser/lexer/stack_state.rb
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/parser-2.5.1.2/lib/parser/lexer/stack_state.rb
parser-2.5.1.2 lib/parser/lexer/stack_state.rb
parser-2.5.1.1 lib/parser/lexer/stack_state.rb