Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/sugar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,19 @@ foldtree(op, init, ex::Expr) =

need_dynamic_optic(ex) =
foldtree(false, ex) do yes, x
yes || x === :end || (x === :begin) || x === :_
yes || x ∈ (:end, :begin, Expr(:end), Expr(:begin), :_)
end

replace_underscore(ex, to) = postwalk(x -> x === :_ ? to : x, ex)

function lower_index(collection::Symbol, index, dim)
index = MacroTools.replace(
index, :end,
dim === nothing ? :($(Base.lastindex)($collection)) : :($(Base.lastindex)($collection, $dim))
)
index = MacroTools.replace(
index, :begin,
dim === nothing ? :($(Base.firstindex)($collection)) : :($(Base.firstindex)($collection, $dim))
)
lasti = dim === nothing ? :($(Base.lastindex)($collection)) : :($(Base.lastindex)($collection, $dim))
firsti = dim === nothing ? :($(Base.firstindex)($collection)) : :($(Base.firstindex)($collection, $dim))
index = MacroTools.replace(index, :end, lasti)
index = MacroTools.replace(index, :begin, firsti)
# New syntax for begin/end in indexing expression, see https://github.com/JuliaLang/julia/pull/57368
index = MacroTools.replace(index, Expr(:end), lasti)
index = MacroTools.replace(index, Expr(:begin), firsti)
end

_secondarg(_, x) = x
Expand Down
Loading