Skip to content

Commit

Permalink
nixd/Syntax: action for expr_app
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc committed Sep 16, 2023
1 parent e19d90d commit a0b0012
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions nixd/include/nixd/Syntax/Nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ struct List : Node {

struct StringAttr : Node {};

struct Call : Node {
Node *Fn;
std::vector<Node *> Args;
};

struct AttrPath : Node {};

struct OpHasAttr : Node {
Expand Down
16 changes: 13 additions & 3 deletions nixd/lib/Syntax/Parser/Parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
nixd::syntax::Formals *Formals;
nixd::syntax::Binds *Binds;
nixd::syntax::AttrPath *AttrPath;
nixd::syntax::Call *Call;

// Tokens
nixd::syntax::StringToken STR;
Expand All @@ -35,11 +36,12 @@
}


%type <Node> start expr expr_function expr_if expr_op
%type <Node> start expr expr_function expr_if expr_op expr_select
%type <Identifier> identifier
%type <Formals> formals
%type <Binds> binds
%type <AttrPath> attrpath
%type <Call> expr_app
%token <Identifier> ID
%token <N> INT
%token <NF> FLOAT
Expand Down Expand Up @@ -161,8 +163,16 @@ expr_op
;

expr_app
: expr_app expr_select
| expr_select
: expr_app expr_select {
$$->Args.emplace_back($1);
$$->Range = mkRange(yylloc, *Data);
}
| expr_select {
$$ = decorateNode(new Call{
.Fn = $1,
.Args = {}
}, yylloc, *Data);
}
;

expr_select
Expand Down

0 comments on commit a0b0012

Please sign in to comment.