Browse Source

Fix K"vect" with parameters

Fixes parameters in K"vect" and fixes eating of empty parameters.
pull/19/head
Fredrik Ekre 1 year ago
parent
commit
dcd1d92cdd
No known key found for this signature in database
GPG Key ID: DE82E6D5E364C0A2
  1. 10
      src/runestone.jl
  2. 2
      test/runtests.jl

10
src/runestone.jl

@ -301,8 +301,8 @@ function spaces_in_listlike(ctx::Context, node::Node) @@ -301,8 +301,8 @@ function spaces_in_listlike(ctx::Context, node::Node)
return nothing
end
if kind(node) === K"parameters"
# TODO: Can probably show up elsewhere but...
@assert ctx.lineage_kinds[end] in KSet"tuple call dotcall curly"
# Note that some of these are not valid Julia syntax but still parse
@assert ctx.lineage_kinds[end] in KSet"tuple call dotcall curly vect"
end
@assert !is_leaf(node)
@ -568,7 +568,8 @@ function spaces_in_listlike(ctx::Context, node::Node) @@ -568,7 +568,8 @@ function spaces_in_listlike(ctx::Context, node::Node)
accept_node!(ctx, kid′)
any_kid_changed && push!(kids′, kid′)
elseif kind(kid′) === K"parameters"
@assert kind(node) in KSet"call dotcall curly tuple" # TODO: Can this happen for named tuples?
# Note that some of these are not valid Julia syntax still parse
@assert kind(node) in KSet"call dotcall curly tuple vect"
@assert i === last_item_idx
@assert findnext(
!JuliaSyntax.is_whitespace, @view(kids[1:(closing_leaf_idx - 1)]), i + 1,
@ -613,6 +614,9 @@ function spaces_in_listlike(ctx::Context, node::Node) @@ -613,6 +614,9 @@ function spaces_in_listlike(ctx::Context, node::Node)
accept_node!(ctx, grandkid)
push!(kids′, grandkid)
end
else
# Nothing in the parameter node needed, overwrite it fully
replace_bytes!(ctx, "", span(kid′))
end
else
# TODO: Tag for requiring trailing comma.

2
test/runtests.jl

@ -274,6 +274,8 @@ end @@ -274,6 +274,8 @@ end
@test format_string("f(\n$(sp)$(a)$(sp);\n$(sp)$(b)$(sp)\n)") ==
format_string("f(\n$(sp)$(a)$(sp);\n$(sp)$(b)$(sp),$(sp)\n)") ==
"f(\n $(a);\n $(b),\n)"
# vect with parameter (not valid Julia syntax, but parses)
@test format_string("[$(sp)1,$(sp)2$(sp);$(sp)]") == "[1, 2]"
end
# Splatting
for sp in ("", " ", " ")

Loading…
Cancel
Save