symparsec: Type level string parser combinators

[ data, library, mit, types ] [ Propose Tags ] [ Report a vulnerability ]
Versions [RSS] 0.4.0, 1.0.0, 1.0.1, 1.1.0, 1.1.1, 2.0.0
Change log CHANGELOG.md
Dependencies base (>=4.18 && <5), defun-core (>=0.1 && <0.2), singleraeh (>=0.4.0 && <0.5), type-level-show (>=0.3.0 && <0.4) [details]
Tested with ghc ==9.12
License MIT
Author Ben Orchard
Maintainer Ben Orchard <thefirstmuffinman@gmail.com>
Category Types, Data
Home page https://github.com/raehik/symparsec#readme
Bug tracker https://github.com/raehik/symparsec/issues
Source repo head: git clone https://github.com/raehik/symparsec
Uploaded by raehik at 2025-10-11T16:23:28Z
Distributions LTSHaskell:1.1.1, NixOS:1.1.1, Stackage:1.1.1
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 233 total (9 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for symparsec-2.0.0

[back to package description]

Symparsec

Type level string parser combinators. A Parsec-like for Symbols; thus, Symparsec! With many of the features you'd expect:

  • define parsers compositionally, largely as you would on the term level
  • define complex parsers, including mutually recursive ones (e.g. expression parsers!)
  • pretty, detailed parse errors
  • good performance (probably? please help me benchmark!)

Requires GHC >= 9.6.

Examples

Define a type-level parser:

import Symparsec
import DeFun.Core
type PExample = Skip 1 *> Tuple (Isolate 2 NatHex) (Literal "_" *> TakeRest)

Use it to parse a type-level string (in a GHCi session):

ghci> :k! Run PExample "xFF_etc"
Run ...
= Right '( '(255, "etc"), "")

See the Symparsec.Example namespace for further examples.

Why?

Via GHC.Generics, we may inspect Haskell data types on the type level. Constructor names are Symbols. Ever reify these, then perform some sort of checking or parsing on the term level? Symparsec does the parsing on the type level instead. Catch bugs earlier, get faster runtime.

Also type-level Haskell authors deserve fun libraries too!!

Limitations

Symparsec defines a lot of low-level parsers you would expect on the term level, even monadic (bind) and applicative (ap) parser combinators. The key limitation Symparsec grapples with is Haskell having no type-level binders. This means:

  • no lets, no wheres
  • no do notation

The workaround is writing extra functions, and writing uglier functions. Otherwise, I believe an average term-level Parsec-like parser should look comparable to a type-level Symparsec one.

Writing complex type-level Haskell programs in 2025 is unintuitive. I intend to provide guides on writing Symparsec parsers that walk through type-level programming design patterns and solutions. Please ping me on the issues tab if you read this, and can't find any such guides!

Contributing

I would gladly accept further combinators or other suggestions. Please add an issue or pull request, or contact me via email or whatever (I'm raehik everywhere).

License

Provided under the MIT license. See LICENSE for license text.