JustParse-2.1: A simple and comprehensive Haskell parsing library

Portabilityportable
Stabilityexperimental
Maintainergrantslatton@gmail.com
Safe HaskellSafe

Data.JustParse.Combinator

Contents

Description

The bread and butter of combinatory parsing.

Synopsis

Utility Parsers

assert :: Stream s t => Bool -> Parser s ()Source

Synonym of guard.

eof :: Stream s t => Parser s ()Source

Only succeeds when supplied with Nothing.

eitherP :: Stream s t => Parser s a -> Parser s b -> Parser s (Either a b)Source

eitherP a b returns the result wrapped in a Left if a succeeds or a Right if b succeeds

greedy :: Stream s t => Parser s a -> Parser s aSource

Modifies a parser so that it will ony return the most consumptive succesful results.

guard :: Stream s t => Bool -> Parser s ()Source

A parser that succeeds on True and fails on False.

lookAhead :: Stream s t => Parser s a -> Parser s aSource

Applies the parser and returns its result, but resets the Stream as if it consumed nothing.

notFollowedBy :: Stream s t => Parser s a -> Parser s ()Source

Only succeeds when the given parser fails. Consumes no input.

option :: Stream s t => a -> Parser s a -> Parser s aSource

Attempts to apply a parser and returns a default value if it fails.

optional :: Stream s t => Parser s a -> Parser s (Maybe a)Source

Attempts to apply the parser, returning Nothing upon failure, or the result wrapped in a Just.

test :: Stream s t => Parser s a -> Parser s BoolSource

Return True if the parser would succeed if one were to apply it, otherwise, it returns False. It does not consume input.

try :: Stream s t => Parser s a -> Parser s aSource

Does nothing -- only used for Parsec compatability.

(<|>) :: Stream s t => Parser s a -> Parser s a -> Parser s aSource

a <|> b is equivalent to choice [a,b]. That is, first a is tried, and if it yields no results, b is tried.

Token Parsers

anyToken :: Stream s t => Parser s tSource

Parse any token.

noneOf :: (Eq t, Stream s t) => [t] -> Parser s tSource

Parse a token that is not a member of the list of tokens.

oneOf :: (Eq t, Stream s t) => [t] -> Parser s tSource

Parse a token that is a member of the list of tokens.

satisfy :: Stream s t => (t -> Bool) -> Parser s tSource

Parse a token that satisfies a predicate.

token :: (Eq t, Stream s t) => t -> Parser s tSource

Parse a specific token.

Repetetive Parsers

chainl :: Stream s t => Parser s a -> Parser s (a -> a -> a) -> a -> Parser s aSource

chainr p o x parses zero or more occurences of p separated by o. The result is the left associative application of the functions to the values. If p succeeds zero times, x is returned.

chainl1 :: Stream s t => Parser s a -> Parser s (a -> a -> a) -> Parser s aSource

Like chainl, but a minimum of one occurence of p must be parsed.

chainr :: Stream s t => Parser s a -> Parser s (a -> a -> a) -> a -> Parser s aSource

Like chainl, but right associative.

chainr1 :: Stream s t => Parser s a -> Parser s (a -> a -> a) -> Parser s aSource

Like chainl1, but right associative.

count :: Stream s t => Int -> Parser s a -> Parser s [a]Source

count n p parses exactly n occurences of p.

endBy :: Stream s t => Parser s a -> Parser s b -> Parser s [a]Source

endBy p s parses multiple occurences of p separated and ended by s.

endBy1 :: Stream s t => Parser s a -> Parser s b -> Parser s [a]Source

endBy1 p s parses one or more occurences of p separated and ended by s.

exactly :: Stream s t => Int -> Parser s a -> Parser s [a]Source

Synonym of count.

many :: Stream s t => Parser s a -> Parser s [a]Source

Applies a parser zero or more times.

many1 :: Stream s t => Parser s a -> Parser s [a]Source

Applies a parser one or more times.

manyTill :: Stream s t => Parser s a -> Parser s b -> Parser s [a]Source

manyTill a b parses multiple occurences of a until b would succeed if tried.

mN :: Stream s t => Int -> Int -> Parser s a -> Parser s [a]Source

mN m n p parses between m and n occurences of p, inclusive.

sepBy :: Stream s t => Parser s a -> Parser s b -> Parser s [a]Source

sepBy1 p s parses many occurences of p separated by s.

sepBy1 :: Stream s t => Parser s a -> Parser s b -> Parser s [a]Source

sepBy1 p s parses one or more occurences of p separated by s.

skipMany :: Stream s t => Parser s a -> Parser s ()Source

Identical to many except the result is discarded.

