In this article we will be exploring what parser combinators are, what runtime parser generation is - why they’re useful, and then walking through a Zig implementation of them.
A parser parses some text to produce a result:
A parser combinator is a higher-order function which takes parsers as input and produces a new parser as output:

Let’s say we want to parse the syntax which describes a regular expression: a[bc].*abc
We can define some parsers to help us parse this syntax (e.g. into tokens or AST nodes):

Suppose that for a[bc].*abc :
RegexLiteralParser can parse a, b, and c, but not abc (the string.)RegexRangeOpenParser can parse [.RegexRangeCloseParser can parse ]RegexAnyParser can parse the . “any character” syntax.