reverse AST to source
BebeSparkelSparkel opened this issue · 3 comments
In the Parsing you stated “This means our original source is fully represented in this tree, and can be printed back out exactly.”
How do you get this to print back to source? I see no implementation for that.
Would you consider a biparsing solution similar to the one outlined in https://github.com/BebeSparkelSparkel/biparsing/blob/master/papers/1902.06950.pdf ?
You'd do the same thing we do for the PureScript compiler here: https://github.com/purescript/purescript/blob/781e9401f78c1f1d0b33643809048c63922db85a/lib/purescript-cst/src/Language/PureScript/CST/Flatten.hs
All source tokens are represented in the CST, so you collect all of them and then print the tokens concatenating the result.
@kritzcreek is correct. This could use additional documentation.
- Lexing:
String -> List Token - Parsing:
List Token -> CST
Reprinting would mean lowering down CST -> List Token and then List Token -> String.
It is a goal of this project to use very straightforward and understandable techniques. I appreciate the flexibility of more exotic methods, but I do not think they serve the pedagogical goals of this project.
@kritzcreek Thanks for the link that helps.
@natefaubion simplicity is good.