aboutsummaryrefslogtreecommitdiff
path: root/grammar/grammar_test.go
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2022-04-16 00:49:58 +0900
committerRyo Nihei <nihei.dev@gmail.com>2022-04-16 00:49:58 +0900
commit389dd0121475bdba7dea54f4cb02287fa48718da (patch)
tree4b2f811a8ce085cef72cdaa54c33d6cc6cb2270f /grammar/grammar_test.go
parentAdd tests for compiler (diff)
downloadurubu-389dd0121475bdba7dea54f4cb02287fa48718da.tar.gz
urubu-389dd0121475bdba7dea54f4cb02287fa48718da.tar.xz
Prohibit specifying associativity and precedence multiple times for a symbol
Diffstat (limited to 'grammar/grammar_test.go')
-rw-r--r--grammar/grammar_test.go100
1 files changed, 100 insertions, 0 deletions
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{