From 5f5127d8093da7c1996538562abb7f1a86bc1790 Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Sun, 17 Sep 2023 22:30:38 +0800 Subject: [PATCH] nixd/Syntax: allow expr_app -> expr_simple passthrough --- nixd/lib/Syntax/Parser/Parser.y | 18 +++++++++++------- nixd/test/Syntax/Basic.cpp | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/nixd/lib/Syntax/Parser/Parser.y b/nixd/lib/Syntax/Parser/Parser.y index 1529d0992..d62e07146 100644 --- a/nixd/lib/Syntax/Parser/Parser.y +++ b/nixd/lib/Syntax/Parser/Parser.y @@ -63,7 +63,7 @@ %type binds %type attrpath %type attrs -%type expr_app +%type expr_app %type path_start %type spath %type uri @@ -192,14 +192,18 @@ expr_op expr_app : expr_app expr_select { - $$->Args.emplace_back($1); + if (auto F = dynamic_cast($1)) { + // If $1 is already a function call, then we insert the arg list + F->Args.emplace_back($2); + } else { + // Otherwise, create a new function + auto N = decorateNode(new Call, yylloc, *Data); + N->Fn = $1; + N->Args = {$2}; + } $$->Range = mkRange(yylloc, *Data); } - | expr_select { - auto N = decorateNode(new Call, yylloc, *Data); - N->Fn = $1; - $$ = N; - } + | expr_select expr_select diff --git a/nixd/test/Syntax/Basic.cpp b/nixd/test/Syntax/Basic.cpp index f51e09c4d..9b6cf058d 100644 --- a/nixd/test/Syntax/Basic.cpp +++ b/nixd/test/Syntax/Basic.cpp @@ -20,7 +20,7 @@ TEST(NixdSyntax, Case1) { .Origin = nix::Pos::Origin(nix::Pos::none_tag())}); Data->Result = nullptr; - char Test[] = "let { x = 1; y = 2; } in x\n\0\0"; + char Test[] = "let x = 1; y = 2; in x\n\0\0"; parse(Test, strlen(Test) + 2, Data.get()); }