From 1eb8c1720dd942d2a6af245e7a97338412ca1d95 Mon Sep 17 00:00:00 2001 From: melonedo <44501064+melonedo@users.noreply.github.com> Date: Fri, 12 Nov 2021 19:51:56 +0800 Subject: [PATCH 1/2] Recurse into Expr(:quote) --- src/Underscores.jl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Underscores.jl b/src/Underscores.jl index 8de3db1..4755d8f 100644 --- a/src/Underscores.jl +++ b/src/Underscores.jl @@ -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 @@ -102,9 +102,7 @@ const _pipeline_ops = [:|>, :<|, :∘, :.|>, :.<|] function lower_underscores(ex) if ex isa Expr - if isquoted(ex) - 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], From bd963a2249a368057b81fe8dd3bd333ab633111f Mon Sep 17 00:00:00 2001 From: melonedo <44501064+melonedo@users.noreply.github.com> Date: Fri, 12 Nov 2021 19:59:14 +0800 Subject: [PATCH 2/2] Add the test case in #7 --- test/runtests.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 79e0899..86d0c04 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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))))