diff options
Diffstat (limited to 'spec/parser_test.go')
-rw-r--r-- | spec/parser_test.go | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/spec/parser_test.go b/spec/parser_test.go index 154aea0..e81f95e 100644 --- a/spec/parser_test.go +++ b/spec/parser_test.go @@ -91,6 +91,19 @@ func TestParse(t *testing.T) { Pattern: p, } } + label := func(name string) *LabelNode { + return &LabelNode{ + Name: name, + } + } + withLabelPos := func(label *LabelNode, pos Position) *LabelNode { + label.Pos = pos + return label + } + withLabel := func(elem *ElementNode, label *LabelNode) *ElementNode { + elem.Label = label + return elem + } withElemPos := func(elem *ElementNode, pos Position) *ElementNode { elem.Pos = pos return elem @@ -536,6 +549,97 @@ fragment number: "[0-9]"; }, }, { + caption: "a symbol can have a label", + src: ` +expr + : term@lhs add term@rhs + ; +`, + ast: &RootNode{ + Productions: []*ProductionNode{ + withProdPos( + prod("expr", + withAltPos( + alt( + withElemPos( + withLabel( + id("term"), + withLabelPos( + label("lhs"), + newPos(3), + ), + ), + newPos(3), + ), + withElemPos( + id("add"), + newPos(3), + ), + withElemPos( + withLabel( + id("term"), + withLabelPos( + label("rhs"), + newPos(3), + ), + ), + newPos(3), + ), + ), + newPos(3), + ), + ), + newPos(2), + ), + }, + }, + }, + { + caption: "a label must be an identifier, not a string", + src: ` +foo + : bar@'baz' + ; +`, + synErr: synErrNoLabel, + }, + { + caption: "a label must be an identifier, not a pattern", + src: ` +foo + : bar@"baz" + ; +`, + synErr: synErrNoLabel, + }, + { + caption: "the symbol marker @ must be followed by an identifier", + src: ` +foo + : bar@ + ; +`, + synErr: synErrNoLabel, + }, + { + caption: "a symbol cannot have more than or equal to two labels", + src: ` +foo + : bar@baz@bra + ; +`, + synErr: synErrLabelWithNoSymbol, + }, + { + caption: "a label must follow a symbol", + src: ` +foo + : @baz + ; +`, + synErr: synErrLabelWithNoSymbol, + }, + { caption: "a grammar can contain left and right associativities", src: ` %left l1 l2 |