Skip to content

Commit

Permalink
Fix trailing comma in single item lists with generators
Browse files Browse the repository at this point in the history
Closes #16.
  • Loading branch information
fredrikekre committed Jul 13, 2024
1 parent f24397e commit 6df3f7a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/runestone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6df3f7a

Please sign in to comment.