Skip to content

Commit

Permalink
nixd/Syntax: action of expr_select
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc committed Sep 16, 2023
1 parent aad6cf7 commit 40ceee3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
14 changes: 11 additions & 3 deletions nixd/include/nixd/Syntax/Nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ struct ExprOp : Node {};

struct Apply : Node {};

struct Select : Node {};

struct Simple : Node {};

struct Variable : Node {
Expand All @@ -76,7 +74,7 @@ struct StringParts : Node {};
struct StringPartsInterpolated : Node {};

struct List : Node {
std::vector<Select> Elems;
std::vector<Node *> Elems;
};

struct StringAttr : Node {};
Expand All @@ -88,6 +86,16 @@ struct Call : Node {

struct AttrPath : Node {};

struct Select : Node {
Node *Body;

AttrPath *AttrPath;

/// expr1 '.' attrpath 'or' expr2
/// expr2 is the default value if we cannot select
Node *Default;
};

struct OpHasAttr : Node {
Node *Operand;
AttrPath *Path;
Expand Down
22 changes: 18 additions & 4 deletions nixd/lib/Syntax/Parser/Parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
}


%type <Node> start expr expr_function expr_if expr_op expr_select
%type <Node> start expr expr_function expr_if expr_op expr_select expr_simple
%type <Identifier> identifier
%type <Formals> formals
%type <Binds> binds
Expand Down Expand Up @@ -176,9 +176,23 @@ expr_app


expr_select
: expr_simple '.' attrpath
| expr_simple '.' attrpath OR_KW expr_select
| expr_simple OR_KW
: expr_simple '.' attrpath {
$$ = decorateNode(new Select{
.Body = $1,
.AttrPath = $3,
.Default = nullptr
}, yylloc, *Data);
}
| expr_simple '.' attrpath OR_KW expr_select {
$$ = decorateNode(new Select{
.Body = $1,
.AttrPath = $3,
.Default = $5
}, yylloc, *Data);
}
| expr_simple OR_KW {
// TODO
}
| expr_simple


Expand Down

0 comments on commit 40ceee3

Please sign in to comment.