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

Copyright | (c) Edward Kmett 2011-2019
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 ErrInfo
- 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)
- foldResult :: (ErrInfo -> b) -> (a -> b) -> Result a -> b
- _Success :: AsResult s t a b => Prism s t a b
- _Failure :: AsResult s s a a => Prism' s ErrInfo
- data Err = Err {
  - _reason :: Maybe (Doc AnsiStyle)
  - _footnotes :: [Doc AnsiStyle]
  - _expected :: Set String
  - _finalDeltas :: [Delta]
  }
- class HasErr c where
  - err :: Lens' c Err
  - expected :: Lens' c (Set String)
  - finalDeltas :: Lens' c [Delta]
  - footnotes :: Lens' c [Doc AnsiStyle]
  - reason :: Lens' c (Maybe (Doc AnsiStyle))
- class Errable (m :: Type -> Type) where
  - raiseErr :: Err -> m a
- data ErrInfo = ErrInfo {
  - _errDoc :: Doc AnsiStyle
  - _errDeltas :: [Delta]
  }
- explain :: Rendering -> Err -> Doc AnsiStyle
- failed :: String -> Err

# Parse Results

data Result a Source #

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

Constructors

Success a |
Failure ErrInfo |

#### Instances

Instances details

Alternative Result Source # |
Instance details Defined in Text.Trifecta.Result Methods empty :: Result a Source # (<|>) :: Result a -> Result a -> Result a Source # some :: Result a -> Result [a] Source # many :: Result a -> Result [a] Source #
Applicative Result Source # |
Instance details Defined in Text.Trifecta.Result Methods pure :: a -> Result a Source # (<*>) :: Result (a -> b) -> Result a -> Result b Source # liftA2 :: (a -> b -> c) -> Result a -> Result b -> Result c Source # (*>) :: Result a -> Result b -> Result b Source # (<*) :: Result a -> Result b -> Result a Source #
Functor Result Source # |
Instance details Defined in Text.Trifecta.Result Methods fmap :: (a -> b) -> Result a -> Result b Source # (<$) :: a -> Result b -> Result a Source #
Monad Result Source # |
Instance details Defined in Text.Trifecta.Result Methods (>>=) :: Result a -> (a -> Result b) -> Result b Source # (>>) :: Result a -> Result b -> Result b Source # return :: a -> Result a Source #
Foldable Result Source # |

Instance details

Defined in Text.Trifecta.Result

Methods

fold :: Monoid m => Result m -> m Source #

foldMap :: Monoid m => (a -> m) -> Result a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Result a -> m Source #

foldr :: (a -> b -> b) -> b -> Result a -> b Source #

foldr' :: (a -> b -> b) -> b -> Result a -> b Source #

foldl :: (b -> a -> b) -> b -> Result a -> b Source #

foldl' :: (b -> a -> b) -> b -> Result a -> b Source #

foldr1 :: (a -> a -> a) -> Result a -> a Source #

foldl1 :: (a -> a -> a) -> Result a -> a Source #

toList :: Result a -> [a] Source #

null :: Result a -> Bool Source #

length :: Result a -> Int Source #

elem :: Eq a => a -> Result a -> Bool Source #

maximum :: Ord a => Result a -> a Source #

minimum :: Ord a => Result a -> a Source #

sum :: Num a => Result a -> a Source #

product :: Num a => Result a -> a Source #

Traversable Result Source # |
Instance details Defined in Text.Trifecta.Result Methods traverse :: Applicative f => (a -> f b) -> Result a -> f (Result b) Source # sequenceA :: Applicative f => Result (f a) -> f (Result a) Source # mapM :: Monad m => (a -> m b) -> Result a -> m (Result b) Source # sequence :: Monad m => Result (m a) -> m (Result a) Source #
Show a => Show (Result a) Source # |
Instance details Defined in Text.Trifecta.Result Methods showsPrec :: Int -> Result a -> ShowS Source # show :: Result a -> String Source # showList :: [Result a] -> ShowS Source #
AsResult (Result a) (Result b) a b Source # |
Instance details Defined in Text.Trifecta.Result Methods _Result :: Prism (Result a) (Result b) (Result a) (Result b) Source #

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

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

