diff --git a/nixd/include/nixd/Syntax/Nodes.inc b/nixd/include/nixd/Syntax/Nodes.inc index 2e1a97f3a..040f3d670 100644 --- a/nixd/include/nixd/Syntax/Nodes.inc +++ b/nixd/include/nixd/Syntax/Nodes.inc @@ -1,13 +1,13 @@ #ifdef NODE NODE(Identifier, { nix::Symbol Symbol; }) NODE(Formal, { - Identifier ID; + Identifier *ID; /// The default argument. Node *Default; }) NODE(Formals, { - std::vector Formals; - bool Elipsis; + std::vector Formals; + bool Ellipsis; }) NODE(Function, { Identifier *Arg; diff --git a/nixd/lib/Syntax/Parser/Parser.y b/nixd/lib/Syntax/Parser/Parser.y index 5c399718f..340d409aa 100644 --- a/nixd/lib/Syntax/Parser/Parser.y +++ b/nixd/lib/Syntax/Parser/Parser.y @@ -22,6 +22,7 @@ nixd::syntax::Identifier *Identifier; nixd::syntax::If *If; nixd::syntax::Formals *Formals; + nixd::syntax::Formal *Formal; nixd::syntax::Binds *Binds; nixd::syntax::AttrPath *AttrPath; nixd::syntax::Call *Call; @@ -50,6 +51,7 @@ %type identifier %type ind_string_parts %type formals +%type formal %type binds %type attrpath %type expr_app @@ -353,6 +355,7 @@ string_parts_interp_expr }, yylloc, *Data); } +// Nixd extension, nix uses the token directly uri : URI { $$ = decorateNode(new nixd::syntax::URI { @@ -406,15 +409,43 @@ expr_list formals - : formal ',' formals - | formal - | - | ELLIPSIS + : formal ',' formals { + $$->Formals.emplace_back($1); + $$->Range = mkRange(yylloc, *Data); + } + | formal { + $$ = decorateNode(new Formals { + .Formals = {$1}, + .Ellipsis = false + }, yylloc, *Data); + } + | { + $$ = decorateNode(new Formals { + .Formals = {}, + .Ellipsis = false + }, yylloc, *Data); + } + | ELLIPSIS { + $$ = decorateNode(new Formals { + .Formals = {}, + .Ellipsis = true + }, yylloc, *Data); + } formal - : identifier - | identifier '?' expr + : identifier { + $$ = decorateNode(new Formal { + .ID = $1, + .Default = nullptr + }, yylloc, *Data); + } + | identifier '?' expr { + $$ = decorateNode(new Formal { + .ID = $1, + .Default = $3 + }, yylloc, *Data); + } %%