Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Basic parser building blocks.
Synopsis
- eof :: ParserT st e ()
- take :: Int -> ParserT st e ByteString
- take# :: Int# -> ParserT st e ByteString
- takeUnsafe# :: Int# -> ParserT st e ByteString
- takeRest :: ParserT st e ByteString
- skip :: Int -> ParserT st e ()
- skip# :: Int# -> ParserT st e ()
- skipBack :: Int -> ParserT st e ()
- skipBack# :: Int# -> ParserT st e ()
- atSkip# :: Int# -> ParserT st e a -> ParserT st e a
- atSkipUnsafe# :: Int# -> ParserT st e r -> ParserT st e r
- branch :: ParserT st e a -> ParserT st e b -> ParserT st e b -> ParserT st e b
- notFollowedBy :: ParserT st e a -> ParserT st e b -> ParserT st e a
- chainl :: (b -> a -> b) -> ParserT st e b -> ParserT st e a -> ParserT st e b
- chainr :: (a -> b -> b) -> ParserT st e a -> ParserT st e b -> ParserT st e b
- lookahead :: ParserT st e a -> ParserT st e a
- ensure :: Int -> ParserT st e ()
- ensure# :: Int# -> ParserT st e ()
- withEnsure :: Int -> ParserT st e r -> ParserT st e r
- withEnsure1 :: ParserT st e r -> ParserT st e r
- withEnsure# :: Int# -> ParserT st e r -> ParserT st e r
- isolate :: Int -> ParserT st e a -> ParserT st e a
- isolate# :: Int# -> ParserT st e a -> ParserT st e a
- isolateUnsafe# :: Int# -> ParserT st e a -> ParserT st e a
- skipMany :: ParserT st e a -> ParserT st e ()
- skipSome :: ParserT st e a -> ParserT st e ()
- failed :: ParserT st e a
- try :: ParserT st e a -> ParserT st e a
- err :: e -> ParserT st e a
- withError :: ParserT st e b -> (e -> ParserT st e b) -> ParserT st e b
- fails :: ParserT st e a -> ParserT st e ()
- cut :: ParserT st e a -> e -> ParserT st e a
- cutting :: ParserT st e a -> e -> (e -> e -> e) -> ParserT st e a
- optional :: ParserT st e a -> ParserT st e (Maybe a)
- optional_ :: ParserT st e a -> ParserT st e ()
- withOption :: ParserT st e a -> (a -> ParserT st e r) -> ParserT st e r -> ParserT st e r
Bytewise
take :: Int -> ParserT st e ByteString Source #
Read the given number of bytes as a ByteString
.
Throws a runtime error if given a negative integer.
This does no copying. The ByteString
returned is a "slice" of the input,
and will keep it alive. To avoid this, use copy
on the output.
take# :: Int# -> ParserT st e ByteString Source #
Read n#
bytes as a ByteString
. Fails if fewer than n#
bytes are
available.
Throws a runtime error if given a negative integer.
This does no copying. The ByteString
returned is a "slice" of the input,
and will keep it alive. To avoid this, use copy
on the output.
takeUnsafe# :: Int# -> ParserT st e ByteString Source #
Read n#
bytes as a ByteString
. Fails if fewer than n#
bytes are
available.
Undefined behaviour if given a negative integer.
This does no copying. The ByteString
returned is a "slice" of the input,
and will keep it alive. To avoid this, use copy
on the output.
takeRest :: ParserT st e ByteString Source #
Consume the rest of the input. May return the empty bytestring.
This does no copying. The ByteString
returned is a "slice" of the input,
and will keep it alive. To avoid this, use copy
on the output.
skip :: Int -> ParserT st e () Source #
Skip forward n
bytes. Fails if fewer than n
bytes are available.
Throws a runtime error if given a negative integer.
skip# :: Int# -> ParserT st e () Source #
Skip forward n#
bytes. Fails if fewer than n#
bytes are available.
Throws a runtime error if given a negative integer.
skipBack :: Int -> ParserT st e () Source #
Go back i
bytes in the input. Takes a positive integer.
Extremely unsafe. Makes no checks. Almost certainly a Bad Idea.
skipBack# :: Int# -> ParserT st e () Source #
Go back n#
bytes. Takes a positive integer.
Extremely unsafe. Makes no checks. Almost certainly a Bad Idea.
atSkip# :: Int# -> ParserT st e a -> ParserT st e a Source #
Skip forward n#
bytes and run the given parser. Fails if fewer than n#
bytes are available.
Throws a runtime error if given a negative integer.
atSkipUnsafe# :: Int# -> ParserT st e r -> ParserT st e r Source #
Skip forward n
bytes and run the given parser. Fails if fewer than n
bytes are available.
Undefined behaviour if given a negative integer.
Combinators
notFollowedBy :: ParserT st e a -> ParserT st e b -> ParserT st e a Source #
Succeed if the first parser succeeds and the second one fails.
lookahead :: ParserT st e a -> ParserT st e a Source #
Save the parsing state, then run a parser, then restore the state.
ensure :: Int -> ParserT st e () Source #
Assert that there are at least n
bytes remaining.
Undefined behaviour if given a negative integer.
ensure# :: Int# -> ParserT st e () Source #
Assert that there are at least n#
bytes remaining.
Undefined behaviour if given a negative integer.
withEnsure :: Int -> ParserT st e r -> ParserT st e r Source #
Assert that there are at least n#
bytes remaining (CPS).
Undefined behaviour if given a negative integer.
withEnsure1 :: ParserT st e r -> ParserT st e r Source #
Assert that there is at least 1 byte remaining (CPS).
Undefined behaviour if given a negative integer.
withEnsure# :: Int# -> ParserT st e r -> ParserT st e r Source #
Assert that there are at least n#
bytes remaining (CPS).
Undefined behaviour if given a negative integer.
isolate :: Int -> ParserT st e a -> ParserT st e a Source #
isolate n p
runs the parser p
isolated to the next n
bytes.
All isolated bytes must be consumed.
Throws a runtime error if given a negative integer.
isolate# :: Int# -> ParserT st e a -> ParserT st e a Source #
isolate# n# p
runs the parser p
isolated to the next n#
bytes.
All isolated bytes must be consumed.
Throws a runtime error if given a negative integer.
isolateUnsafe# :: Int# -> ParserT st e a -> ParserT st e a Source #
isolateUnsafe# n# p
runs the parser p
isolated to the next n#
bytes.
All isolated bytes must be consumed.
Undefined behaviour if given a negative integer.
Non-specific (TODO)
Errors and failures
failed :: ParserT st e a Source #
The failing parser. By default, parser choice (<|>)
arbitrarily backtracks
on parser failure.
withError :: ParserT st e b -> (e -> ParserT st e b) -> ParserT st e b Source #
Run the parser, if an error is thrown, handle it with the given function.
cutting :: ParserT st e a -> e -> (e -> e -> e) -> ParserT st e a Source #
Run the parser, if we get a failure, throw the given error, but if we get an error, merge the
inner and the newly given errors using the e -> e -> e
function. This can be useful for
implementing parsing errors which may propagate hints or accummulate contextual information.