PLAY PODCASTS
006: elm/parser
Episode 6

006: elm/parser

We discuss parsers, how to build them in Elm, and how to try to make your error messages as nice as Elm's.

Elm Radio

May 25, 20201h 4m

Audio is streamed directly from the publisher (cdn.simplecast.com) as published in their RSS feed. Play Podcasts does not host this file. Rights-holders can request removal through the copyright & takedown page.

Show Notes

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)

Comitting

Benchmarking

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

Parser.loop

  • 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