Skip to content

Commit

Permalink
Add an integration test for error recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
yui-knk committed Aug 6, 2023
1 parent 364bb6b commit 57e119d
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions spec/lrama/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <val> NUM
%type <val> 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

0 comments on commit 57e119d

Please sign in to comment.