prim-parser is a total parser combinator library for Lean 4 that uses a graded monad. This blog post describes the library in detail, presents examples and compares it to similar libraries.
PrimParser/: library code.Examples/: example parsers.Tests/:#guard-based compile-time tests.
lake build # build the library
lake build Tests # run the testsSome people have asked why should this library depend on Mathlib. For the following reasons, I think it makes sense to keep it as a dependency:
- It doesn't slow down CI. We use
leanprover/lean-action, which downloads Mathlib prebuilt, so CI still runs in reasonable time (in about 2 minutes at the time of writing this). Latticelemmas. Grades combine with⊔and⊓, and thegrade_byproofs often rely on Mathlib's lattice lemmas.Monoidis used inLawfulGradedMonad,LawfulGradedApplicative,LawfulGradedFunctor.List.Vectoris used for the fixed-count combinators, likesepByN.
If there is an elegant way to drop the Mathlib dependency without sacrificing usability and compatibility, I'd be happy to adapt.