From a0b00122cc07e05446b17d76233a52f13c7da305 Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Sat, 16 Sep 2023 22:44:22 +0800 Subject: [PATCH] nixd/Syntax: action for expr_app --- nixd/include/nixd/Syntax/Nodes.h | 5 +++++ nixd/lib/Syntax/Parser/Parser.y | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/nixd/include/nixd/Syntax/Nodes.h b/nixd/include/nixd/Syntax/Nodes.h index 791c83927..3aa3537ca 100644 --- a/nixd/include/nixd/Syntax/Nodes.h +++ b/nixd/include/nixd/Syntax/Nodes.h @@ -81,6 +81,11 @@ struct List : Node { struct StringAttr : Node {}; +struct Call : Node { + Node *Fn; + std::vector Args; +}; + struct AttrPath : Node {}; struct OpHasAttr : Node { diff --git a/nixd/lib/Syntax/Parser/Parser.y b/nixd/lib/Syntax/Parser/Parser.y index cd2f11713..7cb55e37d 100644 --- a/nixd/lib/Syntax/Parser/Parser.y +++ b/nixd/lib/Syntax/Parser/Parser.y @@ -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; @@ -35,11 +36,12 @@ } -%type start expr expr_function expr_if expr_op +%type start expr expr_function expr_if expr_op expr_select %type identifier %type formals %type binds %type attrpath +%type expr_app %token ID %token INT %token FLOAT @@ -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