From 389dd0121475bdba7dea54f4cb02287fa48718da Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Sat, 16 Apr 2022 00:49:58 +0900 Subject: Prohibit specifying associativity and precedence multiple times for a symbol --- grammar/grammar_test.go | 100 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) (limited to 'grammar/grammar_test.go') diff --git a/grammar/grammar_test.go b/grammar/grammar_test.go index 40c07aa..a90ee8b 100644 --- a/grammar/grammar_test.go +++ b/grammar/grammar_test.go @@ -442,6 +442,56 @@ foo `, errs: []*SemanticError{semErrMDInvalidParam}, }, + { + caption: "the `%left` cannot be specified multiple times for a symbol", + specSrc: ` +%name test + +%left foo foo + +s + : foo + ; + +foo + : 'foo'; +`, + errs: []*SemanticError{semErrDuplicateAssoc}, + }, + { + caption: "a symbol cannot have different precedence", + specSrc: ` +%name test + +%left foo +%left foo + +s + : foo + ; + +foo + : 'foo'; +`, + errs: []*SemanticError{semErrDuplicateAssoc}, + }, + { + caption: "a symbol cannot have different associativity", + specSrc: ` +%name test + +%right foo +%left foo + +s + : foo + ; + +foo + : 'foo'; +`, + errs: []*SemanticError{semErrDuplicateAssoc}, + }, } rightTests := []*specErrTest{ @@ -525,6 +575,56 @@ foo `, errs: []*SemanticError{semErrMDInvalidParam}, }, + { + caption: "the `%right` cannot be specified multiple times for a symbol", + specSrc: ` +%name test + +%right foo foo + +s + : foo + ; + +foo + : 'foo'; +`, + errs: []*SemanticError{semErrDuplicateAssoc}, + }, + { + caption: "a symbol cannot have different precedence", + specSrc: ` +%name test + +%right foo +%right foo + +s + : foo + ; + +foo + : 'foo'; +`, + errs: []*SemanticError{semErrDuplicateAssoc}, + }, + { + caption: "a symbol cannot have different associativity", + specSrc: ` +%name test + +%left foo +%right foo + +s + : foo + ; + +foo + : 'foo'; +`, + errs: []*SemanticError{semErrDuplicateAssoc}, + }, } errorSymTests := []*specErrTest{ -- cgit v1.2.3