class RubyParserStuff::Environment::StackState

Attributes

debug[RW]
name[R]
stack[R]

Public Class Methods

new(name, debug=false) click to toggle source
# File lib/ruby_parser_extras.rb, line 1572
def initialize name, debug=false
  @name = name
  @stack = [false]
  @debug = debug
end

Public Instance Methods

inspect() click to toggle source
# File lib/ruby_parser_extras.rb, line 1578
def inspect
  "StackState(#{@name}, #{@stack.inspect})"
end
is_in_state() click to toggle source
# File lib/ruby_parser_extras.rb, line 1582
def is_in_state
  log :is_in_state if debug
  @stack.last
end
lexpop() click to toggle source
# File lib/ruby_parser_extras.rb, line 1587
def lexpop
  raise if @stack.size == 0
  a = @stack.pop
  b = @stack.pop
  @stack.push(a || b)
  log :lexpop if debug
end
log(action) click to toggle source
# File lib/ruby_parser_extras.rb, line 1595
def log action
  c = caller[1]
  c = caller[2] if c =~ /expr_result/
  warn "%s_stack.%s: %p at %s" % [name, action, @stack, c.clean_caller]
  nil
end
pop() click to toggle source
# File lib/ruby_parser_extras.rb, line 1602
def pop
  r = @stack.pop
  @stack.push false if @stack.empty?
  log :pop if debug
  r
end
push(val) click to toggle source
# File lib/ruby_parser_extras.rb, line 1609
def push val
  @stack.push val
  log :push if debug
end
reset() click to toggle source
# File lib/ruby_parser_extras.rb, line 1614
def reset
  @stack = [false]
  log :reset if debug
end
restore(oldstate) click to toggle source
# File lib/ruby_parser_extras.rb, line 1619
def restore oldstate
  @stack.replace oldstate
  log :restore if debug
end
store(base = false) click to toggle source
# File lib/ruby_parser_extras.rb, line 1624
def store base = false
  result = @stack.dup
  @stack.replace [base]
  log :store if debug
  result
end