Class: Racc::LocationPointer

Inherits:
Object
  • Object
show all
Defined in:
lib/racc/grammar.rb

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

Instance Method Summary collapse

Constructor Details

#initialize(rule, i, sym) ⇒ LocationPointer

Returns a new instance of LocationPointer.



814
815
816
817
818
819
820
# File 'lib/racc/grammar.rb', line 814

def initialize(rule, i, sym)
  @rule   = rule
  @index  = i
  @symbol = sym
  @ident  = @rule.hash + i
  @reduce = sym.nil?
end

Instance Attribute Details

#identObject (readonly) Also known as: hash

Returns the value of attribute ident.



828
829
830
# File 'lib/racc/grammar.rb', line 828

def ident
  @ident
end

#indexObject (readonly)

Returns the value of attribute index.



823
824
825
# File 'lib/racc/grammar.rb', line 823

def index
  @index
end

#reduceObject (readonly) Also known as: reduce?

Returns the value of attribute reduce.



830
831
832
# File 'lib/racc/grammar.rb', line 830

def reduce
  @reduce
end

#ruleObject (readonly)

Returns the value of attribute rule.



822
823
824
# File 'lib/racc/grammar.rb', line 822

def rule
  @rule
end

#symbolObject (readonly) Also known as: dereference

Returns the value of attribute symbol.



824
825
826
# File 'lib/racc/grammar.rb', line 824

def symbol
  @symbol
end

Instance Method Details

#before(len) ⇒ Object



856
857
858
# File 'lib/racc/grammar.rb', line 856

def before(len)
  @rule.ptrs[@index - len] or ptr_bug!
end

#eql?(ot) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


840
841
842
# File 'lib/racc/grammar.rb', line 840

def eql?(ot)
  @hash == ot.hash
end

#head?Boolean

Returns:

  • (Boolean)


846
847
848
# File 'lib/racc/grammar.rb', line 846

def head?
  @index == 0
end

#nextObject Also known as: increment



850
851
852
# File 'lib/racc/grammar.rb', line 850

def next
  @rule.ptrs[@index + 1] or ptr_bug!
end

#to_sObject Also known as: inspect



833
834
835
836
# File 'lib/racc/grammar.rb', line 833

def to_s
  sprintf('(%d,%d %s)',
          @rule.ident, @index, (reduce?() ? '#' : @symbol.to_s))
end