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.
1545 1546 1547 1548 1549 |
# File 'lib/ruby_parser_extras.rb', line 1545 def initialize name, debug=false @name = name @stack = [false] @debug = debug end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
1543 1544 1545 |
# File 'lib/ruby_parser_extras.rb', line 1543 def debug @debug end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
1541 1542 1543 |
# File 'lib/ruby_parser_extras.rb', line 1541 def name @name end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
1542 1543 1544 |
# File 'lib/ruby_parser_extras.rb', line 1542 def stack @stack end |
Instance Method Details
#inspect ⇒ Object
1551 1552 1553 |
# File 'lib/ruby_parser_extras.rb', line 1551 def inspect "StackState(#{@name}, #{@stack.inspect})" end |
#is_in_state ⇒ Object
1555 1556 1557 1558 |
# File 'lib/ruby_parser_extras.rb', line 1555 def is_in_state log :is_in_state if debug @stack.last end |
#lexpop ⇒ Object
1560 1561 1562 1563 1564 1565 1566 |
# File 'lib/ruby_parser_extras.rb', line 1560 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
1568 1569 1570 1571 1572 1573 |
# File 'lib/ruby_parser_extras.rb', line 1568 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
1575 1576 1577 1578 1579 1580 |
# File 'lib/ruby_parser_extras.rb', line 1575 def pop r = @stack.pop @stack.push false if @stack.empty? log :pop if debug r end |
#push(val) ⇒ Object
1582 1583 1584 1585 |
# File 'lib/ruby_parser_extras.rb', line 1582 def push val @stack.push val log :push if debug end |
#reset ⇒ Object
1587 1588 1589 1590 |
# File 'lib/ruby_parser_extras.rb', line 1587 def reset @stack = [false] log :reset if debug end |
#restore(oldstate) ⇒ Object
1592 1593 1594 1595 |
# File 'lib/ruby_parser_extras.rb', line 1592 def restore oldstate @stack.replace oldstate log :restore if debug end |
#store(base = false) ⇒ Object
1597 1598 1599 1600 1601 1602 |
# File 'lib/ruby_parser_extras.rb', line 1597 def store base = false result = @stack.dup @stack.replace [base] log :store if debug result end |