What is a parser?

  • yacc/lex
  • AST (Abstract Syntax Tree) vs. CST (Concrete Syntax Tree)
  • JSON decoding vs. parsing
  • JSON decoding is validating a data structure that has already been parsed. Assumes a valid structure.
  • elm/parser
  • Haskell parsec library - initially used for the Elm compiler, now uses custom parser

What is a parser?

  • One character at a time
  • Takes input string, turns it into structued data (or error)



Elm regex vs elm parser

Indications that you might be better off with parser

  • Lots of regex capture groups
  • Want very precise error messages

Getting source code locations


  • Loop docs in elm/parser
  • Looping allows you to track state and parse groups of expressions
  • Loop over repeated expression type, tell it termination condition with Step type (Loop and Done)

Error Messages

Getting Started with a Parser Project

There's likely a specification doc if you're parsing a language or formal syntax

Look at examples of parser projects

Look at elm/parser docs and resources