From 0fdfc27c83f3c636781120628dc6e8be27847aa6 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Sat, 27 Jul 2024 01:45:26 +0200 Subject: [PATCH] Fix formatting of K"parameters" inside K"ref" --- src/runestone.jl | 4 ++-- test/runtests.jl | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/runestone.jl b/src/runestone.jl index 327137d..2b33672 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -320,7 +320,7 @@ function spaces_in_listlike(ctx::Context, node::Node) end if kind(node) === K"parameters" # Note that some of these are not valid Julia syntax but still parse - @assert ctx.lineage_kinds[end] in KSet"tuple call dotcall macrocall curly vect" + @assert ctx.lineage_kinds[end] in KSet"tuple call dotcall macrocall curly vect ref" end @assert !is_leaf(node) @@ -602,7 +602,7 @@ function spaces_in_listlike(ctx::Context, node::Node) any_kid_changed && push!(kids′, kid′) elseif kind(kid′) === K"parameters" # Note that some of these are not valid Julia syntax still parse - @assert kind(node) in KSet"call dotcall macrocall curly tuple vect" + @assert kind(node) in KSet"call dotcall macrocall curly tuple vect ref" if kind(first_leaf(kid′)) === K"Whitespace" # Delete the whitespace leaf kid_ws = first_leaf(kid′) diff --git a/test/runtests.jl b/test/runtests.jl index d909561..9a568ab 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -287,8 +287,15 @@ end format_string("f(;$(sp)b$(sp)=$(sp)$(b)$(sp)\n)") == format_string("f(;$(sp)b$(sp)=$(sp)$(b)$(sp),$(sp)\n)") == "f(;\n b = $(b),\n)" - # vect with parameter (not valid Julia syntax, but parses) - @test format_string("[$(sp)1,$(sp)2$(sp);$(sp)]") == "[1, 2]" + # vect/ref with parameter (not valid Julia syntax, but parses) + for T in ("", "T") + @test format_string("$(T)[$(sp)$(a),$(sp)$(b)$(sp);$(sp)]") == + "$(T)[$(a), $(b)]" + @test format_string("$(T)[$(sp)$(a),$(sp)$(b)$(sp);$(sp)a=$(a)$(sp)]") == + "$(T)[$(a), $(b); a = $(a)]" + @test format_string("$(T)[$(sp)$(a),$(sp)$(b)$(sp);$(sp)a=$(a)$(sp),$(sp)b=$(b)$(sp)]") == + "$(T)[$(a), $(b); a = $(a), b = $(b)]" + end # Multple `;` in argument list (lowering error but parses....) @test format_string("f($(sp)x$(sp);$(sp)y$(sp)=$(sp)$(a)$(sp);$(sp)z$(sp)=$(sp)$(b)$(sp))") == "f(x; y = $(a); z = $(b))"