Text.Trifecta.Result

trifecta-1.5.2: A modern parser combinator library with convenient diagnostics

Copyright | (c) Edward Kmett 2011-2014
License | BSD3
Maintainer | ekmett@gmail.com
Stability | experimental
Portability | non-portable
Safe Haskell | None
Language | Haskell2010

Text.Trifecta.Result

Contents

- Parse Results
- Parsing Errors

Description

Results and Parse Errors

Synopsis

- data Result a
  - = Success a
  - | Failure Doc
- class AsResult s t a b | s -> a, t -> b, s b -> t, t a -> s where
  - _Result :: Prism s t (Result a) (Result b)
- _Success :: AsResult s t a b => Prism s t a b
- _Failure :: AsResult s s a a => Prism' s Doc
- data Err = Err {
  - _reason :: Maybe Doc
  - _footnotes :: [Doc]
  - _expected :: Set String
  }
- class HasErr c where
  - err :: Lens' c Err
  - expected :: Lens' c (Set String)
  - footnotes :: Lens' c [Doc]
  - reason :: Lens' c (Maybe Doc)
- class Errable m where
  - raiseErr :: Err -> m a
- explain :: Rendering -> Err -> Doc
- failed :: String -> Err

# Parse Results

data Result a

The result of parsing. Either we succeeded or something went wrong.

Constructors

Success a |
Failure Doc |

Instances

Functor Result |
Applicative Result |
Foldable Result |
Traversable Result |
Alternative Result |
Show a => Show (Result a) |
Show a => Pretty (Result a) |
AsResult (Result a) (Result b) a b |

class AsResult s t a b | s -> a, t -> b, s b -> t, t a -> s where

A `Prism` that lets you embed or retrieve a `Result` in a potentially larger type.

Minimal complete definition

Nothing

Methods

_Result :: Prism s t (Result a) (Result b)

Instances

AsResult (Result a) (Result b) a b |

_Success :: AsResult s t a b => Prism s t a b

The `Prism` for the `Success` constructor of `Result`

_Failure :: AsResult s s a a => Prism' s Doc

The `Prism` for the `Failure` constructor of `Result`

# Parsing Errors

data Err

This is used to report an error. What went wrong, some supplemental docs and a set of things expected at the current location. This does not, however, include the actual location.

Constructors

Err |
Fields _reason :: Maybe Doc _footnotes :: [Doc] _expected :: Set String

Instances

Monoid Err |
Semigroup Err |
HasErr Err |

class HasErr c where

Minimal complete definition

err

Methods

err :: Lens' c Err

expected :: Lens' c (Set String)

footnotes :: Lens' c [Doc]

reason :: Lens' c (Maybe Doc)

Instances

HasErr Err |

class Errable m where

Methods

raiseErr :: Err -> m a

Instances

Errable Parser |

explain :: Rendering -> Err -> Doc

Convert a location and an `Err` into a `Doc`

failed :: String -> Err

Generate a simple `Err` word-wrapping the supplied message.