Class: Depager::Rule

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

Direct Known Subclasses

LALR::Rule

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lhs, rhs, prec = nil, rhs_names = nil) ⇒ Rule

Returns a new instance of Rule.



214
215
216
217
218
219
220
221
222
223
224
# File 'lib/depager/grammar.rb', line 214

def initialize(lhs, rhs, prec = nil, rhs_names = nil)
  @lhs = lhs
  @rhs = rhs
  @prec = prec
  @rhs_names = rhs_names

  @grammar = nil
  @n = 0

  initialize_depend
end

Instance Attribute Details

#grammarObject

Returns the value of attribute grammar.



212
213
214
# File 'lib/depager/grammar.rb', line 212

def grammar
  @grammar
end

#lhsObject

Returns the value of attribute lhs.



212
213
214
# File 'lib/depager/grammar.rb', line 212

def lhs
  @lhs
end

#nObject

Returns the value of attribute n.



212
213
214
# File 'lib/depager/grammar.rb', line 212

def n
  @n
end

#precObject

Returns the value of attribute prec.



212
213
214
# File 'lib/depager/grammar.rb', line 212

def prec
  @prec
end

#rhsObject

Returns the value of attribute rhs.



212
213
214
# File 'lib/depager/grammar.rb', line 212

def rhs
  @rhs
end

#rhs_namesObject

Returns the value of attribute rhs_names.



212
213
214
# File 'lib/depager/grammar.rb', line 212

def rhs_names
  @rhs_names
end

Class Method Details

.[](*args) ⇒ Object



208
209
210
# File 'lib/depager/grammar.rb', line 208

def self.[](*args)
  new(*args)
end

Instance Method Details

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

Returns:

  • (Boolean)


248
249
250
# File 'lib/depager/grammar.rb', line 248

def eql?(other)
  @lhs == other.lhs && @rhs == other.rhs
end

#hashObject



244
245
246
# File 'lib/depager/grammar.rb', line 244

def hash
  [@rhs, @lhs].hash
end

#initialize_dependObject



226
# File 'lib/depager/grammar.rb', line 226

def initialize_depend; end

#lhs_nameObject



228
229
230
# File 'lib/depager/grammar.rb', line 228

def lhs_name
  grammar.symname @lhs
end

#rhs_name_to_sym(name) ⇒ Object



232
233
234
235
236
# File 'lib/depager/grammar.rb', line 232

def rhs_name_to_sym(name)
  @rhs and @rhs[@rhs_names.index(name)]
rescue StandardError
  nil
end

#to_sObject



238
239
240
241
242
# File 'lib/depager/grammar.rb', line 238

def to_s
  rhs = @rhs.map { |i| grammar.symname i }.join(" ")

  "(#{format('%03s', @n)}) #{lhs_name} : #{rhs}"
end