Skip to content

Instantly share code, notes, and snippets.

@rozap
Created February 13, 2015 18:10
Show Gist options
  • Select an option

  • Save rozap/23bb214eb0eaaf543a96 to your computer and use it in GitHub Desktop.

Select an option

Save rozap/23bb214eb0eaaf543a96 to your computer and use it in GitHub Desktop.
defmodule Foo do
defp make_guard(:any), do: true
defp make_guard(token) do
quote do
head == token
end
end
defmacro fast_forward(until, mode, body) do
guard = make_guard(until)
quote bind_quoted: [
mode: mode,
body: Macro.escape(body, unquote: true),
guard: Macro.escape(guard, unquote: true)
] do
def ff(<<head::binary-size(1), rest::binary>>, mode) when unquote(guard) do
unquote(body[:do])
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment