From 4b57728072587ba473c9c26b1d4b320ee9b46ec4 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath <2+defunkt@users.noreply.github.com> Date: Tue, 25 Nov 2025 16:35:26 -0800 Subject: [PATCH] fix | --- src/parser/parser2.ts | 2 +- src/parser/tests/pipes.test.ts | 37 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/parser/parser2.ts b/src/parser/parser2.ts index f11579b..6244038 100644 --- a/src/parser/parser2.ts +++ b/src/parser/parser2.ts @@ -123,7 +123,7 @@ export class Parser { // check for parens function call // ex: (ref my-func) my-arg - if (expr.type.is('ParenExpr') && !this.isExprEnd()) + if (expr.type.is('ParenExpr') && !this.isExprEnd() && !this.is($T.Operator, '|')) expr = this.functionCall(expr) // if dotget is followed by binary operator, continue parsing as binary expression diff --git a/src/parser/tests/pipes.test.ts b/src/parser/tests/pipes.test.ts index a359384..44ba028 100644 --- a/src/parser/tests/pipes.test.ts +++ b/src/parser/tests/pipes.test.ts @@ -176,6 +176,43 @@ describe('pipe expressions', () => { Identifier echo `) }) + + test('parenthesized expressions can be piped', () => { + expect(`(1 + 2) | echo`).toMatchTree(` + PipeExpr + ParenExpr + BinOp + Number 1 + Plus + + Number 2 + operator | + FunctionCallOrIdentifier + Identifier echo + `) + }) + + test('complex parenthesized expressions with pipes', () => { + expect(`((math.random) * 10 + 1) | math.floor`).toMatchTree(` + PipeExpr + ParenExpr + BinOp + BinOp + ParenExpr + FunctionCallOrIdentifier + DotGet + IdentifierBeforeDot math + Identifier random + Star * + Number 10 + Plus + + Number 1 + operator | + FunctionCallOrIdentifier + DotGet + IdentifierBeforeDot math + Identifier floor + `) + }) }) describe('pipe continuation', () => {