Class: Lrama::Rule
- Inherits:
-
Struct
- Object
- Struct
- Lrama::Rule
- Defined in:
- lib/lrama/grammar.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#id ⇒ Object
Returns the value of attribute id.
-
#lhs ⇒ Object
Returns the value of attribute lhs.
-
#lineno ⇒ Object
Returns the value of attribute lineno.
-
#nullable ⇒ Object
Returns the value of attribute nullable.
-
#precedence_sym ⇒ Object
Returns the value of attribute precedence_sym.
-
#rhs ⇒ Object
Returns the value of attribute rhs.
Instance Method Summary collapse
-
#as_comment ⇒ Object
Used by #user_actions.
- #initial_rule? ⇒ Boolean
- #precedence ⇒ Object
-
#to_s ⇒ Object
TODO: Change this to display_name.
- #translated_code ⇒ Object
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code
5 6 7 |
# File 'lib/lrama/grammar.rb', line 5 def code @code end |
#id ⇒ Object
Returns the value of attribute id
5 6 7 |
# File 'lib/lrama/grammar.rb', line 5 def id @id end |
#lhs ⇒ Object
Returns the value of attribute lhs
5 6 7 |
# File 'lib/lrama/grammar.rb', line 5 def lhs @lhs end |
#lineno ⇒ Object
Returns the value of attribute lineno
5 6 7 |
# File 'lib/lrama/grammar.rb', line 5 def lineno @lineno end |
#nullable ⇒ Object
Returns the value of attribute nullable
5 6 7 |
# File 'lib/lrama/grammar.rb', line 5 def nullable @nullable end |
#precedence_sym ⇒ Object
Returns the value of attribute precedence_sym
5 6 7 |
# File 'lib/lrama/grammar.rb', line 5 def precedence_sym @precedence_sym end |
#rhs ⇒ Object
Returns the value of attribute rhs
5 6 7 |
# File 'lib/lrama/grammar.rb', line 5 def rhs @rhs end |
Instance Method Details
#as_comment ⇒ Object
Used by #user_actions
15 16 17 18 19 20 |
# File 'lib/lrama/grammar.rb', line 15 def as_comment l = lhs.id.s_value r = rhs.empty? ? "%empty" : rhs.map {|r| r.display_name }.join(" ") "#{l}: #{r}" end |
#initial_rule? ⇒ Boolean
26 27 28 |
# File 'lib/lrama/grammar.rb', line 26 def initial_rule? id == 0 end |
#precedence ⇒ Object
22 23 24 |
# File 'lib/lrama/grammar.rb', line 22 def precedence precedence_sym && precedence_sym.precedence end |
#to_s ⇒ Object
TODO: Change this to display_name
7 8 9 10 11 12 |
# File 'lib/lrama/grammar.rb', line 7 def to_s l = lhs.id.s_value r = rhs.empty? ? "ε" : rhs.map {|r| r.id.s_value }.join(", ") "#{l} -> #{r}" end |
#translated_code ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/lrama/grammar.rb', line 30 def translated_code if code code.translated_code else nil end end |