Skip to content

Commit

Permalink
nixd/Syntax: action for OpHasAttr (expr "?" attrpath)
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc committed Sep 16, 2023
1 parent cda6116 commit e19d90d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions nixd/include/nixd/Syntax/Nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ struct StringAttr : Node {};

struct AttrPath : Node {};

struct OpHasAttr : Node {
Node *Operand;
AttrPath *Path;
};

struct OpNot : Node {
Node *Body;
};
Expand Down
7 changes: 6 additions & 1 deletion nixd/lib/Syntax/Parser/Parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
nixd::syntax::If *If;
nixd::syntax::Formals *Formals;
nixd::syntax::Binds *Binds;
nixd::syntax::AttrPath *AttrPath;

// Tokens
nixd::syntax::StringToken STR;
Expand All @@ -38,6 +39,7 @@
%type <Identifier> identifier
%type <Formals> formals
%type <Binds> binds
%type <AttrPath> attrpath
%token <Identifier> ID
%token <N> INT
%token <NF> FLOAT
Expand Down Expand Up @@ -150,7 +152,10 @@ expr_op
| expr_op '/' expr_op { $$ = mkBinOp<OpDiv>($1, $3, yylloc, *Data); }
| expr_op CONCAT expr_op { $$ = mkBinOp<OpConcatLists>($1, $3, yylloc, *Data); }
| expr_op '?' attrpath {

$$ = decorateNode(new OpHasAttr{
.Operand = $1,
.Path = $3
}, yylloc, *Data);
}
| expr_app
;
Expand Down

0 comments on commit e19d90d

Please sign in to comment.