From 24fd80555cb35d9fc63cca9e8697bf156f41780b Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Sat, 14 May 2022 15:45:09 +0900 Subject: Prohibit applying #left, #right, #assign, and #prec to an error symbol The shift of the error symbol is an operation forced by the driver. Therefore it is impossible to change this behavior by giving precedence to the error symbol. If we desire to change the precedence of a production rule with the error symbol, we can use #prec directive. --- grammar/grammar_test.go | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'grammar/grammar_test.go') diff --git a/grammar/grammar_test.go b/grammar/grammar_test.go index 5a8bb4a..aeeffac 100644 --- a/grammar/grammar_test.go +++ b/grammar/grammar_test.go @@ -1708,6 +1708,25 @@ s : foo ; +foo + : 'foo'; +`, + errs: []*SemanticError{semErrDirInvalidParam}, + }, + { + caption: "the `#left` directive cannot be applied to an error symbol", + specSrc: ` +#name test; + +#prec ( + #left error +); + +s + : foo ';' + | error ';' + ; + foo : 'foo'; `, @@ -1931,6 +1950,25 @@ s : foo ; +foo + : 'foo'; +`, + errs: []*SemanticError{semErrDirInvalidParam}, + }, + { + caption: "the `#right` directive cannot be applied to an error symbol", + specSrc: ` +#name test; + +#prec ( + #right error +); + +s + : foo ';' + | error ';' + ; + foo : 'foo'; `, @@ -2154,6 +2192,25 @@ s : foo ; +foo + : 'foo'; +`, + errs: []*SemanticError{semErrDirInvalidParam}, + }, + { + caption: "the `#assign` directive cannot be applied to an error symbol", + specSrc: ` +#name test; + +#prec ( + #assign error +); + +s + : foo ';' + | error ';' + ; + foo : 'foo'; `, @@ -2663,6 +2720,20 @@ s : foo #prec ; +foo + : 'foo'; +`, + errs: []*SemanticError{semErrDirInvalidParam}, + }, + { + caption: "the `#prec` directive cannot be applied to an error symbol", + specSrc: ` +#name test; + +s + : foo #prec error + ; + foo : 'foo'; `, -- cgit v1.2.3