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.
1753 1754 1755 1756 1757 |
# File 'lib/ruby_parser_extras.rb', line 1753 def initialize name, debug=false @name = name @stack = [false] @debug = debug end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
1751 1752 1753 |
# File 'lib/ruby_parser_extras.rb', line 1751 def debug @debug end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
1749 1750 1751 |
# File 'lib/ruby_parser_extras.rb', line 1749 def name @name end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
1750 1751 1752 |
# File 'lib/ruby_parser_extras.rb', line 1750 def stack @stack end |
Instance Method Details
#inspect ⇒ Object
1759 1760 1761 |
# File 'lib/ruby_parser_extras.rb', line 1759 def inspect "StackState(#{@name}, #{@stack.inspect})" end |
#is_in_state ⇒ Object
1763 1764 1765 1766 |
# File 'lib/ruby_parser_extras.rb', line 1763 def is_in_state log :is_in_state if debug @stack.last end |
#lexpop ⇒ Object
1768 1769 1770 1771 1772 1773 1774 |
# File 'lib/ruby_parser_extras.rb', line 1768 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
1776 1777 1778 1779 1780 1781 |
# File 'lib/ruby_parser_extras.rb', line 1776 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
1783 1784 1785 1786 1787 1788 |
# File 'lib/ruby_parser_extras.rb', line 1783 def pop r = @stack.pop @stack.push false if @stack.empty? log :pop if debug r end |
#push(val) ⇒ Object
1790 1791 1792 1793 |
# File 'lib/ruby_parser_extras.rb', line 1790 def push val @stack.push val log :push if debug end |
#reset ⇒ Object
1795 1796 1797 1798 |
# File 'lib/ruby_parser_extras.rb', line 1795 def reset @stack = [false] log :reset if debug end |
#restore(oldstate) ⇒ Object
1800 1801 1802 1803 |
# File 'lib/ruby_parser_extras.rb', line 1800 def restore oldstate @stack.replace oldstate log :restore if debug end |
#store(base = false) ⇒ Object
1805 1806 1807 1808 1809 1810 |
# File 'lib/ruby_parser_extras.rb', line 1805 def store base = false result = @stack.dup @stack.replace [base] log :store if debug result end |