From 1bf9be140c3c834b50a1acd8d1c6cec5bd9dc630 Mon Sep 17 00:00:00 2001 From: yui-knk Date: Mon, 31 Jul 2023 09:47:52 +0900 Subject: [PATCH 1/2] Add test case for named references --- spec/lrama/integration_spec.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/spec/lrama/integration_spec.rb b/spec/lrama/integration_spec.rb index 5c96c550..ed4bdf49 100644 --- a/spec/lrama/integration_spec.rb +++ b/spec/lrama/integration_spec.rb @@ -109,4 +109,36 @@ def test_rules(rules, input, expected) Rules end end + + describe "named references" do + it "returns 3 for '1 2 +" do + # 1 2 + #=> 3 + input = [ + %w[NUM val 1], + %w[NUM val 2], + %w['+'], + ] + + test_rules(<<~Rules, input, "=> 3") + %union { + int val; + } + %token NUM + %type expr + + %% + + line: expr + { printf("=> %d", $expr); } + ; + + expr[result]: NUM + | expr[left] expr[right] '+' + { $result = $left + $right; } + ; + + %% + Rules + end + end end From 573e42a425f7214a806d0b801315ee800bef1793 Mon Sep 17 00:00:00 2001 From: yui-knk Date: Mon, 31 Jul 2023 09:48:12 +0900 Subject: [PATCH 2/2] Remove unused variable --- spec/lrama/integration_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/lrama/integration_spec.rb b/spec/lrama/integration_spec.rb index ed4bdf49..d0234360 100644 --- a/spec/lrama/integration_spec.rb +++ b/spec/lrama/integration_spec.rb @@ -81,7 +81,6 @@ def test_rules(rules, input, expected) %w['*'], %w[NUM val 3] ] - expected = "9" test_rules(<<~Rules, input, "=> 9") %union {