Parser Combinators
summary
A Haskell-style parser combinator library is implemented in PHP that models parsers as functions returning success or error plus remainder, with concrete combinators: partial combinators, sequence, append and either, and a map combinator to transform parsed values. The author builds a working JSON parser (~230-line implementation) and expression/calculator parsers, using a Result class for success/fail and recursive composition. It runs correctly (but is slower than native PHP parsers) and includes tests showing parsed values, remainders and error messages.
AI-written summary · about
chapters (12)
- 0:00Introduction and setup
- 1:04What is a parser?
- 5:42Defining a parser function
- 9:24Creating a generic parser
- 12:32Combining parsers with sequence
- 18:52Appending parsed values
- 23:08Parsing alternatives with either
- 26:40Mapping parsed results
- 33:47Building an AST with map
- 35:33Real-world parser combinator use
- 38:50Recursive parsing in practice
- 40:15Summary and Q&A
related talks
53mUnderstanding parser combinators: a deep dive
26mParser Combinators in Swift
01h 48mBoost.Parser (Part 2 of 2) - A Parser Combinator Library for C++
15mStaged Selective Parser Combinators
01h 27mBoost.Parser (Part 1 of 2) - A Parser Combinator Library for C++
25mModular grammar and parser for Haskell with extensions
58mParsing in C# from first principles
52mBuilding a parser in C#, from first principles
