Introducing KotZen — a parser-combinator for kotlin

Nick Lydon
2 min readJan 7, 2022

I’ve long been enamored with parser-combinator libraries, such as Sprache. In fact I’ve managed to use them in professional and personal projects on several occasions now.

The first was at a brokerage firm, where traders would write quotes in a specific shorthand to customers, which was very terse in order to save time and energy. The second was whilst rewriting a mini DSL embedded in XML templates, which were then turned into PDFs to be used for things like customer invoices and package labels. The third time I used it to parse assembly files and output binary as part of the wonderful nand2tetris course.

Wanting to broaden my horizon, I thought I should learn a bit about kotlin. The language is nice enough — it reminds me strongly of C#, the language I’m most familiar with. It also has the benefit of being on the JVM, so one could potentially look for java/scala jobs too.

I’ve had this in the back of my mind for several years now:

Sprache was originally written by Nicholas Blumhardt and grew out of some exercises in Hutton’s Haskell book.

I wondered to myself if I could kill three birds with one stone and learn about Haskell, parser-combinators and kotlin at the same time. The result is KotZen! It’s an open-source parser-combinator library written in kotlin, published on github with unit tests, documentation, and examples of how to use it. Here’s the json parser from the readme:

Code for a json parser written using the KotZen library

I’ll write another post explaining the individual components and how they build upon one another. Edit: here’s the followup

--

--

Nick Lydon

British software developer working as a freelancer in Berlin. Mainly dotnet, but happy to try new things! https://github.com/NickLydon