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
- #log(action) ⇒ Object
- #pop ⇒ Object
- #push(val) ⇒ Object
- #reset ⇒ Object
- #restore(oldstate) ⇒ Object
- #store(base = false) ⇒ Object
Constructor Details
#initialize(name, debug = false) ⇒ StackState
Returns a new instance of StackState.
1322 1323 1324 1325 1326 |
# File 'lib/ruby_parser_extras.rb', line 1322 def initialize name, debug=false @name = name @stack = [false] @debug = debug end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
1320 1321 1322 |
# File 'lib/ruby_parser_extras.rb', line 1320 def debug @debug end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
1318 1319 1320 |
# File 'lib/ruby_parser_extras.rb', line 1318 def name @name end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
1319 1320 1321 |
# File 'lib/ruby_parser_extras.rb', line 1319 def stack @stack end |
Instance Method Details
#inspect ⇒ Object
1333 1334 1335 |
# File 'lib/ruby_parser_extras.rb', line 1333 def inspect "StackState(#{@name}, #{@stack.inspect})" end |
#is_in_state ⇒ Object
1337 1338 1339 1340 |
# File 'lib/ruby_parser_extras.rb', line 1337 def is_in_state log :is_in_state if debug @stack.last end |
#lexpop ⇒ Object
1342 1343 1344 1345 1346 1347 1348 |
# File 'lib/ruby_parser_extras.rb', line 1342 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
1350 1351 1352 1353 1354 1355 |
# File 'lib/ruby_parser_extras.rb', line 1350 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
1357 1358 1359 1360 1361 1362 |
# File 'lib/ruby_parser_extras.rb', line 1357 def pop r = @stack.pop @stack.push false if @stack.empty? log :pop if debug r end |
#push(val) ⇒ Object
1364 1365 1366 1367 |
# File 'lib/ruby_parser_extras.rb', line 1364 def push val @stack.push val log :push if debug end |
#reset ⇒ Object
1328 1329 1330 1331 |
# File 'lib/ruby_parser_extras.rb', line 1328 def reset @stack = [false] log :reset if debug end |
#restore(oldstate) ⇒ Object
1376 1377 1378 1379 |
# File 'lib/ruby_parser_extras.rb', line 1376 def restore oldstate @stack.replace oldstate log :restore if debug end |
#store(base = false) ⇒ Object
1369 1370 1371 1372 1373 1374 |
# File 'lib/ruby_parser_extras.rb', line 1369 def store base = false result = @stack.dup @stack.replace [base] log :store if debug result end |