When we last left our hero we had built enough of a recursive descent parser to be able to parse Lisp's S-expressions. In this post I want to show you what I've added to the framework since then. This includes some useful building blocks, including the regexleaf parser; and a demonstration of how easy it is to create a JSON parser with the framework.

I am writing a simple parser framework in Swift; mostly as a learning exercise. Specifically, I am writing a recursive descent parser. Having never been a fan of the traditional lex/yacc parser generators I first came across recursive descent in the Boost Spirit C++ library. Since then, the framework I have used most is FParsecfor F#1. What I'm doing here borrows heavily from FParsec.

The thing I want to talk about is something that, in Swift, is called associated values. Each label can have a different datatype associated with it, which can be bound and matched against within the switch statement. This makes enum a discriminated union. Discriminated unions and pattern matching on them is something to which functional programming languages owe a great deal of their power.

Posts About Swift

Swift is a new language from Apple. At first glance there's a lot to like about this, so I thought I'd spend some time learning it. These are some blog posts about things that come up as I figure things out!