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

**URL:** <https://forum.crystal-lang.org/t/what-would-it-take-to-be-able-to-pass-a-stream-of-ast-nodes-to-the-compiler-directly/1795>\
**Category:** Crystal Contrib\
**Created:** [March 6, 2020, 1:33am UTC](https://forum.crystal-lang.org/t/what-would-it-take-to-be-able-to-pass-a-stream-of-ast-nodes-to-the-compiler-directly/1795 "2020-03-06T01:33:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![scott](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/scott/32/948_2.png) [@scott](https://forum.crystal-lang.org/u/scott)\
**Post date:** [March 6, 2020, 1:33am UTC](https://forum.crystal-lang.org/t/what-would-it-take-to-be-able-to-pass-a-stream-of-ast-nodes-to-the-compiler-directly/1795/1 "2020-03-06T01:33:49Z")

</div>

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](https://github.com/elastic/ecs/blob/master/generated/ecs/ecs_nested.yml), 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.

---

<div class="post-metadata">

**Author:** ![scott](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/scott/32/948_2.png) [@scott](https://forum.crystal-lang.org/u/scott)\
**Post date:** [March 6, 2020, 2:06am UTC](https://forum.crystal-lang.org/t/what-would-it-take-to-be-able-to-pass-a-stream-of-ast-nodes-to-the-compiler-directly/1795/2 "2020-03-06T02:06:21Z")

</div>

Never mind, [#8836](https://github.com/crystal-lang/crystal/pull/8836) will solve this. Thank you so much @asterite

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/rogerdpack/32/117_2.png) [@rogerdpack](https://forum.crystal-lang.org/u/rogerdpack)\
**Post date:** [March 6, 2020, 4:25am UTC](https://forum.crystal-lang.org/t/what-would-it-take-to-be-able-to-pass-a-stream-of-ast-nodes-to-the-compiler-directly/1795/3 "2020-03-06T04:25:27Z")

</div>

You can pass “raw code” in FWIW: [Feature request: macro to pass code to command](https://forum.crystal-lang.org/t/feature-request-macro-to-pass-code-to-command/1698)

---

<div class="post-metadata">

**Author:** ![scott](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/scott/32/948_2.png) [@scott](https://forum.crystal-lang.org/u/scott)\
**Post date:** [August 14, 2020, 6:58pm UTC](https://forum.crystal-lang.org/t/what-would-it-take-to-be-able-to-pass-a-stream-of-ast-nodes-to-the-compiler-directly/1795/4 "2020-08-14T18:58:55Z")

</div>

Wow, thanks, I think that will do what I need!
