|
|
|
|
@ -1127,19 +1127,25 @@ end
@@ -1127,19 +1127,25 @@ end
|
|
|
|
|
function for_loop_use_in(ctx::Context, node::Node) |
|
|
|
|
if !( |
|
|
|
|
(kind(node) === K"for" && !is_leaf(node) && meta_nargs(node) == 4) || |
|
|
|
|
(kind(node) === K"generator" && meta_nargs(node) == 3) # TODO: Unsure about 3. |
|
|
|
|
kind(node) === K"generator" |
|
|
|
|
) |
|
|
|
|
return nothing |
|
|
|
|
end |
|
|
|
|
pos = position(ctx.fmt_io) |
|
|
|
|
kids = verified_kids(node) |
|
|
|
|
kids′ = kids |
|
|
|
|
for_index = findfirst(c -> kind(c) === K"for" && is_leaf(c), kids)::Int |
|
|
|
|
next_index = 1 |
|
|
|
|
any_for_changed = false |
|
|
|
|
# generator can have multiple for nodes |
|
|
|
|
while for_index !== nothing |
|
|
|
|
for_node = kids[for_index] |
|
|
|
|
@assert kind(for_node) === K"for" && span(for_node) == 3 && |
|
|
|
|
is_leaf(for_node) && JuliaSyntax.is_trivia(for_node) |
|
|
|
|
for i in 1:for_index |
|
|
|
|
for i in next_index:for_index |
|
|
|
|
accept_node!(ctx, kids[i]) |
|
|
|
|
end |
|
|
|
|
while_pos = position(ctx.fmt_io) |
|
|
|
|
# The for loop specification node can be either K"=" or K"cartesian_iterator" |
|
|
|
|
for_spec_index = for_index + 1 |
|
|
|
|
for_spec_node = kids[for_spec_index] |
|
|
|
|
@ -1152,17 +1158,28 @@ function for_loop_use_in(ctx::Context, node::Node)
@@ -1152,17 +1158,28 @@ function for_loop_use_in(ctx::Context, node::Node)
|
|
|
|
|
@assert kind(for_spec_node) === K"cartesian_iterator" |
|
|
|
|
for_spec_node′ = replace_with_in_cartesian(ctx, for_spec_node) |
|
|
|
|
end |
|
|
|
|
if for_spec_node′ === nothing |
|
|
|
|
seek(ctx.fmt_io, pos) |
|
|
|
|
return nothing |
|
|
|
|
end |
|
|
|
|
@assert position(ctx.fmt_io) == pos + mapreduce(span, +, @view(kids[1:for_index])) + span(for_spec_node′) |
|
|
|
|
if for_spec_node′ !== nothing |
|
|
|
|
@assert position(ctx.fmt_io) == while_pos + span(for_spec_node′) |
|
|
|
|
any_for_changed = true |
|
|
|
|
# Insert the new for spec node |
|
|
|
|
if kids′ === kids |
|
|
|
|
kids′ = copy(kids) |
|
|
|
|
end |
|
|
|
|
kids′[for_spec_index] = for_spec_node′ |
|
|
|
|
# At this point the eq node is done, just accept any remaining nodes |
|
|
|
|
end |
|
|
|
|
for_index = findnext(c -> kind(c) === K"for" && is_leaf(c), kids, for_spec_index + 1) |
|
|
|
|
if for_index !== nothing |
|
|
|
|
@assert kind(node) === K"generator" |
|
|
|
|
end |
|
|
|
|
next_index = for_spec_index + 1 |
|
|
|
|
end |
|
|
|
|
if !any_for_changed |
|
|
|
|
seek(ctx.fmt_io, pos) |
|
|
|
|
return nothing |
|
|
|
|
end |
|
|
|
|
# At this point the eq nodes are done, just accept any remaining nodes |
|
|
|
|
# TODO: Don't need to do this... |
|
|
|
|
for i in (for_spec_index + 1):length(kids′) |
|
|
|
|
for i in next_index:length(kids′) |
|
|
|
|
accept_node!(ctx, kids′[i]) |
|
|
|
|
end |
|
|
|
|
# Construct the full node and return |
|
|
|
|
|