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.
1837 1838 1839 1840 1841 |
# File 'lib/ruby_parser_extras.rb', line 1837 def initialize name, debug=false @name = name @stack = [false] @debug = debug end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
1835 1836 1837 |
# File 'lib/ruby_parser_extras.rb', line 1835 def debug @debug end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
1833 1834 1835 |
# File 'lib/ruby_parser_extras.rb', line 1833 def name @name end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
1834 1835 1836 |
# File 'lib/ruby_parser_extras.rb', line 1834 def stack @stack end |
Instance Method Details
#inspect ⇒ Object
1843 1844 1845 |
# File 'lib/ruby_parser_extras.rb', line 1843 def inspect "StackState(#{@name}, #{@stack.inspect})" end |
#is_in_state ⇒ Object
1847 1848 1849 1850 |
# File 'lib/ruby_parser_extras.rb', line 1847 def is_in_state log :is_in_state if debug @stack.last end |
#lexpop ⇒ Object
1852 1853 1854 1855 1856 1857 1858 |
# File 'lib/ruby_parser_extras.rb', line 1852 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
1860 1861 1862 1863 1864 1865 |
# File 'lib/ruby_parser_extras.rb', line 1860 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
1867 1868 1869 1870 1871 1872 |
# File 'lib/ruby_parser_extras.rb', line 1867 def pop r = @stack.pop @stack.push false if @stack.empty? log :pop if debug r end |
#push(val) ⇒ Object
1874 1875 1876 1877 |
# File 'lib/ruby_parser_extras.rb', line 1874 def push val @stack.push val log :push if debug end |
#reset ⇒ Object
1879 1880 1881 1882 |
# File 'lib/ruby_parser_extras.rb', line 1879 def reset @stack = [false] log :reset if debug end |
#restore(oldstate) ⇒ Object
1884 1885 1886 1887 |
# File 'lib/ruby_parser_extras.rb', line 1884 def restore oldstate @stack.replace oldstate log :restore if debug end |
#store(base = false) ⇒ Object
1889 1890 1891 1892 1893 1894 |
# File 'lib/ruby_parser_extras.rb', line 1889 def store base = false result = @stack.dup @stack.replace [base] log :store if debug result end |