diff --git a/lib/lrama/grammar/parameterizing_rule_resolver.rb b/lib/lrama/grammar/parameterizing_rule_resolver.rb index 5b8a8fda..9d92a412 100644 --- a/lib/lrama/grammar/parameterizing_rule_resolver.rb +++ b/lib/lrama/grammar/parameterizing_rule_resolver.rb @@ -10,15 +10,21 @@ def add_parameterizing_rule_builder(builder) end def defined?(name) - @parameterizing_rule_builders.any? { |builder| builder.name == name } + !rule_builders(name).empty? end def build_rules(token, rule_counter, lhs_tag, line) - builder = @parameterizing_rule_builders.select { |b| b.name == token.s_value }.last + builder = rule_builders(token.s_value).last raise "Unknown parameterizing rule #{token.s_value} at line #{token.line}" unless builder builder.build_rules(token, token.args, rule_counter, lhs_tag, line, @parameterizing_rule_builders) end + + private + + def rule_builders(name) + @parameterizing_rule_builders.select { |builder| builder.name == name } + end end end end diff --git a/sig/lrama/grammar/parameterizing_rule_resolver.rbs b/sig/lrama/grammar/parameterizing_rule_resolver.rbs index 1347f7a6..b24e06ab 100644 --- a/sig/lrama/grammar/parameterizing_rule_resolver.rbs +++ b/sig/lrama/grammar/parameterizing_rule_resolver.rbs @@ -7,6 +7,10 @@ module Lrama def add_parameterizing_rule_builder: (Grammar::ParameterizingRuleBuilder builder) -> void def defined?: (String) -> bool def build_rules: (Lexer::Token::InstantiateRule token, Counter rule_counter, untyped lhs_tag, Integer? line) -> Array[Grammar::ParameterizingRule] + + private + + def rule_builders: (String) -> Array[Grammar::ParameterizingRuleBuilder] end end end