Here is a program written in Standard ML containing at its heart four small functions. These functions can be combined in a way that corresponds to specifying a regular-expression pattern.

The source linked to above includes an illustration of how to use the combinators to build a pattern-matching function for C's floating-point numbers. Specifically, it implements:


I've added a lot of explanatory comments, but it's worth noting that without them, the entire thing fits on a single page. Although I came up with this technique on my own and originally didn't know the technique had a name, I was later informed that it is an example of parser combinators. I'm calling this particular manifestation lexer combinators because in this case that term seems more accurate.