Parse and validate a small language in Haskell
8 steps · about 4 h · Intermediate
- Compose independent parser choices (reference, Hackage, 30 min)
Learn the applicative structure used to combine tokens and alternatives.
- Remove partial optional handling (reference, Hackage, 20 min)
Represent optional syntax explicitly instead of relying on sentinel values.
- Carry typed validation failures (reference, Hackage, 25 min)
Keep accepted values and explanatory errors in one total result type.
- Prepare line and token sequences (reference, Hackage, 25 min)
Use total list transformations around the parser boundary.
- Define the grammar with Parsec (reference, Hackage, 45 min)
Turn the language rules into a parser that tracks position and expectation.
- Handle repetition and alternatives (reference, Hackage, 35 min)
Parse lists, separators and optional clauses without manual cursor state.
- Keep file effects at the edge (reference, Hackage, 25 min)
Read input and print results outside the pure parse-and-validate core.
- Test success and error locations (reference, Hackage, 35 min)
Verify valid programs, malformed tokens and semantic rejection independently.