Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- class (MonadFail p, MonadPlus p, Chunk k, IsString (p k)) => Parser k p | p -> k where
- getFile :: p FilePath
- getPos :: p Pos
- getRefPos :: p Pos
- withRefPos :: p a -> p a
- notFollowedBy :: Show a => p a -> p ()
- lookAhead :: p a -> p a
- failWith :: Error -> p a
- eof :: p ()
- label :: String -> p a -> p a
- hidden :: p a -> p a
- try :: p a -> p a
- (<!>) :: p a -> p a -> p a
- recover :: p a -> p a -> p a
- chunk :: k -> p k
- asChunk :: p () -> p k
- char :: Char -> p Char
- scan :: (Char -> Maybe a) -> p a
- asciiByte :: Word8 -> p Word8
- asciiScan :: (Word8 -> Maybe a) -> p a
- data Pos = Pos {}
- data Error
- = EInvalidUtf8
- | EExpected [String]
- | EUnexpected String
- | EFail String
- | EIndentNotAligned !Int !Int
- | EIndentOverLine !Int !Int
- | ENotEnoughIndent !Int !Int
- showError :: Error -> String
- class Ord k => Chunk k where
- runParser :: Chunk k => (forall p. Parser k p => p a) -> FilePath -> k -> (Maybe a, [Report])
- runParserWithOptions :: Chunk k => ReportOptions -> (forall p. Parser k p => p a) -> FilePath -> k -> (Maybe a, [Report])
- data Acceptor k a
- runAcceptor :: Chunk k => Acceptor k a -> FilePath -> k -> Maybe a
- data Reporter k a
- data Report = Report {
- _reportFile :: !FilePath
- _reportErrors :: ![ErrorContext]
- _reportLine :: !Int
- _reportCol :: !Int
- data ErrorContext = ErrorContext {
- _ecErrors :: ![Error]
- _ecContext :: ![String]
- data ReportOptions = ReportOptions {}
- runReporter :: Chunk k => Reporter k a -> FilePath -> k -> (Maybe a, [Report])
- showReport :: Report -> String
- showErrors :: [ErrorContext] -> String
- runReporterWithOptions :: Chunk k => ReportOptions -> Reporter k a -> FilePath -> k -> (Maybe a, [Report])
- defaultReportOptions :: ReportOptions
- module Text.PariPari.Internal.Combinators
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.
getFile :: p FilePath Source #
Get file name associated with current parser
Get current position of the parser
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
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.
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.
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.
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
Line and column position starting at (1,1)
Instances
Eq Pos Source # | |
Show Pos Source # | |
Generic Pos Source # | |
type Rep Pos Source # | |
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))) |
Parsing errors
EInvalidUtf8 | |
EExpected [String] | |
EUnexpected String | |
EFail String | |
EIndentNotAligned !Int !Int | |
EIndentOverLine !Int !Int | |
ENotEnoughIndent !Int !Int |
Instances
class Ord k => Chunk k where Source #
Instances
runParser :: Chunk k => (forall p. Parser k p => p a) -> FilePath -> k -> (Maybe a, [Report]) Source #
runParserWithOptions :: Chunk k => ReportOptions -> (forall p. Parser k p => p a) -> FilePath -> k -> (Maybe a, [Report]) Source #
Run parsers **sequentially** with additional ReportOptions
.
Parser which is optimised for fast parsing. Error reporting is minimal.
Instances
Parser which is optimised for good error reports.
Performance is secondary, since the Reporter
is used
as a fallback to the Acceptor
.
Instances
Report | |
|
Instances
Eq Report Source # | |
Show Report Source # | |
Generic Report Source # | |
type Rep Report Source # | |
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 #
ErrorContext | |
|
Instances
Eq ErrorContext Source # | |
Defined in Text.PariPari.Internal.Reporter (==) :: ErrorContext -> ErrorContext -> Bool # (/=) :: ErrorContext -> ErrorContext -> Bool # | |
Show ErrorContext Source # | |
Defined in Text.PariPari.Internal.Reporter showsPrec :: Int -> ErrorContext -> ShowS # show :: ErrorContext -> String # showList :: [ErrorContext] -> ShowS # | |
Generic ErrorContext Source # | |
Defined in Text.PariPari.Internal.Reporter type Rep ErrorContext :: Type -> Type # from :: ErrorContext -> Rep ErrorContext x # to :: Rep ErrorContext x -> ErrorContext # | |
type Rep ErrorContext Source # | |
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
showErrors :: [ErrorContext] -> String Source #
Pretty string representation of '[ErrorContext]'.
runReporterWithOptions :: Chunk k => ReportOptions -> Reporter k a -> FilePath -> k -> (Maybe a, [Report]) Source #
Run Reporter
with additional ReportOptions
.