paripari-0.7.0.0: Parser combinators with fast-path and slower fallback for error reporting

Safe HaskellNone
LanguageHaskell2010

Text.PariPari

Synopsis

Documentation

class (MonadFail p, MonadPlus p, Chunk k, IsString (p k)) => Parser k p | p -> k where Source #

Parser class, which specifies the necessary primitives for parsing. All other parser combinators rely on these primitives.

Methods

getFile :: p FilePath Source #

Get file name associated with current parser

getPos :: p Pos Source #

Get current position of the parser

getRefPos :: p Pos Source #

Get reference position used for indentation-sensitive parsing

withRefPos :: p a -> p a Source #

Update reference position with current position

notFollowedBy :: Show a => p a -> p () Source #

Parser which succeeds when the given parser fails

lookAhead :: p a -> p a Source #

Look ahead and return result of the given parser The current position stays the same.

failWith :: Error -> p a Source #

Parser failure with detailled Error

eof :: p () Source #

Parser which succeeds at the end of file

label :: String -> p a -> p a Source #

Annotate the given parser with a label used for error reporting.

Note: This function has zero cost in the Acceptor. You can use it to improve the error reports without slowing down the fast path of your parser.

hidden :: p a -> p a Source #

Hide errors occurring within the given parser from the error report. Based on the given labels an Error is constructed instead.

Note: This function has zero cost in the Acceptor. You can use it to improve the error reports without slowing down the fast path of your parser.

try :: p a -> p a Source #

Reset position if parser fails

(<!>) :: p a -> p a -> p a infixl 3 Source #

Alternative which does not backtrack.

recover :: p a -> p a -> p a Source #

Parse with error recovery. If the parser p fails in `recover p r` the parser r continues at the position where p failed. If the recovering parser r fails too, the whole parser fails. The errors reported by the recovering parser are ignored in any case. Error recovery support is only available in the Reporter instance.

Note: This function has zero cost in the Acceptor. You can use it to improve the error reports without slowing down the fast path of your parser.

chunk :: k -> p k Source #

Parse a chunk of elements. The chunk must not contain multiple lines, otherwise the position information will be invalid.

asChunk :: p () -> p k Source #

Run the given parser and return the result as buffer

char :: Char -> p Char Source #

Parse a single character

Note: The character '\0' cannot be parsed using this combinator since it is used as decoding sentinel. Use element instead.

scan :: (Char -> Maybe a) -> p a Source #

Scan a single character

Note: The character '\0' cannot be parsed using this combinator since it is used as decoding sentinel. Use elementScan instead.

asciiByte :: Word8 -> p Word8 Source #

Parse a single character within the ASCII charset

Note: The character '\0' cannot be parsed using this combinator since it is used as decoding sentinel. Use element instead.

asciiScan :: (Word8 -> Maybe a) -> p a Source #

Scan a single character within the ASCII charset

Note: The character '\0' cannot be parsed using this combinator since it is used as decoding sentinel. Use elementScan instead.

Instances
Chunk k => Parser k (Acceptor k) Source # 
Instance details

Defined in Text.PariPari.Internal.Acceptor

Chunk k => Parser k (Reporter k) Source # 
Instance details

Defined in Text.PariPari.Internal.Reporter

data Pos Source #

Line and column position starting at (1,1)

Constructors

Pos 

Fields

Instances
Eq Pos Source # 
Instance details

Defined in Text.PariPari.Internal.Class

Methods

(==) :: Pos -> Pos -> Bool #

(/=) :: Pos -> Pos -> Bool #

Show Pos Source # 
Instance details

Defined in Text.PariPari.Internal.Class

Methods

showsPrec :: Int -> Pos -> ShowS #

show :: Pos -> String #

showList :: [Pos] -> ShowS #

Generic Pos Source # 
Instance details

Defined in Text.PariPari.Internal.Class

Associated Types

type Rep Pos :: Type -> Type #

Methods

from :: Pos -> Rep Pos x #

to :: Rep Pos x -> Pos #

type Rep Pos Source # 
Instance details

Defined in Text.PariPari.Internal.Class

