diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2022-04-13 23:09:49 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2022-04-14 00:40:39 +0900 |
commit | 18a3317ac9c79651e5c74a2afc6b14fd9a3f9d4a (patch) | |
tree | 2e935d489805de4ba310a4dfbdfde702a1d5b0e7 /driver/parser_test.go | |
parent | Update CHANGELOG (diff) | |
download | urubu-18a3317ac9c79651e5c74a2afc6b14fd9a3f9d4a.tar.gz urubu-18a3317ac9c79651e5c74a2afc6b14fd9a3f9d4a.tar.xz |
Move compiler tests from driver package to grammar package
Diffstat (limited to 'driver/parser_test.go')
-rw-r--r-- | driver/parser_test.go | 547 |
1 files changed, 2 insertions, 545 deletions
diff --git a/driver/parser_test.go b/driver/parser_test.go index 04c42c5..d6fccc5 100644 --- a/driver/parser_test.go +++ b/driver/parser_test.go @@ -30,7 +30,6 @@ func TestParser_Parse(t *testing.T) { src string cst *Node ast *Node - specErr bool }{ { specSrc: ` @@ -153,118 +152,6 @@ bar_text: "bar"; ), ), }, - // `name` is missing. - { - specSrc: ` -a - : foo - ; -foo: "foo"; -`, - src: `foo`, - specErr: true, - }, - // `name` needs a parameter. - { - specSrc: ` -%name - -a - : foo - ; -foo: "foo"; -`, - src: `foo`, - specErr: true, - }, - // `name` takes just one parameter. - { - specSrc: ` -%name test foo - -a - : foo - ; -foo: "foo"; -`, - src: `foo`, - specErr: true, - }, - // Production `b` is unused. - { - specSrc: ` -%name test - -a - : foo - ; -b - : foo; -foo: "foo"; -`, - src: `foo`, - specErr: true, - }, - // Terminal `bar` is unused. - { - specSrc: ` -%name test - -s - : foo - ; -foo: "foo"; -bar: "bar"; -`, - src: `foo`, - specErr: true, - }, - // Production `b` and terminal `bar` is unused. - { - specSrc: ` -%name test - -a - : foo - ; -b - : bar - ; -foo: "foo"; -bar: "bar"; -`, - src: `foo`, - specErr: true, - }, - // A terminal used in productions cannot have the skip directive. - { - specSrc: ` -%name test - -a - : foo - ; - -foo #skip - : "foo"; -`, - src: `foo`, - specErr: true, - }, - // A production cannot have production directives. - { - specSrc: ` -%name test - -s #prec foo - : foo - ; - -foo: 'foo' #skip; -`, - src: `foo`, - specErr: true, - }, // A production can have multiple alternative productions. { specSrc: ` @@ -348,52 +235,6 @@ pop #mode a b #pop termNode("pop", "<-"), ), }, - // A lexical production cannot have alternative directives. - { - specSrc: ` -%name test - -s - : foo - ; - -foo: 'foo' #skip; -`, - src: `foo`, - specErr: true, - }, - // A production directive must not be duplicated. - { - specSrc: ` -%name test - -s - : foo - ; - -foo #skip #skip - : 'foo'; -`, - src: `foo`, - specErr: true, - }, - // An alternative directive must not be duplicated. - { - specSrc: ` -%name test - -s - : foo bar #ast foo bar #ast foo bar - ; - -foo - : 'foo'; -bar - : 'bar'; -`, - src: `foobar`, - specErr: true, - }, { specSrc: ` %name test @@ -541,221 +382,6 @@ num: "0|[1-9][0-9]*"; ), ), }, - // The expansion cannot be applied to a terminal symbol. - { - specSrc: ` -%name test - -s - : foo #ast foo... - ; -foo: "foo"; -`, - specErr: true, - }, - // The expansion cannot be applied to a pattern. - { - specSrc: ` -%name test - -s - : foo "bar"@b #ast foo b... - ; -foo: "foo"; -`, - specErr: true, - }, - // The expansion cannot be applied to a string. - { - specSrc: ` -%name test - -s - : foo 'bar'@b #ast foo b... - ; -foo: "foo"; -`, - specErr: true, - }, - // A parameter of #ast directive must be either a symbol or a label in an alternative. - { - specSrc: ` -%name test - -s - : foo bar #ast foo x - ; -foo: "foo"; -bar: "bar"; -`, - specErr: true, - }, - // A symbol in a different alternative cannot be a parameter of #ast directive. - { - specSrc: ` -%name test - -s - : foo #ast bar - | bar - ; -foo: "foo"; -bar: "bar"; -`, - specErr: true, - }, - // A label in a different alternative cannot be a parameter of #ast directive. - { - specSrc: ` -%name test - -s - : foo #ast b - | bar@b - ; -foo: "foo"; -bar: "bar"; -`, - specErr: true, - }, - // A production must not have a duplicate alternative. - { - specSrc: ` -%name test - -s - : foo - | foo - ; -foo: "foo"; -`, - specErr: true, - }, - // A production must not have a duplicate alternative. - { - specSrc: ` -%name test - -a - : foo - ; -b - : - | - ; -foo: "foo"; -`, - specErr: true, - }, - // A production must not have a duplicate alternative. - { - specSrc: ` -%name test - -a - : foo - ; -b - : bar - ; -a - : foo - ; -foo: "foo"; -bar: "bar"; -`, - specErr: true, - }, - // A terminal and a non-terminal (start symbol) are duplicates. - { - specSrc: ` -%name test - -a - : foo - ; -foo: "foo"; -a: "a"; -`, - specErr: true, - }, - // A terminal and a non-terminal (not start symbol) are duplicates. - { - specSrc: ` -%name test - -a - : foo - ; -b - : bar - ; -foo: "foo"; -bar: "bar"; -b: "a"; -`, - specErr: true, - }, - // Invalid associativity type - { - specSrc: ` -%name test - -%foo - -s - : a - ; - -a: 'a'; -`, - specErr: true, - }, - // Associativity needs at least one symbol. - { - specSrc: ` -%name test - -%left - -s - : a - ; - -a: 'a'; -`, - specErr: true, - }, - // Associativity cannot take an undefined symbol. - { - specSrc: ` -%name test - -%left b - -s - : a - ; - -a: 'a'; -`, - specErr: true, - }, - // Associativity cannot take a non-terminal symbol. - { - specSrc: ` -%name test - -%left s - -s - : a - ; - -a: 'a'; -`, - specErr: true, - }, // The 'prec' directive can set precedence and associativity of a production. { specSrc: ` @@ -815,53 +441,6 @@ div ), ), }, - // The 'prec' directive needs an ID parameter. - { - specSrc: ` -%name test - -s - : a #prec - ; - -a: 'a'; -`, - specErr: true, - }, - // The 'prec' directive cannot take an unknown symbol. - { - specSrc: ` -%name test - -s - : a #prec foo - ; - -a: 'a'; -`, - specErr: true, - }, - // The 'prec' directive cannot take a non-terminal symbol. - { - specSrc: ` -%name test - -s - : foo #prec bar - | bar - ; -foo - : a - ; -bar - : b - ; - -a: 'a'; -b: 'b'; -`, - specErr: true, - }, // The grammar can contain the 'error' symbol. { specSrc: ` @@ -900,90 +479,6 @@ id `, src: `a b c ; d e f ;`, }, - // The 'recover' directive cannot take a parameter. - { - specSrc: ` -%name test - -seq - : seq elem - | elem - ; -elem - : id id id ';' - | error ';' #recover foo - ; - -ws #skip - : "[\u{0009}\u{0020}]+"; -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: ` -%name test - -s - : foo - ; -error - : bar - ; - -foo: 'foo'; -bar: 'bar'; -`, - specErr: true, - }, - // You cannot use the error symbol as a terminal symbol. - { - specSrc: ` -%name test - -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: ` -%name test - -s - : foo - ; - -foo - : 'foo'; -error #skip - : 'error'; -`, - specErr: true, - }, - // A label must be unique in an alternative. - { - specSrc: ` -%name test - -s - : foo@x bar@x - ; - -foo: 'foo'; -bar: 'bar'; -`, - specErr: true, - }, // The same label can be used between different alternatives. { specSrc: ` @@ -999,37 +494,6 @@ bar: 'bar'; `, src: `foo`, }, - // A label cannot be the same name as terminal symbols. - { - specSrc: ` -%name test - -s - : foo bar@foo - ; - -foo: 'foo'; -bar: 'bar'; -`, - specErr: true, - }, - // A label cannot be the same name as non-terminal symbols. - { - specSrc: ` -%name test - -s - : foo@a - ; -a - : bar - ; - -foo: 'foo'; -bar: 'bar'; -`, - specErr: true, - }, } classes := []grammar.Class{ @@ -1049,15 +513,8 @@ bar: 'bar'; AST: ast, } g, err := b.Build() - if tt.specErr { - if err == nil { - t.Fatal("an expected error didn't occur") - } - return - } else { - if err != nil { - t.Fatal(err) - } + if err != nil { + t.Fatal(err) } cg, err := grammar.Compile(g, grammar.SpecifyClass(class)) |