Text.Trifecta.Result

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

Copyright | (c) Edward Kmett 2011-2015
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
- _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
  - _footnotes :: [Doc]
  - _expected :: Set String
  - _finalDeltas :: [Delta]
  }
- class HasErr c where
- class Errable m where
- data ErrInfo = ErrInfo {
  - _errDoc :: Doc
  - _errDeltas :: [Delta]
  }
- 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 ErrInfo |

Instances

Functor Result # |
Methods fmap :: (a -> b) -> Result a -> Result b # (<$) :: a -> Result b -> Result a #
Applicative Result # |
Methods pure :: a -> Result a # (<*>) :: Result (a -> b) -> Result a -> Result b # (*>) :: Result a -> Result b -> Result b # (<*) :: Result a -> Result b -> Result a #
Foldable Result # |
Methods fold :: Monoid m => Result m -> m # foldMap :: Monoid m => (a -> m) -> Result a -> m # foldr :: (a -> b -> b) -> b -> Result a -> b # foldr' :: (a -> b -> b) -> b -> Result a -> b # foldl :: (b -> a -> b) -> b -> Result a -> b # foldl' :: (b -> a -> b) -> b -> Result a -> b # foldr1 :: (a -> a -> a) -> Result a -> a # foldl1 :: (a -> a -> a) -> Result a -> a # toList :: Result a -> [a] # null :: Result a -> Bool # length :: Result a -> Int # elem :: Eq a => a -> Result a -> Bool # maximum :: Ord a => Result a -> a # minimum :: Ord a => Result a -> a # sum :: Num a => Result a -> a # product :: Num a => Result a -> a #
Traversable Result # |
Methods traverse :: Applicative f => (a -> f b) -> Result a -> f (Result b) # sequenceA :: Applicative f => Result (f a) -> f (Result a) # mapM :: Monad m => (a -> m b) -> Result a -> m (Result b) # sequence :: Monad m => Result (m a) -> m (Result a) #
Alternative Result # |
Methods empty :: Result a # (<|>) :: Result a -> Result a -> Result a # some :: Result a -> Result [a] # many :: Result a -> Result [a] #
Show a => Show (Result a) # |
Methods showsPrec :: Int -> Result a -> ShowS # show :: Result a -> String # showList :: [Result a] -> ShowS #
Show a => Pretty (Result a) # |
Methods pretty :: Result a -> Doc # prettyList :: [Result a] -> Doc #
AsResult (Result a) (Result b) a b # |
Methods _Result :: Prism (Result a) (Result b) (Result a) (Result 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.

Methods

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

Instances

AsResult (Result a) (Result b) a b # |
Methods _Result :: Prism (Result a) (Result b) (Result a) (Result 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 ErrInfo #

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 _finalDeltas :: [Delta]

Instances

Semigroup Err # |
Methods (<>) :: Err -> Err -> Err # sconcat :: NonEmpty Err -> Err # stimes :: Integral b => b -> Err -> Err #
Monoid Err # |
Methods mempty :: Err # mappend :: Err -> Err -> Err # mconcat :: [Err] -> Err #
HasErr Err # |
Methods err :: Lens' Err Err # expected :: Lens' Err (Set String) # finalDeltas :: Lens' Err [Delta] # footnotes :: Lens' Err [Doc] # reason :: Lens' Err (Maybe Doc) #

class HasErr c where #

Minimal complete definition

err

Methods

err :: Lens' c Err #

expected :: Lens' c (Set String) #

finalDeltas :: Lens' c [Delta] #

footnotes :: Lens' c [Doc] #

reason :: Lens' c (Maybe Doc) #

Instances

HasErr Err # |
Methods err :: Lens' Err Err # expected :: Lens' Err (Set String) # finalDeltas :: Lens' Err [Delta] # footnotes :: Lens' Err [Doc] # reason :: Lens' Err (Maybe Doc) #

class Errable m where #

Minimal complete definition

raiseErr

Methods

raiseErr :: Err -> m a #

Instances

Errable Parser # |
Methods raiseErr :: Err -> Parser a #

data ErrInfo #

Constructors

ErrInfo |
Fields _errDoc :: Doc _errDeltas :: [Delta]

Instances

Show ErrInfo # |
Methods showsPrec :: Int -> ErrInfo -> ShowS # show :: ErrInfo -> String # showList :: [ErrInfo] -> ShowS #
Monoid ErrInfo # |
Methods mempty :: ErrInfo # mappend :: ErrInfo -> ErrInfo -> ErrInfo # mconcat :: [ErrInfo] -> ErrInfo #

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.