006: elm/parser

May 25, 2020 1:04:49 62.43 MB Downloads: 0

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