Class: Lrama::Grammar::RuleBuilder
- Inherits:
-
Object
- Object
- Lrama::Grammar::RuleBuilder
- Defined in:
- lib/lrama/grammar/rule_builder.rb
Instance Attribute Summary collapse
-
#lhs ⇒ Object
Returns the value of attribute lhs.
-
#lhs_tag ⇒ Object
readonly
Returns the value of attribute lhs_tag.
-
#line ⇒ Object
Returns the value of attribute line.
-
#precedence_sym ⇒ Object
Returns the value of attribute precedence_sym.
-
#rhs ⇒ Object
readonly
Returns the value of attribute rhs.
-
#user_code ⇒ Object
Returns the value of attribute user_code.
Instance Method Summary collapse
- #add_rhs(rhs) ⇒ Object
- #complete_input ⇒ Object
- #has_inline_rules? ⇒ Boolean
-
#initialize(rule_counter, midrule_action_counter, parameterizing_rule_resolver, position_in_original_rule_rhs = nil, lhs_tag: nil, skip_preprocess_references: false) ⇒ RuleBuilder
constructor
A new instance of RuleBuilder.
- #resolve_inline_rules ⇒ Object
- #rules ⇒ Object
- #setup_rules ⇒ Object
Constructor Details
#initialize(rule_counter, midrule_action_counter, parameterizing_rule_resolver, position_in_original_rule_rhs = nil, lhs_tag: nil, skip_preprocess_references: false) ⇒ RuleBuilder
Returns a new instance of RuleBuilder.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/lrama/grammar/rule_builder.rb', line 9 def initialize(rule_counter, midrule_action_counter, parameterizing_rule_resolver, position_in_original_rule_rhs = nil, lhs_tag: nil, skip_preprocess_references: false) @rule_counter = rule_counter @midrule_action_counter = midrule_action_counter @parameterizing_rule_resolver = parameterizing_rule_resolver @position_in_original_rule_rhs = position_in_original_rule_rhs @skip_preprocess_references = skip_preprocess_references @lhs = nil @lhs_tag = lhs_tag @rhs = [] @user_code = nil @precedence_sym = nil @line = nil @rules = [] @rule_builders_for_parameterizing_rules = [] @rule_builders_for_derived_rules = [] @parameterizing_rules = [] @midrule_action_rules = [] end |
Instance Attribute Details
#lhs ⇒ Object
Returns the value of attribute lhs.
6 7 8 |
# File 'lib/lrama/grammar/rule_builder.rb', line 6 def lhs @lhs end |
#lhs_tag ⇒ Object (readonly)
Returns the value of attribute lhs_tag.
7 8 9 |
# File 'lib/lrama/grammar/rule_builder.rb', line 7 def lhs_tag @lhs_tag end |
#line ⇒ Object
Returns the value of attribute line.
6 7 8 |
# File 'lib/lrama/grammar/rule_builder.rb', line 6 def line @line end |
#precedence_sym ⇒ Object
Returns the value of attribute precedence_sym.
7 8 9 |
# File 'lib/lrama/grammar/rule_builder.rb', line 7 def precedence_sym @precedence_sym end |
#rhs ⇒ Object (readonly)
Returns the value of attribute rhs.
7 8 9 |
# File 'lib/lrama/grammar/rule_builder.rb', line 7 def rhs @rhs end |
#user_code ⇒ Object
Returns the value of attribute user_code.
7 8 9 |
# File 'lib/lrama/grammar/rule_builder.rb', line 7 def user_code @user_code end |
Instance Method Details
#add_rhs(rhs) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/lrama/grammar/rule_builder.rb', line 29 def add_rhs(rhs) @line ||= rhs.line flush_user_code @rhs << rhs end |
#complete_input ⇒ Object
51 52 53 |
# File 'lib/lrama/grammar/rule_builder.rb', line 51 def complete_input freeze_rhs end |
#has_inline_rules? ⇒ Boolean
65 66 67 |
# File 'lib/lrama/grammar/rule_builder.rb', line 65 def has_inline_rules? rhs.any? { |token| @parameterizing_rule_resolver.find_inline(token) } end |
#resolve_inline_rules ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/lrama/grammar/rule_builder.rb', line 69 def resolve_inline_rules resolved_builders = [] #: Array[RuleBuilder] rhs.each_with_index do |token, i| if (inline_rule = @parameterizing_rule_resolver.find_inline(token)) inline_rule.rhs_list.each do |inline_rhs| rule_builder = RuleBuilder.new(@rule_counter, @midrule_action_counter, @parameterizing_rule_resolver, lhs_tag: lhs_tag) if token.is_a?(Lexer::Token::InstantiateRule) resolve_inline_rhs(rule_builder, inline_rhs, i, Binding.new(inline_rule.parameters, token.args)) else resolve_inline_rhs(rule_builder, inline_rhs, i) end rule_builder.lhs = lhs rule_builder.line = line rule_builder.precedence_sym = precedence_sym rule_builder.user_code = replace_inline_user_code(inline_rhs, i) resolved_builders << rule_builder end break end end resolved_builders end |
#rules ⇒ Object
61 62 63 |
# File 'lib/lrama/grammar/rule_builder.rb', line 61 def rules @parameterizing_rules + @midrule_action_rules + @rules end |
#setup_rules ⇒ Object
55 56 57 58 59 |
# File 'lib/lrama/grammar/rule_builder.rb', line 55 def setup_rules preprocess_references unless @skip_preprocess_references process_rhs build_rules end |