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

Add a..b syntax #121

Merged
merged 10 commits into from
Jul 22, 2017
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Requires 0.4.3
Documenter 0.9.0
IterableTables 0.1.0
DataValues 0.0.2
MacroTools 0.3.6
1 change: 1 addition & 0 deletions src/Query.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ using NamedTuples
using DataStructures
using IterableTables
using DataValues
using MacroTools: postwalk, prewalk, @capture

import Base.start
import Base.next
Expand Down
10 changes: 10 additions & 0 deletions src/query_translation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ function query_expression_translation_phase_A(qe)
end
i+=1
end

for i in 1:length(qe)
qe[i] = postwalk(qe[i]) do x
if x isa Expr && x.head==:call && x.args[1]==:(..)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be written

if @capture(x, x_..y_)
    :(map(i->i.$y, x))
else 
    x
end

My MacroTools.jl foo isn't that strong so maybe I am wrong about this

Copy link
Member Author

Choose a reason for hiding this comment

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

It might well be, but my MacroTools.jl foo is almost non-existent and I know the current formulation works, so I'm tempted to just leave as is ;)

return :(map(i->i.$(x.args[3]),$(x.args[2])))
else
return x
end
end
end
end

function query_expression_translation_phase_B(qe)
Expand Down