Class: StackState

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_parser_extras.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ StackState

Returns a new instance of StackState.



970
971
972
973
# File 'lib/ruby_parser_extras.rb', line 970

def initialize(name)
  @name = name
  @stack = [false]
end

Instance Attribute Details

#stackObject (readonly)

Returns the value of attribute stack.



968
969
970
# File 'lib/ruby_parser_extras.rb', line 968

def stack
  @stack
end

Instance Method Details

#inspectObject



975
976
977
# File 'lib/ruby_parser_extras.rb', line 975

def inspect
  "StackState(#{@name}, #{@stack.inspect})"
end

#is_in_stateObject



979
980
981
# File 'lib/ruby_parser_extras.rb', line 979

def is_in_state
  @stack.last
end

#lexpopObject



983
984
985
986
987
988
# File 'lib/ruby_parser_extras.rb', line 983

def lexpop
  raise if @stack.size == 0
  a = @stack.pop
  b = @stack.pop
  @stack.push(a || b)
end

#popObject



990
991
992
993
994
# File 'lib/ruby_parser_extras.rb', line 990

def pop
  r = @stack.pop
  @stack.push false if @stack.size == 0
  r
end

#push(val) ⇒ Object



996
997
998
# File 'lib/ruby_parser_extras.rb', line 996

def push val
  @stack.push val
end