C++ Parser Combinators

I’ve been a big fan of attoparsec for a long time now. Being able to construct parsers of all shapes and sizes in just a few lines has changed been a joy. But in many ways, it was a joy I shouldn’t have had…

A love of haskell is bitter sweet. I am not allowed to use it that much at work and am forced to use c++ and occasionally go. If I haddn’t experianced the elegance of haskell, I would not be so frustrated using these languages! I thought that parser combinator libraries were just one of those things that I would have to learn to live without, but upon reading parts of the changelog in C++20, I had an idea. Maybe I could bring some haskell joy to C++ by writing a functional parser combinator library?

And so I wrote one. I logged it as time spent on a new commandline parsing tool… which wasn’t a lie, but my boss did wonder why it took so long. By the end of the second day, I had a lovely generic command line parsing library, but also version 1 of my parsing combinator library. To pay my boss back for my slightly deceitful use of time, I then used the library to write two TCP servers based on two different TCP protocols in a single day! The speed of usage of this library cannot be underestimated once you see past the templatesand brackets.

6 months later, I have been allowed to publish it on the work github and you can find the repo here. I hope you enjoy using it and have an equally satisfying speed up at work or in your hobby projects!