Skip to content

Commit

Permalink
Fix formatting of K"parameters" inside K"ref"
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Jul 26, 2024
1 parent 49e6c9d commit 0fdfc27
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/runestone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ function spaces_in_listlike(ctx::Context, node::Node)
end
if kind(node) === K"parameters"
# Note that some of these are not valid Julia syntax but still parse
@assert ctx.lineage_kinds[end] in KSet"tuple call dotcall macrocall curly vect"
@assert ctx.lineage_kinds[end] in KSet"tuple call dotcall macrocall curly vect ref"
end

@assert !is_leaf(node)
Expand Down Expand Up @@ -602,7 +602,7 @@ function spaces_in_listlike(ctx::Context, node::Node)
any_kid_changed && push!(kids′, kid′)
elseif kind(kid′) === K"parameters"
# Note that some of these are not valid Julia syntax still parse
@assert kind(node) in KSet"call dotcall macrocall curly tuple vect"
@assert kind(node) in KSet"call dotcall macrocall curly tuple vect ref"
if kind(first_leaf(kid′)) === K"Whitespace"
# Delete the whitespace leaf
kid_ws = first_leaf(kid′)
Expand Down
11 changes: 9 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,15 @@ end
format_string("f(;$(sp)b$(sp)=$(sp)$(b)$(sp)\n)") ==
format_string("f(;$(sp)b$(sp)=$(sp)$(b)$(sp),$(sp)\n)") ==
"f(;\n b = $(b),\n)"
# vect with parameter (not valid Julia syntax, but parses)
@test format_string("[$(sp)1,$(sp)2$(sp);$(sp)]") == "[1, 2]"
# vect/ref with parameter (not valid Julia syntax, but parses)
for T in ("", "T")
@test format_string("$(T)[$(sp)$(a),$(sp)$(b)$(sp);$(sp)]") ==
"$(T)[$(a), $(b)]"
@test format_string("$(T)[$(sp)$(a),$(sp)$(b)$(sp);$(sp)a=$(a)$(sp)]") ==
"$(T)[$(a), $(b); a = $(a)]"
@test format_string("$(T)[$(sp)$(a),$(sp)$(b)$(sp);$(sp)a=$(a)$(sp),$(sp)b=$(b)$(sp)]") ==
"$(T)[$(a), $(b); a = $(a), b = $(b)]"
end
# Multple `;` in argument list (lowering error but parses....)
@test format_string("f($(sp)x$(sp);$(sp)y$(sp)=$(sp)$(a)$(sp);$(sp)z$(sp)=$(sp)$(b)$(sp))") ==
"f(x; y = $(a); z = $(b))"
Expand Down

0 comments on commit 0fdfc27

Please sign in to comment.