From 9061547538ee493a3640b4962589a5c573dbf8d5 Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Sun, 17 Sep 2023 14:57:55 +0800 Subject: [PATCH] nixd/Syntax: actions for attrpath & attrs --- nixd/include/nixd/Syntax/Nodes.inc | 3 ++- nixd/lib/Syntax/Parser/Parser.y | 40 ++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/nixd/include/nixd/Syntax/Nodes.inc b/nixd/include/nixd/Syntax/Nodes.inc index 040f3d670..3e3a0cb9a 100644 --- a/nixd/include/nixd/Syntax/Nodes.inc +++ b/nixd/include/nixd/Syntax/Nodes.inc @@ -50,7 +50,8 @@ NODE(Call, { Node *Fn; std::vector Args; }) -NODE(AttrPath, {}) +NODE(AttrPath, { std::vector Names; }) +NODE(Attrs, { std::vector Names; }) NODE(Select, { Node *Body; diff --git a/nixd/lib/Syntax/Parser/Parser.y b/nixd/lib/Syntax/Parser/Parser.y index 5e8dd20c9..a99dd867f 100644 --- a/nixd/lib/Syntax/Parser/Parser.y +++ b/nixd/lib/Syntax/Parser/Parser.y @@ -32,6 +32,7 @@ nixd::syntax::IndStringParts *IndStringParts; nixd::syntax::SPath *SPath; nixd::syntax::URI *Uri; + nixd::syntax::Attrs *Attrs; // Tokens nixd::syntax::StringToken STR; @@ -55,6 +56,7 @@ %type formal %type binds %type attrpath +%type attrs %type expr_app %type path_start %type spath @@ -381,16 +383,40 @@ binds attrs - : attrs attr - | attrs string_attr - | + : attrs attr { + $$->Names.emplace_back($1); + $$->Range = mkRange(yylloc, *Data); + } + | attrs string_attr { + $$->Names.emplace_back($1); + $$->Range = mkRange(yylloc, *Data); + } + | { + $$ = decorateNode(new AttrPath { + .Names = {$1} + }, yylloc, *Data); + } attrpath - : attrpath '.' attr - | attrpath '.' string_attr - | attr - | string_attr + : attrpath '.' attr { + $$->Names.emplace_back($3); + $$->Range = mkRange(yylloc, *Data); + } + | attrpath '.' string_attr { + $$->Names.emplace_back($3); + $$->Range = mkRange(yylloc, *Data); + } + | attr { + $$ = decorateNode(new AttrPath { + .Names = {$1} + }, yylloc, *Data); + } + | string_attr { + $$ = decorateNode(new AttrPath { + .Names = {$1} + }, yylloc, *Data); + } attr