Class: Depager::Rule
- Inherits:
-
Object
- Object
- Depager::Rule
- Defined in:
- lib/depager/grammar.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#grammar ⇒ Object
Returns the value of attribute grammar.
-
#lhs ⇒ Object
Returns the value of attribute lhs.
-
#n ⇒ Object
Returns the value of attribute n.
-
#prec ⇒ Object
Returns the value of attribute prec.
-
#rhs ⇒ Object
Returns the value of attribute rhs.
-
#rhs_names ⇒ Object
Returns the value of attribute rhs_names.
Class Method Summary collapse
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
-
#initialize(lhs, rhs, prec = nil, rhs_names = nil) ⇒ Rule
constructor
A new instance of Rule.
- #initialize_depend ⇒ Object
- #lhs_name ⇒ Object
- #rhs_name_to_sym(name) ⇒ Object
- #to_s ⇒ Object
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
#grammar ⇒ Object
Returns the value of attribute grammar.
212 213 214 |
# File 'lib/depager/grammar.rb', line 212 def grammar @grammar end |
#lhs ⇒ Object
Returns the value of attribute lhs.
212 213 214 |
# File 'lib/depager/grammar.rb', line 212 def lhs @lhs end |
#n ⇒ Object
Returns the value of attribute n.
212 213 214 |
# File 'lib/depager/grammar.rb', line 212 def n @n end |
#prec ⇒ Object
Returns the value of attribute prec.
212 213 214 |
# File 'lib/depager/grammar.rb', line 212 def prec @prec end |
#rhs ⇒ Object
Returns the value of attribute rhs.
212 213 214 |
# File 'lib/depager/grammar.rb', line 212 def rhs @rhs end |
#rhs_names ⇒ Object
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: ==
248 249 250 |
# File 'lib/depager/grammar.rb', line 248 def eql?(other) @lhs == other.lhs && @rhs == other.rhs end |
#hash ⇒ Object
244 245 246 |
# File 'lib/depager/grammar.rb', line 244 def hash [@rhs, @lhs].hash end |
#initialize_depend ⇒ Object
226 |
# File 'lib/depager/grammar.rb', line 226 def initialize_depend; end |
#lhs_name ⇒ Object
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_s ⇒ Object
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 |