diff --git a/parser.go b/parser.go index f7c30ddb..72f17544 100644 --- a/parser.go +++ b/parser.go @@ -1596,13 +1596,34 @@ func (p *Parser) lookaheadLambdaArg() bool { p.Lexer = lexer }() - if p.Token.Kind != "(" && p.Token.Kind != token.TokenIdent { + switch p.Token.Kind { + case "(": + p.nextToken() + if p.Token.Kind != token.TokenIdent { + return false + } + p.nextToken() + + for p.Token.Kind != ")" { + if p.Token.Kind != "," { + return false + } + p.nextToken() + + if p.Token.Kind != token.TokenIdent { + return false + } + p.nextToken() + } + p.nextToken() + + return p.Token.Kind == "->" + case token.TokenIdent: + p.nextToken() + return p.Token.Kind == "->" + default: return false } - - // Note: all lambda patterns can be parsed as expr -> expr. - p.parseExpr() - return p.Token.Kind == "->" } func (p *Parser) parseLambdaArg() *ast.LambdaArg { diff --git a/testdata/input/expr/array_functions_array_filter_one_arg_with_paren_lambda.sql b/testdata/input/expr/array_functions_array_filter_one_arg_with_paren_lambda.sql new file mode 100644 index 00000000..c303120d --- /dev/null +++ b/testdata/input/expr/array_functions_array_filter_one_arg_with_paren_lambda.sql @@ -0,0 +1 @@ +ARRAY_FILTER([1 ,2, 3], (e) -> e > 1) \ No newline at end of file diff --git a/testdata/result/expr/array_functions_array_filter_one_arg_with_paren_lambda.sql.txt b/testdata/result/expr/array_functions_array_filter_one_arg_with_paren_lambda.sql.txt new file mode 100644 index 00000000..a2037132 --- /dev/null +++ b/testdata/result/expr/array_functions_array_filter_one_arg_with_paren_lambda.sql.txt @@ -0,0 +1,72 @@ +--- array_functions_array_filter_one_arg_with_paren_lambda.sql +ARRAY_FILTER([1 ,2, 3], (e) -> e > 1) +--- AST +&ast.CallExpr{ + Rparen: 36, + Func: &ast.Ident{ + NamePos: 0, + NameEnd: 12, + Name: "ARRAY_FILTER", + }, + Distinct: false, + Args: []ast.Arg{ + &ast.ExprArg{ + Expr: &ast.ArrayLiteral{ + Array: -1, + Lbrack: 13, + Rbrack: 21, + Type: nil, + Values: []ast.Expr{ + &ast.IntLiteral{ + ValuePos: 14, + ValueEnd: 15, + Base: 10, + Value: "1", + }, + &ast.IntLiteral{ + ValuePos: 17, + ValueEnd: 18, + Base: 10, + Value: "2", + }, + &ast.IntLiteral{ + ValuePos: 20, + ValueEnd: 21, + Base: 10, + Value: "3", + }, + }, + }, + }, + &ast.LambdaArg{ + Lparen: 24, + Args: []*ast.Ident{ + &ast.Ident{ + NamePos: 25, + NameEnd: 26, + Name: "e", + }, + }, + Expr: &ast.BinaryExpr{ + Op: ">", + Left: &ast.Ident{ + NamePos: 31, + NameEnd: 32, + Name: "e", + }, + Right: &ast.IntLiteral{ + ValuePos: 35, + ValueEnd: 36, + Base: 10, + Value: "1", + }, + }, + }, + }, + NamedArgs: []*ast.NamedArg(nil), + NullHandling: nil, + Having: nil, +} + +--- SQL +ARRAY_FILTER([1, 2, 3], (e) -> e > 1)