-- 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 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. If the parser result is also a -- monoid, the parser can provide it incrementally, before the complete -- input is parsed. @package incremental-parser @version 0.2.1 -- | This module defines the MonoidNull class. module Data.Monoid.Null -- | Extension of Monoid that allows testing a value for equality -- with mempty. The following law must hold: -- --
--   mnull == (== mempty)
--   
class Monoid m => MonoidNull m mnull :: MonoidNull m => m -> Bool instance MonoidNull (Last a) instance MonoidNull (First a) instance Monoid a => MonoidNull (Maybe a) instance (MonoidNull a, MonoidNull b) => MonoidNull (a, b) instance MonoidNull Text instance MonoidNull ByteString instance MonoidNull [x] -- | This module defines the FactorialMonoid class. module Data.Monoid.Factorial -- | Class of monoids that can be split into irreducible factors, -- i.e., atoms or primes. The methods of this class satisfy the -- following laws: -- --
--   mconcat . factors == id
--   factors mempty == []
--   all (\f-> factors f == [f]) (factors m)
--   factors == unfoldr splitPrimePrefix == reverse . unfoldr (fmap swap . splitPrimeSuffix)
--   primePrefix == maybe mempty fst . splitPrimePrefix
--   primeSuffix == maybe mempty snd . splitPrimeSuffix
--   mfoldl f f0 == foldl f f0 . factors
--   mfoldr f f0 == foldr f f0 . factors
--   mspan p m == (mconcat l, mconcat r) where (l, r) = span p (factors m)
--   
-- -- A minimal instance definition must implement factors or -- splitPrimePrefix. class Monoid m => FactorialMonoid m where factors = unfoldr splitPrimePrefix primePrefix = maybe mempty fst . splitPrimePrefix primeSuffix = maybe mempty snd . splitPrimeSuffix splitPrimePrefix x = case factors x of { [] -> Nothing prefix : rest -> Just (prefix, mconcat rest) } splitPrimeSuffix x = case factors x of { [] -> Nothing fs -> Just (mconcat (init fs), last fs) } mfoldl f f0 = foldl f f0 . factors mfoldr f f0 = foldr f f0 . factors mspan p = mfoldr f (mempty, mempty) where f s (prefix, suffix) = if p s then (mappend s prefix, suffix) else (mempty, mappend s (mappend prefix suffix)) factors :: FactorialMonoid m => m -> [m] primePrefix :: FactorialMonoid m => m -> m primeSuffix :: FactorialMonoid m => m -> m splitPrimePrefix :: FactorialMonoid m => m -> Maybe (m, m) splitPrimeSuffix :: FactorialMonoid m => m -> Maybe (m, m) mfoldl :: FactorialMonoid m => (a -> m -> a) -> a -> m -> a mfoldr :: FactorialMonoid m => (m -> a -> a) -> a -> m -> a mspan :: FactorialMonoid m => (m -> Bool) -> m -> (m, m) -- | A break equivalent. mbreak :: FactorialMonoid m => (m -> Bool) -> m -> (m, m) -- | A length equivalent. mlength :: FactorialMonoid m => m -> Int -- | A map equivalent. mmap :: FactorialMonoid m => (m -> m) -> m -> m -- | A reverse equivalent. mreverse :: FactorialMonoid m => m -> m -- | A takeWhile equivalent. mtakeWhile :: FactorialMonoid m => (m -> Bool) -> m -> m -- | A dropWhile equivalent. mdropWhile :: FactorialMonoid m => (m -> Bool) -> m -> m instance FactorialMonoid Text instance FactorialMonoid ByteString instance FactorialMonoid [x] -- | This module defines the Monoid => CancellativeMonoid -- => GCDMonoid class hierarchy. module Data.Monoid.Cancellative -- | Class of monoids for which the mappend operation can be -- reverted while satisfying the following laws: -- --
--   mstripPrefix a (a `mappend` b) == Just b
--   mstripSuffix b (a `mappend` b) == Just a
--   maybe b (a `mappend`) (mstripPrefix a b) == b
--   maybe b (`mappend` a) (mstripSuffix a b) == b
--   
class (LeftCancellativeMonoid m, RightCancellativeMonoid m) => CancellativeMonoid m -- | Class of monoids that allow the greatest common denominator to be -- found for any two given values. The operations must satisfy the -- following laws: -- --
--   commonPrefix (a `mappend` b) (a `mappend` c) == a `mappend` commonPrefix b c
--   commonSuffix (a `mappend` c) (b `mappend` c) == commonSuffix a b `mappend` c
--   
class (CancellativeMonoid m, LeftGCDMonoid m, RightGCDMonoid m) => GCDMonoid m -- | Class of monoids with a left inverse of mappend, satisfying the -- following law: -- --
--   mstripPrefix a (a `mappend` b) == Just b
--   maybe b (a `mappend`) (mstripPrefix a b) == b
--   
class Monoid m => LeftCancellativeMonoid m mstripPrefix :: LeftCancellativeMonoid m => m -> m -> Maybe m -- | Class of monoids with a right inverse of mappend, satisfying -- the following law: -- --
--   mstripSuffix b (a `mappend` b) == Just a
--   maybe b (`mappend` a) (mstripSuffix a b) == b
--   
class Monoid m => RightCancellativeMonoid m mstripSuffix :: RightCancellativeMonoid m => m -> m -> Maybe m class LeftCancellativeMonoid m => LeftGCDMonoid m commonPrefix :: LeftGCDMonoid m => m -> m -> m class RightCancellativeMonoid m => RightGCDMonoid m commonSuffix :: RightGCDMonoid m => m -> m -> m instance GCDMonoid Text instance RightGCDMonoid Text instance LeftGCDMonoid Text instance CancellativeMonoid Text instance RightCancellativeMonoid Text instance LeftCancellativeMonoid Text instance GCDMonoid ByteString instance RightGCDMonoid ByteString instance LeftGCDMonoid ByteString instance CancellativeMonoid ByteString instance RightCancellativeMonoid ByteString instance LeftCancellativeMonoid ByteString instance Eq x => GCDMonoid [x] instance Eq x => CancellativeMonoid [x] instance Eq x => RightGCDMonoid [x] instance Eq x => RightCancellativeMonoid [x] instance Eq x => LeftGCDMonoid [x] instance Eq x => LeftCancellativeMonoid [x] -- | This module defines the AlternativeMonoid class module Control.Applicative.Monoid class Applicative f => MonoidApplicative f where >< = liftA2 mappend (><) :: (MonoidApplicative f, Monoid a) => f a -> f a -> f a class (Alternative f, MonoidApplicative f) => MonoidAlternative f where moptional x = x <|> pure mempty concatMany = fmap mconcat . many concatSome = fmap mconcat . some moptional :: (MonoidAlternative f, Monoid a) => f a -> f a concatMany :: (MonoidAlternative f, Monoid a) => f a -> f a concatSome :: (MonoidAlternative f, Monoid a) => f a -> f a -- | This module defines 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. -- -- Implementation is based on Brzozowski derivatives. module Text.ParserCombinators.Incremental -- | The central parser type. Its first parameter is the input monoid, the -- second the output. data Parser a s r -- | Feeds a chunk of the input to the parser. feed :: Monoid s => s -> Parser a s r -> Parser a s r -- | Signals the end of the input. feedEof :: Monoid s => Parser a s r -> Parser a s r -- | Extracts all available parsing results. 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 a s r -> ([(r, s)], Maybe (r, Parser a s r)) -- | Like results, but returns only the complete results with the -- corresponding unconsumed inputs. completeResults :: Parser a s r -> [(r, s)] -- | Like results, but returns only the partial result prefix. resultPrefix :: Monoid r => Parser a s r -> (r, Parser a s r) failure :: Parser a s r more :: (s -> Parser a s r) -> Parser a s r -- | A parser that fails on any input and succeeds at its end. eof :: (MonoidNull s, Monoid r) => Parser a s r -- | A parser that accepts any single input atom. anyToken :: FactorialMonoid s => Parser a s s -- | A parser that accepts a specific input atom. token :: (Eq s, FactorialMonoid s) => s -> Parser a s s -- | A parser that accepts an input atom only if it satisfies the given -- predicate. satisfy :: FactorialMonoid s => (s -> Bool) -> Parser a s s -- | A parser that accepts all input. acceptAll :: Monoid s => Parser a s s -- | A parser that consumes and returns the given prefix of the input. string :: (LeftCancellativeMonoid s, MonoidNull s) => s -> Parser a 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 a 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 a s s -- | Accepts the given number of occurrences of the argument parser. count :: (Monoid s, Monoid r) => Int -> Parser a s r -> Parser a s r -- | Discards the results of the argument parser. skip :: (Monoid s, Monoid r) => Parser a s r' -> Parser a s r -- | Like optional, but restricted to Monoid results. moptional :: (MonoidAlternative f, Monoid a) => f a -> f a -- | Zero or more argument occurrences like many, but concatenated. concatMany :: (MonoidAlternative f, Monoid a) => f a -> f a -- | One or more argument occurrences like some, but concatenated. concatSome :: (MonoidAlternative f, Monoid a) => f a -> f a -- | Repeats matching the first argument until the second one succeeds. manyTill :: (Alternative (Parser a s), Monoid s, Monoid r) => Parser a s r -> Parser a s r' -> Parser a s r mapType :: (Parser a s r -> Parser b s r) -> Parser a 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 (<||>) :: Parser a s r -> Parser a s r -> Parser a s r (<<|>) :: Monoid s => Parser a s r -> Parser a s r -> Parser a s r -- | Lifted and potentially optimized monoid mappend operation from -- the parameter type. (><) :: (MonoidApplicative f, Monoid a) => f a -> f a -> f a -- | Behaves like the argument parser, but without consuming any input. lookAhead :: Monoid s => Parser a s r -> Parser a s r -- | Does not consume any input; succeeds (with mempty result) iff -- the argument parser fails. notFollowedBy :: (Monoid s, Monoid r) => Parser a s r' -> Parser a 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 a s r1 -> Parser a s r2 -> Parser a s (r1, r2) -- | A sequence parser that preserves incremental results, otherwise -- equivalent to liftA2 (,) andThen :: (Monoid s, Monoid r1, Monoid r2) => Parser a s r1 -> Parser a s r2 -> Parser a s (r1, r2) isInfallible :: Parser a s r -> Bool showWith :: (Monoid s, Monoid r, Show s) => ((s -> Parser a s r) -> String) -> (r -> String) -> Parser a s r -> String instance (Alternative (Parser a s), Monoid s) => MonoidAlternative (Parser a s) instance (Monoid s, Monoid r) => Monoid (Parser a s r) instance Monoid s => MonoidApplicative (Parser a s) instance Monoid s => Monad (Parser a s) instance Monoid s => Applicative (Parser a s) instance Monoid s => Functor (Parser a s) -- | This module defines 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. -- -- Implementation is based on Brzozowski derivatives. module Text.ParserCombinators.Incremental.LeftBiasedLocal 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 Monoid s => MonadPlus (Parser LeftBiasedLocal s) instance Monoid s => Alternative (Parser LeftBiasedLocal s) -- | This module defines 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. -- -- Implementation is based on Brzozowski derivatives. module Text.ParserCombinators.Incremental.Symmetric 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 Monoid s => MonadPlus (Parser Symmetric s) instance Monoid s => Alternative (Parser Symmetric s)