Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix extra space in export/public/global/local multiline lists, fixes #78 #83

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/runestone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
Loading