type Rep Pos = D1 (MetaData "Pos" "Text.PariPari.Internal.Class" "paripari-0.7.0.0-IvEurrnvmehFR9IQGtFHTg" False) (C1 (MetaCons "Pos" PrefixI True) (S1 (MetaSel (Just "_posLine") SourceUnpack SourceStrict DecidedStrict) (Rec0 Int) :*: S1 (MetaSel (Just "_posCol") SourceUnpack SourceStrict DecidedStrict) (Rec0 Int)))

data Error Source #

Parsing errors

Instances
Eq Error Source # 
Instance details

Defined in Text.PariPari.Internal.Class

Methods

(==) :: Error -> Error -> Bool #

(/=) :: Error -> Error -> Bool #

Ord Error Source # 
Instance details

Defined in Text.PariPari.Internal.Class

Methods

compare :: Error -> Error -> Ordering #

(<) :: Error -> Error -> Bool #

(<=) :: Error -> Error -> Bool #

(>) :: Error -> Error -> Bool #

(>=) :: Error -> Error -> Bool #

max :: Error -> Error -> Error #

min :: Error -> Error -> Error #

Show Error Source # 
Instance details

Defined in Text.PariPari.Internal.Class

Methods

showsPrec :: Int -> Error -> ShowS #

show :: Error -> String #

showList :: [Error] -> ShowS #

Generic Error Source # 
Instance details

Defined in Text.PariPari.Internal.Class

Associated Types

type Rep Error :: Type -> Type #

Methods

from :: Error -> Rep Error x #

to :: Rep Error x -> Error #

type Rep Error Source # 
Instance details

Defined in Text.PariPari.Internal.Class

showError :: Error -> String Source #

Pretty string representation of Error

runParser :: Chunk k => (forall p. Parser k p => p a) -> FilePath -> k -> (Maybe a, [Report]) Source #

Rsun fast Acceptor and slower Reporter on the given sequentially. The FilePath is used for error reporting. When the acceptor does not return successfully, the result from the reporter is awaited.

runParserWithOptions :: Chunk k => ReportOptions -> (forall p. Parser k p => p a) -> FilePath -> k -> (Maybe a, [Report]) Source #

Run parsers **sequentially** with additional ReportOptions.

data Acceptor k a Source #

Parser which is optimised for fast parsing. Error reporting is minimal.

Instances
Chunk k => Parser k (Acceptor k) Source # 
Instance details

Defined in Text.PariPari.Internal.Acceptor

Chunk k => Monad (Acceptor k) Source # 
Instance details

Defined in Text.PariPari.Internal.Acceptor

Methods

(>>=) :: Acceptor k a -> (a -> Acceptor k b) -> Acceptor k b #

(>>) :: Acceptor k a -> Acceptor k b -> Acceptor k b #

return :: a -> Acceptor k a #

fail :: String -> Acceptor k a #

Functor (Acceptor k) Source # 
Instance details

Defined in Text.PariPari.Internal.Acceptor

Methods

fmap :: (a -> b) -> Acceptor k a -> Acceptor k b #

(<$) :: a -> Acceptor k b -> Acceptor k a #

Chunk k => MonadFail (Acceptor k) Source # 
Instance details

Defined in Text.PariPari.Internal.Acceptor

Methods

fail :: String -> Acceptor k a #

Chunk k => Applicative (Acceptor k) Source # 
Instance details

Defined in Text.PariPari.Internal.Acceptor

Methods

pure :: a -> Acceptor k a #

(<*>) :: Acceptor k (a -> b) -> Acceptor k a -> Acceptor k b #

liftA2 :: (a -> b -> c) -> Acceptor k a -> Acceptor k b -> Acceptor k c #

(*>) :: Acceptor k a -> Acceptor k b -> Acceptor k b #

(<*) :: Acceptor k a -> Acceptor k b -> Acceptor k a #

Chunk k => Alternative (Acceptor k) Source # 
Instance details

Defined in Text.PariPari.Internal.Acceptor

Methods

empty :: Acceptor k a #

(<|>) :: Acceptor k a -> Acceptor k a -> Acceptor k a #

some :: Acceptor k a -> Acceptor k [a] #

many :: Acceptor k a -> Acceptor k [a] #

