Not sure if there's a better way of doing this, but then I serialise the AST into a JSON, #go's JSON encoder will encode the struct of each node, but I miss the 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.
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.