Parser Combinators

Parsing is the act of taking less structured input like text, and turning it into more structured data, like objects.

Many of you will be familiar with using regex to parse text, and some of you might know about tree-sitter, a heavy-duty parsing library which powers the syntax highlighting in your code editor.

But regex gets messy on complex tasks, and tree-sitter often is overkill — for this middle ground, parser combinators are perfect. Not many people know about them, so allow me to show you!

The partial parser

The smallest unit of parsing we’ll be looking at is the partial parser. It gets to decide where to cut the input string, and then it returns a tuple consisting of whatever and the rest of the string.