    {-# LANGUAGE CPP #-}
    {-# LANGUAGE MonoLocalBinds #-}

    module UU.Parsing.Derived
      ( -- * Checking
        acceptsepsilon
      , mnz

        -- * Prelude defs
      , (<..>)
      , pExcept
      , opt

        -- * Sequential compositions
      , asList
      , asList1
      , asOpt
      , (<+>)
      , (<**>)
      , (<$$>)
      , (<??>)
      , (<?>)
      , pPacked

        -- * Iterating parsers
      , pFoldr_ng, pFoldr_gr, pFoldr
      , pFoldr1_ng, pFoldr1_gr, pFoldr1
      , pFoldrSep_ng, pFoldrSep_gr, pFoldrSep
      , pFoldr1Sep_ng, pFoldr1Sep_gr, pFoldr1Sep

      , pList_ng, pList_gr, pList
      , pList1_ng, pList1_gr, pList1
      , pListSep_ng, pListSep_gr, pListSep
      , pList1Sep_ng, pList1Sep_gr, pList1Sep

      , pChainr_ng, pChainr_gr, pChainr
      , pChainl_ng, pChainl_gr, pChainl

        -- * Misc
      , pAny
      , pAnySym
      , pToks
      , pLocate
      )
      where

    import UU.Parsing.Interface
    import Control.Applicative

    infixl 2 <?>
    -- infixl 4  <**>
    infixl 4  <??>, <+>
    infixl 2 `opt`
    infixl 5 <..>

    -- =======================================================================================
    -- ===== CHECKING ========================================================================
    -- =======================================================================================
    -- | Checks if the parser accepts epsilon.
    acceptsepsilon :: (IsParser p s) => p v -> Bool
    acceptsepsilon :: p v -> Bool
    acceptsepsilon p :: p v
    p       = case p v -> Maybe (p v)
    forall (p :: * -> *) s v. IsParser p s => p v -> Maybe (p v)
    getzerop p v
    p of {Nothing -> Bool
    False; _ -> Bool
    True}

    mnz :: (IsParser p s) => p v -> t -> String -> t
    mnz :: p v -> t -> String -> t
    mnz p :: p v
    p v :: t
    v comb :: String
    comb
       = if( p v -> Bool
    forall (p :: * -> *) s v. IsParser p s => p v -> Bool
    acceptsepsilon p v
    p)
         then   String -> t
    forall a. String -> a
    usererror ("The combinator <" String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String
    comb String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ "> from <Derived.hs>is called with a parser that accepts the empty string.\n"
                        String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++
                       "The library cannot handle the resulting left recursive formulation (which is ambiguous too).\n"
                     --  ++
                     --  (case getfirsts p of
                     --   ESeq []  ->  "There are no other alternatives for this parser"
                     --   d        ->  "The other alternatives of this parser may start with:\n"++ show d
                      ) --)
         else t
    v
    -- =======================================================================================
    -- ===== START OF PRELUDE DEFINITIONS ========== =========================================
    -- =======================================================================================

    -- | Parses the specified range, see also 'pRange'.
    --
    -- Example:
    --
    -- > pDig = 'a' <..> 'z'
    (<..>) :: (IsParser p s) => s -> s -> p s
    a :: s
    a <..> :: s -> s -> p s
    <..> b :: s
    b   = s -> SymbolR s -> p s
    forall (p :: * -> *) s. IsParser p s => s -> SymbolR s -> p s
    pRange s
    a (s -> s -> SymbolR s
    forall s. s -> s -> SymbolR s
    Range s
    a s
    b)

    pExcept :: (IsParser p s, Symbol s, Ord s, Eq (SymbolR s)) => (s, s, s) -> [s] -> p s
    pExcept :: (s, s, s) -> [s] -> p s
    pExcept (l :: s
    l,r :: s
    r,err :: s
    err) elems :: [s]
    elems = let ranges :: [SymbolR s]
    ranges = (SymbolR s -> Bool) -> [SymbolR s] -> [SymbolR s]
    forall a. (a -> Bool) -> [a] -> [a]
    filter (SymbolR s -> SymbolR s -> Bool
    forall a. Eq a => a -> a -> Bool
    /= SymbolR s
    forall s. SymbolR s
    EmptyR) (s -> s -> SymbolR s
    forall s. s -> s -> SymbolR s
    Range s
    l s
    r SymbolR s -> [s] -> [SymbolR s]
    forall (t :: * -> *) s.
    (Foldable t, Ord s, Symbol s) =>
    SymbolR s -> t s -> [SymbolR s]
    `except` [s]
    elems)
                              in if [SymbolR s] -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null [SymbolR s]
    ranges then p s
    forall (p :: * -> *) s a. IsParser p s => p a
    pFail
                                 else (p s -> p s -> p s) -> p s -> [p s] -> p s
    forall (t :: * -> *) a b.
    Foldable t =>
    (a -> b -> b) -> b -> t a -> b
    foldr p s -> p s -> p s
    forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
    (<|>) p s
    forall (p :: * -> *) s a. IsParser p s => p a
    pFail ((SymbolR s -> p s) -> [SymbolR s] -> [p s]
    forall a b. (a -> b) -> [a] -> [b]
    map (s -> SymbolR s -> p s
    forall (p :: * -> *) s. IsParser p s => s -> SymbolR s -> p s
    pRange s
    err) [SymbolR s]
    ranges)

    -- | Optionally recognize parser 'p'.
    --
    -- If 'p' can be recognized, the return value of 'p' is used. Otherwise,
    -- the value 'v' is used. Note that opt is greedy, if you do not want
    -- this use @... <|> pSucceed v@  instead. Furthermore, 'p' should not
    -- recognise the empty string.
    opt ::  (IsParser p s) => p a -> a -> p a
    p :: p a
    p opt :: p a -> a -> p a
    `opt` v :: a
    v       = p a -> p a -> String -> p a
    forall (p :: * -> *) s v t. IsParser p s => p v -> t -> String -> t
    mnz p a
    p (p a
    p  p a -> p a -> p a
    forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
    <|> a -> p a
    forall (p :: * -> *) s a. IsParser p s => a -> p a
    pLow a
    v)  "opt"

    -- =======================================================================================
    -- ===== Special sequential compositions =========================================
    -- =======================================================================================
    asList ::  (IsParser p s) =>  Expecting s -> p v -> p v
    asList :: Expecting s -> p v -> p v
    asList  exp :: Expecting s
    exp = Expecting s -> p v -> p v
    forall (p :: * -> *) s v. IsParser p s => Expecting s -> p v -> p v
    setfirsts ([Expecting s] -> Expecting s
    forall s. [Expecting s] -> Expecting s
    ESeq [String -> Expecting s
    forall s. String -> Expecting s
    EStr "(",  Expecting s
    exp, String -> Expecting s
    forall s. String -> Expecting s
    EStr  " ...)*"])

    asList1 :: (IsParser p s) => Expecting s -> p v -> p v
    asList1 :: Expecting s -> p v -> p v
    asList1 exp :: Expecting s
    exp = Expecting s -> p v -> p v
    forall (p :: * -> *) s v. IsParser p s => Expecting s -> p v -> p v
    setfirsts ([Expecting s] -> Expecting s
    forall s. [Expecting s] -> Expecting s
    ESeq [String -> Expecting s
    forall s. String -> Expecting s
    EStr "(",  Expecting s
    exp, String -> Expecting s
    forall s. String -> Expecting s
    EStr  " ...)+"])

    asOpt :: (IsParser p s) => Expecting s -> p v -> p v
    asOpt :: Expecting s -> p v -> p v
    asOpt   exp :: Expecting s
    exp = Expecting s -> p v -> p v
    forall (p :: * -> *) s v. IsParser p s => Expecting s -> p v -> p v
    setfirsts ([Expecting s] -> Expecting s
    forall s. [Expecting s] -> Expecting s
    ESeq [String -> Expecting s
    forall s. String -> Expecting s
    EStr "( ", Expecting s
    exp, String -> Expecting s
    forall s. String -> Expecting s
    EStr  " ...)?"])

    -- | Parses the sequence of 'pa' and 'pb', and combines them as a tuple.
    (<+>) :: (IsParser p s) => p a -> p b -> p (a, b)
    pa :: p a
    pa <+> :: p a -> p b -> p (a, b)
    <+> pb :: p b
    pb       = (,) (a -> b -> (a, b)) -> p a -> p (b -> (a, b))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> p a
    pa p (b -> (a, b)) -> p b -> p (a, b)
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> p b
    pb

    {-
    -- | Suppose we have a parser a with two alternatives that both start
    -- with recognizing a non-terminal p, then we will typically rewrite:
    --
    -- > a =     f <$> p <*> q
    -- >     <|> g <$> p <*> r
    --
    -- into:
    --
    -- > a = p <**> (f <$$> q <|> g <$$> r)
    (<**>) :: (IsParser p s) => p a -> p (a -> b) -> p b
    p <**> q        = (\ x f -> f x) <$> p <*> q
    -}

    (<$$>) :: (IsParser p s) => (a -> b -> c) -> p b -> p (a -> c)
    f :: a -> b -> c
    f <$$> :: (a -> b -> c) -> p b -> p (a -> c)
    <$$> p :: p b
    p        = (b -> a -> c) -> p (b -> a -> c)
    forall (p :: * -> *) s a. IsParser p s => a -> p a
    pSucceed ((a -> b -> c) -> b -> a -> c
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip a -> b -> c
    f) p (b -> a -> c) -> p b -> p (a -> c)
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> p b
    p

    (<??>) :: (IsParser p s) => p a -> p (a -> a) -> p a
    p :: p a
    p <??> :: p a -> p (a -> a) -> p a
    <??> q :: p (a -> a)
    q        = p a
    p p a -> p (a -> a) -> p a
    forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
    <**> (p (a -> a)
    q p (a -> a) -> (a -> a) -> p (a -> a)
    forall (p :: * -> *) s a. IsParser p s => p a -> a -> p a
    `opt` a -> a
    forall a. a -> a
    id)

    (<?>) :: (IsParser p s) => p v -> String -> p v
    p :: p v
    p <?> :: p v -> String -> p v
    <?>  str :: String
    str      = Expecting s -> p v -> p v
    forall (p :: * -> *) s v. IsParser p s => Expecting s -> p v -> p v
    setfirsts  (String -> Expecting s
    forall s. String -> Expecting s
    EStr String
    str) p v
    p

    -- | This can be used to parse 'x' surrounded by 'l' and 'r'.
    --
    -- Example:
    --
    -- > pParens = pPacked pOParen pCParen
    pPacked :: (IsParser p s) => p a -> p b1 -> p b -> p b
    pPacked :: p a -> p b1 -> p b -> p b
    pPacked l :: p a
    l r :: p b1
    r x :: p b
    x   =   p a
    l p a -> p b -> p b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *>  p b
    x p b -> p b1 -> p b
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
    <*   p b1
    r

    -- =======================================================================================
    -- ===== Iterating ps ===============================================================
    -- =======================================================================================
    pFoldr_ng :: (IsParser p s) => (a -> a1 -> a1, a1) -> p a -> p a1
    pFoldr_ng :: (a -> a1 -> a1, a1) -> p a -> p a1
    pFoldr_ng      alg :: (a -> a1 -> a1, a1)
    alg@(op :: a -> a1 -> a1
    op,e :: a1
    e)     p :: p a
    p = p a -> p a1 -> String -> p a1
    forall (p :: * -> *) s v t. IsParser p s => p v -> t -> String -> t
    mnz p a
    p (Expecting s -> p a1 -> p a1
    forall (p :: * -> *) s v. IsParser p s => Expecting s -> p v -> p v
    asList (p a -> Expecting s
    forall (p :: * -> *) s v. IsParser p s => p v -> Expecting s
    getfirsts p a
    p) p a1
    pfm) "pFoldr_ng"
                                      where pfm :: p a1
    pfm = (a -> a1 -> a1
    op (a -> a1 -> a1) -> p a -> p (a1 -> a1)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> p a
    p p (a1 -> a1) -> p a1 -> p a1
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> p a1
    pfm)  p a1 -> p a1 -> p a1
    forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
    <|> a1 -> p a1
    forall (p :: * -> *) s a. IsParser p s => a -> p a
    pSucceed a1
    e
    pFoldr_gr :: (IsParser p s) => (a -> b -> b, b) -> p a -> p b
    pFoldr_gr :: (a -> b -> b, b) -> p a -> p b
    pFoldr_gr      alg :: (a -> b -> b, b)
    alg@(op :: a -> b -> b
    op,e :: b
    e)     p :: p a
    p = p a -> p b -> String -> p b
    forall (p :: * -> *) s v t. IsParser p s => p v -> t -> String -> t
    mnz p a
    p (Expecting s -> p b -> p b
    forall (p :: * -> *) s v. IsParser p s => Expecting s -> p v -> p v
    asList (p a -> Expecting s
    forall (p :: * -> *) s v. IsParser p s => p v -> Expecting s
    getfirsts p a
    p) p b
    pfm) "pFoldr_gr"
                                      where pfm :: p b
    pfm = (a -> b -> b
    op (a -> b -> b) -> p a -> p (b -> b)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> p a
    p p (b -> b) -> p b -> p b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> p b
    pfm) p b -> b -> p b
    forall (p :: * -> *) s a. IsParser p s => p a -> a -> p a
    `opt` b
    e
    pFoldr :: (IsParser p s) =>(a -> b -> b, b) -> p a -> p b
    pFoldr :: (a -> b -> b, b) -> p a -> p b
    pFoldr         alg :: (a -> b -> b, b)
    alg            p :: p a
    p = (a -> b -> b, b) -> p a -> p b
    forall (p :: * -> *) s a b.
    IsParser p s =>
    (a -> b -> b, b) -> p a -> p b
    pFoldr_gr (a -> b -> b, b)
    alg p a
    p

    pFoldr1_gr :: (IsParser p s) => (v -> b -> b, b) -> p v -> p b
    pFoldr1_gr :: (v -> b -> b, b) -> p v -> p b
    pFoldr1_gr     alg :: (v -> b -> b, b)
    alg@(op :: v -> b -> b
    op,e :: b
    e)     p :: p v
    p = Expecting s -> p b -> p b
    forall (p :: * -> *) s v. IsParser p s => Expecting s -> p v -> p v
    asList1 (p v -> Expecting s
    forall (p :: * -> *) s v. IsParser p s => p v -> Expecting s
    getfirsts p v
    p) (v -> b -> b
    op (v -> b -> b) -> p v -> p (b -> b)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> p v
    p p (b -> b) -> p b -> p b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> (v -> b -> b, b) -> p v -> p b
    forall (p :: * -> *) s a b.
    IsParser p s =>
    (a -> b -> b, b) -> p a -> p b
    pFoldr_gr  (v -> b -> b, b)
    alg p v
    p)
    pFoldr1_ng ::  (IsParser p s) => (v -> b -> b, b) -> p v -> p b
    pFoldr1_ng :: (v -> b -> b, b) -> p v -> p b
    pFoldr1_ng     alg :: (v -> b -> b, b)
    alg@(op :: v -> b -> b
    op,e :: b
    e)     p :: p v
    p = Expecting s -> p b -> p b
    forall (p :: * -> *) s v. IsParser p s => Expecting s -> p v -> p v
    asList1 (p v -> Expecting s
    forall (p :: * -> *) s v. IsParser p s => p v -> Expecting s
    getfirsts p v
    p) (v -> b -> b
    op (v -> b -> b) -> p v -> p (b -> b)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> p v
    p p (b -> b) -> p b -> p b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> (v -> b -> b, b) -> p v -> p b
    forall (p :: * -> *) s a b.
    IsParser p s =>
    (a -> b -> b, b) -> p a -> p b
    pFoldr_ng  (v -> b -> b, b)
    alg p v
    p)
    pFoldr1 :: (IsParser p s) => (v -> b -> b, b) -> p v -> p b
    pFoldr1 :: (v -> b -> b, b) -> p v -> p b
    pFoldr1        alg :: (v -> b -> b, b)
    alg            p :: p v
    p = (v -> b -> b, b) -> p v -> p b
    forall (p :: * -> *) s a b.
    IsParser p s =>
    (a -> b -> b, b) -> p a -> p b
    pFoldr1_gr (v -> b -> b, b)
    alg  p v
    p

    pFoldrSep_gr :: (IsParser p s) => (v -> b -> b, b) -> p a -> p v -> p b
    pFoldrSep_gr :: (v -> b -> b, b) -> p a -> p v -> p b
    pFoldrSep_gr   alg :: (v -> b -> b, b)
    alg@(op :: v -> b -> b
    op,e :: b
    e) sep :: p a
    sep p :: p v
    p = p v -> p b -> String -> p b
    forall (p :: * -> *) s v t. IsParser p s => p v -> t -> String -> t
    mnz p v
    sepp (Expecting s -> p b -> p b
    forall (p :: * -> *) s v. IsParser p s => Expecting s -> p v -> p v
    asList (p v -> Expecting s
    forall (p :: * -> *) s v. IsParser p s => p v -> Expecting s
    getfirsts p v
    p)((v -> b -> b
    op (v -> b -> b) -> p v -> p (b -> b)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> p v
    p p (b -> b) -> p b -> p b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> (v -> b -> b, b) -> p v -> p b
    forall (p :: * -> *) s a b.
    IsParser p s =>
    (a -> b -> b, b) -> p a -> p b
    pFoldr_gr (v -> b -> b, b)
    alg p v
    sepp) p b -> b -> p b
    forall (p :: * -> *) s a. IsParser p s => p a -> a -> p a
    `opt` b
    e )) "pFoldrSep_gr (both args)"
                                      where sepp :: p v
    sepp = p a
    sep p a -> p v -> p v
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> p v
    p
    pFoldrSep_ng :: (IsParser p s) => (v -> b -> b, b) -> p a -> p v -> p b
    pFoldrSep_ng :: (v -> b -> b, b) -> p a -> p v -> p b
    pFoldrSep_ng   alg :: (v -> b -> b, b)
    alg@(op :: v -> b -> b
    op,e :: b
    e) sep :: p a
    sep p :: p v
    p = p v -> p b -> String -> p b
    forall (p :: * -> *) s v t. IsParser p s => p v -> t -> String -> t
    mnz p v
    sepp (Expecting s -> p b -> p b
    forall (p :: * -> *) s v. IsParser p s => Expecting s -> p v -> p v
    asList (p v -> Expecting s
    forall (p :: * -> *) s v. IsParser p s => p v -> Expecting s
    getfirsts p v
    p)((v -> b -> b
    op (v -> b -> b) -> p v -> p (b -> b)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> p v
    p p (b -> b) -> p b -> p b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> (v -> b -> b, b) -> p v -> p b
    forall (p :: * -> *) s a b.
    IsParser p s =>
    (a -> b -> b, b) -> p a -> p b
    pFoldr_ng (v -> b -> b, b)
    alg p v
    sepp)  p b -> p b -> p b
    forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
    <|>  b -> p b
    forall (p :: * -> *) s a. IsParser p s => a -> p a
    pSucceed b
    e)) "pFoldrSep_ng (both args)"
                                      where sepp :: p v
    sepp = p a
    sep p a -> p v -> p v
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> p v
    p
    pFoldrSep ::  (IsParser p s) => (v -> b -> b, b) -> p a -> p v -> p b
    pFoldrSep :: (v -> b -> b, b) -> p a -> p v -> p b
    pFoldrSep      alg :: (v -> b -> b, b)
    alg        sep :: p a
    sep p :: p v
    p = (v -> b -> b, b) -> p a -> p v -> p b
    forall (p :: * -> *) s v b a.
    IsParser p s =>
    (v -> b -> b, b) -> p a -> p v -> p b
    pFoldrSep_gr (v -> b -> b, b)
    alg p a
    sep p v
    p

    pFoldr1Sep_gr :: (IsParser p s) => (a -> b -> b, b) -> p a1 -> p a -> p b
    pFoldr1Sep_gr :: (a -> b -> b, b) -> p a1 -> p a -> p b
    pFoldr1Sep_gr  alg :: (a -> b -> b, b)
    alg@(op :: a -> b -> b
    op,e :: b
    e) sep :: p a1
    sep p :: p a
    p = if p a1 -> Bool
    forall (p :: * -> *) s v. IsParser p s => p v -> Bool
    acceptsepsilon p a1
    sep then p a -> p b -> String -> p b
    forall (p :: * -> *) s v t. IsParser p s => p v -> t -> String -> t
    mnz p a
    p p b
    pfm "pFoldr1Sep_gr (both arguments)" else p b
    pfm
                                      where pfm :: p b
    pfm = a -> b -> b
    op (a -> b -> b) -> p a -> p (b -> b)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> p a
    p p (b -> b) -> p b -> p b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> (a -> b -> b, b) -> p a -> p b
    forall (p :: * -> *) s a b.
    IsParser p s =>
    (a -> b -> b, b) -> p a -> p b
    pFoldr_gr (a -> b -> b, b)
    alg (p a1
    sep p a1 -> p a -> p a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> p a
    p)
    pFoldr1Sep_ng :: (IsParser p s) => (a -> b -> b, b) -> p a1 -> p a -> p b
    pFoldr1Sep_ng :: (a -> b -> b, b) -> p a1 -> p a -> p b
    pFoldr1Sep_ng  alg :: (a -> b -> b, b)
    alg@(op :: a -> b -> b
    op,e :: b
    e) sep :: p a1
    sep p :: p a
    p = if p a1 -> Bool
    forall (p :: * -> *) s v. IsParser p s => p v -> Bool
    acceptsepsilon p a1
    sep  then p a -> p b -> String -> p b
    forall (p :: * -> *) s v t. IsParser p s => p v -> t -> String -> t
    mnz p a
    p p b
    pfm "pFoldr1Sep_ng (both arguments)" else p b
    pfm
                                      where pfm :: p b
    pfm = a -> b -> b
    op (a -> b -> b) -> p a -> p (b -> b)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> p a
    p p (b -> b) -> p b -> p b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> (a -> b -> b, b) -> p a -> p b
    forall (p :: * -> *) s a b.
    IsParser p s =>
    (a -> b -> b, b) -> p a -> p b
    pFoldr_ng (a -> b -> b, b)
    alg (p a1
    sep p a1 -> p a -> p a
    forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
    *> p a
    p)
    pFoldr1Sep :: (IsParser p s) => (a -> b -> b, b) -> p a1 -> p a -> p b
    pFoldr1Sep :: (a -> b -> b, b) -> p a1 -> p a -> p b
    pFoldr1Sep     alg :: (a -> b -> b, b)
    alg        sep :: p a1
    sep p :: p a
    p = (a -> b -> b, b) -> p a1 -> p a -> p b
    forall (p :: * -> *) s v b a.
    IsParser p s =>
    (v -> b -> b, b) -> p a -> p v -> p b
    pFoldr1Sep_gr (a -> b -> b, b)
    alg p a1
    sep p a
    p

    list_alg :: (a -> [a] -> [a], [a1])
    list_alg :: (a -> [a] -> [a], [a1])
    list_alg = ((:), [])

    pList_gr ::  (IsParser p s) => p a -> p [a]
    pList_gr :: p a -> p [a]
    pList_gr        p :: p a
    p = (a -> [a] -> [a], [a]) -> p a -> p [a]
    forall (p :: * -> *) s a b.
    IsParser p s =>
    (a -> b -> b, b) -> p a -> p b
    pFoldr_gr     (a -> [a] -> [a], [a])
    forall a a1. (a -> [a] -> [a], [a1])
    list_alg   p a
    p
    pList_ng :: (IsParser p s) =>  p a -> p [a]
    pList_ng :: p a -> p [a]
    pList_ng        p :: p a
    p = (a -> [a] -> [a], [a]) -> p a -> p [a]
    forall (p :: * -> *) s a b.
    IsParser p s =>
    (a -> b -> b, b) -> p a -> p b
    pFoldr_ng     (a -> [a] -> [a], [a])
    forall a a1. (a -> [a] -> [a], [a1])
    list_alg   p a
    p
    pList ::  (IsParser p s) => p a -> p [a]
    pList :: p a -> p [a]
    pList           p :: p a
    p = p a -> p [a]
    forall (p :: * -> *) s a. IsParser p s => p a -> p [a]
    pList_gr p a
    p

    pList1_gr ::  (IsParser p s) => p a -> p [a]
    pList1_gr :: p a -> p [a]
    pList1_gr       p :: p a
    p = (a -> [a] -> [a], [a]) -> p a -> p [a]
    forall (p :: * -> *) s a b.
    IsParser p s =>
    (a -> b -> b, b) -> p a -> p b
    pFoldr1_gr    (a -> [a] -> [a], [a])
    forall a a1. (a -> [a] -> [a], [a1])
    list_alg   p a
    p
    pList1_ng :: (IsParser p s) => p a -> p [a]
    pList1_ng :: p a -> p [a]
    pList1_ng       p :: p a
    p = (a -> [a] -> [a], [a]) -> p a -> p [a]
    forall (p :: * -> *) s a b.
    IsParser p s =>
    (a -> b -> b, b) -> p a -> p b
    pFoldr1_ng    (a -> [a] -> [a], [a])
    forall a a1. (a -> [a] -> [a], [a1])
    list_alg   p a
    p
    pList1 :: (IsParser p s) =>  p a -> p [a]
    pList1 :: p a -> p [a]
    pList1          p :: p a
    p = p a -> p [a]
    forall (p :: * -> *) s a. IsParser p s => p a -> p [a]
    pList1_gr                p a
    p

    pListSep_gr :: (IsParser p s) => p a1 -> p a -> p [a]
    pListSep_gr :: p a1 -> p a -> p [a]
    pListSep_gr   s :: p a1
    s p :: p a
    p = (a -> [a] -> [a], [a]) -> p a1 -> p a -> p [a]
    forall (p :: * -> *) s v b a.
    IsParser p s =>
    (v -> b -> b, b) -> p a -> p v -> p b
    pFoldrSep_gr  (a -> [a] -> [a], [a])
    forall a a1. (a -> [a] -> [a], [a1])
    list_alg p a1
    s p a
    p
    pListSep_ng :: (IsParser p s) => p a1 -> p a -> p [a]
    pListSep_ng :: p a1 -> p a -> p [a]
    pListSep_ng   s :: p a1
    s p :: p a
    p = (a -> [a] -> [a], [a]) -> p a1 -> p a -> p [a]
    forall (p :: * -> *) s v b a.
    IsParser p s =>
    (v -> b -> b, b) -> p a -> p v -> p b
    pFoldrSep_ng  (a -> [a] -> [a], [a])
    forall a a1. (a -> [a] -> [a], [a1])
    list_alg p a1
    s p a
    p
    pListSep :: (IsParser p s) => p a -> p a1 -> p [a1]
    pListSep :: p a -> p a1 -> p [a1]
    pListSep      s :: p a
    s p :: p a1
    p = p a -> p a1 -> p [a1]
    forall (p :: * -> *) s a1 a. IsParser p s => p a1 -> p a -> p [a]
    pListSep_gr            p a
    s p a1
    p

    pList1Sep_gr :: (IsParser p s) => p a1 -> p a -> p [a]
    pList1Sep_gr :: p a1 -> p a -> p [a]
    pList1Sep_gr  s :: p a1
    s p :: p a
    p = (a -> [a] -> [a], [a]) -> p a1 -> p a -> p [a]
    forall (p :: * -> *) s v b a.
    IsParser p s =>
    (v -> b -> b, b) -> p a -> p v -> p b
    pFoldr1Sep_gr (a -> [a] -> [a], [a])
    forall a a1. (a -> [a] -> [a], [a1])
    list_alg p a1
    s p a
    p
    pList1Sep_ng :: (IsParser p s) =>  p a1 -> p a -> p [a]
    pList1Sep_ng :: p a1 -> p a -> p [a]
    pList1Sep_ng  s :: p a1
    s p :: p a
    p = (a -> [a] -> [a], [a]) -> p a1 -> p a -> p [a]
    forall (p :: * -> *) s v b a.
    IsParser p s =>
    (v -> b -> b, b) -> p a -> p v -> p b
    pFoldr1Sep_ng (a -> [a] -> [a], [a])
    forall a a1. (a -> [a] -> [a], [a1])
    list_alg p a1
    s p a
    p
    pList1Sep :: (IsParser p s) =>p a -> p a1 -> p [a1]
    pList1Sep :: p a -> p a1 -> p [a1]
    pList1Sep     s :: p a
    s p :: p a1
    p = p a -> p a1 -> p [a1]
    forall (p :: * -> *) s a1 a. IsParser p s => p a1 -> p a -> p [a]
    pList1Sep_gr          p a
    s p a1
    p

    pChainr_gr :: (IsParser p s) => p (c -> c -> c) -> p c -> p c
    pChainr_gr :: p (c -> c -> c) -> p c -> p c
    pChainr_gr op :: p (c -> c -> c)
    op x :: p c
    x    =  if p (c -> c -> c) -> Bool
    forall (p :: * -> *) s v. IsParser p s => p v -> Bool
    acceptsepsilon p (c -> c -> c)
    op then p c -> p c -> String -> p c
    forall (p :: * -> *) s v t. IsParser p s => p v -> t -> String -> t
    mnz p c
    x p c
    r "pChainr_gr (both arguments)" else p c
    r
                       where r :: p c
    r = p c
    x p c -> p (c -> c) -> p c
    forall (p :: * -> *) s a. IsParser p s => p a -> p (a -> a) -> p a
    <??> ((c -> c -> c) -> c -> c -> c
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip ((c -> c -> c) -> c -> c -> c)
    -> p (c -> c -> c) -> p (c -> c -> c)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> p (c -> c -> c)
    op p (c -> c -> c) -> p c -> p (c -> c)
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> p c
    r)
    pChainr_ng :: (IsParser p s) => p (a -> a -> a) -> p a -> p a
    pChainr_ng :: p (a -> a -> a) -> p a -> p a
    pChainr_ng op :: p (a -> a -> a)
    op x :: p a
    x    =  if p (a -> a -> a) -> Bool
    forall (p :: * -> *) s v. IsParser p s => p v -> Bool
    acceptsepsilon p (a -> a -> a)
    op then p a -> p a -> String -> p a
    forall (p :: * -> *) s v t. IsParser p s => p v -> t -> String -> t
    mnz p a
    x p a
    r "pChainr_ng (both arguments)" else p a
    r
                       where r :: p a
    r = p a
    x p a -> p (a -> a) -> p a
    forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
    <**> (((a -> a -> a) -> a -> a -> a
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip ((a -> a -> a) -> a -> a -> a)
    -> p (a -> a -> a) -> p (a -> a -> a)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> p (a -> a -> a)
    op p (a -> a -> a) -> p a -> p (a -> a)
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> p a
    r)  p (a -> a) -> p (a -> a) -> p (a -> a)
    forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
    <|> (a -> a) -> p (a -> a)
    forall (p :: * -> *) s a. IsParser p s => a -> p a
    pSucceed a -> a
    forall a. a -> a
    id)
    pChainr :: (IsParser p s) => p (c -> c -> c) -> p c -> p c
    pChainr :: p (c -> c -> c) -> p c -> p c
    pChainr    op :: p (c -> c -> c)
    op x :: p c
    x    = p (c -> c -> c) -> p c -> p c
    forall (p :: * -> *) s c.
    IsParser p s =>
    p (c -> c -> c) -> p c -> p c
    pChainr_gr p (c -> c -> c)
    op p c
    x

    pChainl_gr :: (IsParser p s) => p (c -> c -> c) -> p c -> p c
    pChainl_gr :: p (c -> c -> c) -> p c -> p c
    pChainl_gr op :: p (c -> c -> c)
    op x :: p c
    x    =  if p (c -> c -> c) -> Bool
    forall (p :: * -> *) s v. IsParser p s => p v -> Bool
    acceptsepsilon p (c -> c -> c)
    op then p c -> p c -> String -> p c
    forall (p :: * -> *) s v t. IsParser p s => p v -> t -> String -> t
    mnz p c
    x p c
    r "pChainl_gr (both arguments)" else p c
    r
                          where
                           r :: p c
    r      = (c -> [c -> c] -> c
    forall t. t -> [t -> t] -> t
    f (c -> [c -> c] -> c) -> p c -> p ([c -> c] -> c)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> p c
    x p ([c -> c] -> c) -> p [c -> c] -> p c
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> p (c -> c) -> p [c -> c]
    forall (p :: * -> *) s a. IsParser p s => p a -> p [a]
    pList_gr ((c -> c -> c) -> c -> c -> c
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip ((c -> c -> c) -> c -> c -> c)
    -> p (c -> c -> c) -> p (c -> c -> c)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> p (c -> c -> c)
    op p (c -> c -> c) -> p c -> p (c -> c)
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> p c
    x) )
                           f :: t -> [t -> t] -> t
    f x :: t
    x [] = t
    x
                           f x :: t
    x (func :: t -> t
    func:rest :: [t -> t]
    rest) = t -> [t -> t] -> t
    f (t -> t
    func t
    x) [t -> t]
    rest

    pChainl_ng :: (IsParser p s) => p (c -> c -> c) -> p c -> p c
    pChainl_ng :: p (c -> c -> c) -> p c -> p c
    pChainl_ng op :: p (c -> c -> c)
    op x :: p c
    x    =  if p (c -> c -> c) -> Bool
    forall (p :: * -> *) s v. IsParser p s => p v -> Bool
    acceptsepsilon p (c -> c -> c)
    op then p c -> p c -> String -> p c
    forall (p :: * -> *) s v t. IsParser p s => p v -> t -> String -> t
    mnz p c
    x p c
    r "pChainl_ng (both arguments)" else p c
    r
                       where
                        r :: p c
    r      = (c -> [c -> c] -> c
    forall t. t -> [t -> t] -> t
    f (c -> [c -> c] -> c) -> p c -> p ([c -> c] -> c)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> p c
    x p ([c -> c] -> c) -> p [c -> c] -> p c
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> p (c -> c) -> p [c -> c]
    forall (p :: * -> *) s a. IsParser p s => p a -> p [a]
    pList_ng ((c -> c -> c) -> c -> c -> c
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip ((c -> c -> c) -> c -> c -> c)
    -> p (c -> c -> c) -> p (c -> c -> c)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> p (c -> c -> c)
    op p (c -> c -> c) -> p c -> p (c -> c)
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> p c
    x) )
                        f :: t -> [t -> t] -> t
    f x :: t
    x [] = t
    x
                        f x :: t
    x (func :: t -> t
    func:rest :: [t -> t]
    rest) = t -> [t -> t] -> t
    f (t -> t
    func t
    x) [t -> t]
    rest
    pChainl :: (IsParser p s) => p (c -> c -> c) -> p c -> p c
    pChainl :: p (c -> c -> c) -> p c -> p c
    pChainl    op :: p (c -> c -> c)
    op x :: p c
    x    = p (c -> c -> c) -> p c -> p c
    forall (p :: * -> *) s c.
    IsParser p s =>
    p (c -> c -> c) -> p c -> p c
    pChainl_gr p (c -> c -> c)
    op p c
    x

    -- | Parses using any of the parsers in the list 'l'.
    --
    -- Warning: 'l' may not be an empty list.
    pAny :: (IsParser p s) =>(a -> p a1) -> [a] -> p a1
    pAny :: (a -> p a1) -> [a] -> p a1
    pAny  f :: a -> p a1
    f l :: [a]
    l = if [a] -> Bool
    forall (t :: * -> *) a. Foldable t => t a -> Bool
    null [a]
    l then String -> p a1
    forall a. String -> a
    usererror "pAny: argument may not be empty list" else (p a1 -> p a1 -> p a1) -> [p a1] -> p a1
    forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
    foldr1 p a1 -> p a1 -> p a1
    forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
    (<|>) ((a -> p a1) -> [a] -> [p a1]
    forall a b. (a -> b) -> [a] -> [b]
    map a -> p a1
    f [a]
    l)

    -- | Parses any of the symbols in 'l'.
    pAnySym :: (IsParser p s) =>[s] -> p s
    pAnySym :: [s] -> p s
    pAnySym l :: [s]
    l = (s -> p s) -> [s] -> p s
    forall (p :: * -> *) s a a1.
    IsParser p s =>
    (a -> p a1) -> [a] -> p a1
    pAny s -> p s
    forall (p :: * -> *) s. IsParser p s => s -> p s
    pSym [s]
    l -- used to be called pAnySym

    pToks :: (IsParser p s) => [s] -> p [s]
    pToks :: [s] -> p [s]
    pToks []     = [s] -> p [s]
    forall (p :: * -> *) s a. IsParser p s => a -> p a
    pSucceed []
    pToks (a :: s
    a:as :: [s]
    as) = (:) (s -> [s] -> [s]) -> p s -> p ([s] -> [s])
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> s -> p s
    forall (p :: * -> *) s. IsParser p s => s -> p s
    pSym s
    a p ([s] -> [s]) -> p [s] -> p [s]
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> [s] -> p [s]
    forall (p :: * -> *) s. IsParser p s => [s] -> p [s]
    pToks [s]
    as

    pLocate :: (IsParser p s) => [[s]] -> p [s]
    pLocate :: [[s]] -> p [s]
    pLocate list :: [[s]]
    list = ([s] -> p [s]) -> [[s]] -> p [s]
    forall (p :: * -> *) s a a1.
    IsParser p s =>
    (a -> p a1) -> [a] -> p a1
    pAny [s] -> p [s]
    forall (p :: * -> *) s. IsParser p s => [s] -> p [s]
    pToks [[s]]
    list