Class: Dhaka::Production
- Inherits:
-
Object
- Object
- Dhaka::Production
- Includes:
- Comparable
- Defined in:
- lib/dhaka/grammar/production.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#expansion ⇒ Object
readonly
Returns the value of attribute expansion.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(symbol, expansion, name, action, priority, precedence = nil) ⇒ Production
constructor
A new instance of Production.
- #precedence ⇒ Object
-
#to_s ⇒ Object
:nodoc:.
Constructor Details
#initialize(symbol, expansion, name, action, priority, precedence = nil) ⇒ Production
Returns a new instance of Production.
7 8 9 10 11 12 13 14 |
# File 'lib/dhaka/grammar/production.rb', line 7 def initialize(symbol, expansion, name, action, priority, precedence = nil) @symbol = symbol @expansion = expansion @name = name @precedence = precedence @action = action || proc { self } @priority = priority end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
5 6 7 |
# File 'lib/dhaka/grammar/production.rb', line 5 def action @action end |
#expansion ⇒ Object (readonly)
Returns the value of attribute expansion.
5 6 7 |
# File 'lib/dhaka/grammar/production.rb', line 5 def expansion @expansion end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/dhaka/grammar/production.rb', line 5 def name @name end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
5 6 7 |
# File 'lib/dhaka/grammar/production.rb', line 5 def priority @priority end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
5 6 7 |
# File 'lib/dhaka/grammar/production.rb', line 5 def symbol @symbol end |
Instance Method Details
#<=>(other) ⇒ Object
32 33 34 |
# File 'lib/dhaka/grammar/production.rb', line 32 def <=> other priority <=> other.priority end |
#precedence ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dhaka/grammar/production.rb', line 16 def precedence unless @precedence expansion.reverse_each do |symbol| if symbol.terminal @precedence = symbol.precedence break end end end @precedence end |
#to_s ⇒ Object
:nodoc:
28 29 30 |
# File 'lib/dhaka/grammar/production.rb', line 28 def to_s #:nodoc: "#{name} #{symbol} ::= #{expansion.join(' ')}" end |