How i can use temporary variables in macros for building code in the Crystal Lang. For examle, i have:
module Rule
macro included
{% rules = [] of TypeDeclaration %}
macro rule(declaration)
raise("Should be TypeDeclaration") unless \{{declaration.is_a?(TypeDeclaration)}}
\{% {{rules}} << declaration %}
end
macro finished
\{% for declaration in rules %}
puts \{{declaration}}
\{% end %}
end
end
end
class StringRule
include Rule
rule min : Int32 = 0
rule max : Int32 = 255
end
And i have compile error
> 6 | {% [] << declaration %}
^
Error: for empty arrays use '[] of ElementType'
I need store all rules for reusing it in a hook finished. Is it posible?