Fix an error for Lrama::Grammar::ParameterizingRule::Rhs#resolve_user_code when multiple execute method - #411
Conversation
ydah
commented
May 2, 2024
|
|
| def resolve_user_code(bindings) | ||
| return unless user_code | ||
|
|
||
| resolved = Lexer::Token::UserCode.new(s_value: user_code.s_value, location: user_code.location) |
There was a problem hiding this comment.
[note] The same parameterizing rule can be instantiated multiple times. For example in "spec/fixtures/integration/user_defined_parameterizing_rules.y", pair is instantiated two times. Before this change, original user_code reference name is overwritten by the first instantiation and it's not overwritten by the second instantiation. Therefore we need to dup the user code.
|
Is it inevitable to depend on #410? It seems that we can reproduce the issue by these diff without diff --git a/spec/fixtures/integration/user_defined_parameterizing_rules.y b/spec/fixtures/integration/user_defined_parameterizing_rules.y
index 9dda3b2..308c7e3 100644
--- a/spec/fixtures/integration/user_defined_parameterizing_rules.y
+++ b/spec/fixtures/integration/user_defined_parameterizing_rules.y
@@ -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);
}
;
diff --git a/spec/lrama/integration_spec.rb b/spec/lrama/integration_spec.rb
index fd87547..99af41f 100644
--- a/spec/lrama/integration_spec.rb
+++ b/spec/lrama/integration_spec.rb
@@ -97,10 +97,12 @@ RSpec.describe "integration" do
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 |
1efa425 to
abda2ab
Compare
Ah, indeed it is. sorry. I updated this PR. |
abda2ab to
5ed44f7
Compare
…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)>'
```
5ed44f7 to
3c501fb
Compare
|
Thank you! |