skipMany1 :: Stream s t => Parser s a -> Parser s ()Source

Identical to many1 except the result is discarded.

sepEndBy :: Stream s t => Parser s a -> Parser s b -> Parser s [a]Source

sepEndBy p s parses multiple occurences of p separated and optionally ended by s.

sepEndBy1 :: Stream s t => Parser s a -> Parser s b -> Parser s [a]Source

sepEndBy p s parses one or more occurences of p separated and optionally ended by s.

takeWhile :: Stream s t => (t -> Bool) -> Parser s [t]Source

Parse tokens while a predicate remains true.

takeWhile1 :: Stream s t => (t -> Bool) -> Parser s [t]Source

Parse one or more tokens while a predicate remains true.

Group Parsers

choice :: Stream s t => [Parser s a] -> Parser s aSource

Attempt to apply each parser in the list in order until one succeeds.

perm :: Stream s t => [Parser s a] -> Parser s [a]Source

Parses a sequence of parsers in any order.

select :: Stream s t => [Parser s a] -> Parser s (Int, a)Source

Like choice, but returns the index of the successful parser as well as the result.

Branching Parsers

branch :: Parser s a -> Parser s a -> Parser s aSource

Splits the current parse branch between the two parsers.

(<||>) :: Parser s a -> Parser s a -> Parser s aSource

Infix version of branch.

chainl_ :: Stream s t => Parser s a -> Parser s (a -> a -> a) -> a -> Parser s aSource

Branches every iteration where one branch stops and one branch continues.

chainr_ :: Stream s t => Parser s a -> Parser s (a -> a -> a) -> a -> Parser s aSource

Branches every iteration where one branch stops and one branch continues.

chainl1_ :: Stream s t => Parser s a -> Parser s (a -> a -> a) -> Parser s aSource

Branches every iteration where one branch stops and one branch continues.

chainr1_ :: Stream s t => Parser s a -> Parser s (a -> a -> a) -> Parser s aSource

Branches every iteration where one branch stops and one branch continues.

choice_ :: Stream s t => [Parser s a] -> Parser s aSource

Given a list of parsers, split off a branch for each one.

eitherP_ :: Stream s t => Parser s a -> Parser s b -> Parser s (Either a b)Source

Like eitherP, but tries both a and b.

endBy_ :: Stream s t => Parser s a -> Parser s b -> Parser s [a]Source

Branches every iteration where one branch stops and one branch continues.

endBy1_ :: Stream s t => Parser s a -> Parser s b -> Parser s [a]Source

Branches every iteration where one branch stops and one branch continues.

many_ :: Parser s a -> Parser s [a]Source

Branches every iteration where one branch stops and one branch continues.

many1_ :: Parser s a -> Parser s [a]Source

Branches every iteration where one branch stops and one branch continues.

mN_ :: Stream s t => Int -> Int -> Parser s a -> Parser s [a]Source

Branches every iteration where one branch stops and one branch continues.

option_ :: Stream s t => a -> Parser s a -> Parser s aSource

Splits off two branches, one where the parse is attempted, and one where it is not.

optional_ :: Stream s t => Parser s a -> Parser s (Maybe a)Source

Splits off two branches, one where the parse is attempted, and one where it is not.

perm_ :: Stream s t => [Parser s a] -> Parser s [a]Source

Parses a sequence of parsers in all possible orders.

select_ :: Stream s t => [Parser s a] -> Parser s (Int, a)Source

Like choice_, but returns the index of the successful parser.

sepBy_ :: Stream s t => Parser s a -> Parser s b -> Parser s [a]Source

Branches every iteration where one branch stops and one branch continues.

sepBy1_ :: Stream s t => Parser s a -> Parser s b -> Parser s [a]Source

Branches every iteration where one branch stops and one branch continues.

sepEndBy_ :: Stream s t => Parser s a -> Parser s b -> Parser s [a]Source

Branches every iteration where one branch stops and one branch continues.

sepEndBy1_ :: Stream s t => Parser s a -> Parser s b -> Parser s [a]Source

Branches every iteration where one branch stops and one branch continues.

skipMany_ :: Stream s t => Parser s a -> Parser s ()Source

Branches every iteration where one branch stops and one branch continues.

skipMany1_ :: Stream s t => Parser s a -> Parser s ()Source

Branches every iteration where one branch stops and one branch continues.

takeWhile_ :: Stream s t => (t -> Bool) -> Parser s [t]Source

Branches every iteration where one branch stops and one branch continues.

takeWhile1_ :: Stream s t => (t -> Bool) -> Parser s [t]Source

Branches every iteration where one branch stops and one branch continues.