Skip to content

Commit

Permalink
Fix an error for using parameterizing rules with own stack in semanti…
Browse files Browse the repository at this point in the history
…c action

```
tool/lrama/lib/lrama/grammar/code/rule_action.rb:58:in 'Integer#+': nil can't be coerced into Integer (TypeError)
```
  • Loading branch information
ydah committed Apr 26, 2024
1 parent 3b1ade0 commit 6e36867
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/lrama/grammar/rule_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def process_rhs(parameterizing_rule_resolver)
@replaced_rhs << lhs_token
parameterizing_rule_resolver.created_lhs_list << lhs_token
parameterizing_rule.rhs_list.each do |r|
rule_builder = RuleBuilder.new(@rule_counter, @midrule_action_counter, lhs_tag: token.lhs_tag, skip_preprocess_references: true)
rule_builder = RuleBuilder.new(@rule_counter, @midrule_action_counter, lhs_tag: token.lhs_tag)
rule_builder.lhs = lhs_token
r.symbols.each { |sym| rule_builder.add_rhs(bindings.resolve_symbol(sym)) }
rule_builder.line = line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ static int yyerror(YYLTYPE *loc, const char *str);
{
$$ = $1 + $2;
printf("(%d, %d)\n", $1, $2);
printf("(%d, %d)\n", $:1, $:2);
}
;

Expand Down
2 changes: 2 additions & 0 deletions spec/lrama/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ def generate_object(grammar_file_path, c_path, obj_path, command_args: [])
it "prints messages corresponding to rules" do
expected = <<~STR
(2, 3)
(-2, -1)
pair even odd: 5
(1, 0)
(-2, -1)
pair odd even: 1
STR
test_parser("user_defined_parameterizing_rules", "2 3 ; 1 0", expected)
Expand Down

0 comments on commit 6e36867

Please sign in to comment.