diff --git a/src/runestone.jl b/src/runestone.jl index bfda2ff..7173bc6 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -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) 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)] diff --git a/test/runtests.jl b/test/runtests.jl index d6eeff9..6666b4e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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