forked from lix-project/lix
Merge pull request #5581 from edolstra/parse-calls
Parse '(f x) y' the same as 'f x y'
This commit is contained in:
commit
9e845df339
|
@ -39,12 +39,6 @@ namespace nix {
|
||||||
{ };
|
{ };
|
||||||
};
|
};
|
||||||
|
|
||||||
// Helper to prevent an expensive dynamic_cast call in expr_app.
|
|
||||||
struct App
|
|
||||||
{
|
|
||||||
Expr * e;
|
|
||||||
bool isCall;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define YY_DECL int yylex \
|
#define YY_DECL int yylex \
|
||||||
|
@ -284,12 +278,10 @@ void yyerror(YYLTYPE * loc, yyscan_t scanner, ParseData * data, const char * err
|
||||||
char * uri;
|
char * uri;
|
||||||
std::vector<nix::AttrName> * attrNames;
|
std::vector<nix::AttrName> * attrNames;
|
||||||
std::vector<nix::Expr *> * string_parts;
|
std::vector<nix::Expr *> * string_parts;
|
||||||
nix::App app; // bool == whether this is an ExprCall
|
|
||||||
}
|
}
|
||||||
|
|
||||||
%type <e> start expr expr_function expr_if expr_op
|
%type <e> start expr expr_function expr_if expr_op
|
||||||
%type <e> expr_select expr_simple
|
%type <e> expr_select expr_simple expr_app
|
||||||
%type <app> expr_app
|
|
||||||
%type <list> expr_list
|
%type <list> expr_list
|
||||||
%type <attrs> binds
|
%type <attrs> binds
|
||||||
%type <formals> formals
|
%type <formals> formals
|
||||||
|
@ -377,20 +369,18 @@ expr_op
|
||||||
| expr_op '*' expr_op { $$ = new ExprCall(CUR_POS, new ExprVar(data->symbols.create("__mul")), {$1, $3}); }
|
| expr_op '*' expr_op { $$ = new ExprCall(CUR_POS, new ExprVar(data->symbols.create("__mul")), {$1, $3}); }
|
||||||
| expr_op '/' expr_op { $$ = new ExprCall(CUR_POS, new ExprVar(data->symbols.create("__div")), {$1, $3}); }
|
| expr_op '/' expr_op { $$ = new ExprCall(CUR_POS, new ExprVar(data->symbols.create("__div")), {$1, $3}); }
|
||||||
| expr_op CONCAT expr_op { $$ = new ExprOpConcatLists(CUR_POS, $1, $3); }
|
| expr_op CONCAT expr_op { $$ = new ExprOpConcatLists(CUR_POS, $1, $3); }
|
||||||
| expr_app { $$ = $1.e; }
|
| expr_app
|
||||||
;
|
;
|
||||||
|
|
||||||
expr_app
|
expr_app
|
||||||
: expr_app expr_select {
|
: expr_app expr_select {
|
||||||
if ($1.isCall) {
|
if (auto e2 = dynamic_cast<ExprCall *>($1)) {
|
||||||
((ExprCall *) $1.e)->args.push_back($2);
|
e2->args.push_back($2);
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
} else {
|
} else
|
||||||
$$.e = new ExprCall(CUR_POS, $1.e, {$2});
|
$$ = new ExprCall(CUR_POS, $1, {$2});
|
||||||
$$.isCall = true;
|
|
||||||
}
|
}
|
||||||
}
|
| expr_select
|
||||||
| expr_select { $$.e = $1; $$.isCall = false; }
|
|
||||||
;
|
;
|
||||||
|
|
||||||
expr_select
|
expr_select
|
||||||
|
|
Loading…
Reference in a new issue