circuits-parser
Safe HaskellNone
LanguageGHC2024

Circuit.Parser.Examples

Description

Example instantiations of the unified parser over different base monads.

The primitives in Circuit.Parser are polymorphic in the base monad m. This module shows how to run the same parser syntax under two different interpretations:

  • Identity — attoparsec-style pure parser
  • StateT st (ExceptT e n) — megaparsec-style state + errors
Synopsis

Runners

runMega :: forall e st n f a. (Monad n, Uncons f Char) => Parser (StateT st (ExceptT e n)) f Char a -> f -> st -> n (Either e (These a f, st)) Source #

Megaparsec-style runner: stateful, error-aware.

The state st can hold offset, tab width, etc. Errors are returned via ExceptT e n.

Example parsers

abOrA :: forall (m :: Type -> Type) f. (Monad m, Uncons f Char) => Parser m f Char String Source #

A parser that accepts "ab" or "a".

Defined once, runnable under any base monad.