This commit is contained in:
Chris Wanstrath 2025-11-25 16:35:26 -08:00 committed by Chris Wanstrath
parent cc604bea49
commit d0005d9ccd
2 changed files with 38 additions and 1 deletions

View File

@ -123,7 +123,7 @@ export class Parser {
// check for parens function call // check for parens function call
// ex: (ref my-func) my-arg // 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) expr = this.functionCall(expr)
// if dotget is followed by binary operator, continue parsing as binary expression // if dotget is followed by binary operator, continue parsing as binary expression

View File

@ -176,6 +176,43 @@ describe('pipe expressions', () => {
Identifier echo 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', () => { describe('pipe continuation', () => {