diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2021-08-26 23:16:09 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2021-08-26 23:18:49 +0900 |
commit | 7271e46bbcb11acf860c91eddfe12dd7eed5ccad (patch) | |
tree | fafbf797ca806ff1e4cc68acaaaa6db66aec632d /driver/parser_test.go | |
parent | Update CHANGELOG (diff) | |
download | urubu-7271e46bbcb11acf860c91eddfe12dd7eed5ccad.tar.gz urubu-7271e46bbcb11acf860c91eddfe12dd7eed5ccad.tar.xz |
Add error symbol and #recover directive to recover from an error state
Diffstat (limited to 'driver/parser_test.go')
-rw-r--r-- | driver/parser_test.go | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/driver/parser_test.go b/driver/parser_test.go index 9467d6c..224f12e 100644 --- a/driver/parser_test.go +++ b/driver/parser_test.go @@ -447,6 +447,94 @@ a: 'a'; `, specErr: true, }, + // The grammar can contain the 'error' symbol. + { + specSrc: ` +s + : id id id ';' + | error ';' + ; + +ws: "[\u{0009}\u{0020}]+" #skip; +id: "[A-Za-z_]+"; +`, + src: `foo bar baz ;`, + }, + // The grammar can contain the 'recover' directive. + { + specSrc: ` +seq + : seq elem + | elem + ; +elem + : id id id ';' + | error ';' #recover + ; + +ws: "[\u{0009}\u{0020}]+" #skip; +id: "[A-Za-z_]+"; +`, + src: `a b c ; d e f ;`, + }, + // The 'recover' directive cannot take a parameter. + { + specSrc: ` +seq + : seq elem + | elem + ; +elem + : id id id ';' + | error ';' #recover foo + ; + +ws: "[\u{0009}\u{0020}]+" #skip; +id: "[A-Za-z_]+"; +`, + src: `a b c ; d e f ;`, + specErr: true, + }, + // You cannot use the error symbol as a non-terminal symbol. + { + specSrc: ` +s + : foo + ; +error + : bar + ; + +foo: 'foo'; +bar: 'bar'; +`, + specErr: true, + }, + // You cannot use the error symbol as a terminal symbol. + { + specSrc: ` +s + : foo + | error + ; + +foo: 'foo'; +error: 'error'; +`, + specErr: true, + }, + // You cannot use the error symbol as a terminal symbol, even if given the skip directive. + { + specSrc: ` +s + : foo + ; + +foo: 'foo'; +error: 'error' #skip; +`, + specErr: true, + }, } classes := []grammar.Class{ @@ -492,6 +580,10 @@ a: 'a'; t.Fatal(err) } + if len(p.SyntaxErrors()) > 0 { + t.Fatalf("unexpected syntax errors occurred: %+v", p.SyntaxErrors()) + } + if tt.cst != nil { testTree(t, p.CST(), tt.cst) } |