Skip to content

Commit

Permalink
nixd/Syntax: actions for attrpath & attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc committed Sep 17, 2023
1 parent a0f9b19 commit 9061547
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
3 changes: 2 additions & 1 deletion nixd/include/nixd/Syntax/Nodes.inc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ NODE(Call, {
Node *Fn;
std::vector<Node *> Args;
})
NODE(AttrPath, {})
NODE(AttrPath, { std::vector<Node *> Names; })
NODE(Attrs, { std::vector<Node *> Names; })
NODE(Select, {
Node *Body;

Expand Down
40 changes: 33 additions & 7 deletions nixd/lib/Syntax/Parser/Parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
nixd::syntax::IndStringParts *IndStringParts;
nixd::syntax::SPath *SPath;
nixd::syntax::URI *Uri;
nixd::syntax::Attrs *Attrs;

// Tokens
nixd::syntax::StringToken STR;
Expand All @@ -55,6 +56,7 @@
%type <Formal> formal
%type <Binds> binds
%type <AttrPath> attrpath
%type <Attrs> attrs
%type <Call> expr_app
%type <Node> path_start
%type <SPath> spath
Expand Down Expand Up @@ -381,16 +383,40 @@ binds


attrs
: attrs attr
| attrs string_attr
|
: attrs attr {
$$->Names.emplace_back($1);
$$->Range = mkRange(yylloc, *Data);
}
| attrs string_attr {
$$->Names.emplace_back($1);
$$->Range = mkRange(yylloc, *Data);
}
| {
$$ = decorateNode(new AttrPath {
.Names = {$1}
}, yylloc, *Data);
}


attrpath
: attrpath '.' attr
| attrpath '.' string_attr
| attr
| string_attr
: attrpath '.' attr {
$$->Names.emplace_back($3);
$$->Range = mkRange(yylloc, *Data);
}
| attrpath '.' string_attr {
$$->Names.emplace_back($3);
$$->Range = mkRange(yylloc, *Data);
}
| attr {
$$ = decorateNode(new AttrPath {
.Names = {$1}
}, yylloc, *Data);
}
| string_attr {
$$ = decorateNode(new AttrPath {
.Names = {$1}
}, yylloc, *Data);
}


attr
Expand Down

0 comments on commit 9061547

Please sign in to comment.