Not sure if there's a better way of doing this, but then I serialise the AST into a JSON, 's JSON encoder will encode the struct of each node, but I miss the type.

I want to include the node type.

So what I came up with is a Marshaller for each top level node type, that wraps in a "node" struct (type string and object any), and local type to avoid an infinite loop.

This works fine, but not sure if there's a better way of doing it.

Providing the MarshalJSON for each node isn't terrible.

For now this is fine. The JSON is readable and it works fine when I want to check something in the AST. So WIN! 🎉

Sign in to participate in the conversation
Mastodon @ SDF

"I appreciate SDF but it's a general-purpose server and the name doesn't make it obvious that it's about art." - Eugen Rochko