Skip to content

Commit

Permalink
nixd/Syntax: attribute & inherited_attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc committed Sep 17, 2023
1 parent 8dc640b commit 7f5aa9a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
11 changes: 11 additions & 0 deletions nixd/include/nixd/Syntax/Nodes.inc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ NODE(Call, {
})
NODE(AttrPath, { std::vector<Node *> Names; })
NODE(Attrs, { std::vector<Node *> Names; })

NODE(Attribute, {
AttrPath *Path;
Node *Body;
})

NODE(InheritedAttribute, {
Attrs *Attrs;
Node *E;
})

NODE(Select, {
Node *Body;

Expand Down
33 changes: 29 additions & 4 deletions nixd/lib/Syntax/Parser/Parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
nixd::syntax::SPath *SPath;
nixd::syntax::URI *Uri;
nixd::syntax::Attrs *Attrs;
nixd::syntax::Attribute *Attribute;
nixd::syntax::InheritedAttribute *IA;

// Tokens
nixd::syntax::StringToken STR;
Expand Down Expand Up @@ -61,6 +63,8 @@
%type <Node> path_start
%type <SPath> spath
%type <Uri> uri
%type <IA> inherited_attribute
%type <Attribute> attribute
%token <ID> ID
%token <N> INT
%token <NF> FLOAT
Expand Down Expand Up @@ -374,13 +378,34 @@ identifier
}



binds
: binds attrpath '=' expr ';'
| binds INHERIT attrs ';'
| binds INHERIT '(' expr ')' attrs ';'
: binds attribute
| binds inherited_attribute
|

// Nixd extension
inherited_attribute
: INHERIT attrs ';' {
$$ = decorateNode(new InheritedAttribute {
.Attrs = $2,
.E = nullptr
}, yylloc, *Data);
}
| INHERIT '(' expr ')' attrs ';' {
$$ = decorateNode(new InheritedAttribute {
.Attrs = $5,
.E = $3
}, yylloc, *Data);
}

// Nixd extension
attribute
: attrpath '=' expr ';' {
$$ = decorateNode(new Attribute {
.Path = $1,
.Body = $3
}, yylloc, *Data);
}

attrs
: attrs attr {
Expand Down

0 comments on commit 7f5aa9a

Please sign in to comment.