Text Parsing the Case for Monads
summary
Compares two concrete Python parser libraries: pyparsing (2001) and a Python port of Parsec, showing identical CSV parsers where pyparsing gives a richer result object and Parsec requires manual trimming but is terser. Implements a counted-field parser that fails early and a CSV builder that returns nested lists. Demonstrates parser combinators implemented as functions/classes and a generator decorator that turns a generator yielding parsers into a single parser, binding intermediate results and short‑circuiting on failures. Notes monads (Either/Maybe) power the bind semantics.
AI-written summary · about
chapters (11)
- 0:00Introduction
- 1:04Text parsing overview
- 2:21Limitations of Yacc
- 4:33Parsing libraries in Python
- 7:24Comparing parsing methods
- 8:57Combinator design pattern
- 10:12Implementing combinators
- 13:11Understanding monads
- 18:55Monadic parsing logic
- 21:35Generator-based parsing
- 24:01Conclusion and history
related talks
41mMonadic Parsers at the Input Boundary
32mMonads, in my Python?
53mUnderstanding parser combinators: a deep dive
42mMonoidal Parsing
58mMonoids, Monads, and Applicative Functors: Repeated Software Patterns
43mctparse: a practical parser for natural language time expressions...
28mSimplifying Python Code through the Lens of Functional Programming
44mPretty Parsing
