Resolve shift/reduce conflict of 'def' vs '|'
This was an important conflict. In the following expression:
def a: 0; . | a
Bison needs to decide between these two equally valid
parses:
(def a: 0; .) | a
def a: 0; (. | a)
For jq we want the second one, because the first results in
"a/0 is not defined". In the current parser the first parse
is a reduce and the second parse is a shift. Since Bison
prefers to shift in shift/reduce conflicts, we accidentally
got the correct behavior.
This commit adds a precedence level FUNCDEF which is lower
precedence than '|', meaning we explicitly choose the
correct parse.
Of course many unit tests already cover this case, but I
added one specifically for it.
This commit is contained in:
1 parent
1628bbf95f
commit
66ef8e2c24
4 files changed
+825
-834
No files matched your search
@@ -91,8 +91,9 @@ struct lexer_param;
|
||||
%token QQSTRING_END
|
||||
|
||||
/* see Exp '?' rule */
|
||||
%expect 34
|
||||
%expect 9
|
||||
|
||||
%precedence FUNCDEF
|
||||
%right '|'
|
||||
%left ','
|
||||
%right "//"
|
||||
@@ -306,7 +307,7 @@ FuncDef FuncDefs {
|
||||
}
|
||||
|
||||
Exp:
|
||||
FuncDef Exp %prec ';' {
|
||||
FuncDef Exp %prec FUNCDEF {
|
||||
$$ = block_bind_referenced($1, $2, OP_IS_CALL_PSEUDO);
|
||||
} |
|
||||
|
||||
|
||||
Reference in new issue
Block a user