Browse Source

Fix space after keywords with parenthesized expression

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

6
src/runestone.jl

@ -809,7 +809,7 @@ end @@ -809,7 +809,7 @@ end
# TODO: local, const
function spaces_around_keywords(ctx::Context, node::Node)
is_leaf(node) && return nothing
keyword_set = KSet"where do mutable struct abstract primitive type function if elseif catch"
keyword_set = KSet"where do mutable struct abstract primitive type function if elseif catch while"
if !(kind(node) in keyword_set)
return nothing
end
@ -907,8 +907,8 @@ function spaces_around_keywords(ctx::Context, node::Node) @@ -907,8 +907,8 @@ function spaces_around_keywords(ctx::Context, node::Node)
elseif !space_after && kind(last_leaf(kid)) === K"Whitespace"
@assert false # Unreachable?
else
# Reachable in e.g. `T where{T}`, insert space
@assert kind(node) === K"where"
# Reachable in e.g. `T where{T}`, `if(`, ... insert space
@assert kind(node) in KSet"where if elseif while"
any_changes = true
if kids′ === kids
kids′ = kids[1:(i - 1)]

3
test/runtests.jl

@ -392,6 +392,9 @@ end @@ -392,6 +392,9 @@ end
@test format_string("try\nerror()\ncatch\nend") == "try\n error()\ncatch\nend"
@test format_string("A where{T}") == "A where {T}"
@test format_string("A{T}where{T}") == "A{T} where {T}"
# Some keywords can have a parenthesized expression directly after without the space...
@test format_string("if(a)\nelseif(b)\nend") == "if (a)\nelseif (b)\nend"
@test format_string("while(a)\nend") == "while (a)\nend"
end
@testset "replace ∈ and = with in in for loops and generators" begin

Loading…
Cancel
Save