Class: Lrama::Grammar::Rule
- Inherits:
-
Struct
- Object
- Struct
- Lrama::Grammar::Rule
- Defined in:
- lib/lrama/grammar/rule.rb
Overview
_rhs holds original RHS element. Use rhs to refer to Symbol.
Instance Attribute Summary collapse
-
#_lhs ⇒ Object
Returns the value of attribute _lhs.
-
#_rhs ⇒ Object
Returns the value of attribute _rhs.
-
#id ⇒ Object
Returns the value of attribute id.
-
#lhs ⇒ Object
Returns the value of attribute lhs.
-
#lhs_tag ⇒ Object
Returns the value of attribute lhs_tag.
-
#lineno ⇒ Object
Returns the value of attribute lineno.
-
#nullable ⇒ Object
Returns the value of attribute nullable.
-
#original_rule ⇒ Object
Returns the value of attribute original_rule.
-
#position_in_original_rule_rhs ⇒ Object
Returns the value of attribute position_in_original_rule_rhs.
-
#precedence_sym ⇒ Object
Returns the value of attribute precedence_sym.
-
#rhs ⇒ Object
Returns the value of attribute rhs.
-
#token_code ⇒ Object
Returns the value of attribute token_code.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#as_comment ⇒ Object
Used by #user_actions.
- #contains_at_reference? ⇒ Boolean
- #display_name ⇒ Object
- #display_name_without_action ⇒ Object
-
#empty_rule? ⇒ Boolean
opt_nl: ε <– empty_rule | ‘n’ <– not empty_rule.
- #initial_rule? ⇒ Boolean
- #precedence ⇒ Object
- #translated_code ⇒ Object
- #with_actions ⇒ Object
Instance Attribute Details
#_lhs ⇒ Object
Returns the value of attribute _lhs
6 7 8 |
# File 'lib/lrama/grammar/rule.rb', line 6 def _lhs @_lhs end |
#_rhs ⇒ Object
Returns the value of attribute _rhs
6 7 8 |
# File 'lib/lrama/grammar/rule.rb', line 6 def _rhs @_rhs end |
#id ⇒ Object
Returns the value of attribute id
6 7 8 |
# File 'lib/lrama/grammar/rule.rb', line 6 def id @id end |
#lhs ⇒ Object
Returns the value of attribute lhs
6 7 8 |
# File 'lib/lrama/grammar/rule.rb', line 6 def lhs @lhs end |
#lhs_tag ⇒ Object
Returns the value of attribute lhs_tag
6 7 8 |
# File 'lib/lrama/grammar/rule.rb', line 6 def lhs_tag @lhs_tag end |
#lineno ⇒ Object
Returns the value of attribute lineno
6 7 8 |
# File 'lib/lrama/grammar/rule.rb', line 6 def lineno @lineno end |
#nullable ⇒ Object
Returns the value of attribute nullable
6 7 8 |
# File 'lib/lrama/grammar/rule.rb', line 6 def nullable @nullable end |
#original_rule ⇒ Object
Returns the value of attribute original_rule.
7 8 9 |
# File 'lib/lrama/grammar/rule.rb', line 7 def original_rule @original_rule end |
#position_in_original_rule_rhs ⇒ Object
Returns the value of attribute position_in_original_rule_rhs
6 7 8 |
# File 'lib/lrama/grammar/rule.rb', line 6 def position_in_original_rule_rhs @position_in_original_rule_rhs end |
#precedence_sym ⇒ Object
Returns the value of attribute precedence_sym
6 7 8 |
# File 'lib/lrama/grammar/rule.rb', line 6 def precedence_sym @precedence_sym end |
#rhs ⇒ Object
Returns the value of attribute rhs
6 7 8 |
# File 'lib/lrama/grammar/rule.rb', line 6 def rhs @rhs end |
#token_code ⇒ Object
Returns the value of attribute token_code
6 7 8 |
# File 'lib/lrama/grammar/rule.rb', line 6 def token_code @token_code end |
Instance Method Details
#==(other) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/lrama/grammar/rule.rb', line 9 def ==(other) self.class == other.class && self.lhs == other.lhs && self.lhs_tag == other.lhs_tag && self.rhs == other.rhs && self.token_code == other.token_code && self.position_in_original_rule_rhs == other.position_in_original_rule_rhs && self.nullable == other.nullable && self.precedence_sym == other.precedence_sym && self.lineno == other.lineno end |
#as_comment ⇒ Object
Used by #user_actions
37 38 39 40 41 42 |
# File 'lib/lrama/grammar/rule.rb', line 37 def as_comment l = lhs.id.s_value r = empty_rule? ? "%empty" : rhs.map(&:display_name).join(" ") "#{l}: #{r}" end |
#contains_at_reference? ⇒ Boolean
68 69 70 71 72 |
# File 'lib/lrama/grammar/rule.rb', line 68 def contains_at_reference? return false unless token_code token_code.references.any? {|r| r.type == :at } end |
#display_name ⇒ Object
21 22 23 24 25 |
# File 'lib/lrama/grammar/rule.rb', line 21 def display_name l = lhs.id.s_value r = empty_rule? ? "ε" : rhs.map {|r| r.id.s_value }.join(" ") "#{l} -> #{r}" end |
#display_name_without_action ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/lrama/grammar/rule.rb', line 27 def display_name_without_action l = lhs.id.s_value r = empty_rule? ? "ε" : rhs.map do |r| r.id.s_value if r.first_set.any? end.compact.join(" ") "#{l} -> #{r}" end |
#empty_rule? ⇒ Boolean
opt_nl: ε <– empty_rule
| '\n' <-- not empty_rule
50 51 52 |
# File 'lib/lrama/grammar/rule.rb', line 50 def empty_rule? rhs.empty? end |
#initial_rule? ⇒ Boolean
58 59 60 |
# File 'lib/lrama/grammar/rule.rb', line 58 def initial_rule? id == 0 end |
#precedence ⇒ Object
54 55 56 |
# File 'lib/lrama/grammar/rule.rb', line 54 def precedence precedence_sym&.precedence end |
#translated_code ⇒ Object
62 63 64 65 66 |
# File 'lib/lrama/grammar/rule.rb', line 62 def translated_code return nil unless token_code Code::RuleAction.new(type: :rule_action, token_code: token_code, rule: self).translated_code end |
#with_actions ⇒ Object
44 45 46 |
# File 'lib/lrama/grammar/rule.rb', line 44 def with_actions "#{display_name} {#{token_code&.s_value}}" end |