Skip to content

Instantly share code, notes, and snippets.

@Ragmaanir
Created March 28, 2016 22:35
Show Gist options
  • Save Ragmaanir/2a8f292bf3d76b2f0ee2 to your computer and use it in GitHub Desktop.
Save Ragmaanir/2a8f292bf3d76b2f0ee2 to your computer and use it in GitHub Desktop.
# flatten a tuple literal
macro flatten_tuple(t)
{%
queue = [] of ASTNode
res = [] of ASTNode
%}
{% for e in t %}
{% queue << e %}
{% end %}
{% for e in queue %}
{% if e.class_name == "TupleLiteral" %}
{% for n in e %}
{% queue << n %}
{% end %}
{% else %}
{% res << e %}
{% end %}
{% end %}
{ {{*res}} }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment