Created
February 13, 2015 18:10
-
-
Save rozap/23bb214eb0eaaf543a96 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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