Skip to content

Commit

Permalink
Work around for change to Elixir 1.7's handling of macro expansion of…
Browse files Browse the repository at this point in the history
… and.
  • Loading branch information
noizu committed Nov 20, 2018
1 parent ff8446c commit ef0d0c6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/deps
/doc
erl_crash.dump
/.idea
29 changes: 18 additions & 11 deletions lib/exquisite.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
#
# 0. You just DO WHAT THE FUCK YOU WANT TO.

defmodule Exquisite do
def x &&& y do
x && y
end

def x ||| y do
x || y
end

@type spec :: :ets.match_spec | :ets.compiled_match_spec

@spec run(spec, tuple | [tuple]) :: { :ok, term } | { :error, term }
Expand Down Expand Up @@ -240,12 +247,12 @@ defmodule Exquisite do
end

# and, gets converted to andalso
defp internal({ op, _, [left, right] }, table, caller) when op in [:and, :andalso] do
defp internal({ op, _, [left, right] }, table, caller) when op in [:and, :andalso, :&&&] do
{ :andalso, internal(left, table, caller), internal(right, table, caller) }
end

# or, gets converted to orelse
defp internal({ op, _, [left, right] }, table, caller) when op in [:or, :orelse] do
defp internal({ op, _, [left, right] }, table, caller) when op in [:or, :orelse, :|||] do
{ :orelse, internal(left, table, caller), internal(right, table, caller) }
end

Expand Down Expand Up @@ -321,7 +328,7 @@ defmodule Exquisite do

@function [ :is_atom, :is_float, :is_integer, :is_list, :is_number,
:is_pid, :is_port, :is_reference, :is_tuple, :is_binary ]
defp internal({ name, _, [ref] } = whole, table, caller) when name in @function do
defp internal({ name, _, [ref] } = whole, table, _caller) when name in @function do
if id = identify(ref, table) do
{ name, id }
else
Expand All @@ -330,7 +337,7 @@ defmodule Exquisite do
end

# is_record(id, name)
defp internal({ :is_record, _, [ref, name] } = whole, table, caller) do
defp internal({ :is_record, _, [ref, name] } = whole, table, _caller) do
if id = identify(ref, table) do
{ :is_record, id, name }
else
Expand All @@ -339,7 +346,7 @@ defmodule Exquisite do
end

# is_record(id, name, size)
defp internal({ :is_record, _, [ref, name, size] } = whole, table, caller) do
defp internal({ :is_record, _, [ref, name, size] } = whole, table, _caller) do
if id = identify(ref, table) do
{ :is_record, id, name, size }
else
Expand All @@ -348,7 +355,7 @@ defmodule Exquisite do
end

# elem(id, index)
defp internal({ :elem, _, [ref, index] } = whole, table, caller) do
defp internal({ :elem, _, [ref, index] } = whole, table, _caller) do
if id = identify(ref, table) do
{ :element, index + 1, id }
else
Expand All @@ -357,7 +364,7 @@ defmodule Exquisite do
end

@function [ :abs, :hd, :length, :round, :tl, :trunc ]
defp internal({ name, _, [ref] } = whole, table, caller) when name in @function do
defp internal({ name, _, [ref] } = whole, table, _caller) when name in @function do
if id = identify(ref, table) do
{ name, id }
else
Expand All @@ -366,7 +373,7 @@ defmodule Exquisite do
end

# bnot foo
defp internal({ :bnot, _, [ref] } = whole, table, caller) do
defp internal({ :bnot, _, [ref] } = whole, table, _caller) do
if id = identify(ref, table) do
{ :bnot, id }
else
Expand All @@ -385,7 +392,7 @@ defmodule Exquisite do
end

# foo.bar
defp internal({{ :., _, _ }, _, _ } = whole, table, caller) do
defp internal({{ :., _, _ }, _, _ } = whole, table, _caller) do
if id = identify(whole, table) do
id
else
Expand All @@ -404,7 +411,7 @@ defmodule Exquisite do
end

# foo
defp internal({ ref, _, _ } = whole, table, caller) do
defp internal({ ref, _, _ } = whole, table, _caller) do
if id = identify(ref, table) do
id
else
Expand Down
2 changes: 1 addition & 1 deletion test/exquisite_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ defmodule ExquisiteTest do
to = {{2013,2,2},{1,1,1}}

s = Exquisite.match { a, b },
where: a >= from and b <= to,
where: a >= from &&& b <= to,
select: 2

assert Exquisite.run!(s, { from, to }) == 2
Expand Down

0 comments on commit ef0d0c6

Please sign in to comment.