diff --git a/spec/lrama/integration_spec.rb b/spec/lrama/integration_spec.rb index 162fa609..51315157 100644 --- a/spec/lrama/integration_spec.rb +++ b/spec/lrama/integration_spec.rb @@ -151,4 +151,47 @@ def test_rules(rules, input, expected, command_args: [], debug: false) Rules end end + + # TODO: Add test case for "(1+2" + describe "error_recovery" do + it "returns 6 for '(1+)'" do + # (1+) #=> 101 + # '100' is complemented + input = [ + %w['('], + %w[NUM val 1], + %w['+'], + %w[')'], + ] + + test_rules(<<~Rules, input, "=> 101", command_args: %W[-e]) + %union { + int val; + } + %token NUM + %type expr + %left '+' '-' + %left '*' '/' + + %error-token { + $$ = 100; + } NUM + + %% + + program : { (void)yynerrs; } + | expr { printf("=> %d", $1); } + ; + expr : NUM + | expr '+' expr { $$ = $1 + $3; } + | expr '-' expr { $$ = $1 - $3; } + | expr '*' expr { $$ = $1 * $3; } + | expr '/' expr { $$ = $1 / $3; } + | '(' expr ')' { $$ = $2; } + ; + + %% + Rules + end + end end