Class: RubyParser::Legacy::RubyParserStuff::StackState
- Inherits:
-
Object
- Object
- RubyParser::Legacy::RubyParserStuff::StackState
- Defined in:
- lib/ruby_parser/legacy/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
- #log(action) ⇒ Object
- #pop ⇒ Object
- #push(val) ⇒ Object
- #reset ⇒ Object
- #restore(oldstate) ⇒ Object
- #store(base = false) ⇒ Object
Constructor Details
#initialize(name, debug = false) ⇒ StackState
1329 1330 1331 1332 1333 |
# File 'lib/ruby_parser/legacy/ruby_parser_extras.rb', line 1329 def initialize name, debug=false @name = name @stack = [false] @debug = debug end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
1327 1328 1329 |
# File 'lib/ruby_parser/legacy/ruby_parser_extras.rb', line 1327 def debug @debug end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
1325 1326 1327 |
# File 'lib/ruby_parser/legacy/ruby_parser_extras.rb', line 1325 def name @name end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
1326 1327 1328 |
# File 'lib/ruby_parser/legacy/ruby_parser_extras.rb', line 1326 def stack @stack end |
Instance Method Details
#inspect ⇒ Object
1340 1341 1342 |
# File 'lib/ruby_parser/legacy/ruby_parser_extras.rb', line 1340 def inspect "StackState(#{@name}, #{@stack.inspect})" end |
#is_in_state ⇒ Object
1344 1345 1346 1347 |
# File 'lib/ruby_parser/legacy/ruby_parser_extras.rb', line 1344 def is_in_state log :is_in_state if debug @stack.last end |
#lexpop ⇒ Object
1349 1350 1351 1352 1353 1354 1355 |
# File 'lib/ruby_parser/legacy/ruby_parser_extras.rb', line 1349 def lexpop raise if @stack.size == 0 a = @stack.pop b = @stack.pop @stack.push(a || b) log :lexpop if debug end |
#log(action) ⇒ Object
1357 1358 1359 1360 1361 1362 |
# File 'lib/ruby_parser/legacy/ruby_parser_extras.rb', line 1357 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 ⇒ Object
1364 1365 1366 1367 1368 1369 |
# File 'lib/ruby_parser/legacy/ruby_parser_extras.rb', line 1364 def pop r = @stack.pop @stack.push false if @stack.empty? log :pop if debug r end |
#push(val) ⇒ Object
1371 1372 1373 1374 |
# File 'lib/ruby_parser/legacy/ruby_parser_extras.rb', line 1371 def push val @stack.push val log :push if debug end |
#reset ⇒ Object
1335 1336 1337 1338 |
# File 'lib/ruby_parser/legacy/ruby_parser_extras.rb', line 1335 def reset @stack = [false] log :reset if debug end |
#restore(oldstate) ⇒ Object
1383 1384 1385 1386 |
# File 'lib/ruby_parser/legacy/ruby_parser_extras.rb', line 1383 def restore oldstate @stack.replace oldstate log :restore if debug end |
#store(base = false) ⇒ Object
1376 1377 1378 1379 1380 1381 |
# File 'lib/ruby_parser/legacy/ruby_parser_extras.rb', line 1376 def store base = false result = @stack.dup @stack.replace [base] log :store if debug result end |