Browse Source

Fix single line do-end terminated by semicolon

pull/19/head
Fredrik Ekre 1 year ago
parent
commit
f517d032f3
No known key found for this signature in database
GPG Key ID: DE82E6D5E364C0A2
  1. 4
      src/runestone.jl
  2. 1
      test/runtests.jl

4
src/runestone.jl

@ -937,7 +937,7 @@ function spaces_around_keywords(ctx::Context, node::Node) @@ -937,7 +937,7 @@ function spaces_around_keywords(ctx::Context, node::Node)
if kind(node) === K"do"
nkid = kids[i + 1]
@assert kind(nkid) === K"tuple"
if !any(!JuliaSyntax.is_whitespace, verified_kids(nkid))
if !any(x -> !(JuliaSyntax.is_whitespace(x) || kind(x) === K";"), verified_kids(nkid))
state = :closing
end
end
@ -990,7 +990,7 @@ function spaces_around_keywords(ctx::Context, node::Node) @@ -990,7 +990,7 @@ function spaces_around_keywords(ctx::Context, node::Node)
@assert false # Unreachable?
else
# Reachable in e.g. `T where{T}`, `if(`, ... insert space
@assert kind(node) in KSet"where if elseif while"
@assert kind(node) in KSet"where if elseif while do"
any_changes = true
if kids′ === kids
kids′ = kids[1:(i - 1)]

1
test/runtests.jl

@ -402,6 +402,7 @@ end @@ -402,6 +402,7 @@ end
@test format_string("A$(sp)where$(sp){T}$(sp)where$(sp){S}") == "A where {T} where {S}"
@test format_string("f()$(sp)do$(sp)x\ny\nend") == "f() do x\n y\nend"
@test format_string("f()$(sp)do\ny\nend") == "f() do\n y\nend"
@test format_string("f()$(sp)do; y end") == "f() do; y end"
# After `where` (anywhere else?) a newline can be used instead of a space
@test format_string("A$(sp)where$(sp)\n{A}") == "A where\n{A}"
end

Loading…
Cancel
Save