Class: RubyParserStuff::StackState
- Inherits:
-
Object
- Object
- RubyParserStuff::StackState
- Defined in:
- lib/ruby_parser_extras.rb
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Instance Method Summary collapse
-
#initialize(name, debug = false) ⇒ StackState
constructor
A new instance of StackState.
- #inspect ⇒ Object
- #is_in_state ⇒ Object
- #lexpop ⇒ Object
- #pop ⇒ Object
- #push(val) ⇒ Object
- #reset ⇒ Object
- #restore(oldstate) ⇒ Object
- #store ⇒ Object
Constructor Details
#initialize(name, debug = false) ⇒ StackState
Returns a new instance of StackState.
1330 1331 1332 1333 1334 |
# File 'lib/ruby_parser_extras.rb', line 1330 def initialize name, debug=false @name = name @stack = [false] @debug = debug end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
1328 1329 1330 |
# File 'lib/ruby_parser_extras.rb', line 1328 def debug @debug end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
1326 1327 1328 |
# File 'lib/ruby_parser_extras.rb', line 1326 def name @name end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
1327 1328 1329 |
# File 'lib/ruby_parser_extras.rb', line 1327 def stack @stack end |
Instance Method Details
#inspect ⇒ Object
1341 1342 1343 |
# File 'lib/ruby_parser_extras.rb', line 1341 def inspect "StackState(#{@name}, #{@stack.inspect})" end |
#is_in_state ⇒ Object
1345 1346 1347 |
# File 'lib/ruby_parser_extras.rb', line 1345 def is_in_state @stack.last end |
#lexpop ⇒ Object
1349 1350 1351 1352 1353 1354 1355 |
# File 'lib/ruby_parser_extras.rb', line 1349 def lexpop warn "#{name}_stack.lexpop" if debug raise if @stack.size == 0 a = @stack.pop b = @stack.pop @stack.push(a || b) end |
#pop ⇒ Object
1357 1358 1359 1360 1361 1362 |
# File 'lib/ruby_parser_extras.rb', line 1357 def pop r = @stack.pop warn "#{name}_stack.pop" if debug @stack.push false if @stack.size == 0 r end |
#push(val) ⇒ Object
1364 1365 1366 1367 1368 1369 1370 |
# File 'lib/ruby_parser_extras.rb', line 1364 def push val @stack.push val c = caller.first c = caller[1] if c =~ /expr_result/ warn "#{name}_stack(push): #{val} at line #{c.clean_caller}" if debug nil end |
#reset ⇒ Object
1336 1337 1338 1339 |
# File 'lib/ruby_parser_extras.rb', line 1336 def reset @stack = [false] warn "#{name}_stack(set): 0" if debug end |
#restore(oldstate) ⇒ Object
1378 1379 1380 |
# File 'lib/ruby_parser_extras.rb', line 1378 def restore oldstate @stack.replace oldstate end |
#store ⇒ Object
1372 1373 1374 1375 1376 |
# File 'lib/ruby_parser_extras.rb', line 1372 def store result = @stack.dup @stack.replace [false] result end |