Methods

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

#### Instances

Instances details

AsResult (Result a) (Result b) a b Source # |
Instance details Defined in Text.Trifecta.Result Methods _Result :: Prism (Result a) (Result b) (Result a) (Result b) Source #

foldResult :: (ErrInfo -> b) -> (a -> b) -> Result a -> b Source #

Fold over a `Result`

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

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

_Failure :: AsResult s s a a => Prism' s ErrInfo Source #

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

# Parsing Errors

data Err Source #

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 AnsiStyle)
- _footnotes :: [Doc AnsiStyle]
- _expected :: Set String
- _finalDeltas :: [Delta]

#### Instances

Instances details

Monoid Err Source # |
Instance details Defined in Text.Trifecta.Result Methods mempty :: Err Source # mappend :: Err -> Err -> Err Source # mconcat :: [Err] -> Err Source #
Semigroup Err Source # |
Instance details Defined in Text.Trifecta.Result Methods (<>) :: Err -> Err -> Err Source # sconcat :: NonEmpty Err -> Err Source # stimes :: Integral b => b -> Err -> Err Source #
HasErr Err Source # |
Instance details Defined in Text.Trifecta.Result Methods err :: Lens' Err Err Source # expected :: Lens' Err (Set String) Source # finalDeltas :: Lens' Err [Delta] Source # footnotes :: Lens' Err [Doc AnsiStyle] Source # reason :: Lens' Err (Maybe (Doc AnsiStyle)) Source #

class HasErr c where Source #

Minimal complete definition

err

Methods

err :: Lens' c Err Source #

expected :: Lens' c (Set String) Source #

finalDeltas :: Lens' c [Delta] Source #

footnotes :: Lens' c [Doc AnsiStyle] Source #

reason :: Lens' c (Maybe (Doc AnsiStyle)) Source #

#### Instances

Instances details

HasErr Err Source # |
Instance details Defined in Text.Trifecta.Result Methods err :: Lens' Err Err Source # expected :: Lens' Err (Set String) Source # finalDeltas :: Lens' Err [Delta] Source # footnotes :: Lens' Err [Doc AnsiStyle] Source # reason :: Lens' Err (Maybe (Doc AnsiStyle)) Source #

class Errable (m :: Type -> Type) where Source #

Methods

raiseErr :: Err -> m a Source #

#### Instances

Instances details

Errable Parser Source # |
Instance details Defined in Text.Trifecta.Parser Methods raiseErr :: Err -> Parser a Source #

data ErrInfo Source #

Constructors

ErrInfo |

Fields

- _errDoc :: Doc AnsiStyle
- _errDeltas :: [Delta]

#### Instances

Instances details

Monoid ErrInfo Source # |
Instance details Defined in Text.Trifecta.Result Methods mempty :: ErrInfo Source # mappend :: ErrInfo -> ErrInfo -> ErrInfo Source # mconcat :: [ErrInfo] -> ErrInfo Source #
Semigroup ErrInfo Source # |
Instance details Defined in Text.Trifecta.Result Methods (<>) :: ErrInfo -> ErrInfo -> ErrInfo Source # sconcat :: NonEmpty ErrInfo -> ErrInfo Source # stimes :: Integral b => b -> ErrInfo -> ErrInfo Source #
Show ErrInfo Source # |
Instance details Defined in Text.Trifecta.Result Methods showsPrec :: Int -> ErrInfo -> ShowS Source # show :: ErrInfo -> String Source # showList :: [ErrInfo] -> ShowS Source #

explain :: Rendering -> Err -> Doc AnsiStyle Source #

Convert a `Rendering` of auxiliary information and an `Err` into a 'Doc AnsiStyle', ready to be prettyprinted to the user.

failed :: String -> Err Source #

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