forked from lix-project/lix
remove ParserFormals
this is a proper subset of Formals anyway, so let's just use those and avoid the extra allocations and moves.
This commit is contained in:
parent
268c49264a
commit
f07388bf98
|
@ -63,11 +63,6 @@ namespace nix {
|
||||||
std::optional<ErrorInfo> error;
|
std::optional<ErrorInfo> error;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ParserFormals {
|
|
||||||
std::vector<Formal> formals;
|
|
||||||
bool ellipsis = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// using C a struct allows us to avoid having to define the special
|
// using C a struct allows us to avoid having to define the special
|
||||||
|
@ -179,7 +174,7 @@ static void addAttr(ExprAttrs * attrs, AttrPath && attrPath,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Formals * toFormals(ParseData & data, ParserFormals * formals,
|
static Formals * validateFormals(ParseData & data, Formals * formals,
|
||||||
PosIdx pos = noPos, Symbol arg = {})
|
PosIdx pos = noPos, Symbol arg = {})
|
||||||
{
|
{
|
||||||
std::sort(formals->formals.begin(), formals->formals.end(),
|
std::sort(formals->formals.begin(), formals->formals.end(),
|
||||||
|
@ -200,18 +195,13 @@ static Formals * toFormals(ParseData & data, ParserFormals * formals,
|
||||||
.errPos = data.state.positions[duplicate->second]
|
.errPos = data.state.positions[duplicate->second]
|
||||||
});
|
});
|
||||||
|
|
||||||
Formals result;
|
if (arg && formals->has(arg))
|
||||||
result.ellipsis = formals->ellipsis;
|
|
||||||
result.formals = std::move(formals->formals);
|
|
||||||
|
|
||||||
if (arg && result.has(arg))
|
|
||||||
throw ParseError({
|
throw ParseError({
|
||||||
.msg = hintfmt("duplicate formal function argument '%1%'", data.symbols[arg]),
|
.msg = hintfmt("duplicate formal function argument '%1%'", data.symbols[arg]),
|
||||||
.errPos = data.state.positions[pos]
|
.errPos = data.state.positions[pos]
|
||||||
});
|
});
|
||||||
|
|
||||||
delete formals;
|
return formals;
|
||||||
return new Formals(std::move(result));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -339,7 +329,7 @@ void yyerror(YYLTYPE * loc, yyscan_t scanner, ParseData * data, const char * err
|
||||||
nix::Expr * e;
|
nix::Expr * e;
|
||||||
nix::ExprList * list;
|
nix::ExprList * list;
|
||||||
nix::ExprAttrs * attrs;
|
nix::ExprAttrs * attrs;
|
||||||
nix::ParserFormals * formals;
|
nix::Formals * formals;
|
||||||
nix::Formal * formal;
|
nix::Formal * formal;
|
||||||
nix::NixInt n;
|
nix::NixInt n;
|
||||||
nix::NixFloat nf;
|
nix::NixFloat nf;
|
||||||
|
@ -397,16 +387,16 @@ expr_function
|
||||||
: ID ':' expr_function
|
: ID ':' expr_function
|
||||||
{ $$ = new ExprLambda(CUR_POS, data->symbols.create($1), 0, $3); }
|
{ $$ = new ExprLambda(CUR_POS, data->symbols.create($1), 0, $3); }
|
||||||
| '{' formals '}' ':' expr_function
|
| '{' formals '}' ':' expr_function
|
||||||
{ $$ = new ExprLambda(CUR_POS, toFormals(*data, $2), $5); }
|
{ $$ = new ExprLambda(CUR_POS, validateFormals(*data, $2), $5); }
|
||||||
| '{' formals '}' '@' ID ':' expr_function
|
| '{' formals '}' '@' ID ':' expr_function
|
||||||
{
|
{
|
||||||
auto arg = data->symbols.create($5);
|
auto arg = data->symbols.create($5);
|
||||||
$$ = new ExprLambda(CUR_POS, arg, toFormals(*data, $2, CUR_POS, arg), $7);
|
$$ = new ExprLambda(CUR_POS, arg, validateFormals(*data, $2, CUR_POS, arg), $7);
|
||||||
}
|
}
|
||||||
| ID '@' '{' formals '}' ':' expr_function
|
| ID '@' '{' formals '}' ':' expr_function
|
||||||
{
|
{
|
||||||
auto arg = data->symbols.create($1);
|
auto arg = data->symbols.create($1);
|
||||||
$$ = new ExprLambda(CUR_POS, arg, toFormals(*data, $4, CUR_POS, arg), $7);
|
$$ = new ExprLambda(CUR_POS, arg, validateFormals(*data, $4, CUR_POS, arg), $7);
|
||||||
}
|
}
|
||||||
| ASSERT expr ';' expr_function
|
| ASSERT expr ';' expr_function
|
||||||
{ $$ = new ExprAssert(CUR_POS, $2, $4); }
|
{ $$ = new ExprAssert(CUR_POS, $2, $4); }
|
||||||
|
@ -650,11 +640,11 @@ formals
|
||||||
: formal ',' formals
|
: formal ',' formals
|
||||||
{ $$ = $3; $$->formals.emplace_back(*$1); delete $1; }
|
{ $$ = $3; $$->formals.emplace_back(*$1); delete $1; }
|
||||||
| formal
|
| formal
|
||||||
{ $$ = new ParserFormals; $$->formals.emplace_back(*$1); $$->ellipsis = false; delete $1; }
|
{ $$ = new Formals; $$->formals.emplace_back(*$1); $$->ellipsis = false; delete $1; }
|
||||||
|
|
|
|
||||||
{ $$ = new ParserFormals; $$->ellipsis = false; }
|
{ $$ = new Formals; $$->ellipsis = false; }
|
||||||
| ELLIPSIS
|
| ELLIPSIS
|
||||||
{ $$ = new ParserFormals; $$->ellipsis = true; }
|
{ $$ = new Formals; $$->ellipsis = true; }
|
||||||
;
|
;
|
||||||
|
|
||||||
formal
|
formal
|
||||||
|
|
Loading…
Reference in a new issue