Class: Lrama::Grammar::Rule
- Inherits:
-
Struct
- Object
- Struct
- Lrama::Grammar::Rule
- Defined in:
- lib/lrama/grammar/rule.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.
-
#empty_rule? ⇒ Boolean
opt_nl: ε <– empty_rule | ‘n’ <– not empty_rule.
- #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
3 4 5 |
# File 'lib/lrama/grammar/rule.rb', line 3 def code @code end |
#id ⇒ Object
Returns the value of attribute id
3 4 5 |
# File 'lib/lrama/grammar/rule.rb', line 3 def id @id end |
#lhs ⇒ Object
Returns the value of attribute lhs
3 4 5 |
# File 'lib/lrama/grammar/rule.rb', line 3 def lhs @lhs end |
#lineno ⇒ Object
Returns the value of attribute lineno
3 4 5 |
# File 'lib/lrama/grammar/rule.rb', line 3 def lineno @lineno end |
#nullable ⇒ Object
Returns the value of attribute nullable
3 4 5 |
# File 'lib/lrama/grammar/rule.rb', line 3 def nullable @nullable end |
#precedence_sym ⇒ Object
Returns the value of attribute precedence_sym
3 4 5 |
# File 'lib/lrama/grammar/rule.rb', line 3 def precedence_sym @precedence_sym end |
#rhs ⇒ Object
Returns the value of attribute rhs
3 4 5 |
# File 'lib/lrama/grammar/rule.rb', line 3 def rhs @rhs end |
Instance Method Details
#as_comment ⇒ Object
Used by #user_actions
13 14 15 16 17 18 |
# File 'lib/lrama/grammar/rule.rb', line 13 def as_comment l = lhs.id.s_value r = rhs.empty? ? "%empty" : rhs.map(&:display_name).join(" ") "#{l}: #{r}" end |
#empty_rule? ⇒ Boolean
opt_nl: ε <– empty_rule
| '\n' <-- not empty_rule
22 23 24 |
# File 'lib/lrama/grammar/rule.rb', line 22 def empty_rule? rhs.empty? end |
#initial_rule? ⇒ Boolean
30 31 32 |
# File 'lib/lrama/grammar/rule.rb', line 30 def initial_rule? id == 0 end |
#precedence ⇒ Object
26 27 28 |
# File 'lib/lrama/grammar/rule.rb', line 26 def precedence precedence_sym&.precedence end |
#to_s ⇒ Object
TODO: Change this to display_name
5 6 7 8 9 10 |
# File 'lib/lrama/grammar/rule.rb', line 5 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
34 35 36 |
# File 'lib/lrama/grammar/rule.rb', line 34 def translated_code code&.translated_code end |