123456789_123456789_123456789_123456789_123456789_

Class: Racc::LocationPointer

Relationships & Source Files
Inherits: Object
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.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(rule, i, sym) ⇒ LocationPointer

[ GitHub ]

  
# File 'lib/racc/grammar.rb', line 809

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

Instance Attribute Details

#dereference (readonly)

Alias for #symbol.

[ GitHub ]

  
# File 'lib/racc/grammar.rb', line 821

alias dereference symbol

#hash (readonly)

Alias for #ident.

[ GitHub ]

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

alias hash ident

#head?Boolean (readonly)

[ GitHub ]

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

def head?
  @index == 0
end

#ident (readonly) Also known as: #hash

[ GitHub ]

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

attr_reader :ident

#index (readonly)

[ GitHub ]

  
# File 'lib/racc/grammar.rb', line 818

attr_reader :index

#reduce? (readonly)

Alias for #reduce.

[ GitHub ]

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

alias reduce? reduce

#rule (readonly)

[ GitHub ]

  
# File 'lib/racc/grammar.rb', line 817

attr_reader :rule

#symbol (readonly) Also known as: #dereference

[ GitHub ]

  
# File 'lib/racc/grammar.rb', line 819

attr_reader :symbol

Instance Method Details

#==(ot)

Alias for #eql?.

[ GitHub ]

  
# File 'lib/racc/grammar.rb', line 839

alias == eql?

#before(len)

[ GitHub ]

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

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

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

[ GitHub ]

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

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

#increment

Alias for #next.

[ GitHub ]

  
# File 'lib/racc/grammar.rb', line 849

alias increment next

#inspect

Alias for #to_s.

[ GitHub ]

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

alias inspect to_s

#next Also known as: #increment

[ GitHub ]

  
# File 'lib/racc/grammar.rb', line 845

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

#ptr_bug! (private)

[ GitHub ]

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

def ptr_bug!
  raise "racc: fatal: pointer not exist: self: #{to_s}"
end

#reduce (readonly) Also known as: #reduce?

[ GitHub ]

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

attr_reader :reduce

#to_s Also known as: #inspect

[ GitHub ]

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

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