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.



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

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

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



1272
1273
1274
# File 'lib/ruby_parser_extras.rb', line 1272

def debug
  @debug
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#stackObject (readonly)

Returns the value of attribute stack.



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

def stack
  @stack
end

Instance Method Details

#inspectObject



1280
1281
1282
# File 'lib/ruby_parser_extras.rb', line 1280

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

#is_in_stateObject



1284
1285
1286
1287
# File 'lib/ruby_parser_extras.rb', line 1284

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

#lexpopObject



1289
1290
1291
1292
1293
1294
1295
# File 'lib/ruby_parser_extras.rb', line 1289

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



1297
1298
1299
1300
1301
1302
# File 'lib/ruby_parser_extras.rb', line 1297

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



1304
1305
1306
1307
1308
# File 'lib/ruby_parser_extras.rb', line 1304

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

#restore(oldstate) ⇒ Object



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

def restore oldstate
  @stack.replace oldstate
end

#storeObject



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

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