Chunk k => MonadPlus (Acceptor k) Source # 
Instance details

Defined in Text.PariPari.Internal.Acceptor

Methods

mzero :: Acceptor k a #

mplus :: Acceptor k a -> Acceptor k a -> Acceptor k a #

Chunk k => IsString (Acceptor k k) Source # 
Instance details

Defined in Text.PariPari.Internal.Acceptor

Methods

fromString :: String -> Acceptor k k #

(Chunk k, Semigroup a) => Semigroup (Acceptor k a) Source # 
Instance details

Defined in Text.PariPari.Internal.Acceptor

Methods

(<>) :: Acceptor k a -> Acceptor k a -> Acceptor k a #

sconcat :: NonEmpty (Acceptor k a) -> Acceptor k a #

stimes :: Integral b => b -> Acceptor k a -> Acceptor k a #

(Chunk k, Semigroup a, Monoid a) => Monoid (Acceptor k a) Source # 
Instance details

Defined in Text.PariPari.Internal.Acceptor

Methods

mempty :: Acceptor k a #

mappend :: Acceptor k a -> Acceptor k a -> Acceptor k a #

mconcat :: [Acceptor k a] -> Acceptor k a #

runAcceptor :: Chunk k => Acceptor k a -> FilePath -> k -> Maybe a Source #

Run Acceptor on the given chunk, returning either a simple Error or, if successful, the result.

data Reporter k a Source #

Parser which is optimised for good error reports. Performance is secondary, since the Reporter is used as a fallback to the Acceptor.

Instances
Chunk k => Parser k (Reporter k) Source # 
Instance details

Defined in Text.PariPari.Internal.Reporter

Chunk k => Monad (Reporter k) Source # 
Instance details

Defined in Text.PariPari.Internal.Reporter

Methods

(>>=) :: Reporter k a -> (a -> Reporter k b) -> Reporter k b #

(>>) :: Reporter k a -> Reporter k b -> Reporter k b #

return :: a -> Reporter k a #

fail :: String -> Reporter k a #

Chunk k => Functor (Reporter k) Source # 
Instance details

Defined in Text.PariPari.Internal.Reporter

Methods

fmap :: (a -> b) -> Reporter k a -> Reporter k b #

(<$) :: a -> Reporter k b -> Reporter k a #

Chunk k => MonadFail (Reporter k) Source # 
Instance details

Defined in Text.PariPari.Internal.Reporter

Methods

fail :: String -> Reporter k a #

Chunk k => Applicative (Reporter k) Source # 
Instance details

Defined in Text.PariPari.Internal.Reporter

Methods

pure :: a -> Reporter k a #

(<*>) :: Reporter k (a -> b) -> Reporter k a -> Reporter k b #

liftA2 :: (a -> b -> c) -> Reporter k a -> Reporter k b -> Reporter k c #

(*>) :: Reporter k a -> Reporter k b -> Reporter k b #

(<*) :: Reporter k a -> Reporter k b -> Reporter k a #

Chunk k => Alternative (Reporter k) Source # 
Instance details

Defined in Text.PariPari.Internal.Reporter

Methods

empty :: Reporter k a #

(<|>) :: Reporter k a -> Reporter k a -> Reporter k a #

some :: Reporter k a -> Reporter k [a] #

many :: Reporter k a -> Reporter k [a] #

Chunk k => MonadPlus (Reporter k) Source # 
Instance details

Defined in Text.PariPari.Internal.Reporter

Methods

mzero :: Reporter k a #

mplus :: Reporter k a -> Reporter k a -> Reporter k a #

Chunk k => IsString (Reporter k k) Source # 
Instance details

Defined in Text.PariPari.Internal.Reporter

Methods

fromString :: String -> Reporter k k #

(Chunk k, Semigroup a) => Semigroup (Reporter k a) Source # 
Instance details

Defined in Text.PariPari.Internal.Reporter

Methods

(<>) :: Reporter k a -> Reporter k a -> Reporter k a #

sconcat :: NonEmpty (Reporter k a) -> Reporter k a #

stimes :: Integral b => b -> Reporter k a -> Reporter k a #

(Chunk k, Semigroup a, Monoid a) => Monoid (Reporter k a) Source # 
Instance details

