1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

Fix #484, try/catch syntax has conflicts

This commit is contained in:
Nicolas Williams
2014-07-14 15:38:58 -05:00
parent ea3e947b50
commit 2bb9fc5dda

View File

@@ -50,7 +50,6 @@ struct lexer_param;
%token <literal> FIELD %token <literal> FIELD
%token <literal> LITERAL %token <literal> LITERAL
%token <literal> FORMAT %token <literal> FORMAT
%token Q "?"
%token REC ".." %token REC ".."
%token SETMOD "%=" %token SETMOD "%="
%token EQ "==" %token EQ "=="
@@ -84,6 +83,9 @@ struct lexer_param;
%token QQSTRING_INTERP_END %token QQSTRING_INTERP_END
%token QQSTRING_END %token QQSTRING_END
/* see Exp '?' rule */
%expect 9
/* revolting hack */ /* revolting hack */
%left ';' %left ';'
%right '|' %right '|'
@@ -95,6 +97,9 @@ struct lexer_param;
%nonassoc NEQ EQ '<' '>' LESSEQ GREATEREQ %nonassoc NEQ EQ '<' '>' LESSEQ GREATEREQ
%left '+' '-' %left '+' '-'
%left '*' '/' '%' %left '*' '/' '%'
%precedence '?'
%precedence "try"
%precedence "catch"
%type <blk> Exp Term MkDict MkDictPair ExpD ElseBody QQString FuncDef FuncDefs String %type <blk> Exp Term MkDict MkDictPair ExpD ElseBody QQString FuncDef FuncDefs String
@@ -269,11 +274,15 @@ Term "as" '$' IDENT '|' Exp {
$$ = $2; $$ = $2;
} | } |
// This rule conflicts with all the other rules using the '?' operator.
// It doesn't matter which bison prefers: all of them result in the same
// syntax and semantics, but the more specific rules optimize better
// because they use opcodes specifically made for the purpose. We
// expect 9 such conflicts.
Exp '?' { Exp '?' {
$$ = gen_try($1, gen_op_simple(BACKTRACK)); $$ = gen_try($1, gen_op_simple(BACKTRACK));
} | } |
Exp '=' Exp { Exp '=' Exp {
$$ = gen_call("_assign", BLOCK(gen_lambda($1), gen_lambda($3))); $$ = gen_call("_assign", BLOCK(gen_lambda($1), gen_lambda($3)));
} | } |