The Crystal Programming Language Forum

What would it take to be able to pass a stream of AST nodes to the compiler directly?

If there were some defined way to pass a stream of AST directly to the compiler, or have a kind of macro which can modify AST nodes directly, it would be very convenient for me. I’ve looked into doing this as things are now, and it looks like conceptually it could work, but those methods are protected, and I’m assuming for a reason – someone (like me) who doesn’t know how the compiler works shouldn’t be messing with it.

My use-case is building libraries which ingest a configuration file and output a crystal program. For example, I’ve started to write a library that ingests the elastic common schema, and would generate another library which would simplify structured logging in crystal. As it stands now, it seems that my best option is to use ecr, but I’d rather avoid the serialization/deserialization headaches of converting to text-based code and then back into a data structure when I could just transform from one data structure to the other.

I would be open to helping to implement this feature, but the compiler is a large, complicated, and undocumented piece of software and I feel that I could at least use some guidance on how it could/should be done.

Never mind, #8836 will solve this. Thank you so much @asterite

You can pass “raw code” in FWIW: Feature request: macro to pass code to command