Browse Source

Fix formatting of K"parameters" inside K"ref"

pull/30/head
Fredrik Ekre 1 year ago
parent
commit
0fdfc27c83
No known key found for this signature in database
GPG Key ID: DE82E6D5E364C0A2
  1. 4
      src/runestone.jl
  2. 11
      test/runtests.jl

4
src/runestone.jl

@ -320,7 +320,7 @@ function spaces_in_listlike(ctx::Context, node::Node) @@ -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)
@ -602,7 +602,7 @@ function spaces_in_listlike(ctx::Context, node::Node) @@ -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′)

11
test/runtests.jl

@ -287,8 +287,15 @@ end @@ -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))"

Loading…
Cancel
Save