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.



1315
1316
1317
1318
1319
# File 'lib/ruby_parser_extras.rb', line 1315

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

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



1313
1314
1315
# File 'lib/ruby_parser_extras.rb', line 1313

def debug
  @debug
end

#nameObject (readonly)

Returns the value of attribute name.



1311
1312
1313
# File 'lib/ruby_parser_extras.rb', line 1311

def name
  @name
end

#stackObject (readonly)

Returns the value of attribute stack.



1312
1313
1314
# File 'lib/ruby_parser_extras.rb', line 1312

def stack
  @stack
end

Instance Method Details

#inspectObject



1321
1322
1323
# File 'lib/ruby_parser_extras.rb', line 1321

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

#is_in_stateObject



1325
1326
1327
1328
# File 'lib/ruby_parser_extras.rb', line 1325

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

#lexpopObject



1330
1331
1332
1333
1334
1335
1336
# File 'lib/ruby_parser_extras.rb', line 1330

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



1338
1339
1340
1341
1342
1343
# File 'lib/ruby_parser_extras.rb', line 1338

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



1345
1346
1347
1348
1349
# File 'lib/ruby_parser_extras.rb', line 1345

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

#restore(oldstate) ⇒ Object



1357
1358
1359
# File 'lib/ruby_parser_extras.rb', line 1357

def restore oldstate
  @stack.replace oldstate
end

#storeObject



1351
1352
1353
1354
1355
# File 'lib/ruby_parser_extras.rb', line 1351

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