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