-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Generic parser library capable of providing partial results from partial input.
--
-- This package defines yet another parser combinator library. This one
-- is implemented using the concept of Brzozowski derivatives, tweaked
-- and optimized to work with any monoidal input type. Lists, ByteString,
-- and Text are supported out of the box, as well as any other data type
-- for which the monoid-subclasses package defines instances. If the
-- parser result is also a monoid, its chunks can be extracted
-- incrementally, before the complete input is parsed.
@package incremental-parser
@version 0.3.2.2
-- | This module defines the MonoidApplicative and
-- MonoidAlternative type classes. Their methods are specialized
-- forms of the standard Applicative and Alternative class
-- methods. Instances of these classes should override the default method
-- implementations with more efficient ones.
module Control.Applicative.Monoid
class Applicative f => MonoidApplicative f
-- | A variant of the Applicative's <*> operator specialized
-- for endomorphic functions.
(+<*>) :: MonoidApplicative f => f (a -> a) -> f a -> f a
-- | Lifted and potentially optimized monoid mappend operation from
-- the parameter type.
(><) :: (MonoidApplicative f, Semigroup a) => f a -> f a -> f a
infixl 5 ><
infixl 4 +<*>
class (Alternative f, MonoidApplicative f) => MonoidAlternative f
-- | Like optional, but restricted to Monoid results.
moptional :: (MonoidAlternative f, Semigroup a, Monoid a) => f a -> f a
-- | Zero or more argument occurrences like many, but concatenated.
concatMany :: (MonoidAlternative f, Semigroup a, Monoid a) => f a -> f a
-- | One or more argument occurrences like some, but concatenated.
concatSome :: (MonoidAlternative f, Semigroup a, Monoid a) => f a -> f a
-- | This module defines parsing combinators for incremental parsers.
--
-- The exported Parser type can provide partial parsing results
-- from partial input, as long as the output is a Monoid.
-- Construct a parser using the primitives and combinators, supply it
-- with input using functions feed and feedEof, and extract
-- the parsed output using results.
--
-- If your parser only ever uses the symmetric choice <||>,
-- import the Text.ParserCombinators.Incremental.Symmetric module
-- instead. Vice versa, if you always use the shortcutting
-- <<|> choice, import
-- Text.ParserCombinators.Incremental.LeftBiasedLocal instead of
-- this module.
--
-- Implementation is based on Brzozowski derivatives.
module Text.ParserCombinators.Incremental
-- | The central parser type. Its first parameter is the subtype of the
-- parser, the second is the input monoid type, the third the output
-- type.
data Parser t s r
-- | Feeds a chunk of the input to the parser.
feed :: Monoid s => s -> Parser t s r -> Parser t s r
-- | Signals the end of the input.
feedEof :: Monoid s => Parser t s r -> Parser t s r
-- | Like results, but more general: doesn't assume that the result
-- type is a Monoid.
inspect :: Parser t s r -> ([(r, s)], Maybe (Maybe (r -> r), Parser t s r))
-- | Extracts all available parsing results from a Parser. The first
-- component of the result pair is a list of complete results together
-- with the unconsumed remainder of the input. If the parsing can
-- continue further, the second component of the pair provides the
-- partial result prefix together with the parser for the rest of the
-- input.
results :: Monoid r => Parser t s r -> ([(r, s)], Maybe (r, Parser t s r))
-- | Like results, but returns only the complete results with the
-- corresponding unconsumed inputs.
completeResults :: Parser t s r -> [(r, s)]
-- | Like results, but returns only the partial result prefix.
resultPrefix :: Monoid r => Parser t s r -> (r, Parser t s r)
failure :: Parser t s r
-- | Name a parser for error reporting in case it fails.
(>) :: Monoid s => Parser t s r -> String -> Parser t s r
infix 0 >
more :: (s -> Parser t s r) -> Parser t s r
-- | A parser that fails on any non-empty input and succeeds at its end.
eof :: (MonoidNull s, Monoid r, Semigroup r) => Parser t s r
-- | A parser that accepts any single input atom.
anyToken :: FactorialMonoid s => Parser t s s
-- | A parser that accepts a specific input atom.
token :: (Eq s, FactorialMonoid s) => s -> Parser t s s
-- | A parser that accepts an input atom only if it satisfies the given
-- predicate.
satisfy :: FactorialMonoid s => (s -> Bool) -> Parser t s s
-- | A parser that accepts and consumes all input.
acceptAll :: (Semigroup s, Monoid s) => Parser t s s
-- | A parser that consumes and returns the given prefix of the input.
string :: (LeftReductiveMonoid s, MonoidNull s, Semigroup s) => s -> Parser t s s
-- | A parser accepting the longest sequence of input atoms that match the
-- given predicate; an optimized version of 'concatMany . satisfy'.
takeWhile :: (FactorialMonoid s, MonoidNull s) => (s -> Bool) -> Parser t s s
-- | A parser accepting the longest non-empty sequence of input atoms that
-- match the given predicate; an optimized version of 'concatSome .
-- satisfy'.
takeWhile1 :: (FactorialMonoid s, MonoidNull s) => (s -> Bool) -> Parser t s s
-- | Specialization of satisfy on TextualMonoid inputs,
-- accepting an input character only if it satisfies the given predicate.
satisfyChar :: TextualMonoid s => (Char -> Bool) -> Parser t s s
-- | Specialization of takeWhile on TextualMonoid inputs,
-- accepting the longest sequence of input characters that match the
-- given predicate; an optimized version of 'concatMany . satisfyChar'.
takeCharsWhile :: (TextualMonoid s, MonoidNull s) => (Char -> Bool) -> Parser t s s
-- | Specialization of takeWhile1 on TextualMonoid inputs,
-- accepting the longest non-empty sequence of input atoms that match the
-- given predicate; an optimized version of 'concatSome . satisfyChar'.
takeCharsWhile1 :: (TextualMonoid s, MonoidNull s) => (Char -> Bool) -> Parser t s s
-- | Accepts the given number of occurrences of the argument parser.
count :: (Monoid s, Monoid r, Semigroup r) => Int -> Parser t s r -> Parser t s r
-- | Discards the results of the argument parser.
skip :: (Monoid s, Monoid r, Semigroup r) => Parser t s r' -> Parser t s r
-- | Like optional, but restricted to Monoid results.
moptional :: (MonoidAlternative f, Semigroup a, Monoid a) => f a -> f a
-- | Zero or more argument occurrences like many, but concatenated.
concatMany :: (MonoidAlternative f, Semigroup a, Monoid a) => f a -> f a
-- | One or more argument occurrences like some, but concatenated.
concatSome :: (MonoidAlternative f, Semigroup a, Monoid a) => f a -> f a
-- | Repeats matching the first argument until the second one succeeds.
manyTill :: (Monoid s, Monoid r, Semigroup r) => Parser t s r -> Parser t s r' -> Parser t s r
mapType :: (Parser t s r -> Parser b s r) -> Parser t s r -> Parser b s r
-- | Like fmap, but capable of mapping partial results, being
-- restricted to Monoid types only.
mapIncremental :: (Monoid s, Monoid a, Monoid b) => (a -> b) -> Parser p s a -> Parser p s b
-- | A variant of the Applicative's <*> operator specialized
-- for endomorphic functions.
(+<*>) :: MonoidApplicative f => f (a -> a) -> f a -> f a
infixl 4 +<*>
(<||>) :: Parser t s r -> Parser t s r -> Parser t s r
infixl 3 <||>
(<<|>) :: Monoid s => Parser t s r -> Parser t s r -> Parser t s r
infixl 3 <<|>
-- | Lifted and potentially optimized monoid mappend operation from
-- the parameter type.
(><) :: (MonoidApplicative f, Semigroup a) => f a -> f a -> f a
infixl 5 ><
-- | Behaves like the argument parser, but without consuming any input.
lookAhead :: Monoid s => Parser t s r -> Parser t s r
-- | Does not consume any input; succeeds (with mempty result) iff
-- the argument parser fails.
notFollowedBy :: (Monoid s, Monoid r) => Parser t s r' -> Parser t s r
-- | Parallel parser conjunction: the combined parser keeps accepting input
-- as long as both arguments do.
and :: (Monoid s, Monoid r1, Monoid r2) => Parser t s r1 -> Parser t s r2 -> Parser t s (r1, r2)
-- | A sequence parser that preserves incremental results, otherwise
-- equivalent to liftA2 (,)
andThen :: (Monoid s, Monoid r1, Monoid r2) => Parser t s r1 -> Parser t s r2 -> Parser t s (r1, r2)
isInfallible :: Parser t s r -> Bool
showWith :: (Monoid s, Monoid r, Show s) => ((s -> Parser t s r) -> String) -> (r -> String) -> Parser t s r -> String
defaultMany :: (Monoid s, Alternative (Parser t s)) => Parser t s r -> Parser t s [r]
defaultSome :: (Monoid s, Alternative (Parser t s)) => Parser t s r -> Parser t s [r]
instance GHC.Base.Monoid s => GHC.Base.Functor (Text.ParserCombinators.Incremental.Parser t s)
instance GHC.Base.Monoid s => GHC.Base.Applicative (Text.ParserCombinators.Incremental.Parser t s)
instance GHC.Base.Monoid s => GHC.Base.Monad (Text.ParserCombinators.Incremental.Parser t s)
instance GHC.Base.Monoid s => Control.Monad.Fail.MonadFail (Text.ParserCombinators.Incremental.Parser t s)
instance GHC.Base.Monoid s => Control.Applicative.Monoid.MonoidApplicative (Text.ParserCombinators.Incremental.Parser t s)
instance (GHC.Base.Monoid s, GHC.Base.Semigroup r) => GHC.Base.Semigroup (Text.ParserCombinators.Incremental.Parser t s r)
instance (GHC.Base.Monoid s, GHC.Base.Monoid r, GHC.Base.Semigroup r) => GHC.Base.Monoid (Text.ParserCombinators.Incremental.Parser t s r)
instance (GHC.Base.Alternative (Text.ParserCombinators.Incremental.Parser t s), GHC.Base.Monoid s) => Control.Applicative.Monoid.MonoidAlternative (Text.ParserCombinators.Incremental.Parser t s)
-- | This module defines parsing combinators for incremental parsers with
-- left-biased local choice.
--
-- The exported Parser type can provide partial parsing results
-- from partial input, as long as the output is a Monoid.
-- Construct a parser using the primitives and combinators, supply it
-- with input using functions feed and feedEof, and extract
-- the parsed output using results.
--
-- Implementation is based on Brzozowski derivatives.
module Text.ParserCombinators.Incremental.LeftBiasedLocal
-- | Like optional, but restricted to Monoid results.
moptional :: (MonoidAlternative f, Semigroup a, Monoid a) => f a -> f a
-- | Zero or more argument occurrences like many, but concatenated.
concatMany :: (MonoidAlternative f, Semigroup a, Monoid a) => f a -> f a
-- | One or more argument occurrences like some, but concatenated.
concatSome :: (MonoidAlternative f, Semigroup a, Monoid a) => f a -> f a
-- | Lifted and potentially optimized monoid mappend operation from
-- the parameter type.
(><) :: (MonoidApplicative f, Semigroup a) => f a -> f a -> f a
infixl 5 ><
-- | A variant of the Applicative's <*> operator specialized
-- for endomorphic functions.
(+<*>) :: MonoidApplicative f => f (a -> a) -> f a -> f a
infixl 4 +<*>
-- | Feeds a chunk of the input to the parser.
feed :: Monoid s => s -> Parser t s r -> Parser t s r
-- | Signals the end of the input.
feedEof :: Monoid s => Parser t s r -> Parser t s r
-- | Extracts all available parsing results from a Parser. The first
-- component of the result pair is a list of complete results together
-- with the unconsumed remainder of the input. If the parsing can
-- continue further, the second component of the pair provides the
-- partial result prefix together with the parser for the rest of the
-- input.
results :: Monoid r => Parser t s r -> ([(r, s)], Maybe (r, Parser t s r))
-- | Like results, but more general: doesn't assume that the result
-- type is a Monoid.
inspect :: Parser t s r -> ([(r, s)], Maybe (Maybe (r -> r), Parser t s r))
-- | Like results, but returns only the complete results with the
-- corresponding unconsumed inputs.
completeResults :: Parser t s r -> [(r, s)]
-- | Like results, but returns only the partial result prefix.
resultPrefix :: Monoid r => Parser t s r -> (r, Parser t s r)
failure :: Parser t s r
-- | Name a parser for error reporting in case it fails.
(>) :: Monoid s => Parser t s r -> String -> Parser t s r
infix 0 >
(<||>) :: Parser t s r -> Parser t s r -> Parser t s r
infixl 3 <||>
(<<|>) :: Monoid s => Parser t s r -> Parser t s r -> Parser t s r
infixl 3 <<|>
defaultMany :: (Monoid s, Alternative (Parser t s)) => Parser t s r -> Parser t s [r]
defaultSome :: (Monoid s, Alternative (Parser t s)) => Parser t s r -> Parser t s [r]
showWith :: (Monoid s, Monoid r, Show s) => ((s -> Parser t s r) -> String) -> (r -> String) -> Parser t s r -> String
-- | Like fmap, but capable of mapping partial results, being
-- restricted to Monoid types only.
mapIncremental :: (Monoid s, Monoid a, Monoid b) => (a -> b) -> Parser p s a -> Parser p s b
-- | Behaves like the argument parser, but without consuming any input.
lookAhead :: Monoid s => Parser t s r -> Parser t s r
-- | Does not consume any input; succeeds (with mempty result) iff
-- the argument parser fails.
notFollowedBy :: (Monoid s, Monoid r) => Parser t s r' -> Parser t s r
isInfallible :: Parser t s r -> Bool
mapType :: (Parser t s r -> Parser b s r) -> Parser t s r -> Parser b s r
more :: (s -> Parser t s r) -> Parser t s r
-- | A parser that fails on any non-empty input and succeeds at its end.
eof :: (MonoidNull s, Monoid r, Semigroup r) => Parser t s r
-- | A parser that accepts any single input atom.
anyToken :: FactorialMonoid s => Parser t s s
-- | A parser that accepts a specific input atom.
token :: (Eq s, FactorialMonoid s) => s -> Parser t s s
-- | A parser that accepts an input atom only if it satisfies the given
-- predicate.
satisfy :: FactorialMonoid s => (s -> Bool) -> Parser t s s
-- | Specialization of satisfy on TextualMonoid inputs,
-- accepting an input character only if it satisfies the given predicate.
satisfyChar :: TextualMonoid s => (Char -> Bool) -> Parser t s s
-- | A parser that consumes and returns the given prefix of the input.
string :: (LeftReductiveMonoid s, MonoidNull s, Semigroup s) => s -> Parser t s s
-- | A parser accepting the longest sequence of input atoms that match the
-- given predicate; an optimized version of 'concatMany . satisfy'.
takeWhile :: (FactorialMonoid s, MonoidNull s) => (s -> Bool) -> Parser t s s
-- | A parser accepting the longest non-empty sequence of input atoms that
-- match the given predicate; an optimized version of 'concatSome .
-- satisfy'.
takeWhile1 :: (FactorialMonoid s, MonoidNull s) => (s -> Bool) -> Parser t s s
-- | Specialization of takeWhile on TextualMonoid inputs,
-- accepting the longest sequence of input characters that match the
-- given predicate; an optimized version of 'concatMany . satisfyChar'.
takeCharsWhile :: (TextualMonoid s, MonoidNull s) => (Char -> Bool) -> Parser t s s
-- | Specialization of takeWhile1 on TextualMonoid inputs,
-- accepting the longest non-empty sequence of input atoms that match the
-- given predicate; an optimized version of 'concatSome . satisfyChar'.
takeCharsWhile1 :: (TextualMonoid s, MonoidNull s) => (Char -> Bool) -> Parser t s s
-- | Accepts the given number of occurrences of the argument parser.
count :: (Monoid s, Monoid r, Semigroup r) => Int -> Parser t s r -> Parser t s r
-- | Discards the results of the argument parser.
skip :: (Monoid s, Monoid r, Semigroup r) => Parser t s r' -> Parser t s r
-- | Repeats matching the first argument until the second one succeeds.
manyTill :: (Monoid s, Monoid r, Semigroup r) => Parser t s r -> Parser t s r' -> Parser t s r
-- | A parser that accepts and consumes all input.
acceptAll :: (Semigroup s, Monoid s) => Parser t s s
-- | Parallel parser conjunction: the combined parser keeps accepting input
-- as long as both arguments do.
and :: (Monoid s, Monoid r1, Monoid r2) => Parser t s r1 -> Parser t s r2 -> Parser t s (r1, r2)
-- | A sequence parser that preserves incremental results, otherwise
-- equivalent to liftA2 (,)
andThen :: (Monoid s, Monoid r1, Monoid r2) => Parser t s r1 -> Parser t s r2 -> Parser t s (r1, r2)
type Parser s r = Parser LeftBiasedLocal s r
-- | An empty type to specialize Parser for the left-biased
-- Alternative instance.
data LeftBiasedLocal
leftmost :: Parser s r -> Parser a s r
instance GHC.Base.Monoid s => GHC.Base.Alternative (Text.ParserCombinators.Incremental.Parser Text.ParserCombinators.Incremental.LeftBiasedLocal.LeftBiasedLocal s)
instance GHC.Base.Monoid s => GHC.Base.MonadPlus (Text.ParserCombinators.Incremental.Parser Text.ParserCombinators.Incremental.LeftBiasedLocal.LeftBiasedLocal s)
-- | This module defines parsing combinators for incremental parsers with
-- symmetric choice.
--
-- The exported Parser type can provide partial parsing results
-- from partial input, as long as the output is a Monoid.
-- Construct a parser using the primitives and combinators, supply it
-- with input using functions feed and feedEof, and extract
-- the parsed output using results.
--
-- Implementation is based on Brzozowski derivatives.
module Text.ParserCombinators.Incremental.Symmetric
-- | Like optional, but restricted to Monoid results.
moptional :: (MonoidAlternative f, Semigroup a, Monoid a) => f a -> f a
-- | Zero or more argument occurrences like many, but concatenated.
concatMany :: (MonoidAlternative f, Semigroup a, Monoid a) => f a -> f a
-- | One or more argument occurrences like some, but concatenated.
concatSome :: (MonoidAlternative f, Semigroup a, Monoid a) => f a -> f a
-- | Lifted and potentially optimized monoid mappend operation from
-- the parameter type.
(><) :: (MonoidApplicative f, Semigroup a) => f a -> f a -> f a
infixl 5 ><
-- | A variant of the Applicative's <*> operator specialized
-- for endomorphic functions.
(+<*>) :: MonoidApplicative f => f (a -> a) -> f a -> f a
infixl 4 +<*>
-- | Feeds a chunk of the input to the parser.
feed :: Monoid s => s -> Parser t s r -> Parser t s r
-- | Signals the end of the input.
feedEof :: Monoid s => Parser t s r -> Parser t s r
-- | Extracts all available parsing results from a Parser. The first
-- component of the result pair is a list of complete results together
-- with the unconsumed remainder of the input. If the parsing can
-- continue further, the second component of the pair provides the
-- partial result prefix together with the parser for the rest of the
-- input.
results :: Monoid r => Parser t s r -> ([(r, s)], Maybe (r, Parser t s r))
-- | Like results, but more general: doesn't assume that the result
-- type is a Monoid.
inspect :: Parser t s r -> ([(r, s)], Maybe (Maybe (r -> r), Parser t s r))
-- | Like results, but returns only the complete results with the
-- corresponding unconsumed inputs.
completeResults :: Parser t s r -> [(r, s)]
-- | Like results, but returns only the partial result prefix.
resultPrefix :: Monoid r => Parser t s r -> (r, Parser t s r)
failure :: Parser t s r
-- | Name a parser for error reporting in case it fails.
(>) :: Monoid s => Parser t s r -> String -> Parser t s r
infix 0 >
(<||>) :: Parser t s r -> Parser t s r -> Parser t s r
infixl 3 <||>
(<<|>) :: Monoid s => Parser t s r -> Parser t s r -> Parser t s r
infixl 3 <<|>
defaultMany :: (Monoid s, Alternative (Parser t s)) => Parser t s r -> Parser t s [r]
defaultSome :: (Monoid s, Alternative (Parser t s)) => Parser t s r -> Parser t s [r]
showWith :: (Monoid s, Monoid r, Show s) => ((s -> Parser t s r) -> String) -> (r -> String) -> Parser t s r -> String
-- | Like fmap, but capable of mapping partial results, being
-- restricted to Monoid types only.
mapIncremental :: (Monoid s, Monoid a, Monoid b) => (a -> b) -> Parser p s a -> Parser p s b
-- | Behaves like the argument parser, but without consuming any input.
lookAhead :: Monoid s => Parser t s r -> Parser t s r
-- | Does not consume any input; succeeds (with mempty result) iff
-- the argument parser fails.
notFollowedBy :: (Monoid s, Monoid r) => Parser t s r' -> Parser t s r
isInfallible :: Parser t s r -> Bool
mapType :: (Parser t s r -> Parser b s r) -> Parser t s r -> Parser b s r
more :: (s -> Parser t s r) -> Parser t s r
-- | A parser that fails on any non-empty input and succeeds at its end.
eof :: (MonoidNull s, Monoid r, Semigroup r) => Parser t s r
-- | A parser that accepts any single input atom.
anyToken :: FactorialMonoid s => Parser t s s
-- | A parser that accepts a specific input atom.
token :: (Eq s, FactorialMonoid s) => s -> Parser t s s
-- | A parser that accepts an input atom only if it satisfies the given
-- predicate.
satisfy :: FactorialMonoid s => (s -> Bool) -> Parser t s s
-- | Specialization of satisfy on TextualMonoid inputs,
-- accepting an input character only if it satisfies the given predicate.
satisfyChar :: TextualMonoid s => (Char -> Bool) -> Parser t s s
-- | A parser that consumes and returns the given prefix of the input.
string :: (LeftReductiveMonoid s, MonoidNull s, Semigroup s) => s -> Parser t s s
-- | A parser accepting the longest sequence of input atoms that match the
-- given predicate; an optimized version of 'concatMany . satisfy'.
takeWhile :: (FactorialMonoid s, MonoidNull s) => (s -> Bool) -> Parser t s s
-- | A parser accepting the longest non-empty sequence of input atoms that
-- match the given predicate; an optimized version of 'concatSome .
-- satisfy'.
takeWhile1 :: (FactorialMonoid s, MonoidNull s) => (s -> Bool) -> Parser t s s
-- | Specialization of takeWhile on TextualMonoid inputs,
-- accepting the longest sequence of input characters that match the
-- given predicate; an optimized version of 'concatMany . satisfyChar'.
takeCharsWhile :: (TextualMonoid s, MonoidNull s) => (Char -> Bool) -> Parser t s s
-- | Specialization of takeWhile1 on TextualMonoid inputs,
-- accepting the longest non-empty sequence of input atoms that match the
-- given predicate; an optimized version of 'concatSome . satisfyChar'.
takeCharsWhile1 :: (TextualMonoid s, MonoidNull s) => (Char -> Bool) -> Parser t s s
-- | Accepts the given number of occurrences of the argument parser.
count :: (Monoid s, Monoid r, Semigroup r) => Int -> Parser t s r -> Parser t s r
-- | Discards the results of the argument parser.
skip :: (Monoid s, Monoid r, Semigroup r) => Parser t s r' -> Parser t s r
-- | Repeats matching the first argument until the second one succeeds.
manyTill :: (Monoid s, Monoid r, Semigroup r) => Parser t s r -> Parser t s r' -> Parser t s r
-- | A parser that accepts and consumes all input.
acceptAll :: (Semigroup s, Monoid s) => Parser t s s
-- | Parallel parser conjunction: the combined parser keeps accepting input
-- as long as both arguments do.
and :: (Monoid s, Monoid r1, Monoid r2) => Parser t s r1 -> Parser t s r2 -> Parser t s (r1, r2)
-- | A sequence parser that preserves incremental results, otherwise
-- equivalent to liftA2 (,)
andThen :: (Monoid s, Monoid r1, Monoid r2) => Parser t s r1 -> Parser t s r2 -> Parser t s (r1, r2)
type Parser s r = Parser Symmetric s r
-- | An empty type to specialize Parser for the symmetric
-- Alternative instance.
data Symmetric
allOf :: Parser s r -> Parser a s r
instance GHC.Base.Monoid s => GHC.Base.Alternative (Text.ParserCombinators.Incremental.Parser Text.ParserCombinators.Incremental.Symmetric.Symmetric s)
instance GHC.Base.Monoid s => GHC.Base.MonadPlus (Text.ParserCombinators.Incremental.Parser Text.ParserCombinators.Incremental.Symmetric.Symmetric s)