Skip to content

Commit

Permalink
nixd/Syntax: actions for lists
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc committed Sep 17, 2023
1 parent 3584f0c commit ef82b5d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
5 changes: 4 additions & 1 deletion nixd/include/nixd/Syntax/Nodes.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ NODE(With, {
Node *Body;
})
NODE(Binds, { std::vector<Node *> Attributes; })

NODE(ListBody, { std::vector<Node *> Elems; })
NODE(List, { ListBody *Body; })

NODE(Let, {
Node *Binds;
Node *Body;
Expand All @@ -45,7 +49,6 @@ NODE(Path, { std::string S; })
NODE(SPath, { std::string S; })
NODE(URI, { std::string S; })

NODE(List, { std::vector<Node *> Elems; })
NODE(Call, {
Node *Fn;
std::vector<Node *> Args;
Expand Down
21 changes: 14 additions & 7 deletions nixd/lib/Syntax/Parser/Parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,6 +66,7 @@
%type <Uri> uri
%type <IA> inherited_attribute
%type <Attribute> attribute
%type <LB> list_body
%token <ID> ID
%token <N> INT
%token <NF> FLOAT
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ef82b5d

Please sign in to comment.