Today's post isn't specifically about games, but about parsing, which I find is a recurring task in many programming tasks.
In F#, the most popular methods for writing parsers are FParsec and fslex/fsyacc. Although parser generators are very useful, I'm always a bit reluctant to depend on third-party software.
In the past I have worked on a development tool for safety-critical systems, which was itself subject to some of the limitations of software for safety-critical systems. In particular, the use of lex and yacc was not accepted.
I fell back on a technique suitable for hand-written parsers,
namely recursive descent parsers. I was positively surprised by the inherent simplicity of the method and the clarity of code that resulted.
I was first exposed to the idea of using active patterns for parsing when I read a blog post
by Jon Harrop.
Active patterns is a feature specific to F#, and the F# wikibook has a chapter
dedicated to them. I'll be using parameterized partial active patterns.
We start by defining a type for the input. The integer denotes the number of lines read so far, the list of strings is the...(Read whole news on source site)