From d4bc81775582cf0510bb1ea55a54ec156c8a7323 Mon Sep 17 00:00:00 2001 From: Sebastian Pfitzner Date: Tue, 11 Jun 2024 17:19:16 +0200 Subject: [PATCH 1/2] fix: anon long form func definition with one or fewer non-kw args --- src/packagedef.jl | 2 +- test/parser/test_parser.jl | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/packagedef.jl b/src/packagedef.jl index af354c4c..1d3e45eb 100644 --- a/src/packagedef.jl +++ b/src/packagedef.jl @@ -172,7 +172,7 @@ Parses an expression starting with a `(`. function parse_paren(ps::ParseState) args = EXPR[] trivia = EXPR[EXPR(ps)] - @closeparen ps @default ps @nocloser ps :inwhere parse_comma_sep(ps, args, trivia, false, true, true, insert_params_at = 1) + @closeparen ps @default ps @nocloser ps :inwhere parse_comma_sep(ps, args, trivia, false, kindof(ps.lt) != Tokens.FUNCTION, true, insert_params_at = 1) if length(args) == 1 && length(trivia) == 1 && ((kindof(ps.ws) !== SemiColonWS || headof(args[1]) === :block) && headof(args[1]) !== :parameters) accept_rparen(ps, trivia) ret = EXPR(:brackets, args, trivia) diff --git a/test/parser/test_parser.jl b/test/parser/test_parser.jl index 18676de5..54bab35b 100644 --- a/test/parser/test_parser.jl +++ b/test/parser/test_parser.jl @@ -343,6 +343,9 @@ end @test "-1^a" |> test_expr @test "function(f, args...; kw...) end" |> test_expr @test "function(f, args...=1; kw...) end" |> test_expr + @test "function (f; args...) end" |> test_expr + @test "function (; args...) end" |> test_expr + @test "function (args...) end" |> test_expr @test "2a * b" |> test_expr @test "(g1090(x::T)::T) where {T} = x+1.0" |> test_expr @test "(:) = Colon()" |> test_expr From a75373740f0d1a4f748b4e5ce0907fd085aa03d4 Mon Sep 17 00:00:00 2001 From: Sebastian Pfitzner Date: Wed, 12 Jun 2024 09:30:36 +0200 Subject: [PATCH 2/2] fix: correct anon func block parsing on old julia versions --- src/packagedef.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/packagedef.jl b/src/packagedef.jl index 1d3e45eb..abe731e5 100644 --- a/src/packagedef.jl +++ b/src/packagedef.jl @@ -172,7 +172,10 @@ Parses an expression starting with a `(`. function parse_paren(ps::ParseState) args = EXPR[] trivia = EXPR[EXPR(ps)] - @closeparen ps @default ps @nocloser ps :inwhere parse_comma_sep(ps, args, trivia, false, kindof(ps.lt) != Tokens.FUNCTION, true, insert_params_at = 1) + + anon_func_block = VERSION < v"1.11-" || kindof(ps.lt) != Tokens.FUNCTION + + @closeparen ps @default ps @nocloser ps :inwhere parse_comma_sep(ps, args, trivia, false, anon_func_block, true, insert_params_at = 1) if length(args) == 1 && length(trivia) == 1 && ((kindof(ps.ws) !== SemiColonWS || headof(args[1]) === :block) && headof(args[1]) !== :parameters) accept_rparen(ps, trivia) ret = EXPR(:brackets, args, trivia)