simple-parser-0.7.0: Simple parser combinators

SimpleParser.Input

Description

Useful combinators for ParserT and Stream. Classified as SAFE or UNSAFE. SAFE always return a value. UNSAFE throw.

Synopsis

# Documentation

withToken :: (Stream s, Monad m) => Maybe l -> (Maybe (Token s) -> ParserT l s e m a) -> ParserT l s e m a Source #

Fetches the next token from the stream and runs the callback.

withChunk :: (Stream s, Monad m) => Maybe l -> Int -> (Maybe (Chunk s) -> ParserT l s e m a) -> ParserT l s e m a Source #

Fetches the next chunk from the stream and runs the callback.

peekToken :: (Stream s, Monad m) => ParserT l s e m (Maybe (Token s)) Source #

Return the next token, if any, but don't consume it. (SAFE)

popToken :: (Stream s, Monad m) => ParserT l s e m (Maybe (Token s)) Source #

Return the next token, if any, and consume it. (SAFE)

peekChunk :: (Stream s, Monad m) => Int -> ParserT l s e m (Maybe (Chunk s)) Source #

Return the next chunk of the given size, if any, but don't consume it. May return a smaller chunk at end of stream, but never returns an empty chunk. (SAFE)

popChunk :: (Stream s, Monad m) => Int -> ParserT l s e m (Maybe (Chunk s)) Source #

Return the next chunk of the given size, if any, and consume it. May return a smaller chunk at end of stream, but never returns an empty chunk. (SAFE)

dropChunk :: (Stream s, Monad m) => Int -> ParserT l s e m (Maybe Int) Source #

Drop the next chunk of the given size, if any, and consume it. May return a smaller size at end of stream, but never returns size 0. (SAFE)

isEnd :: (Stream s, Monad m) => ParserT l s e m Bool Source #

Is this the end of the stream? (SAFE)

matchEnd :: (Stream s, Monad m) => ParserT l s e m () Source #

Match the end of the stream or terminate the parser. (UNSAFE)

anyToken :: (Stream s, Monad m) => ParserT l s e m (Token s) Source #

Return the next token or terminate the parser at end of stream. (UNSAFE)

anyChunk :: (Stream s, Monad m) => Int -> ParserT l s e m (Chunk s) Source #

Return the next chunk of the given size or terminate the parser at end of stream. May return a smaller chunk at end of stream, but never returns an empty chunk. (UNSAFE)

satisfyToken :: (Stream s, Monad m) => Maybe l -> (Token s -> Bool) -> ParserT l s e m (Token s) Source #

Match the next token with the given predicate or terminate the parser at predicate false or end of stream. (UNSAFE)

foldTokensWhile :: (Stream s, Monad m) => (Token s -> x -> (Bool, x)) -> x -> ParserT l s e m x Source #

Folds over a stream of tokens while the boolean value is true. Always succeeds, even at end of stream. Only consumes greediest match. (SAFE)

takeTokensWhile :: (Stream s, Monad m) => (Token s -> Bool) -> ParserT l s e m (Chunk s) Source #

Take tokens into a chunk while they satisfy the given predicate. Always succeeds, even at end of stream. May return an empty chunk. Only yields greediest match. (SAFE)

takeTokensWhile1 :: (Stream s, Monad m) => Maybe l -> (Token s -> Bool) -> ParserT l s e m (Chunk s) Source #

Take tokens into a chunk while they satisfy the given predicate. Only succeeds if 1 or more tokens are taken, so it never returns an empty chunk. Also takes an optional label to describe the predicate. (UNSAFE)

dropTokensWhile :: (Stream s, Monad m) => (Token s -> Bool) -> ParserT l s e m Int Source #

Drop tokens and return chunk size while they satisfy the given predicate. Always succeeds, even at end of stream. May return empty chunk size 0. Only drops greediest match. (SAFE)

dropTokensWhile1 :: (Stream s, Monad m) => Maybe l -> (Token s -> Bool) -> ParserT l s e m Int Source #

Drop tokens and return chunk size while they satisfy the given predicate. Only succeeds if 1 or more tokens are dropped. Also takes an optional label to describe the predicate. (UNSAFE)

matchToken :: (Stream s, Monad m, Eq (Token s)) => Token s -> ParserT l s e m (Token s) Source #

Match token with equality or terminate the parser at inequality or end of stream. (UNSAFE)

matchChunk :: (Stream s, Monad m, Eq (Chunk s)) => Chunk s -> ParserT l s e m (Chunk s) Source #

Match chunk with equality or terminate the parser at inequality or end of stream. (UNSAFE)