Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Basic parser building blocks.
Synopsis
- eof :: ParserT st r e ()
- take :: Int -> ParserT st r e ByteString
- take# :: Int# -> ParserT st r e ByteString
- takeUnsafe# :: Int# -> ParserT st r e ByteString
- takeRest :: ParserT st r e ByteString
- skip :: Int -> ParserT st r e ()
- skip# :: Int# -> ParserT st r e ()
- skipBack :: Int -> ParserT st r e ()
- skipBack# :: Int# -> ParserT st r e ()
- atSkip# :: Int# -> ParserT st r e ret -> ParserT st r e ret
- atSkipUnsafe# :: Int# -> ParserT st r e ret -> ParserT st r e ret
- branch :: ParserT st r e a -> ParserT st r e b -> ParserT st r e b -> ParserT st r e b
- notFollowedBy :: ParserT st r e a -> ParserT st r e b -> ParserT st r e a
- chainl :: (b -> a -> b) -> ParserT st r e b -> ParserT st r e a -> ParserT st r e b
- chainr :: (a -> b -> b) -> ParserT st r e a -> ParserT st r e b -> ParserT st r e b
- lookahead :: ParserT st r e a -> ParserT st r e a
- ensure :: Int -> ParserT st r e ()
- ensure# :: Int# -> ParserT st r e ()
- withEnsure :: Int -> ParserT st r e ret -> ParserT st r e ret
- withEnsure1 :: ParserT st r e ret -> ParserT st r e ret
- withEnsure# :: Int# -> ParserT st r e ret -> ParserT st r e ret
- isolate :: Int -> ParserT st r e a -> ParserT st r e a
- isolate# :: Int# -> ParserT st r e a -> ParserT st r e a
- isolateUnsafe# :: Int# -> ParserT st r e ret -> ParserT st r e ret
- skipMany :: ParserT st r e a -> ParserT st r e ()
- skipSome :: ParserT st r e a -> ParserT st r e ()
- failed :: ParserT st r e a
- try :: ParserT st r e a -> ParserT st r e a
- err :: e -> ParserT st r e a
- withError :: ParserT st r e b -> (e -> ParserT st r e b) -> ParserT st r e b
- fails :: ParserT st r e a -> ParserT st r e ()
- cut :: ParserT st r e a -> e -> ParserT st r e a
- cutting :: ParserT st r e a -> e -> (e -> e -> e) -> ParserT st r e a
- optional :: ParserT st r e a -> ParserT st r e (Maybe a)
- optional_ :: ParserT st r e a -> ParserT st r e ()
- withOption :: ParserT st r e a -> (a -> ParserT st r e ret) -> ParserT st r e ret -> ParserT st r e ret
Bytewise
take :: Int -> ParserT st r 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.
take# :: Int# -> ParserT st r 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 r e ByteString Source #
Read i#
bytes as a ByteString
. Fails if newer than i#
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 r 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 r 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 r 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 r 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 r e () Source #
Go back i#
bytes in the input. Takes a positive integer.
Extremely unsafe. Makes no checks. Almost certainly a Bad Idea.
atSkip# :: Int# -> ParserT st r e ret -> ParserT st r e ret 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 r e ret -> ParserT st r e ret Source #
Skip forward i#
bytes and run the given parser. Fails if fewer than i
bytes are available.
Undefined behaviour if given a negative integer.
Combinators
branch :: ParserT st r e a -> ParserT st r e b -> ParserT st r e b -> ParserT st r e b Source #
Branch on a parser: if the first argument succeeds, continue with the second, else with the third.
This can produce slightly more efficient code than (<|>)
. Moreover, ḃranch
does not
backtrack from the true/false cases.
notFollowedBy :: ParserT st r e a -> ParserT st r e b -> ParserT st r e a Source #
Succeed if the first parser succeeds and the second one fails.
lookahead :: ParserT st r e a -> ParserT st r e a Source #
Save the parsing state, then run a parser, then restore the state.
ensure :: Int -> ParserT st r e () Source #
Assert that there are at least n
bytes remaining.
Undefined behaviour if given a negative integer.
ensure# :: Int# -> ParserT st r e () Source #
Assert that there are at least n#
bytes remaining.
Undefined behaviour if given a negative integer.
withEnsure :: Int -> ParserT st r e ret -> ParserT st r e ret Source #
Assert that there are at least n#
bytes remaining (CPS).
Undefined behaviour if given a negative integer.
withEnsure1 :: ParserT st r e ret -> ParserT st r e ret Source #
Assert that there is at least 1 byte remaining (CPS).
Undefined behaviour if given a negative integer.
withEnsure# :: Int# -> ParserT st r e ret -> ParserT st r e ret Source #
Assert that there are at least n#
bytes remaining (CPS).
Undefined behaviour if given a negative integer.
isolate :: Int -> ParserT st r e a -> ParserT st r 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 r e a -> ParserT st r 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 r e ret -> ParserT st r e ret Source #
isolateUnsafe# i# p
runs the parser p
isolated to the next i#
bytes.
All isolated bytes must be consumed.
Undefined behaviour if given a negative integer.
Non-specific (TODO)
Errors and failures
withError :: ParserT st r e b -> (e -> ParserT st r e b) -> ParserT st r e b Source #
Run the parser, if an error is thrown, handle it with the given function.
cutting :: ParserT st r e a -> e -> (e -> e -> e) -> ParserT st r 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.