From dd5fd3372cdb53e7a3a36b5ef61b0b0c35023798 Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Mon, 9 May 2022 00:36:06 +0900 Subject: Add ordered symbol notation --- spec/parser_test.go | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) (limited to 'spec/parser_test.go') diff --git a/spec/parser_test.go b/spec/parser_test.go index 3fe950f..15f1330 100644 --- a/spec/parser_test.go +++ b/spec/parser_test.go @@ -14,14 +14,12 @@ func TestParse(t *testing.T) { Parameters: []*ParameterNode{param}, } } - prec := func(param *ParameterNode) *DirectiveNode { return &DirectiveNode{ Name: "prec", Parameters: []*ParameterNode{param}, } } - leftAssoc := func(params ...*ParameterNode) *DirectiveNode { return &DirectiveNode{ Name: "left", @@ -82,6 +80,11 @@ func TestParse(t *testing.T) { ID: id, } } + ordSymParam := func(id string) *ParameterNode { + return &ParameterNode{ + OrderedSymbol: id, + } + } exp := func(param *ParameterNode) *ParameterNode { param.Expansion = true return param @@ -152,9 +155,9 @@ func TestParse(t *testing.T) { #name test; #prec ( - #left a b - #right c d - #assign e f + #left a b $x1 + #right c d $x2 + #assign e f $x3 ); `, ast: &RootNode{ @@ -182,6 +185,10 @@ func TestParse(t *testing.T) { idParam("b"), newPos(5), ), + withParamPos( + ordSymParam("x1"), + newPos(5), + ), ), newPos(5), ), @@ -195,6 +202,10 @@ func TestParse(t *testing.T) { idParam("d"), newPos(6), ), + withParamPos( + ordSymParam("x2"), + newPos(6), + ), ), newPos(6), ), @@ -208,6 +219,10 @@ func TestParse(t *testing.T) { idParam("f"), newPos(7), ), + withParamPos( + ordSymParam("x3"), + newPos(7), + ), ), newPos(7), ), @@ -236,6 +251,15 @@ func TestParse(t *testing.T) { `, synErr: synErrUnclosedDirGroup, }, + { + caption: "an ordered symbol marker '$' must be followed by and ID", + src: ` +#prec ( + #assign $ +); +`, + synErr: synErrNoOrderedSymbolName, + }, { caption: "single production is a valid grammar", src: `a: "a";`, @@ -298,6 +322,13 @@ c: ; }, }, }, + { + caption: "a production cannot contain an ordered symbol", + src: ` +a: $x; +`, + synErr: synErrNoSemicolon, + }, { caption: "`fragment` is a reserved word", src: `fragment: 'fragment';`, -- cgit v1.2.3