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* Backtrackable parsers
* chompIf and chompWhile
* Parser.oneOf
Benchmarking* elm-explorations/benchmark
* Benchmark before making assumptions about where performance bottlenecks are
* Write unit tests for your parser
* GFM table parsing live stream
* Parser.succeed
Elm regex vs elm parserIndications that you might be better off with parser
Getting source code locations* Parser.getRow and getCol
* Parser.getSource
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* You can fail with Parser.problem * Parser.Advanced module is designed to give you more precise context and error messages on failure * Parser.Advanced.inContext
Getting Started with a Parser Project* Write lots of unit tests with elm-test!
There's likely a specification doc if you're parsing a language or formal syntax
Look at examples of parser projects
dillonkearns/elm-markdownelm-in-elm parsermdgriffith/elm-markup - good reference for parsing, fault-tolerant parsing, and giving nice error messagesLook at elm/parser docs and resources