Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #7 #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 2 additions & 4 deletions src/Underscores.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ end Underscores

export @_

isquoted(ex) = ex isa Expr && ex.head in (:quote, :inert, :meta)
isquoted(ex) = ex isa Expr && ex.head in (:inert, :meta)

function _replacesyms(sym_map, ex)
if ex isa Symbol
Expand Down Expand Up @@ -102,9 +102,7 @@ const _pipeline_ops = [:|>, :<|, :∘, :.|>, :.<|]

function lower_underscores(ex)
if ex isa Expr
if isquoted(ex)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be removed — it currently ignores Expr(:meta, ...) which it should continue doing (and Expr(:inert) I guess... though :meta and particularly :inert are quite obscure!)

return ex
elseif ex.head == :call && length(ex.args) > 1 &&
if ex.head == :call && length(ex.args) > 1 &&
ex.args[1] in _pipeline_ops
# Special case for pipelining and composition operators
return Expr(ex.head, ex.args[1],
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ end
@test lower(:(f(g(_[3]),h)[4])) == cleanup!(:(f((_1,)->g(_1[3]),h)[4]))
@test lower(:(f(__)[5])) == cleanup!(:((__1,)->f(__1)[5]))

# Quote
@test lower(:(map(:(a[$_]), 1:4))) == cleanup!(:(map((_1,)->:(a[$_1]), 1:4)))

# Random sample of other syntax
@test lower(:([_])) == cleanup!(:([(_1,)->_1]))
@test lower(:((f(_), g(_)))) == cleanup!(:(((_1,)->f(_1)), ((_1,)->g(_1))))
Expand Down