From dcd1d92cdd751bb4f3698454059b8907db5b390b Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Fri, 12 Jul 2024 18:33:31 +0200 Subject: [PATCH] Fix K"vect" with parameters Fixes parameters in K"vect" and fixes eating of empty parameters. --- src/runestone.jl | 10 +++++++--- test/runtests.jl | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/runestone.jl b/src/runestone.jl index faf167f..23a0930 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -301,8 +301,8 @@ function spaces_in_listlike(ctx::Context, node::Node) return nothing end if kind(node) === K"parameters" - # TODO: Can probably show up elsewhere but... - @assert ctx.lineage_kinds[end] in KSet"tuple call dotcall curly" + # Note that some of these are not valid Julia syntax but still parse + @assert ctx.lineage_kinds[end] in KSet"tuple call dotcall curly vect" end @assert !is_leaf(node) @@ -568,7 +568,8 @@ function spaces_in_listlike(ctx::Context, node::Node) accept_node!(ctx, kid′) any_kid_changed && push!(kids′, kid′) elseif kind(kid′) === K"parameters" - @assert kind(node) in KSet"call dotcall curly tuple" # TODO: Can this happen for named tuples? + # Note that some of these are not valid Julia syntax still parse + @assert kind(node) in KSet"call dotcall curly tuple vect" @assert i === last_item_idx @assert findnext( !JuliaSyntax.is_whitespace, @view(kids[1:(closing_leaf_idx - 1)]), i + 1, @@ -613,6 +614,9 @@ function spaces_in_listlike(ctx::Context, node::Node) accept_node!(ctx, grandkid) push!(kids′, grandkid) end + else + # Nothing in the parameter node needed, overwrite it fully + replace_bytes!(ctx, "", span(kid′)) end else # TODO: Tag for requiring trailing comma. diff --git a/test/runtests.jl b/test/runtests.jl index 82d54de..d402dfb 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -274,6 +274,8 @@ end @test format_string("f(\n$(sp)$(a)$(sp);\n$(sp)$(b)$(sp)\n)") == format_string("f(\n$(sp)$(a)$(sp);\n$(sp)$(b)$(sp),$(sp)\n)") == "f(\n $(a);\n $(b),\n)" + # vect with parameter (not valid Julia syntax, but parses) + @test format_string("[$(sp)1,$(sp)2$(sp);$(sp)]") == "[1, 2]" end # Splatting for sp in ("", " ", " ")