Skip to content

Commit

Permalink
Support scope in generator expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Jan 17, 2025
1 parent 328ffb9 commit d54c4da
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
24 changes: 24 additions & 0 deletions frontend/components/CellInput/scopestate_statefield.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,30 @@ export let explore_variable_usage = (tree, doc, _scopestate, verbose = VERBOSE)
if (verbose) console.groupEnd()
return false
}
} else if (cursor.name === "Generator") {
// This is: (f(x) for x in xs) or [f(x) for x in xs]
const savior = back_to_parent_resetter(cursor)

// We do a Generator in two steps:
// First we explore all the ForBindings (where locals get defined), and then we go into the first child (where those locals are used).

// 1. The for bindings `x in xs`
if (cursor.firstChild()) {
// Note that we skip the first child here, which is what we want! That's the iterated expression that we leave for the end.
while (cursor.nextSibling()) {
cursor.iterate(enter, leave)
}
savior()
}
// 2. The iterated expression `f(x)`
if (cursor.firstChild()) {
cursor.iterate(enter, leave)
savior()
}

// k thx byeee
leave(cursor)
return false
}
}

Expand Down
4 changes: 4 additions & 0 deletions sample/cm6 crash test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ end
x = a : b:c
end

# ╔═╡ f248e96a-4050-4888-940b-f38158c102fe


# ╔═╡ daba5486-8d5e-4fce-959b-251e821e5dea
# https://github.com/fonsp/Pluto.jl/issues/2639
let x = 1 end
Expand Down Expand Up @@ -355,6 +358,7 @@ end
# ╠═bf834c19-3d0d-4989-9ba3-ef7cb77f9a00
# ╠═3da33f9d-1240-4522-9463-8772b0c2539a
# ╠═c88fe37a-c2e6-46f1-b92b-98737437a741
# ╠═f248e96a-4050-4888-940b-f38158c102fe
# ╠═daba5486-8d5e-4fce-959b-251e821e5dea
# ╠═287dd3c7-33e6-482d-9639-d502fcff9234
# ╠═6db1e583-54f2-4d8f-9181-a7913345c7fd
Expand Down

0 comments on commit d54c4da

Please sign in to comment.