Welcome to the companion Github repository for our Parsing series on the Monday Morning Haskell blog! In this series, we explore a few different libraries for parsing strings into Haskell data structures.
Our overarching example for this series is Gherkin Syntax. This is a special syntax that allows us to describe a set of test behaviors for our program. We have a few example files you can observe in this directory that are written in Gerkhin syntax. Our main objective in this series is to parse each of these files into the Haskell data types described in this module.
The examples all relate to a fake "banking" application. So you can also observe the expected results in these files:
We use these files as the expected output for some unit tests.
To run the code, you just have to start by building it:
>> stack build
We try three different parsing libraries: Applicative Regex Parsing, Attoparsec, and Megaparsec. There's a test suite corresponding to each of these libraries:
>> stack build Parsing:test:regex-tests
>> stack build Parsing:test:atto-tests
>> stack build Parsing:test:mega-tests
For the 3 primary articles in the series, you can follow along with the code examples and try making changes. You can run the tests to see if you still get the correct results. Just take a look at the proper source module:
There are a few different ways you can extend this repository if you want to do some of your own practicing with these libraries. Here are a couple ideas:
- Try extending one or more of the parsers so it can handle more features of Gherkin syntax. Remember to use test driven development!
- Make use of the Haskell data structures in some way. Run some code based on what you've parsed! For example, in Cucumber, each feature test can be used to perform test assertions.