Skip to content

Instantly share code, notes, and snippets.

@josevalim
Created Aug 17, 2014
Embed
What would you like to do?
defmodule Parsec do
# Handles parsec for ..., do: ...
defmacro parsec({:for, _, args}) do
{exprs, [[do: return]]} = Enum.split(args, -1)
do_parsec(exprs, return)
end
# Handles parsec for ... do ... end
defmacro parsec({:for, _, args}, do: return) do
do_parsec(args, return)
end
defp do_parsec(exprs, return) do
IO.inspect {exprs, return}
end
end
defmodule Run do
import Parsec
parsec for 1 < 2, do: :ok
parsec for 1 < 2 do
:ok
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment