From 31ebac0f592b9918f8fc9520b8b7c360ef51573d Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Sun, 27 Oct 2024 23:07:04 +0100 Subject: [PATCH] Fix extra space in export/public/global/local multiline lists, fixes #78 --- src/runestone.jl | 7 +++++-- test/runtests.jl | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/runestone.jl b/src/runestone.jl index a1a6ddb..c25088c 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -940,6 +940,7 @@ function spaces_in_export_public(ctx::Context, node::Node) while i <= length(kids) kid = kids[i] if state === :expect_space + state = :expect_identifier if kind(kid) === K"NewlineWs" || (kind(kid) === K"Whitespace" && span(kid) == 1) any_changes && push!(kids′, kid) accept_node!(ctx, kid) @@ -952,6 +953,10 @@ function spaces_in_export_public(ctx::Context, node::Node) end accept_node!(ctx, kid′) push!(kids′, kid′) + elseif kind(kid) === K"Comment" + any_changes && push!(kids′, kid) + accept_node!(ctx, kid) + state = :expect_space else @assert kind(first_leaf(kid)) !== K"Whitespace" # Insert a space @@ -962,10 +967,8 @@ function spaces_in_export_public(ctx::Context, node::Node) replace_bytes!(ctx, " ", 0) push!(kids′, spacenode) accept_node!(ctx, spacenode) - state = :expect_identifier continue # Skip increment of i end - state = :expect_identifier elseif state === :expect_identifier state = :expect_comma if kind(kid) in KSet"Identifier @ MacroName $ var" || JuliaSyntax.is_operator(kid) diff --git a/test/runtests.jl b/test/runtests.jl index a9dbe16..0d44ce6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -977,6 +977,8 @@ end @test format_string("$(verb) $(a)$(sp),\n# b\n$(b)") == "$(verb) $(a),\n # b\n $(b)" # Inline comments @test format_string("$(verb) a$(sp),$(sp)#= b, =#$(sp)c") == "$(verb) a, #= b, =# c" + # https://github.com/fredrikekre/Runic.jl/issues/78 + @test format_string("$(verb)\n #a\n a,\n\n #b\nb") == "$(verb)\n #a\n a,\n\n #b\n b" end # Interpolated identifiers (currently only expected in K"quote" and K"macrocall") @test format_string(":(export \$a)") == ":(export \$a)"