r/Compilers • • 2d ago

What Makes PEG Unparsing Difficult?

https://blog.wybxc.cc/blog/peg-unparse/
22 Upvotes

4 comments sorted by

1

u/Discordbothost 1d ago

Start a prototype's test corpus with ASTs obtained by parsing valid inputs, then unparse and reparse them. That keeps unsupported ASTs from being mistaken for composition bugs. Shrinking failing inputs while preserving the round-trip failure could help isolate missing construction conditions.

1

u/Sad-Grocery-1570 18h ago

I agree that's a good and practicable approach for testing an unparser. However, the problem I'm interested in is slightly different. Rather than how to implement an unparser for a particular grammar, I'm interested in how to systematically derive an unparser from a grammar in the first place, like what a parser-generator does, but in an inverted direction.

Starting with parser-generated ASTs ensures that the unparsing problem has a solution, but the question is how to derive a construction strategy from the grammar itself, preferably in a compositional way. The difficulty of doing so is what motivates the distinction between verification and construction in the article.

1

u/realestLink 2d ago

Interesting!

1

u/realestLink 2d ago

This whole blog looks awesome. Lots of other really interesting articles 👀