File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
lrpar/cttests/src/ctfails Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ name: Test calculator with malformed input from %grmtools{test_files}
2+ grammar: |
3+ %grmtools {
4+ yacckind: Original(YaccOriginalActionKind::UserAction),
5+ recoverer: RecoveryKind::None,
6+ test_files: "*.bad_input"
7+ }
8+ %start Expr
9+ %actiontype Result<u64, ()>
10+ %avoid_insert 'INT'
11+ %%
12+ Expr: Expr '+' Term { Ok($1? + $3?) }
13+ | Term { $1 }
14+ ;
15+
16+ Term: Term '*' Factor { Ok($1? * $3?) }
17+ | Factor { $1 }
18+ ;
19+
20+ Factor: '(' Expr ')' { $2 }
21+ | 'INT' {
22+ let l = $1.map_err(|_| ())?;
23+ match $lexer.span_str(l.span()).parse::<u64>() {
24+ Ok(v) => Ok(v),
25+ Err(_) => {
26+ let ((_, col), _) = $lexer.line_col(l.span());
27+ eprintln!("Error at column {}: '{}' cannot be represented as a u64",
28+ col,
29+ $lexer.span_str(l.span()));
30+ Err(())
31+ }
32+ }
33+ }
34+ ;
35+
36+ lexer: |
37+ %%
38+ [0-9]+ "INT"
39+ \+ "+"
40+ \* "*"
41+ \( "("
42+ \) ")"
43+ [\t\n ]+ ;
44+ extra_files:
45+ input1.bad_input: |
46+ (1 + 2 * 3
47+
You can’t perform that action at this time.
0 commit comments