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
mx-platform-ruby-0.3.2 vendor/bundle/ruby/2.6.0/gems/parser-3.0.2.0/lib/parser/lexer/stack_state.rb
mx-platform-ruby-0.3.1 vendor/bundle/ruby/2.6.0/gems/parser-3.0.2.0/lib/parser/lexer/stack_state.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/parser-3.0.2.0/lib/parser/lexer/stack_state.rb
parser-3.0.2.0 lib/parser/lexer/stack_state.rb
passbase-1.3.0 vendor/bundle/ruby/2.7.0/gems/parser-2.7.1.4/lib/parser/lexer/stack_state.rb
cocRb-0.1.0 .bundle/ruby/3.0.0/gems/parser-3.0.1.1/lib/parser/lexer/stack_state.rb
parser-3.0.1.1 lib/parser/lexer/stack_state.rb
parser-3.0.1.0 lib/parser/lexer/stack_state.rb
mfk_openapi_ruby_client-1.0.0 vendor/bundle/ruby/2.7.0/gems/parser-3.0.0.0/lib/parser/lexer/stack_state.rb
parser-3.0.0.0 lib/parser/lexer/stack_state.rb
passbase-1.2.0 vendor/bundle/ruby/2.7.0/gems/parser-2.7.1.4/lib/parser/lexer/stack_state.rb
passbase-1.1.0 vendor/bundle/ruby/2.7.0/gems/parser-2.7.1.4/lib/parser/lexer/stack_state.rb
passbase-1.0.3 vendor/bundle/ruby/2.7.0/gems/parser-2.7.1.4/lib/parser/lexer/stack_state.rb
passbase-1.0.2 vendor/bundle/ruby/2.7.0/gems/parser-2.7.1.4/lib/parser/lexer/stack_state.rb
passbase-1.0.1 vendor/bundle/ruby/2.7.0/gems/parser-2.7.1.4/lib/parser/lexer/stack_state.rb
passbase-1.0.0 vendor/bundle/ruby/2.7.0/gems/parser-2.7.1.4/lib/parser/lexer/stack_state.rb
parser-2.7.2.0 lib/parser/lexer/stack_state.rb
parser-2.7.1.5 lib/parser/lexer/stack_state.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/parser-2.7.0.2/lib/parser/lexer/stack_state.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/parser-2.7.1.4/lib/parser/lexer/stack_state.rb