diff --git a/lib/lrama/grammar/parameterizing_rule_resolver.rb b/lib/lrama/grammar/parameterizing_rule_resolver.rb index 3392768b..f44ae0f6 100644 --- a/lib/lrama/grammar/parameterizing_rule_resolver.rb +++ b/lib/lrama/grammar/parameterizing_rule_resolver.rb @@ -19,12 +19,13 @@ def defined?(name) end def build_rules(token, rule_counter, lhs_tag, user_code, precedence_sym, line) - @parameterizing_rule_builders.each do |builder| - build_token = builder.build_token(token) - @rules = @rules + builder.build_rules(token, build_token, rule_counter, lhs_tag, user_code, precedence_sym, line) - @tokens << build_token - @term = builder.term - end + builder = @parameterizing_rule_builders.select { |b| b.name == token.s_value }.last + raise "Unknown parameterizing rule #{token.s_value} at line #{token.line}" unless builder + + build_token = builder.build_token(token) + @rules = @rules + builder.build_rules(token, build_token, rule_counter, lhs_tag, user_code, precedence_sym, line) + @tokens << build_token + @term = builder.term end end end diff --git a/spec/fixtures/parameterizing_rules/user_defined.y b/spec/fixtures/parameterizing_rules/user_defined.y index ae67a97a..b370f279 100644 --- a/spec/fixtures/parameterizing_rules/user_defined.y +++ b/spec/fixtures/parameterizing_rules/user_defined.y @@ -16,6 +16,10 @@ static int yyerror(YYLTYPE *loc, const char *str); | X ; +%rule unused_define(X): /* empty */ + | X + ; + %% program : defined_option(number) diff --git a/spec/lrama/parser_spec.rb b/spec/lrama/parser_spec.rb index ffffde8e..22e47df9 100644 --- a/spec/lrama/parser_spec.rb +++ b/spec/lrama/parser_spec.rb @@ -1238,7 +1238,7 @@ token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("YYEOF"), - lineno: 21, + lineno: 25, ), Rule.new( id: 1, @@ -1249,7 +1249,7 @@ token_code: nil, nullable: true, precedence_sym: nil, - lineno: 21, + lineno: 25, ), Rule.new( id: 2, @@ -1259,7 +1259,7 @@ token_code: nil, nullable: true, precedence_sym: nil, - lineno: 21, + lineno: 25, ), Rule.new( id: 3, @@ -1271,7 +1271,7 @@ token_code: nil, nullable: false, precedence_sym: grammar.find_symbol_by_s_value!("number"), - lineno: 21, + lineno: 25, ), ]) end