To clarify, in this case AST means a node structure where everything is a string rather than a type right? If so, that seems easy to generate from the parse tree, just give every type in the tree a "tostring" method and call that recursively to get the whole tree and return the result. I wonder if we could implement whatever AST features we want selectively this way without supporting a full conversion to AST:
- Given a node of any type in the parse tree, create AST subtree
- Apply syntactic sugar to the AST subtree
- Convert back to Parse Tree - maybe it would even be possible to convert the AST to code and parse it starting from whatever step the original parser was at. If the types of the parse tree nodes don't work out and we can't parse as a result, we know there's an error
Maybe this would be easier to implement than doing a full conversion to an AST, doing transforms, and then creating an IR. Additionally I think this would provide a good opportunity to catch any errors in the transforms applied to the AST.