HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Modulepolyparse-1.13.1Haskell2010

Text.ParserCombinators.HuttonMeijerWallace

This library of monadic parser combinators is based on the ones defined by Graham Hutton and Erik Meijer. It has been extended by Malcolm Wallace to use an abstract token type (no longer just a string) as input, and to incorporate state in the monad, useful for symbol tables, macros, and so on. Basic facilities for error reporting have also been added, and later extended by Graham Klyne to return the errors through an Either type, rather than just calling error.

Contents
  1. The parser monad
  2. Primitive parser combinators
  3. Derived combinators
  4. Error handling
  5. State handling
  6. Re-parsing
Synopsis
  • Packagepolyparse-1.13.1
  • Exports24
  • LanguageHaskell2010
  • LicenceLicenseRef-LGPL
  • SourceHuttonMeijerWallace.hs

The parser monad

newtypenewtype Parser s t e a
#

Constructors

  • P (s -> [Either e t] -> ParseResult s t e a)

    The parser type is parametrised on the types of the state s, the input tokens t, error-type e, and the result value a. The state and remaining input are threaded through the monad.

Instances6Monad, Functor, MonadFail, Applicative, Alternative, MonadPlus
  • Monad (Parser s t e)Defined in polyparse-1.13.1 · Text.ParserCombinators.HuttonMeijerWallace
  • Functor (Parser s t e)Defined in polyparse-1.13.1 · Text.ParserCombinators.HuttonMeijerWallace
  • MonadFail (Parser s t e)Defined in polyparse-1.13.1 · Text.ParserCombinators.HuttonMeijerWallace
  • Applicative (Parser s t e)Defined in polyparse-1.13.1 · Text.ParserCombinators.HuttonMeijerWallace
  • Alternative (Parser s t e)Defined in polyparse-1.13.1 · Text.ParserCombinators.HuttonMeijerWallace
  • MonadPlus (Parser s t e)Defined in polyparse-1.13.1 · Text.ParserCombinators.HuttonMeijerWallace

Primitive parser combinators

valuepapply
  1. :: Parser s t String a
  2. -> s
  3. -> [Either String t]
  4. -> [(a, s, [Either String t])]

Apply the parser to some real input, given an initial state value. If the parser fails, raise error to halt the program. (This is the original exported behaviour - to allow the caller to deal with the error differently, see papply'.)

valuepapply'
  1. :: Parser s t e a
  2. -> s
  3. -> [Either e t]
  4. -> Either e [(a, s, [Either e t])]

Apply the parser to some real input, given an initial state value. If the parser fails, return a diagnostic message to the caller.

Derived combinators

valuetok :: Eq t => t -> Parser s (p, t) e t

Deliver the first token if it equals the argument.

valuenottok :: Eq t => [t] -> Parser s (p, t) e t

Deliver the first token if it does not equal the argument.

Error handling

State handling

Re-parsing

valuereparse :: [Either e t] -> Parser s t e ()

This is useful for recursively expanding macros. When the user-parser recognises a macro use, it can lookup the macro expansion from the parse state, lex it, and then stuff the lexed expansion back down into the parser.