diff options
Diffstat (limited to 'driver')
-rw-r--r-- | driver/conflict_test.go | 42 | ||||
-rw-r--r-- | driver/lac_test.go | 2 | ||||
-rw-r--r-- | driver/parser_test.go | 66 | ||||
-rw-r--r-- | driver/semantic_action_test.go | 4 | ||||
-rw-r--r-- | driver/syntax_error_test.go | 8 |
5 files changed, 70 insertions, 52 deletions
diff --git a/driver/conflict_test.go b/driver/conflict_test.go index 7672c00..042d932 100644 --- a/driver/conflict_test.go +++ b/driver/conflict_test.go @@ -18,7 +18,7 @@ func TestParserWithConflicts(t *testing.T) { { caption: "when a shift/reduce conflict occurred, we prioritize the shift action", specSrc: ` -%name test +#name test; expr : expr assign expr @@ -48,7 +48,7 @@ assign: '='; { caption: "when a reduce/reduce conflict occurred, we prioritize the production defined earlier in the grammar", specSrc: ` -%name test +#name test; s : a @@ -73,10 +73,12 @@ id: "[A-Za-z0-9_]+"; { caption: "left associativities defined earlier in the grammar have higher precedence", specSrc: ` -%name test +#name test; -%left mul -%left add +#prec ( + #left mul + #left add +); expr : expr add expr @@ -120,9 +122,11 @@ mul: '*'; { caption: "left associativities defined in the same line have the same precedence", specSrc: ` -%name test +#name test; -%left add sub +#prec ( + #left add sub +); expr : expr add expr @@ -166,10 +170,12 @@ sub: '-'; { caption: "right associativities defined earlier in the grammar have higher precedence", specSrc: ` -%name test +#name test; -%right r1 -%right r2 +#prec ( + #right r1 + #right r2 +); expr : expr r2 expr @@ -218,9 +224,11 @@ id { caption: "right associativities defined in the same line have the same precedence", specSrc: ` -%name test +#name test; -%right r1 r2 +#prec ( + #right r1 r2 +); expr : expr r2 expr @@ -269,11 +277,13 @@ id { caption: "left and right associativities can be mixed", specSrc: ` -%name test +#name test; -%left mul div -%left add sub -%right assign +#prec ( + #left mul div + #left add sub + #right assign +); expr : expr add expr diff --git a/driver/lac_test.go b/driver/lac_test.go index c127c0b..54001d5 100644 --- a/driver/lac_test.go +++ b/driver/lac_test.go @@ -10,7 +10,7 @@ import ( func TestParserWithLAC(t *testing.T) { specSrc := ` -%name test +#name test; S : C C diff --git a/driver/parser_test.go b/driver/parser_test.go index c717205..c37d268 100644 --- a/driver/parser_test.go +++ b/driver/parser_test.go @@ -43,7 +43,7 @@ func TestParser_Parse(t *testing.T) { }{ { specSrc: ` -%name test +#name test; expr : expr "\+" term @@ -117,7 +117,7 @@ id: "[A-Za-z_][0-9A-Za-z_]*"; // The driver can reduce productions that have the empty alternative and can generate a CST (and AST) node. { specSrc: ` -%name test +#name test; s : foo bar @@ -140,7 +140,7 @@ bar_text: "bar"; // The driver can reduce productions that have the empty alternative and can generate a CST (and AST) node. { specSrc: ` -%name test +#name test; s : foo bar @@ -165,10 +165,12 @@ bar_text: "bar"; // A production can have multiple alternative productions. { specSrc: ` -%name test +#name test; -%left mul div -%left add sub +#prec ( + #left mul div + #left add sub +); expr : expr add expr @@ -224,7 +226,7 @@ div // A lexical production can have multiple production directives. { specSrc: ` -%name test +#name test; s : push_a push_b pop pop @@ -247,7 +249,7 @@ pop #mode a b #pop }, { specSrc: ` -%name test +#name test; mode_tran_seq : mode_tran_seq mode_tran @@ -275,7 +277,7 @@ whitespace #mode default m1 m2 #skip }, { specSrc: ` -%name test +#name test; s : foo bar @@ -291,7 +293,7 @@ bar #mode default // When #push and #pop are applied to the same symbol, #pop will run first, then #push. { specSrc: ` -%name test +#name test; s : foo bar baz @@ -316,7 +318,7 @@ baz #mode m2 // they are executed. { specSrc: ` -%name test +#name test; s : foo bar baz @@ -339,7 +341,7 @@ baz #mode m2 // The parser can skips specified tokens. { specSrc: ` -%name test +#name test; s : foo bar @@ -357,7 +359,7 @@ white_space #skip // A grammar can contain fragments. { specSrc: ` -%name test +#name test; s : tagline @@ -370,7 +372,7 @@ fragment words: "[A-Za-z\u{0020}]+"; // A grammar can contain ast actions. { specSrc: ` -%name test +#name test; list : "\[" elems "]" #ast elems... @@ -410,7 +412,7 @@ id // The '...' operator can expand child nodes. { specSrc: ` -%name test +#name test; s : a #ast a... @@ -433,7 +435,7 @@ foo // The '...' operator also can applied to an element having no children. { specSrc: ` -%name test +#name test; s : a ';' #ast a... @@ -449,9 +451,11 @@ a // A label can be a parameter of #ast directive. { specSrc: ` -%name test +#name test; -%left add sub +#prec ( + #left add sub +); expr : expr@lhs add expr@rhs #ast add lhs rhs @@ -482,7 +486,7 @@ num: "0|[1-9][0-9]*"; // An AST can contain a symbol name, even if the symbol has a label. That is, unused labels are allowed. { specSrc: ` -%name test +#name test; s : foo@x ';' #ast foo @@ -499,9 +503,11 @@ foo // A production has the same precedence and associativity as the right-most terminal symbol. { specSrc: ` -%name test +#name test; -%left add +#prec ( + #left add +); expr : expr add expr // This alternative has the same precedence and associativiry as 'add'. @@ -544,10 +550,12 @@ add // The 'prec' directive can set precedence of a production. { specSrc: ` -%name test +#name test; -%left mul div -%left add sub +#prec ( + #left mul div + #left add sub +); expr : expr add expr @@ -603,7 +611,7 @@ div // The grammar can contain the 'error' symbol. { specSrc: ` -%name test +#name test; s : id id id ';' @@ -620,7 +628,7 @@ id // The 'error' symbol can appear in an #ast directive. { specSrc: ` -%name test +#name test; s : foo ';' @@ -639,7 +647,7 @@ foo // The 'error' symbol can have a label, and an #ast can reference it. { specSrc: ` -%name test +#name test; s : foo ';' @@ -658,7 +666,7 @@ foo // The grammar can contain the 'recover' directive. { specSrc: ` -%name test +#name test; seq : seq elem @@ -679,7 +687,7 @@ id // The same label can be used between different alternatives. { specSrc: ` -%name test +#name test; s : foo@x bar diff --git a/driver/semantic_action_test.go b/driver/semantic_action_test.go index f9708b7..ad58780 100644 --- a/driver/semantic_action_test.go +++ b/driver/semantic_action_test.go @@ -47,7 +47,7 @@ func (a *testSemAct) MissError(cause VToken) { func TestParserWithSemanticAction(t *testing.T) { specSrcWithErrorProd := ` -%name test +#name test; seq : seq elem semicolon @@ -70,7 +70,7 @@ char ` specSrcWithoutErrorProd := ` -%name test +#name test; seq : seq elem semicolon diff --git a/driver/syntax_error_test.go b/driver/syntax_error_test.go index 329ccef..93cf637 100644 --- a/driver/syntax_error_test.go +++ b/driver/syntax_error_test.go @@ -19,7 +19,7 @@ func TestParserWithSyntaxErrors(t *testing.T) { { caption: "the parser can report a syntax error", specSrc: ` -%name test +#name test; s : foo @@ -33,7 +33,7 @@ foo: 'foo'; { caption: "when the parser reduced a production having the reduce directive, the parser will recover from an error state", specSrc: ` -%name test +#name test; seq : seq elem ';' @@ -59,7 +59,7 @@ c { caption: "After the parser shifts the error symbol, symbols are ignored until a symbol the parser can perform shift appears", specSrc: ` -%name test +#name test; seq : seq elem ';' @@ -87,7 +87,7 @@ c { caption: "when the parser performs shift three times, the parser recovers from the error state", specSrc: ` -%name test +#name test; seq : seq elem ';' |