Wrapping Up

We covered an awful lot in this chapter, and it’s worth digesting. We first looked at StringScanner, which gave us a way to step through a string while keeping track of our position. This allowed us to implement relatively simple parsers that were an improvement on large and complex regular expressions.

Then we tried out writing more formal grammars, describing the rules of languages and having a library—in this case, Parslet—generate the parsing code for us. We looked first at a simple example, parsing a config file, before moving onto something much more complex—parsing RTF files. We looked at how to write transformations that took the tree generated by a parser and transformed it into a different format.

Next, we’ll look at an ...

Get Text Processing with Ruby now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.