    {-# LANGUAGE CPP #-}

    module UU.Parsing.Merge((<||>), pMerged, list_of) where

    import UU.Parsing

    -- ==== merging
    -- e.g. chars_digs = cat3 `pMerged` (list_of pDig <||> list_of pL <||> list_of pU)
    --      parsing "12abCD1aV" now returns "121abaCDV", so the sequence of
    -- recognised elements is stored in three lists, which are then passed to cat3

    (<||>) :: IsParser p s => (c,p (d -> d),e -> f -> g) -> (h,p (i -> i),g -> j -> k) -> ((c,h),p ((d,i) -> (d,i)),e -> (f,j) -> k)
    (pe :: c
    pe, pp :: p (d -> d)
    pp, punp :: e -> f -> g
    punp) <||> :: (c, p (d -> d), e -> f -> g)
    -> (h, p (i -> i), g -> j -> k)
    -> ((c, h), p ((d, i) -> (d, i)), e -> (f, j) -> k)
    <||> (qe :: h
    qe, qp :: p (i -> i)
    qp, qunp :: g -> j -> k
    qunp)
     =( (c
    pe, h
    qe)
      , (\f :: d -> d
    f (pv :: d
    pv, qv :: i
    qv) -> (d -> d
    f d
    pv, i
    qv)) ((d -> d) -> (d, i) -> (d, i))
    -> p (d -> d) -> p ((d, i) -> (d, i))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> p (d -> d)
    pp
                  p ((d, i) -> (d, i))
    -> p ((d, i) -> (d, i)) -> p ((d, i) -> (d, i))
    forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
    <|>
        (\f :: i -> i
    f (pv :: d
    pv, qv :: i
    qv) -> (d
    pv, i -> i
    f i
    qv)) ((i -> i) -> (d, i) -> (d, i))
    -> p (i -> i) -> p ((d, i) -> (d, i))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> p (i -> i)
    qp
      , \f :: e
    f (x :: f
    x, y :: j
    y) -> g -> j -> k
    qunp (e -> f -> g
    punp e
    f f
    x) j
    y
      )

    pMerged :: IsParser p s => c -> (d,p (d -> d),c -> d -> e) -> p e
    sem :: c
    sem pMerged :: c -> (d, p (d -> d), c -> d -> e) -> p e
    `pMerged` (units :: d
    units, alts :: p (d -> d)
    alts, unp :: c -> d -> e
    unp)
     = let pres :: p d
    pres = p (d -> d)
    alts p (d -> d) -> p d -> p d
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> p d
    pres p d -> d -> p d
    forall (p :: * -> *) s a. IsParser p s => p a -> a -> p a
    `opt` d
    units
       in c -> d -> e
    unp c
    sem (d -> e) -> p d -> p e
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> p d
    pres

    list_of :: IsParser p s => p c -> ([d],p ([c] -> [c]),e -> e)
    list_of :: p c -> ([d], p ([c] -> [c]), e -> e)
    list_of p :: p c
    p = ([], (:) (c -> [c] -> [c]) -> p c -> p ([c] -> [c])
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> p c
    p, e -> e
    forall a. a -> a
    id)