How to use a macro to define a class hash constant?

Hi all, I struggle to use a macro to define a class hash constant

Can’t get it to compile : unexpected token “=>”

The code is here : Carcin

I think you need a {% begin %} ... {% end %} around the constant. AFAIK macros can only generate fully parseable code, not fragments: Carcin

There is a section in the documentation about it somewhere.

Thanks !!

But am I missing something, because I was not aware of the {% begin %} {% end %}
I can’t see it mentionned in Macros - Crystal

Its at the bottom of the page under “Pitfalls” with a case-statement as an example.

I don’t understand the meaning of this begin/end block. I mean, seems to be mandatory because my macro is outside of a macro definition, but what this block does ?

It basically tells the compiler that all the expanded code of its body belongs together.
Without {% begin %}...{% end %} the compiler would expect the expansion of the for loop to be valid code. But it needs the surrounding literal to be valid, and that’s why you need to declare that.