Defined in Text.PariPari.Internal.Reporter

Methods

mempty :: Reporter k a #

mappend :: Reporter k a -> Reporter k a -> Reporter k a #

mconcat :: [Reporter k a] -> Reporter k a #

data Report Source #

Instances
Eq Report Source # 
Instance details

Defined in Text.PariPari.Internal.Reporter

Methods

(==) :: Report -> Report -> Bool #

(/=) :: Report -> Report -> Bool #

Show Report Source # 
Instance details

Defined in Text.PariPari.Internal.Reporter

Generic Report Source # 
Instance details

Defined in Text.PariPari.Internal.Reporter

Associated Types

type Rep Report :: Type -> Type #

Methods

from :: Report -> Rep Report x #

to :: Rep Report x -> Report #

type Rep Report Source # 
Instance details

Defined in Text.PariPari.Internal.Reporter

type Rep Report = D1 (MetaData "Report" "Text.PariPari.Internal.Reporter" "paripari-0.7.0.0-IvEurrnvmehFR9IQGtFHTg" False) (C1 (MetaCons "Report" PrefixI True) ((S1 (MetaSel (Just "_reportFile") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 FilePath) :*: S1 (MetaSel (Just "_reportErrors") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 [ErrorContext])) :*: (S1 (MetaSel (Just "_reportLine") SourceUnpack SourceStrict DecidedStrict) (Rec0 Int) :*: S1 (MetaSel (Just "_reportCol") SourceUnpack SourceStrict DecidedStrict) (Rec0 Int))))

data ErrorContext Source #

Constructors

ErrorContext 

Fields

Instances
Eq ErrorContext Source # 
Instance details

Defined in Text.PariPari.Internal.Reporter

Show ErrorContext Source # 
Instance details

Defined in Text.PariPari.Internal.Reporter

Generic ErrorContext Source # 
Instance details

Defined in Text.PariPari.Internal.Reporter

Associated Types

type Rep ErrorContext :: Type -> Type #

type Rep ErrorContext Source # 
Instance details

Defined in Text.PariPari.Internal.Reporter

type Rep ErrorContext = D1 (MetaData "ErrorContext" "Text.PariPari.Internal.Reporter" "paripari-0.7.0.0-IvEurrnvmehFR9IQGtFHTg" False) (C1 (MetaCons "ErrorContext" PrefixI True) (S1 (MetaSel (Just "_ecErrors") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 [Error]) :*: S1 (MetaSel (Just "_ecContext") NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 [String])))

data ReportOptions Source #

Instances
Eq ReportOptions Source # 
Instance details

Defined in Text.PariPari.Internal.Reporter

Show ReportOptions Source # 
Instance details

Defined in Text.PariPari.Internal.Reporter

Generic ReportOptions Source # 
Instance details

Defined in Text.PariPari.Internal.Reporter

Associated Types

type Rep ReportOptions :: Type -> Type #

type Rep ReportOptions Source # 
Instance details

Defined in Text.PariPari.Internal.Reporter

type Rep ReportOptions = D1 (MetaData "ReportOptions" "Text.PariPari.Internal.Reporter" "paripari-0.7.0.0-IvEurrnvmehFR9IQGtFHTg" False) (C1 (MetaCons "ReportOptions" PrefixI True) (S1 (MetaSel (Just "_optMaxContexts") SourceUnpack SourceStrict DecidedStrict) (Rec0 Int) :*: (S1 (MetaSel (Just "_optMaxErrorsPerContext") SourceUnpack SourceStrict DecidedStrict) (Rec0 Int) :*: S1 (MetaSel (Just "_optMaxLabelsPerContext") SourceUnpack SourceStrict DecidedStrict) (Rec0 Int))))

runReporter :: Chunk k => Reporter k a -> FilePath -> k -> (Maybe a, [Report]) Source #

Run Reporter on the given chunk, returning the result if successful and reports from error recoveries. In the case of an error, Nothing is returned and the Report list is non-empty.

showReport :: Report -> String Source #

Pretty string representation of Report.

showErrors :: [ErrorContext] -> String Source #

Pretty string representation of '[ErrorContext]'.