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.
1813 1814 1815 1816 1817 |
# File 'lib/ruby_parser_extras.rb', line 1813 def initialize name, debug=false @name = name @stack = [false] @debug = debug end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
1811 1812 1813 |
# File 'lib/ruby_parser_extras.rb', line 1811 def debug @debug end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
1809 1810 1811 |
# File 'lib/ruby_parser_extras.rb', line 1809 def name @name end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
1810 1811 1812 |
# File 'lib/ruby_parser_extras.rb', line 1810 def stack @stack end |
Instance Method Details
#inspect ⇒ Object
1819 1820 1821 |
# File 'lib/ruby_parser_extras.rb', line 1819 def inspect "StackState(#{@name}, #{@stack.inspect})" end |
#is_in_state ⇒ Object
1823 1824 1825 1826 |
# File 'lib/ruby_parser_extras.rb', line 1823 def is_in_state log :is_in_state if debug @stack.last end |
#lexpop ⇒ Object
1828 1829 1830 1831 1832 1833 1834 |
# File 'lib/ruby_parser_extras.rb', line 1828 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
1836 1837 1838 1839 1840 1841 |
# File 'lib/ruby_parser_extras.rb', line 1836 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
1843 1844 1845 1846 1847 1848 |
# File 'lib/ruby_parser_extras.rb', line 1843 def pop r = @stack.pop @stack.push false if @stack.empty? log :pop if debug r end |
#push(val) ⇒ Object
1850 1851 1852 1853 |
# File 'lib/ruby_parser_extras.rb', line 1850 def push val @stack.push val log :push if debug end |
#reset ⇒ Object
1855 1856 1857 1858 |
# File 'lib/ruby_parser_extras.rb', line 1855 def reset @stack = [false] log :reset if debug end |
#restore(oldstate) ⇒ Object
1860 1861 1862 1863 |
# File 'lib/ruby_parser_extras.rb', line 1860 def restore oldstate @stack.replace oldstate log :restore if debug end |
#store(base = false) ⇒ Object
1865 1866 1867 1868 1869 1870 |
# File 'lib/ruby_parser_extras.rb', line 1865 def store base = false result = @stack.dup @stack.replace [base] log :store if debug result end |