Safe Haskell | None |
---|---|
Language | Haskell2010 |
FlatParse.Stateful.Base
Description
Basic parser building blocks.
Synopsis
- eof :: forall (st :: ZeroBitType) r e. ParserT st r e ()
- take :: forall (st :: ZeroBitType) r e. Int -> ParserT st r e ByteString
- take# :: forall (st :: ZeroBitType) r e. Int# -> ParserT st r e ByteString
- takeUnsafe# :: forall (st :: ZeroBitType) r e. Int# -> ParserT st r e ByteString
- takeRest :: forall (st :: ZeroBitType) r e. ParserT st r e ByteString
- skip :: forall (st :: ZeroBitType) r e. Int -> ParserT st r e ()
- skip# :: forall (st :: ZeroBitType) r e. Int# -> ParserT st r e ()
- skipBack :: forall (st :: ZeroBitType) r e. Int -> ParserT st r e ()
- skipBack# :: forall (st :: ZeroBitType) r e. Int# -> ParserT st r e ()
- atSkip# :: forall (st :: ZeroBitType) r e ret. Int# -> ParserT st r e ret -> ParserT st r e ret
- atSkipUnsafe# :: forall (st :: ZeroBitType) r e ret. Int# -> ParserT st r e ret -> ParserT st r e ret
- branch :: forall (st :: ZeroBitType) r e a b. ParserT st r e a -> ParserT st r e b -> ParserT st r e b -> ParserT st r e b
- notFollowedBy :: forall (st :: ZeroBitType) r e a b. ParserT st r e a -> ParserT st r e b -> ParserT st r e a
- chainl :: forall b a (st :: ZeroBitType) r e. (b -> a -> b) -> ParserT st r e b -> ParserT st r e a -> ParserT st r e b
- chainr :: forall a b (st :: ZeroBitType) r e. (a -> b -> b) -> ParserT st r e a -> ParserT st r e b -> ParserT st r e b
- lookahead :: forall (st :: ZeroBitType) r e a. ParserT st r e a -> ParserT st r e a
- ensure :: forall (st :: ZeroBitType) r e. Int -> ParserT st r e ()
- ensure# :: forall (st :: ZeroBitType) r e. Int# -> ParserT st r e ()
- withEnsure :: forall (st :: ZeroBitType) r e ret. Int -> ParserT st r e ret -> ParserT st r e ret
- withEnsure1 :: forall (st :: ZeroBitType) r e ret. ParserT st r e ret -> ParserT st r e ret
- withEnsure# :: forall (st :: ZeroBitType) r e ret. Int# -> ParserT st r e ret -> ParserT st r e ret
- isolate :: forall (st :: ZeroBitType) r e a. Int -> ParserT st r e a -> ParserT st r e a
- isolate# :: forall (st :: ZeroBitType) r e a. Int# -> ParserT st r e a -> ParserT st r e a
- isolateUnsafe# :: forall (st :: ZeroBitType) r e ret. Int# -> ParserT st r e ret -> ParserT st r e ret
- skipMany :: forall (st :: ZeroBitType) r e a. ParserT st r e a -> ParserT st r e ()
- skipSome :: forall (st :: ZeroBitType) r e a. ParserT st r e a -> ParserT st r e ()
- failed :: forall (st :: ZeroBitType) r e a. ParserT st r e a
- try :: forall (st :: ZeroBitType) r e a. ParserT st r e a -> ParserT st r e a
- err :: forall e (st :: ZeroBitType) r a. e -> ParserT st r e a
- withError :: forall (st :: ZeroBitType) r e b. ParserT st r e b -> (e -> ParserT st r e b) -> ParserT st r e b
- withAnyResult :: forall (st :: ZeroBitType) r t a e b. ParserT st r t a -> (a -> ParserT st r e b) -> ParserT st r e b -> (t -> ParserT st r e b) -> ParserT st r e b
- fails :: forall (st :: ZeroBitType) r e a. ParserT st r e a -> ParserT st r e ()
- cut :: forall (st :: ZeroBitType) r e a. ParserT st r e a -> e -> ParserT st r e a
- cutting :: forall (st :: ZeroBitType) r e a. ParserT st r e a -> e -> (e -> e -> e) -> ParserT st r e a
- optional :: forall (st :: ZeroBitType) r e a. ParserT st r e a -> ParserT st r e (Maybe a)
- optional_ :: forall (st :: ZeroBitType) r e a. ParserT st r e a -> ParserT st r e ()
- withOption :: forall (st :: ZeroBitType) r e a ret. ParserT st r e a -> (a -> ParserT st r e ret) -> ParserT st r e ret -> ParserT st r e ret
Bytewise
eof :: forall (st :: ZeroBitType) r e. ParserT st r e () Source #
Succeed if the input is empty.
take :: forall (st :: ZeroBitType) r e. 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# :: forall (st :: ZeroBitType) r e. 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# :: forall (st :: ZeroBitType) r e. 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 :: forall (st :: ZeroBitType) r e. 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 :: forall (st :: ZeroBitType) r e. 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# :: forall (st :: ZeroBitType) r e. 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 :: forall (st :: ZeroBitType) r e. 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# :: forall (st :: ZeroBitType) r e. 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# :: forall (st :: ZeroBitType) r e ret. 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# :: forall (st :: ZeroBitType) r e ret. 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 :: forall (st :: ZeroBitType) r e a b. 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 :: forall (st :: ZeroBitType) r e a b. 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.
chainl :: forall b a (st :: ZeroBitType) r e. (b -> a -> b) -> ParserT st r e b -> ParserT st r e a -> ParserT st r e b Source #
chainr :: forall a b (st :: ZeroBitType) r e. (a -> b -> b) -> ParserT st r e a -> ParserT st r e b -> ParserT st r e b Source #
lookahead :: forall (st :: ZeroBitType) r e a. ParserT st r e a -> ParserT st r e a Source #
Save the parsing state, then run a parser, then restore the state.
ensure :: forall (st :: ZeroBitType) r e. Int -> ParserT st r e () Source #
Assert that there are at least n
bytes remaining.
Undefined behaviour if given a negative integer.
ensure# :: forall (st :: ZeroBitType) r e. Int# -> ParserT st r e () Source #
Assert that there are at least n#
bytes remaining.
Undefined behaviour if given a negative integer.
withEnsure :: forall (st :: ZeroBitType) r e ret. 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 :: forall (st :: ZeroBitType) r e ret. 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# :: forall (st :: ZeroBitType) r e ret. 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 :: forall (st :: ZeroBitType) r e a. 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# :: forall (st :: ZeroBitType) r e a. 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# :: forall (st :: ZeroBitType) r e ret. 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)
skipMany :: forall (st :: ZeroBitType) r e a. ParserT st r e a -> ParserT st r e () Source #
Skip a parser zero or more times.
skipSome :: forall (st :: ZeroBitType) r e a. ParserT st r e a -> ParserT st r e () Source #
Skip a parser one or more times.
Errors and failures
failed :: forall (st :: ZeroBitType) r e a. ParserT st r e a Source #
try :: forall (st :: ZeroBitType) r e a. ParserT st r e a -> ParserT st r e a Source #
Convert a parsing error into failure.
err :: forall e (st :: ZeroBitType) r a. e -> ParserT st r e a Source #
withError :: forall (st :: ZeroBitType) r e b. 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.
Arguments
:: forall (st :: ZeroBitType) r t a e b. ParserT st r t a | The parser to run. |
-> (a -> ParserT st r e b) | The parser to run in case of success. |
-> ParserT st r e b | The parser to run in case of failure. |
-> (t -> ParserT st r e b) | The parser to run in case of error. |
-> ParserT st r e b |
Run the parser, and handle each possible result.
fails :: forall (st :: ZeroBitType) r e a. ParserT st r e a -> ParserT st r e () Source #
Convert a parsing failure to a success.
cut :: forall (st :: ZeroBitType) r e a. ParserT st r e a -> e -> ParserT st r e a Source #
Convert a parsing failure to an error.
cutting :: forall (st :: ZeroBitType) r e a. 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.
optional :: forall (st :: ZeroBitType) r e a. ParserT st r e a -> ParserT st r e (Maybe a) Source #
Convert a parsing failure to a Maybe
. If possible, use withOption
instead.
optional_ :: forall (st :: ZeroBitType) r e a. ParserT st r e a -> ParserT st r e () Source #
Convert a parsing failure to a ()
.
withOption :: forall (st :: ZeroBitType) r e a ret. ParserT st r e a -> (a -> ParserT st r e ret) -> ParserT st r e ret -> ParserT st r e ret Source #