Class: Depager::LALR::LRItem

Inherits:
Object
  • Object
show all
Defined in:
lib/depager/lr.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rule, n, la = nil) ⇒ LRItem

Returns a new instance of LRItem.



141
142
143
144
145
146
# File 'lib/depager/lr.rb', line 141

def initialize(rule, n, la = nil)
  @rule = rule
  @n = n
  @la = la || rule.grammar.symset
  @_hash = nil
end

Instance Attribute Details

#laObject

Returns the value of attribute la.



139
140
141
# File 'lib/depager/lr.rb', line 139

def la
  @la
end

#nObject

Returns the value of attribute n.



139
140
141
# File 'lib/depager/lr.rb', line 139

def n
  @n
end

#ruleObject

Returns the value of attribute rule.



139
140
141
# File 'lib/depager/lr.rb', line 139

def rule
  @rule
end

Class Method Details

.[](rule, n, la = nil) ⇒ Object



148
149
150
# File 'lib/depager/lr.rb', line 148

def self.[](rule, n, la = nil)
  LRItem.new rule, n, la
end

Instance Method Details

#closureObject



177
178
179
# File 'lib/depager/lr.rb', line 177

def closure
  @rule.grammar.closure @rule, @n, self
end

#closure1(la) ⇒ Object



173
174
175
# File 'lib/depager/lr.rb', line 173

def closure1(la)
  @rule.grammar.closure1 @rule, @n, la
end

#dotrestObject



185
186
187
# File 'lib/depager/lr.rb', line 185

def dotrest
  @rule.rhs[@n + 1..]
end

#dotsymObject



181
182
183
# File 'lib/depager/lr.rb', line 181

def dotsym
  @rule.rhs[@n]
end

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

Returns:

  • (Boolean)


158
159
160
# File 'lib/depager/lr.rb', line 158

def eql?(other)
  @rule == other.rule && @n == other.n
end

#hashObject



152
153
154
155
156
# File 'lib/depager/lr.rb', line 152

def hash
  return @_hash if @_hash

  @_hash = [@rule, @n].hash
end

#to_sObject



163
164
165
166
167
168
169
170
171
# File 'lib/depager/lr.rb', line 163

def to_s
  la  = @la.map { |i| @rule.grammar.symname i }.sort.join(" ")
  lhs = @rule.grammar.symname @rule.lhs
  rhs = @rule.rhs.map { |i| @rule.grammar.symname i }.insert(@n, "_").join(" ")

  str =  "(#{format('%03s', @rule.n)}) #{lhs} : #{rhs}"
  str << "\n      # #{la}" if Depager.debug_mode?(:l)
  str
end