diff options
Diffstat (limited to 'driver')
-rw-r--r-- | driver/conflict_test.go | 24 | ||||
-rw-r--r-- | driver/parser_test.go | 126 | ||||
-rw-r--r-- | driver/semantic_action_test.go | 21 | ||||
-rw-r--r-- | driver/syntax_error_test.go | 36 |
4 files changed, 136 insertions, 71 deletions
diff --git a/driver/conflict_test.go b/driver/conflict_test.go index f507d4f..1f8914f 100644 --- a/driver/conflict_test.go +++ b/driver/conflict_test.go @@ -179,10 +179,14 @@ expr | id ; -whitespaces: "[\u{0009}\u{0020}]+" #skip; -r1: 'r1'; -r2: 'r2'; -id: "[A-Za-z0-9_]+"; +whitespaces #skip + : "[\u{0009}\u{0020}]+"; +r1 + : 'r1'; +r2 + : 'r2'; +id + : "[A-Za-z0-9_]+"; `, src: `a r2 b r1 c r1 d r2 e`, cst: nonTermNode("expr", @@ -226,10 +230,14 @@ expr | id ; -whitespaces: "[\u{0009}\u{0020}]+" #skip; -r1: 'r1'; -r2: 'r2'; -id: "[A-Za-z0-9_]+"; +whitespaces #skip + : "[\u{0009}\u{0020}]+"; +r1 + : 'r1'; +r2 + : 'r2'; +id + : "[A-Za-z0-9_]+"; `, src: `a r2 b r1 c r1 d r2 e`, cst: nonTermNode("expr", diff --git a/driver/parser_test.go b/driver/parser_test.go index 9a3e040..9d89efa 100644 --- a/driver/parser_test.go +++ b/driver/parser_test.go @@ -245,7 +245,38 @@ bar: "bar"; a : foo ; -foo: "foo" #skip; + +foo #skip + : "foo"; +`, + src: `foo`, + specErr: true, + }, + // A lexical production cannot have alternative productions. + { + specSrc: ` +%name test + +s + : foo + ; + +foo: 'foo' #skip; +`, + src: `foo`, + specErr: true, + }, + // A directive must not be duplicated. + { + specSrc: ` +%name test + +s + : foo + ; + +foo #skip #skip + : 'foo'; `, src: `foo`, specErr: true, @@ -265,16 +296,16 @@ mode_tran | pop_m2 ; -push_m1 - : "->" #push m1; -push_m2 #mode m1 - : "-->" #push m2; -pop_m1 #mode m1 - : "<-" #pop; -pop_m2 #mode m2 - : "<--" #pop; -whitespace #mode default m1 m2 - : "\u{0020}+" #skip; +push_m1 #push m1 + : "->"; +push_m2 #mode m1 #push m2 + : "-->"; +pop_m1 #mode m1 #pop + : "<-"; +pop_m2 #mode m2 #pop + : "<--"; +whitespace #mode default m1 m2 #skip + : "\u{0020}+"; `, src: ` -> --> <-- <- `, }, @@ -301,9 +332,13 @@ bar #mode default s : foo bar ; -foo: "foo"; -bar: "bar"; -white_space: "[\u{0009}\u{0020}]+" #skip; + +foo + : "foo"; +bar + : "bar"; +white_space #skip + : "[\u{0009}\u{0020}]+"; `, src: `foo bar`, }, @@ -332,8 +367,11 @@ elems : elems "," id #ast elems... id | id ; -whitespace: "\u{0020}+" #skip; -id: "[A-Za-z]+"; + +whitespace #skip + : "\u{0020}+"; +id + : "[A-Za-z]+"; `, src: `[Byers, Frohike, Langly]`, cst: nonTermNode("list", @@ -390,20 +428,6 @@ num: "0|[1-9][0-9]*"; ), ), }, - // An ast action cannot be applied to a terminal symbol. - { - specSrc: ` -%name test - -s - : foo - ; -foo - : "foo"@f #ast f... - ; -`, - specErr: true, - }, // The expansion cannot be applied to a terminal symbol. { specSrc: ` @@ -636,12 +660,18 @@ expr | int ; -ws: "[\u{0009}\u{0020}]+" #skip; -int: "0|[1-9][0-9]*"; -add: '+'; -sub: '-'; -mul: '*'; -div: '/'; +ws #skip + : "[\u{0009}\u{0020}]+"; +int + : "0|[1-9][0-9]*"; +add + : '+'; +sub + : '-'; +mul + : '*'; +div + : '/'; `, // This source is recognized as the following structure because the production `expr → sub expr` // has the `#prec mul` directive and has the same precedence and associativity of the symbol `mul`. @@ -729,8 +759,10 @@ s | error ';' ; -ws: "[\u{0009}\u{0020}]+" #skip; -id: "[A-Za-z_]+"; +ws #skip + : "[\u{0009}\u{0020}]+"; +id + : "[A-Za-z_]+"; `, src: `foo bar baz ;`, }, @@ -748,8 +780,10 @@ elem | error ';' #recover ; -ws: "[\u{0009}\u{0020}]+" #skip; -id: "[A-Za-z_]+"; +ws #skip + : "[\u{0009}\u{0020}]+"; +id + : "[A-Za-z_]+"; `, src: `a b c ; d e f ;`, }, @@ -767,8 +801,10 @@ elem | error ';' #recover foo ; -ws: "[\u{0009}\u{0020}]+" #skip; -id: "[A-Za-z_]+"; +ws #skip + : "[\u{0009}\u{0020}]+"; +id + : "[A-Za-z_]+"; `, src: `a b c ; d e f ;`, specErr: true, @@ -814,8 +850,10 @@ s : foo ; -foo: 'foo'; -error: 'error' #skip; +foo + : 'foo'; +error #skip + : 'error'; `, specErr: true, }, diff --git a/driver/semantic_action_test.go b/driver/semantic_action_test.go index 791b5f0..f9708b7 100644 --- a/driver/semantic_action_test.go +++ b/driver/semantic_action_test.go @@ -59,10 +59,14 @@ elem : char char char ; -ws: "[\u{0009}\u{0020}]+" #skip; -semicolon: ';'; -star: '*'; -char: "[a-z]"; +ws #skip + : "[\u{0009}\u{0020}]+"; +semicolon + : ';'; +star + : '*'; +char + : "[a-z]"; ` specSrcWithoutErrorProd := ` @@ -76,9 +80,12 @@ elem : char char char ; -ws: "[\u{0009}\u{0020}]+" #skip; -semicolon: ';'; -char: "[a-z]"; +ws #skip + : "[\u{0009}\u{0020}]+"; +semicolon + : ';'; +char + : "[a-z]"; ` tests := []struct { diff --git a/driver/syntax_error_test.go b/driver/syntax_error_test.go index a7f363f..329ccef 100644 --- a/driver/syntax_error_test.go +++ b/driver/syntax_error_test.go @@ -44,10 +44,14 @@ elem : a b c ; -ws: "[\u{0009}\u{0020}]+" #skip; -a: 'a'; -b: 'b'; -c: 'c'; +ws #skip + : "[\u{0009}\u{0020}]+"; +a + : 'a'; +b + : 'b'; +c + : 'c'; `, src: `!; a!; ab!;`, synErrCount: 3, @@ -66,10 +70,14 @@ elem : a b c ; -ws: "[\u{0009}\u{0020}]+" #skip; -a: 'a'; -b: 'b'; -c: 'c'; +ws #skip + : "[\u{0009}\u{0020}]+"; +a + : 'a'; +b + : 'b'; +c + : 'c'; `, // After the parser trasits to the error state reading the first invalid symbol ('!'), // the second and third invalid symbols ('!') are ignored. @@ -90,10 +98,14 @@ elem : a b c ; -ws: "[\u{0009}\u{0020}]+" #skip; -a: 'a'; -b: 'b'; -c: 'c'; +ws #skip + : "[\u{0009}\u{0020}]+"; +a + : 'a'; +b + : 'b'; +c + : 'c'; `, src: `!**; a!**; ab!**; abc!`, synErrCount: 4, |