Pretty Printing and Parsing

Pretty Printing and Parsing

Reversible parsing is a technique that lets you write a parser that can also be used to encode data. This is particularly useful when you want to impelement parsing for files like json, XML, or our own FilePack format. A common use for reversible parsing is to implement a “pretty printing” tool that will let users re-format a document so that it’s more readable.

Using what you’ve learned in this chapter, try to implement a parser for a simple plain text format, and then make the parser reversible. Your reversible parser should reformat the original input so that it’s easier to read.

Hint 1

Some high level hint text

Hint 2

Some more detailed hint text

Hint 3

Even more detailed hint text

Solution

A complete solution for the exercise