From ef82b5d8d2098cb11c5fd3b0391e077e6754ac4f Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Sun, 17 Sep 2023 15:47:16 +0800 Subject: [PATCH] nixd/Syntax: actions for lists --- nixd/include/nixd/Syntax/Nodes.inc | 5 ++++- nixd/lib/Syntax/Parser/Parser.y | 21 ++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/nixd/include/nixd/Syntax/Nodes.inc b/nixd/include/nixd/Syntax/Nodes.inc index 28876f114..6aa406827 100644 --- a/nixd/include/nixd/Syntax/Nodes.inc +++ b/nixd/include/nixd/Syntax/Nodes.inc @@ -23,6 +23,10 @@ NODE(With, { Node *Body; }) NODE(Binds, { std::vector Attributes; }) + +NODE(ListBody, { std::vector Elems; }) +NODE(List, { ListBody *Body; }) + NODE(Let, { Node *Binds; Node *Body; @@ -45,7 +49,6 @@ NODE(Path, { std::string S; }) NODE(SPath, { std::string S; }) NODE(URI, { std::string S; }) -NODE(List, { std::vector Elems; }) NODE(Call, { Node *Fn; std::vector Args; diff --git a/nixd/lib/Syntax/Parser/Parser.y b/nixd/lib/Syntax/Parser/Parser.y index c3be2912d..9ee777c78 100644 --- a/nixd/lib/Syntax/Parser/Parser.y +++ b/nixd/lib/Syntax/Parser/Parser.y @@ -35,6 +35,7 @@ nixd::syntax::Attrs *Attrs; nixd::syntax::Attribute *Attribute; nixd::syntax::InheritedAttribute *IA; + nixd::syntax::ListBody *LB; // Tokens nixd::syntax::StringToken STR; @@ -65,6 +66,7 @@ %type uri %type inherited_attribute %type attribute +%type list_body %token ID %token INT %token FLOAT @@ -273,7 +275,18 @@ expr_simple .Recursive = false }, yylloc, *Data); } - | '[' expr_list ']' + | '[' list_body ']' { + $$ = decorateNode(new List { + .Body = $2 + }, yylloc, *Data); + } + +list_body + : list_body expr_select { + $$->Elems.emplace_back($2); + $$->Range = mkRange(yylloc, *Data); + } + | { $$ = decorateNode(new ListBody, yylloc, *Data); } string_parts : string { $$ = $1; } @@ -461,12 +474,6 @@ string_attr : '"' string_parts '"' { $$ = $2; } | string_parts_interp_expr { $$ = $1; } - -expr_list - : expr_list expr_select - | - - formals : formal ',' formals { $$->Formals.emplace_back($1);