Class: RubyParserStuff::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.



1245
1246
1247
1248
1249
# File 'lib/ruby_parser_extras.rb', line 1245

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

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



1243
1244
1245
# File 'lib/ruby_parser_extras.rb', line 1243

def debug
  @debug
end

#nameObject (readonly)

Returns the value of attribute name.



1241
1242
1243
# File 'lib/ruby_parser_extras.rb', line 1241

def name
  @name
end

#stackObject (readonly)

Returns the value of attribute stack.



1242
1243
1244
# File 'lib/ruby_parser_extras.rb', line 1242

def stack
  @stack
end

Instance Method Details

#inspectObject



1251
1252
1253
# File 'lib/ruby_parser_extras.rb', line 1251

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

#is_in_stateObject



1255
1256
1257
1258
# File 'lib/ruby_parser_extras.rb', line 1255

def is_in_state
  p :stack_is_in_state => [name, @stack.last, caller.first] if debug
  @stack.last
end

#lexpopObject



1260
1261
1262
1263
1264
1265
1266
# File 'lib/ruby_parser_extras.rb', line 1260

def lexpop
  p :stack_lexpop => caller.first if debug
  raise if @stack.size == 0
  a = @stack.pop
  b = @stack.pop
  @stack.push(a || b)
end

#popObject



1268
1269
1270
1271
1272
1273
# File 'lib/ruby_parser_extras.rb', line 1268

def pop
  r = @stack.pop
  p :stack_pop => [name, r, @stack, caller.first] if debug
  @stack.push false if @stack.size == 0
  r
end

#push(val) ⇒ Object



1275
1276
1277
1278
1279
# File 'lib/ruby_parser_extras.rb', line 1275

def push val
  @stack.push val
  p :stack_push => [name, @stack, caller.first] if debug
  nil
end

#restore(oldstate) ⇒ Object



1287
1288
1289
# File 'lib/ruby_parser_extras.rb', line 1287

def restore oldstate
  @stack.replace oldstate
end

#storeObject



1281
1282
1283
1284
1285
# File 'lib/ruby_parser_extras.rb', line 1281

def store
  result = @stack.dup
  @stack.replace [false]
  result
end