diff --git a/src/runestone.jl b/src/runestone.jl index 787224d..0786ec4 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -384,6 +384,10 @@ function spaces_in_listlike(ctx::Context, node::Node) kind(kids[first_item_idx::Int]) !== K"parameters" # TODO: May also have to check for K"where" and K"::" in the lineage above require_trailing_comma = true + elseif kind(node) in KSet"call" && n_items == 1 && kind(kids[first_item_idx::Int]) === K"generator" + # https://github.com/fredrikekre/Runic.jl/issues/16 + # TODO: There is probably a more generic pattern for the check above. + require_trailing_comma = false elseif kind(node) in KSet"bracescat parens" require_trailing_comma = false # Leads to parser error elseif kind(node) in KSet"block" diff --git a/test/runtests.jl b/test/runtests.jl index a118faf..d66ebb6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -316,6 +316,9 @@ end @test format_string("(a = A;;)") == "(a = A)" @test format_string("(;;)") == format_string("( ; ; )") == "(;;)" @test format_string("(;)") == format_string("( ; )") == "(;)" + # 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)" end @testset "whitespace around ->" begin