Skip to content

Commit

Permalink
Fix an error for `Lrama::Grammar::ParameterizingRule::Rhs#resolve_use…
Browse files Browse the repository at this point in the history
…r_code` when multiple execute method

```
  1) integration user defined parameterizing rules prints messages corresponding to rules
     Failure/Error: expect(out).to eq(expected)

       expected: "(2, 3)\n(2, 3)\n(-2, -1)\npair even odd: 5\n(1, 0)\n(1, 0)\n(-2, -1)\npair odd even: 1\n"
            got: "(2, 3)\n(3, 3)\n(-2, -1)\npair even odd: 5\n(1, 0)\n(0, 0)\n(-2, -1)\npair odd even: 1\n"

       (compared using ==)

       Diff:

       @@ -1,9 +1,9 @@
        (2, 3)
       -(2, 3)
       +(3, 3)
        (-2, -1)
        pair even odd: 5
        (1, 0)
       -(1, 0)
       +(0, 0)
        (-2, -1)
        pair odd even: 1

     # ./spec/lrama/integration_spec.rb:46:in `test_parser'
     # ./spec/lrama/integration_spec.rb:109:in `block (3 levels) in <top (required)>'
```
  • Loading branch information
ydah committed May 2, 2024
1 parent f8c0232 commit 3c501fb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/lrama/grammar/parameterizing_rule/rhs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def initialize
def resolve_user_code(bindings)
return unless user_code

resolved = Lexer::Token::UserCode.new(s_value: user_code.s_value, location: user_code.location)
var_to_arg = {}
symbols.each do |sym|
resolved_sym = bindings.resolve_symbol(sym)
Expand All @@ -22,14 +23,14 @@ def resolve_user_code(bindings)
end

var_to_arg.each do |var, arg|
user_code.references.each do |ref|
resolved.references.each do |ref|
if ref.name == var
ref.name = arg
end
end
end

return user_code
return resolved
end
end
end
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", $X, $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 @@ -97,10 +97,12 @@ def generate_object(grammar_file_path, c_path, obj_path, command_args: [])
describe "user defined parameterizing rules" do
it "prints messages corresponding to rules" do
expected = <<~STR
(2, 3)
(2, 3)
(-2, -1)
pair even odd: 5
(1, 0)
(1, 0)
(-2, -1)
pair odd even: 1
STR
Expand Down

0 comments on commit 3c501fb

Please sign in to comment.