Browse Source

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

pull/84/head
Fredrik Ekre 1 year ago committed by GitHub
parent
commit
f9450a5fd5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 7
      src/runestone.jl
  2. 2
      test/runtests.jl

7
src/runestone.jl

@ -940,6 +940,7 @@ function spaces_in_export_public(ctx::Context, node::Node)
while i <= length(kids) while i <= length(kids)
kid = kids[i] kid = kids[i]
if state === :expect_space if state === :expect_space
state = :expect_identifier
if kind(kid) === K"NewlineWs" || (kind(kid) === K"Whitespace" && span(kid) == 1) if kind(kid) === K"NewlineWs" || (kind(kid) === K"Whitespace" && span(kid) == 1)
any_changes && push!(kids′, kid) any_changes && push!(kids′, kid)
accept_node!(ctx, kid) accept_node!(ctx, kid)
@ -952,6 +953,10 @@ function spaces_in_export_public(ctx::Context, node::Node)
end end
accept_node!(ctx, kid′) accept_node!(ctx, kid′)
push!(kids′, kid′) push!(kids′, kid′)
elseif kind(kid) === K"Comment"
any_changes && push!(kids′, kid)
accept_node!(ctx, kid)
state = :expect_space
else else
@assert kind(first_leaf(kid)) !== K"Whitespace" @assert kind(first_leaf(kid)) !== K"Whitespace"
# Insert a space # Insert a space
@ -962,10 +967,8 @@ function spaces_in_export_public(ctx::Context, node::Node)
replace_bytes!(ctx, " ", 0) replace_bytes!(ctx, " ", 0)
push!(kids′, spacenode) push!(kids′, spacenode)
accept_node!(ctx, spacenode) accept_node!(ctx, spacenode)
state = :expect_identifier
continue # Skip increment of i continue # Skip increment of i
end end
state = :expect_identifier
elseif state === :expect_identifier elseif state === :expect_identifier
state = :expect_comma state = :expect_comma
if kind(kid) in KSet"Identifier @ MacroName $ var" || JuliaSyntax.is_operator(kid) if kind(kid) in KSet"Identifier @ MacroName $ var" || JuliaSyntax.is_operator(kid)

2
test/runtests.jl

@ -977,6 +977,8 @@ end
@test format_string("$(verb) $(a)$(sp),\n# b\n$(b)") == "$(verb) $(a),\n # b\n $(b)" @test format_string("$(verb) $(a)$(sp),\n# b\n$(b)") == "$(verb) $(a),\n # b\n $(b)"
# Inline comments # Inline comments
@test format_string("$(verb) a$(sp),$(sp)#= b, =#$(sp)c") == "$(verb) a, #= b, =# c" @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 end
# Interpolated identifiers (currently only expected in K"quote" and K"macrocall") # Interpolated identifiers (currently only expected in K"quote" and K"macrocall")
@test format_string(":(export \$a)") == ":(export \$a)" @test format_string(":(export \$a)") == ":(export \$a)"

Loading…
Cancel
Save