diff --git a/src/runestone.jl b/src/runestone.jl index 3c79620..aaeae49 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -407,7 +407,7 @@ function spaces_in_listlike(ctx::Context, node::Node) require_trailing_comma = false # Leads to parser error elseif kind(node) in KSet"block" require_trailing_comma = false - allow_trailing_semi = n_items == 0 + allow_trailing_semi = n_items < 2 elseif kind(node) === K"parameters" # For parameters the trailing comma is configured from the parent require_trailing_comma = has_tag(node, TAG_TRAILING_COMMA) @@ -756,6 +756,7 @@ function spaces_in_listlike(ctx::Context, node::Node) replace_bytes!(ctx, "", span(kid′)) elseif kind(node) === K"block" && kind(kid′) === K";" && allow_trailing_semi || (kind(kid′) === K"Whitespace" && peek(i) !== K"Comment") + allow_trailing_semi = n_items == 0 # Only one semicolon allowed accept_node!(ctx, kid′) any_kid_changed && push!(kids′, kid′) elseif kind(kid′) === K"NewlineWs" || diff --git a/test/runtests.jl b/test/runtests.jl index fdd0882..c990082 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -333,12 +333,13 @@ end "$(x){\n $(a), $(a); $(b),\n}" end # Trailing `;` in paren-block - @test format_string("(a = A;)") == "(a = A)" - @test format_string("cond && (a = A;)") == "cond && (a = A)" + @test format_string("(a = A;)") == "(a = A;)" + @test format_string("cond && (a = A;)") == "cond && (a = A;)" @test format_string("(a = A; b = B;)") == "(a = A; b = B)" - @test format_string("(a = A;;)") == "(a = A)" + @test format_string("(a = A;;)") == "(a = A;)" @test format_string("(;;)") == format_string("( ; ; )") == "(;;)" @test format_string("(;)") == format_string("( ; )") == "(;)" + @test format_string("(@a b(c);)") == "(@a b(c);)" # https://github.com/fredrikekre/Runic.jl/issues/16 @test format_string("(i for i in\nI)") == "(\n i for i in\n I\n)" @test format_string("f(i for i in\nI)") == "f(\n i for i in\n I\n)"