diff --git a/nixd/include/nixd/Syntax/Nodes.inc b/nixd/include/nixd/Syntax/Nodes.inc index 3e3a0cb9a..7b19b14ba 100644 --- a/nixd/include/nixd/Syntax/Nodes.inc +++ b/nixd/include/nixd/Syntax/Nodes.inc @@ -52,6 +52,17 @@ NODE(Call, { }) NODE(AttrPath, { std::vector Names; }) NODE(Attrs, { std::vector Names; }) + +NODE(Attribute, { + AttrPath *Path; + Node *Body; +}) + +NODE(InheritedAttribute, { + Attrs *Attrs; + Node *E; +}) + NODE(Select, { Node *Body; diff --git a/nixd/lib/Syntax/Parser/Parser.y b/nixd/lib/Syntax/Parser/Parser.y index 15d1b3461..affbf0722 100644 --- a/nixd/lib/Syntax/Parser/Parser.y +++ b/nixd/lib/Syntax/Parser/Parser.y @@ -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; @@ -61,6 +63,8 @@ %type path_start %type spath %type uri +%type inherited_attribute +%type attribute %token ID %token INT %token FLOAT @@ -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 {