feat(pp): pretty print implementation draft#351
Conversation
Compiles without warnings
I think
Round-tripping between pretty-printing and parsing (CST -> text -> same CST) is a good way to gain confidence in the printer, but it might be kind of arduous to write. I'll be pragmatic and say that checking some specific input-output (cst, text) pairs is good enough. We can add regression tests if we find any bugs.
I think we could use it in the
You mean limiting the number of columns per line of code? It's famously pretty difficult. There is a famous paper by Philip Wadler outlining a pretty decent and simple approach. Tbh I am happy with the printer in this PR (no column limit), but if you want to add that, a separate PR would be welcome. |
- not using curly braces introduced null pointer reads - not using const made the linker fail
Now it looks a lot more like source code. There seems to be a context issue tho... I may not be able to tell ahead of time where to write braces, endlines and the like. I also seem to have issues with printing tokens or interned strings. A main pain point is that if statements can have either blocks or other statements inside of them and I should check for blocks, because these are used elsewhere (where they should end in semicolon) but not here. I may have made a mess here.
|
Keep in mind I've removed the overloaded |
Compiles without warnings for now...
I will draft this because I need some suggestions:
pretty_printfunction?Closes #136.
Progress so far (basic_op.jp)
I've made incredible progress but seem to run into a couple of problems. First I get this weird addresses, I get them only in some cases I think I can figure each one out with time. Secondly (and I might need a hand with this) is that I can't find a way to output tabs + braces + endlines + semicolons in a way that satisfies all cases. This is due to the fact that
Blockexists I think, and that it sometimes is a child of an if statement and sometimes it is not. Should I just add context to the block printing? Wonder what your thoughts are... By all means test it yourself if you'd like...