Parser 2.0 (Major Delezer) #52

Merged
defunkt merged 35 commits from parser2 into main 2025-12-08 16:35:34 +00:00
2 changed files with 38 additions and 1 deletions
Showing only changes of commit d0005d9ccd - Show all commits

View File

@ -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

View File

@ -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', () => {