Skip to content

Commit

Permalink
Support inline with parameterizing rule
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed Apr 18, 2024
1 parent f21791c commit f002019
Show file tree
Hide file tree
Showing 6 changed files with 455 additions and 327 deletions.
10 changes: 7 additions & 3 deletions lib/lrama/grammar/rule_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ def resolve_inline_rules
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)
resolve_inline_rhs(rule_builder, inline_rhs, i)
if token.is_a?(Lexer::Token::InstantiateRule)
resolve_inline_rhs(rule_builder, inline_rhs, i, Binding.new(inline_rule, 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
Expand Down Expand Up @@ -184,10 +188,10 @@ def lhs_s_value(token, bindings)
"#{token.rule_name}_#{s_values.join('_')}"
end

def resolve_inline_rhs(rule_builder, inline_rhs, index)
def resolve_inline_rhs(rule_builder, inline_rhs, index, bindings = nil)
rhs.each_with_index do |token, i|
if index == i
inline_rhs.symbols.each { |sym| rule_builder.add_rhs(sym) }
inline_rhs.symbols.each { |sym| rule_builder.add_rhs(bindings.nil? ? sym : bindings.resolve_symbol(sym)) }
else
rule_builder.add_rhs(token)
end
Expand Down
Loading

0 comments on commit f002019

Please sign in to comment.