Browse Source

Fix multiple K"parameters" in argument list

pull/19/head
Fredrik Ekre 1 year ago
parent
commit
ab6e38fe01
No known key found for this signature in database
GPG Key ID: DE82E6D5E364C0A2
  1. 9
      src/runestone.jl
  2. 3
      test/runtests.jl

9
src/runestone.jl

@ -570,10 +570,6 @@ function spaces_in_listlike(ctx::Context, node::Node)
elseif kind(kid′) === K"parameters" elseif kind(kid′) === K"parameters"
# Note that some of these are not valid Julia syntax still parse # Note that some of these are not valid Julia syntax still parse
@assert kind(node) in KSet"call dotcall curly tuple vect" @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,
) === nothing
if kind(first_leaf(kid′)) === K"Whitespace" if kind(first_leaf(kid′)) === K"Whitespace"
# Delete the whitespace leaf # Delete the whitespace leaf
kid_ws = first_leaf(kid′) kid_ws = first_leaf(kid′)
@ -629,7 +625,10 @@ function spaces_in_listlike(ctx::Context, node::Node)
push!(kids′, kid′) push!(kids′, kid′)
end end
end end
state = :expect_closing # parameters must be the last item(?) # K"parameter" is always the last item in valid Julia code but we need to
# handle all expression that parses and there might be multiple
# K"parameters"...
state = i == last_item_idx ? (:expect_closing) : (:expect_item)
else else
@assert false # Unreachable? @assert false # Unreachable?
end end

3
test/runtests.jl

@ -276,6 +276,9 @@ end
"f(\n $(a);\n $(b),\n)" "f(\n $(a);\n $(b),\n)"
# vect with parameter (not valid Julia syntax, but parses) # vect with parameter (not valid Julia syntax, but parses)
@test format_string("[$(sp)1,$(sp)2$(sp);$(sp)]") == "[1, 2]" @test format_string("[$(sp)1,$(sp)2$(sp);$(sp)]") == "[1, 2]"
# 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))"
end end
# Splatting # Splatting
for sp in ("", " ", " ") for sp in ("", " ", " ")

Loading…
Cancel
Save