Class: Racc::LocationPointer
Overview
A set of rule and position in it’s RHS. Note that the number of pointers is more than rule’s RHS array, because pointer points right edge of the final symbol when reducing.
Instance Attribute Summary collapse
-
#ident ⇒ Object
(also: #hash)
readonly
Returns the value of attribute ident.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#reduce ⇒ Object
(also: #reduce?)
readonly
Returns the value of attribute reduce.
-
#rule ⇒ Object
readonly
Returns the value of attribute rule.
-
#symbol ⇒ Object
(also: #dereference)
readonly
Returns the value of attribute symbol.
Instance Method Summary collapse
- #before(len) ⇒ Object
- #eql?(ot) ⇒ Boolean (also: #==)
- #head? ⇒ Boolean
-
#initialize(rule, i, sym) ⇒ LocationPointer
constructor
A new instance of LocationPointer.
- #next ⇒ Object (also: #increment)
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(rule, i, sym) ⇒ LocationPointer
Returns a new instance of LocationPointer.
811 812 813 814 815 816 817 |
# File 'lib/racc/grammar.rb', line 811 def initialize(rule, i, sym) @rule = rule @index = i @symbol = sym @ident = @rule.hash + i @reduce = sym.nil? end |
Instance Attribute Details
#ident ⇒ Object (readonly) Also known as: hash
Returns the value of attribute ident.
825 826 827 |
# File 'lib/racc/grammar.rb', line 825 def ident @ident end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
820 821 822 |
# File 'lib/racc/grammar.rb', line 820 def index @index end |
#reduce ⇒ Object (readonly) Also known as: reduce?
Returns the value of attribute reduce.
827 828 829 |
# File 'lib/racc/grammar.rb', line 827 def reduce @reduce end |
#rule ⇒ Object (readonly)
Returns the value of attribute rule.
819 820 821 |
# File 'lib/racc/grammar.rb', line 819 def rule @rule end |
#symbol ⇒ Object (readonly) Also known as: dereference
Returns the value of attribute symbol.
821 822 823 |
# File 'lib/racc/grammar.rb', line 821 def symbol @symbol end |
Instance Method Details
#before(len) ⇒ Object
853 854 855 |
# File 'lib/racc/grammar.rb', line 853 def before(len) @rule.ptrs[@index - len] or ptr_bug! end |
#eql?(ot) ⇒ Boolean Also known as: ==
837 838 839 |
# File 'lib/racc/grammar.rb', line 837 def eql?(ot) @hash == ot.hash end |
#head? ⇒ Boolean
843 844 845 |
# File 'lib/racc/grammar.rb', line 843 def head? @index == 0 end |
#next ⇒ Object Also known as: increment
847 848 849 |
# File 'lib/racc/grammar.rb', line 847 def next @rule.ptrs[@index + 1] or ptr_bug! end |
#to_s ⇒ Object Also known as: inspect
830 831 832 833 |
# File 'lib/racc/grammar.rb', line 830 def to_s sprintf('(%d,%d %s)', @rule.ident, @index, (reduce?() ? '#' : @symbol.to_s)) end |