    -- ------------------------------------------------------------

    {- |
       Module     : Text.XML.HXT.Arrow.GeneralEntitySubstitution
       Copyright  : Copyright (C) 2005 Uwe Schmidt
       License    : MIT

       Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
       Stability  : experimental
       Portability: portable

       general entity substitution

    -}

    -- ------------------------------------------------------------

    module Text.XML.HXT.Arrow.GeneralEntitySubstitution
        ( processGeneralEntities )
    where

    import Control.Arrow                            -- arrow classes
    import Control.Arrow.ArrowList
    import Control.Arrow.ArrowIf
    import Control.Arrow.ArrowTree

    import Text.XML.HXT.DOM.Interface

    import Text.XML.HXT.Arrow.XmlArrow
    import Text.XML.HXT.Arrow.XmlState

    import Text.XML.HXT.Arrow.ParserInterface
        ( parseXmlEntityValueAsAttrValue
        , parseXmlEntityValueAsContent
        )

    import Text.XML.HXT.Arrow.Edit
        ( transfCharRef
        )

    import Text.XML.HXT.Arrow.DocumentInput
        ( getXmlEntityContents
        )

    import qualified Data.Map as M
        ( Map
        , empty
        , lookup
        , insert
        )

    -- ------------------------------------------------------------

    data GEContext
        = ReferenceInContent
        | ReferenceInAttributeValue
        | ReferenceInEntityValue
        -- or OccursInAttributeValue                                -- not used during substitution but during validation
        -- or ReferenceInDTD                                        -- not used: syntax check detects errors

    type GESubstArrow       = GEContext -> RecList -> GEArrow XmlTree XmlTree

    type GEArrow b c        = IOStateArrow GEEnv b c

    type RecList            = [String]

    -- ------------------------------------------------------------

    newtype GEEnv   = GEEnv (M.Map String GESubstArrow)

    emptyGeEnv      :: GEEnv
    emptyGeEnv :: GEEnv
    emptyGeEnv      = Map String GESubstArrow -> GEEnv
    GEEnv Map String GESubstArrow
    forall k a. Map k a
    M.empty

    lookupGeEnv     :: String -> GEEnv -> Maybe GESubstArrow
    lookupGeEnv :: String -> GEEnv -> Maybe GESubstArrow
    lookupGeEnv k :: String
    k (GEEnv env :: Map String GESubstArrow
    env)
        = String -> Map String GESubstArrow -> Maybe GESubstArrow
    forall k a. Ord k => k -> Map k a -> Maybe a
    M.lookup String
    k Map String GESubstArrow
    env

    addGeEntry      :: String -> GESubstArrow -> GEEnv -> GEEnv
    addGeEntry :: String -> GESubstArrow -> GEEnv -> GEEnv
    addGeEntry k :: String
    k a :: GESubstArrow
    a (GEEnv env :: Map String GESubstArrow
    env)
        = Map String GESubstArrow -> GEEnv
    GEEnv (Map String GESubstArrow -> GEEnv)
    -> Map String GESubstArrow -> GEEnv
    forall a b. (a -> b) -> a -> b
    $ String
    -> GESubstArrow
    -> Map String GESubstArrow
    -> Map String GESubstArrow
    forall k a. Ord k => k -> a -> Map k a -> Map k a
    M.insert String
    k GESubstArrow
    a Map String GESubstArrow
    env

    -- ------------------------------------------------------------

    -- |
    -- substitution of general entities
    --
    -- input: a complete document tree including root node

    processGeneralEntities  :: IOStateArrow s XmlTree XmlTree
    processGeneralEntities :: IOStateArrow s XmlTree XmlTree
    processGeneralEntities
        = ( Int -> String -> IOStateArrow s XmlTree XmlTree
    forall s b. Int -> String -> IOStateArrow s b b
    traceMsg 1 "processGeneralEntities: collect and substitute general entities"
            IOStateArrow s XmlTree XmlTree
    -> IOStateArrow s XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
            GEEnv
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow s XmlTree XmlTree
    forall s1 b c s0. s1 -> IOStateArrow s1 b c -> IOStateArrow s0 b c
    withOtherUserState GEEnv
    emptyGeEnv (IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *) (t :: * -> *) b.
    (ArrowTree a, Tree t) =>
    a (t b) (t b) -> a (t b) (t b)
    processChildren (GESubstArrow
    processGeneralEntity GEContext
    ReferenceInContent []))
            IOStateArrow s XmlTree XmlTree
    -> IOStateArrow s XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
            String -> IOStateArrow s XmlTree XmlTree
    forall s. String -> IOStateArrow s XmlTree XmlTree
    setDocumentStatusFromSystemState "in general entity processing"
            IOStateArrow s XmlTree XmlTree
    -> IOStateArrow s XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
            IOStateArrow s XmlTree XmlTree
    forall s. IOStateArrow s XmlTree XmlTree
    traceTree
            IOStateArrow s XmlTree XmlTree
    -> IOStateArrow s XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
            IOStateArrow s XmlTree XmlTree
    forall s. IOStateArrow s XmlTree XmlTree
    traceSource
          )
          IOStateArrow s XmlTree XmlTree
    -> IOStateArrow s XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree
    forall (a :: * -> * -> *) b c. ArrowIf a => a b b -> a b c -> a b b
    `when`
          IOStateArrow s XmlTree XmlTree
    forall (a :: * -> * -> *). ArrowXml a => a XmlTree XmlTree
    documentStatusOk

    processGeneralEntity    :: GESubstArrow
    processGeneralEntity :: GESubstArrow
    processGeneralEntity context :: GEContext
    context recl :: RecList
    recl
        = [IfThen
       (IOStateArrow GEEnv XmlTree XmlTree)
       (IOStateArrow GEEnv XmlTree XmlTree)]
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *) b c d.
    ArrowIf a =>
    [IfThen (a b c) (a b d)] -> a b d
    choiceA [ IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *). ArrowXml a => a XmlTree XmlTree
    isElem          IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IfThen
         (IOStateArrow GEEnv XmlTree XmlTree)
         (IOStateArrow GEEnv XmlTree XmlTree)
    forall a b. a -> b -> IfThen a b
    :-> ( IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *).
    ArrowXml a =>
    a XmlTree XmlTree -> a XmlTree XmlTree
    processAttrl (IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *) (t :: * -> *) b.
    (ArrowTree a, Tree t) =>
    a (t b) (t b) -> a (t b) (t b)
    processChildren IOStateArrow GEEnv XmlTree XmlTree
    substEntitiesInAttrValue)
                                          IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
                                          IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *) (t :: * -> *) b.
    (ArrowTree a, Tree t) =>
    a (t b) (t b) -> a (t b) (t b)
    processChildren (GESubstArrow
    processGeneralEntity GEContext
    context RecList
    recl)
                                        )
                  , IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *). ArrowXml a => a XmlTree XmlTree
    isEntityRef     IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IfThen
         (IOStateArrow GEEnv XmlTree XmlTree)
         (IOStateArrow GEEnv XmlTree XmlTree)
    forall a b. a -> b -> IfThen a b
    :-> IOStateArrow GEEnv XmlTree XmlTree
    substEntityRef
                  , IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *). ArrowDTD a => a XmlTree XmlTree
    isDTDDoctype    IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IfThen
         (IOStateArrow GEEnv XmlTree XmlTree)
         (IOStateArrow GEEnv XmlTree XmlTree)
    forall a b. a -> b -> IfThen a b
    :-> IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *) (t :: * -> *) b.
    (ArrowTree a, Tree t) =>
    a (t b) (t b) -> a (t b) (t b)
    processChildren (GESubstArrow
    processGeneralEntity GEContext
    context RecList
    recl)
                  , IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *). ArrowDTD a => a XmlTree XmlTree
    isDTDEntity     IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IfThen
         (IOStateArrow GEEnv XmlTree XmlTree)
         (IOStateArrow GEEnv XmlTree XmlTree)
    forall a b. a -> b -> IfThen a b
    :-> IOStateArrow GEEnv XmlTree XmlTree
    addEntityDecl
                  , IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *). ArrowDTD a => a XmlTree XmlTree
    isDTDAttlist    IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IfThen
         (IOStateArrow GEEnv XmlTree XmlTree)
         (IOStateArrow GEEnv XmlTree XmlTree)
    forall a b. a -> b -> IfThen a b
    :-> IOStateArrow GEEnv XmlTree XmlTree
    substEntitiesInAttrDefaultValue
                  , IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *) b. ArrowList a => a b b
    this            IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IfThen
         (IOStateArrow GEEnv XmlTree XmlTree)
         (IOStateArrow GEEnv XmlTree XmlTree)
    forall a b. a -> b -> IfThen a b
    :-> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *) b. ArrowList a => a b b
    this
                  ]
        where
        addEntityDecl       :: GEArrow XmlTree XmlTree
        addEntityDecl :: IOStateArrow GEEnv XmlTree XmlTree
    addEntityDecl
            = IOSLA (XIOState GEEnv) XmlTree Any
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *) b c. ArrowList a => a b c -> a b b
    perform ( [IfThen
       (IOStateArrow GEEnv XmlTree XmlTree)
       (IOSLA (XIOState GEEnv) XmlTree Any)]
    -> IOSLA (XIOState GEEnv) XmlTree Any
    forall (a :: * -> * -> *) b c d.
    ArrowIf a =>
    [IfThen (a b c) (a b d)] -> a b d
    choiceA [ IOStateArrow GEEnv XmlTree XmlTree
    isIntern          IOStateArrow GEEnv XmlTree XmlTree
    -> IOSLA (XIOState GEEnv) XmlTree Any
    -> IfThen
         (IOStateArrow GEEnv XmlTree XmlTree)
         (IOSLA (XIOState GEEnv) XmlTree Any)
    forall a b. a -> b -> IfThen a b
    :-> IOSLA (XIOState GEEnv) XmlTree Any
    forall b. GEArrow XmlTree b
    addInternalEntity           -- don't change sequence of cases
                                , IOStateArrow GEEnv XmlTree XmlTree
    isExtern          IOStateArrow GEEnv XmlTree XmlTree
    -> IOSLA (XIOState GEEnv) XmlTree Any
    -> IfThen
         (IOStateArrow GEEnv XmlTree XmlTree)
         (IOSLA (XIOState GEEnv) XmlTree Any)
    forall a b. a -> b -> IfThen a b
    :-> IOSLA (XIOState GEEnv) XmlTree Any
    forall b. GEArrow XmlTree b
    addExternalEntity
                                , IOStateArrow GEEnv XmlTree XmlTree
    forall b. IOSLA (XIOState GEEnv) b b
    isUnparsed        IOStateArrow GEEnv XmlTree XmlTree
    -> IOSLA (XIOState GEEnv) XmlTree Any
    -> IfThen
         (IOStateArrow GEEnv XmlTree XmlTree)
         (IOSLA (XIOState GEEnv) XmlTree Any)
    forall a b. a -> b -> IfThen a b
    :-> IOSLA (XIOState GEEnv) XmlTree Any
    forall b. GEArrow XmlTree b
    addUnparsedEntity
                                ]
                      )
            where
            isIntern :: IOStateArrow GEEnv XmlTree XmlTree
    isIntern        = IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *) b c. ArrowList a => a b c
    none IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *) b c. ArrowIf a => a b b -> a b c -> a b b
    `when` String -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *).
    ArrowDTD a =>
    String -> a XmlTree XmlTree
    hasDTDAttr String
    k_system
            isExtern :: IOStateArrow GEEnv XmlTree XmlTree
    isExtern        = IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *) b c. ArrowList a => a b c
    none IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *) b c. ArrowIf a => a b b -> a b c -> a b b
    `when` String -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *).
    ArrowDTD a =>
    String -> a XmlTree XmlTree
    hasDTDAttr String
    k_ndata
            isUnparsed :: IOSLA (XIOState GEEnv) b b
    isUnparsed      = IOSLA (XIOState GEEnv) b b
    forall (a :: * -> * -> *) b. ArrowList a => a b b
    this

        addInternalEntity   :: GEArrow XmlTree b
        addInternalEntity :: GEArrow XmlTree b
    addInternalEntity
            = String -> String -> GEArrow XmlTree b
    forall b c. String -> String -> IOSLA (XIOState GEEnv) b c
    insertInternal (String -> String -> GEArrow XmlTree b)
    -> IOSLA (XIOState GEEnv) XmlTree (String, String)
    -> GEArrow XmlTree b
    forall (a :: * -> * -> *) c1 c2 b d.
    ArrowList a =>
    (c1 -> c2 -> a b d) -> a b (c1, c2) -> a b d
    $<<
              ( ( String -> IOSLA (XIOState GEEnv) XmlTree String
    forall (a :: * -> * -> *). ArrowDTD a => String -> a XmlTree String
    getDTDAttrValue String
    a_name
                  IOSLA (XIOState GEEnv) XmlTree String
    -> IOSLA (XIOState GEEnv) String String
    -> IOSLA (XIOState GEEnv) XmlTree String
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
                  Int -> (String -> String) -> IOSLA (XIOState GEEnv) String String
    forall b s. Int -> (b -> String) -> IOStateArrow s b b
    traceValue 2 (("processGeneralEntity: general entity definition for " String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++) (String -> String) -> (String -> String) -> String -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> String
    forall a. Show a => a -> String
    show)
                )
                IOSLA (XIOState GEEnv) XmlTree String
    -> IOSLA (XIOState GEEnv) XmlTree String
    -> IOSLA (XIOState GEEnv) XmlTree (String, String)
    forall (a :: * -> * -> *) b c c'.
    Arrow a =>
    a b c -> a b c' -> a b (c, c')
    &&&
                IOStateArrow GEEnv XmlTree XmlTree
    -> IOSLA (XIOState GEEnv) XmlTree String
    forall (a :: * -> * -> *) n.
    ArrowXml a =>
    a n XmlTree -> a n String
    xshow (IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *) (t :: * -> *) b.
    (ArrowTree a, Tree t) =>
    a (t b) (t b)
    getChildren IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *). ArrowXml a => a XmlTree XmlTree
    isText)
              )
            where
            insertInternal :: String -> String -> IOSLA (XIOState GEEnv) b c
    insertInternal entity :: String
    entity contents :: String
    contents
                = (String -> GESubstArrow) -> String -> GEArrow b b
    forall b. (String -> GESubstArrow) -> String -> GEArrow b b
    insertEntity (String -> String -> GESubstArrow
    substInternal String
    contents) String
    entity
                  GEArrow b b
    -> IOSLA (XIOState GEEnv) b c -> IOSLA (XIOState GEEnv) b c
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
                  IOSLA (XIOState GEEnv) b c
    forall (a :: * -> * -> *) b c. ArrowList a => a b c
    none

        addExternalEntity   :: GEArrow XmlTree b
        addExternalEntity :: GEArrow XmlTree b
    addExternalEntity
            = String -> String -> GEArrow XmlTree b
    forall b c. String -> String -> IOSLA (XIOState GEEnv) b c
    insertExternal (String -> String -> GEArrow XmlTree b)
    -> IOSLA (XIOState GEEnv) XmlTree (String, String)
    -> GEArrow XmlTree b
    forall (a :: * -> * -> *) c1 c2 b d.
    ArrowList a =>
    (c1 -> c2 -> a b d) -> a b (c1, c2) -> a b d
    $<<
              ( ( String -> IOSLA (XIOState GEEnv) XmlTree String
    forall (a :: * -> * -> *). ArrowDTD a => String -> a XmlTree String
    getDTDAttrValue String
    a_name
                  IOSLA (XIOState GEEnv) XmlTree String
    -> IOSLA (XIOState GEEnv) String String
    -> IOSLA (XIOState GEEnv) XmlTree String
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
                  Int -> (String -> String) -> IOSLA (XIOState GEEnv) String String
    forall b s. Int -> (b -> String) -> IOStateArrow s b b
    traceValue 2 (("processGeneralEntity: external entity definition for " String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++) (String -> String) -> (String -> String) -> String -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> String
    forall a. Show a => a -> String
    show)
                )
                IOSLA (XIOState GEEnv) XmlTree String
    -> IOSLA (XIOState GEEnv) XmlTree String
    -> IOSLA (XIOState GEEnv) XmlTree (String, String)
    forall (a :: * -> * -> *) b c c'.
    Arrow a =>
    a b c -> a b c' -> a b (c, c')
    &&&
                String -> IOSLA (XIOState GEEnv) XmlTree String
    forall (a :: * -> * -> *). ArrowDTD a => String -> a XmlTree String
    getDTDAttrValue String
    a_url                       -- the absolute URL, not the relative in attr: k_system
              )
            where
            insertExternal :: String -> String -> IOSLA (XIOState GEEnv) b c
    insertExternal entity :: String
    entity uri :: String
    uri
                = (String -> GESubstArrow) -> String -> GEArrow b b
    forall b. (String -> GESubstArrow) -> String -> GEArrow b b
    insertEntity (String -> String -> GESubstArrow
    substExternalParsed1Time String
    uri) String
    entity
                  GEArrow b b
    -> IOSLA (XIOState GEEnv) b c -> IOSLA (XIOState GEEnv) b c
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
                  IOSLA (XIOState GEEnv) b c
    forall (a :: * -> * -> *) b c. ArrowList a => a b c
    none

        addUnparsedEntity   :: GEArrow XmlTree b
        addUnparsedEntity :: GEArrow XmlTree b
    addUnparsedEntity
            = String -> IOSLA (XIOState GEEnv) XmlTree String
    forall (a :: * -> * -> *). ArrowDTD a => String -> a XmlTree String
    getDTDAttrValue String
    a_name
              IOSLA (XIOState GEEnv) XmlTree String
    -> IOSLA (XIOState GEEnv) String b -> GEArrow XmlTree b
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
              Int -> (String -> String) -> IOSLA (XIOState GEEnv) String String
    forall b s. Int -> (b -> String) -> IOStateArrow s b b
    traceValue 2 (("processGeneralEntity: unparsed entity definition for " String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++) (String -> String) -> (String -> String) -> String -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> String
    forall a. Show a => a -> String
    show)
              IOSLA (XIOState GEEnv) String String
    -> IOSLA (XIOState GEEnv) String b
    -> IOSLA (XIOState GEEnv) String b
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
              IOSLA
      (XIOState GEEnv) String (IOSLA (XIOState GEEnv) String String)
    -> IOSLA (XIOState GEEnv) String String
    forall (a :: * -> * -> *) b c. ArrowList a => a b (a b c) -> a b c
    applyA ((String -> IOSLA (XIOState GEEnv) String String)
    -> IOSLA
         (XIOState GEEnv) String (IOSLA (XIOState GEEnv) String String)
    forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
    arr ((String -> GESubstArrow)
    -> String -> IOSLA (XIOState GEEnv) String String
    forall b. (String -> GESubstArrow) -> String -> GEArrow b b
    insertEntity String -> GESubstArrow
    substUnparsed))
              IOSLA (XIOState GEEnv) String String
    -> IOSLA (XIOState GEEnv) String b
    -> IOSLA (XIOState GEEnv) String b
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
              IOSLA (XIOState GEEnv) String b
    forall (a :: * -> * -> *) b c. ArrowList a => a b c
    none

        insertEntity        :: (String -> GESubstArrow) -> String -> GEArrow b b
        insertEntity :: (String -> GESubstArrow) -> String -> GEArrow b b
    insertEntity fct :: String -> GESubstArrow
    fct entity :: String
    entity
            = ( IOStateArrow GEEnv b GEEnv
    forall s b. IOStateArrow s b s
    getUserState
                IOStateArrow GEEnv b GEEnv
    -> IOSLA (XIOState GEEnv) GEEnv GEEnv -> IOStateArrow GEEnv b GEEnv
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
                IOSLA (XIOState GEEnv) GEEnv (IOSLA (XIOState GEEnv) GEEnv GEEnv)
    -> IOSLA (XIOState GEEnv) GEEnv GEEnv
    forall (a :: * -> * -> *) b c. ArrowList a => a b (a b c) -> a b c
    applyA ((GEEnv -> IOSLA (XIOState GEEnv) GEEnv GEEnv)
    -> IOSLA
         (XIOState GEEnv) GEEnv (IOSLA (XIOState GEEnv) GEEnv GEEnv)
    forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
    arr GEEnv -> IOSLA (XIOState GEEnv) GEEnv GEEnv
    forall s b. GEEnv -> IOSLA (XIOState s) b b
    checkDefined)
              )
              IOStateArrow GEEnv b GEEnv -> GEArrow b b -> GEArrow b b
    forall (a :: * -> * -> *) b c d.
    ArrowIf a =>
    a b c -> a b d -> a b d
    `guards`
              (String -> GESubstArrow) -> String -> GEArrow b b
    forall b. (String -> GESubstArrow) -> String -> GEArrow b b
    addEntity String -> GESubstArrow
    fct String
    entity
            where
            checkDefined :: GEEnv -> IOSLA (XIOState s) b b
    checkDefined geEnv :: GEEnv
    geEnv
                = IOSLA (XIOState s) b b
    -> (GESubstArrow -> IOSLA (XIOState s) b b)
    -> Maybe GESubstArrow
    -> IOSLA (XIOState s) b b
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe IOSLA (XIOState s) b b
    forall b. IOSLA (XIOState s) b b
    ok GESubstArrow -> IOSLA (XIOState s) b b
    forall p s b c. p -> IOSLA (XIOState s) b c
    alreadyDefined (Maybe GESubstArrow -> IOSLA (XIOState s) b b)
    -> (GEEnv -> Maybe GESubstArrow) -> GEEnv -> IOSLA (XIOState s) b b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> GEEnv -> Maybe GESubstArrow
    lookupGeEnv String
    entity (GEEnv -> IOSLA (XIOState s) b b)
    -> GEEnv -> IOSLA (XIOState s) b b
    forall a b. (a -> b) -> a -> b
    $ GEEnv
    geEnv
                where
                ok :: IOSLA (XIOState s) b b
    ok  = IOSLA (XIOState s) b b
    forall (a :: * -> * -> *) b. ArrowList a => a b b
    this
                alreadyDefined :: p -> IOSLA (XIOState s) b c
    alreadyDefined _
                    = String -> IOStateArrow s b b
    forall s b. String -> IOStateArrow s b b
    issueWarn ("entity " String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String -> String
    forall a. Show a => a -> String
    show String
    entity String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ " already defined, repeated definition ignored")
                      IOStateArrow s b b
    -> IOSLA (XIOState s) b c -> IOSLA (XIOState s) b c
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
                      IOSLA (XIOState s) b c
    forall (a :: * -> * -> *) b c. ArrowList a => a b c
    none

        addEntity   :: (String -> GESubstArrow) -> String -> GEArrow b b
        addEntity :: (String -> GESubstArrow) -> String -> GEArrow b b
    addEntity fct :: String -> GESubstArrow
    fct entity :: String
    entity
            = (b -> GEEnv -> GEEnv) -> GEArrow b b
    forall b s. (b -> s -> s) -> IOStateArrow s b b
    changeUserState b -> GEEnv -> GEEnv
    forall p. p -> GEEnv -> GEEnv
    ins
            where
            ins :: p -> GEEnv -> GEEnv
    ins _ geEnv :: GEEnv
    geEnv = String -> GESubstArrow -> GEEnv -> GEEnv
    addGeEntry String
    entity (String -> GESubstArrow
    fct String
    entity) GEEnv
    geEnv

        substEntitiesInAttrDefaultValue     :: GEArrow XmlTree XmlTree
        substEntitiesInAttrDefaultValue :: IOStateArrow GEEnv XmlTree XmlTree
    substEntitiesInAttrDefaultValue
            = IOSLA (XIOState GEEnv) XmlTree (IOStateArrow GEEnv XmlTree XmlTree)
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *) b c. ArrowList a => a b (a b c) -> a b c
    applyA ( IOStateArrow GEEnv XmlTree XmlTree
    -> IOSLA (XIOState GEEnv) XmlTree String
    forall (a :: * -> * -> *) n.
    ArrowXml a =>
    a n XmlTree -> a n String
    xshow ( String -> IOSLA (XIOState GEEnv) XmlTree String
    forall (a :: * -> * -> *). ArrowDTD a => String -> a XmlTree String
    getDTDAttrValue String
    a_default                    -- parse the default value
                               IOSLA (XIOState GEEnv) XmlTree String
    -> IOSLA (XIOState GEEnv) String XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>                                          -- substitute entities
                               IOSLA (XIOState GEEnv) String XmlTree
    forall (a :: * -> * -> *). ArrowXml a => a String XmlTree
    mkText                                       -- and convert value into a string
                               IOSLA (XIOState GEEnv) String XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IOSLA (XIOState GEEnv) String XmlTree
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
                               String -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *).
    ArrowXml a =>
    String -> a XmlTree XmlTree
    parseXmlEntityValueAsAttrValue "default value of attribute"
                               IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
                               IOStateArrow GEEnv XmlTree XmlTree
    forall s. IOStateArrow s XmlTree XmlTree
    filterErrorMsg
                               IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
                               IOStateArrow GEEnv XmlTree XmlTree
    substEntitiesInAttrValue
                             )
                       IOSLA (XIOState GEEnv) XmlTree String
    -> IOSLA
         (XIOState GEEnv) String (IOStateArrow GEEnv XmlTree XmlTree)
    -> IOSLA
         (XIOState GEEnv) XmlTree (IOStateArrow GEEnv XmlTree XmlTree)
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>> (String -> IOStateArrow GEEnv XmlTree XmlTree)
    -> IOSLA
         (XIOState GEEnv) String (IOStateArrow GEEnv XmlTree XmlTree)
    forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
    arr (String -> String -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *).
    ArrowDTD a =>
    String -> String -> a XmlTree XmlTree
    setDTDAttrValue String
    a_default)
                     )
              IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *) b c. ArrowIf a => a b b -> a b c -> a b b
    `when` String -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *).
    ArrowDTD a =>
    String -> a XmlTree XmlTree
    hasDTDAttr String
    a_default

        substEntitiesInAttrValue    :: GEArrow XmlTree XmlTree
        substEntitiesInAttrValue :: IOStateArrow GEEnv XmlTree XmlTree
    substEntitiesInAttrValue
            = ( GESubstArrow
    processGeneralEntity GEContext
    ReferenceInAttributeValue RecList
    recl
                IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *) b c. ArrowIf a => a b b -> a b c -> a b b
    `when`
                IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *). ArrowXml a => a XmlTree XmlTree
    isEntityRef
              )
              IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
              (String -> String) -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *).
    ArrowXml a =>
    (String -> String) -> a XmlTree XmlTree
    changeText String -> String
    normalizeWhiteSpace
              IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
              IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *). ArrowXml a => a XmlTree XmlTree
    transfCharRef
            where
            normalizeWhiteSpace :: String -> String
    normalizeWhiteSpace = (Char -> Char) -> String -> String
    forall a b. (a -> b) -> [a] -> [b]
    map ( \c :: Char
    c -> if Char
    c Char -> String -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` "\n\t\r" then ' ' else Char
    c )

        substEntityRef      :: GEArrow XmlTree XmlTree
        substEntityRef :: IOStateArrow GEEnv XmlTree XmlTree
    substEntityRef
            = IOSLA (XIOState GEEnv) XmlTree (IOStateArrow GEEnv XmlTree XmlTree)
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *) b c. ArrowList a => a b (a b c) -> a b c
    applyA ( ( ( IOSLA (XIOState GEEnv) XmlTree String
    forall (a :: * -> * -> *). ArrowXml a => a XmlTree String
    getEntityRef                             -- get the entity name and the env
                           IOSLA (XIOState GEEnv) XmlTree String
    -> IOSLA (XIOState GEEnv) String String
    -> IOSLA (XIOState GEEnv) XmlTree String
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>                                      -- and compute the arrow to be applied
                           Int -> (String -> String) -> IOSLA (XIOState GEEnv) String String
    forall b s. Int -> (b -> String) -> IOStateArrow s b b
    traceValue 2 (("processGeneralEntity: entity reference for entity " String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++) (String -> String) -> (String -> String) -> String -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> String
    forall a. Show a => a -> String
    show)
                           IOSLA (XIOState GEEnv) String String
    -> IOSLA (XIOState GEEnv) String String
    -> IOSLA (XIOState GEEnv) String String
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
                           Int -> String -> IOSLA (XIOState GEEnv) String String
    forall s b. Int -> String -> IOStateArrow s b b
    traceMsg 3 ("recursion list = " String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ RecList -> String
    forall a. Show a => a -> String
    show RecList
    recl)
                         )
                         IOSLA (XIOState GEEnv) XmlTree String
    -> IOSLA (XIOState GEEnv) XmlTree GEEnv
    -> IOSLA (XIOState GEEnv) XmlTree (String, GEEnv)
    forall (a :: * -> * -> *) b c c'.
    Arrow a =>
    a b c -> a b c' -> a b (c, c')
    &&&
                         IOSLA (XIOState GEEnv) XmlTree GEEnv
    forall s b. IOStateArrow s b s
    getUserState
                       ) IOSLA (XIOState GEEnv) XmlTree (String, GEEnv)
    -> IOSLA
         (XIOState GEEnv)
         (String, GEEnv)
         (IOStateArrow GEEnv XmlTree XmlTree)
    -> IOSLA
         (XIOState GEEnv) XmlTree (IOStateArrow GEEnv XmlTree XmlTree)
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
                       (String -> GEEnv -> IOStateArrow GEEnv XmlTree XmlTree)
    -> IOSLA
         (XIOState GEEnv)
         (String, GEEnv)
         (IOStateArrow GEEnv XmlTree XmlTree)
    forall (a :: * -> * -> *) b1 b2 c.
    ArrowList a =>
    (b1 -> b2 -> c) -> a (b1, b2) c
    arr2 String -> GEEnv -> IOStateArrow GEEnv XmlTree XmlTree
    substA
                     )
              where
              substA        :: String -> GEEnv -> GEArrow XmlTree XmlTree
              substA :: String -> GEEnv -> IOStateArrow GEEnv XmlTree XmlTree
    substA entity :: String
    entity geEnv :: GEEnv
    geEnv
                  = IOStateArrow GEEnv XmlTree XmlTree
    -> (GESubstArrow -> IOStateArrow GEEnv XmlTree XmlTree)
    -> Maybe GESubstArrow
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall b a. b -> (a -> b) -> Maybe a -> b
    maybe IOStateArrow GEEnv XmlTree XmlTree
    forall s b. IOStateArrow s b b
    entityNotFound GESubstArrow -> IOStateArrow GEEnv XmlTree XmlTree
    forall s b.
    (GEContext -> RecList -> IOStateArrow s b b) -> IOStateArrow s b b
    entityFound (Maybe GESubstArrow -> IOStateArrow GEEnv XmlTree XmlTree)
    -> (GEEnv -> Maybe GESubstArrow)
    -> GEEnv
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> GEEnv -> Maybe GESubstArrow
    lookupGeEnv String
    entity (GEEnv -> IOStateArrow GEEnv XmlTree XmlTree)
    -> GEEnv -> IOStateArrow GEEnv XmlTree XmlTree
    forall a b. (a -> b) -> a -> b
    $ GEEnv
    geEnv
                  where
                  errMsg :: String -> IOStateArrow s b b
    errMsg msg :: String
    msg
                      = String -> IOStateArrow s b b
    forall s b. String -> IOStateArrow s b b
    issueErr String
    msg

                  entityNotFound :: IOStateArrow s b b
    entityNotFound
                      = String -> IOStateArrow s b b
    forall s b. String -> IOStateArrow s b b
    errMsg ("general entity reference \"&" String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String
    entity String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ ";\" not processed, no definition found, (forward reference?)")

                  entityFound :: (GEContext -> RecList -> IOStateArrow s b b) -> IOStateArrow s b b
    entityFound fct :: GEContext -> RecList -> IOStateArrow s b b
    fct
                      | String
    entity String -> RecList -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` RecList
    recl
                          = String -> IOStateArrow s b b
    forall s b. String -> IOStateArrow s b b
    errMsg ("general entity reference \"&" String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String
    entity String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ ";\" not processed, cyclic definition")
                      | Bool
    otherwise
                          = GEContext -> RecList -> IOStateArrow s b b
    fct GEContext
    context RecList
    recl

        substExternalParsed1Time                            :: String -> String -> GESubstArrow
        substExternalParsed1Time :: String -> String -> GESubstArrow
    substExternalParsed1Time uri :: String
    uri entity :: String
    entity cx :: GEContext
    cx rl :: RecList
    rl
            = IOSLA (XIOState GEEnv) XmlTree String
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *) b c. ArrowList a => a b c -> a b b
    perform ( Int -> String -> IOStateArrow GEEnv XmlTree XmlTree
    forall s b. Int -> String -> IOStateArrow s b b
    traceMsg 2 ("substExternalParsed1Time: read and parse external parsed entity " String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String -> String
    forall a. Show a => a -> String
    show String
    entity)
                        IOStateArrow GEEnv XmlTree XmlTree
    -> IOSLA (XIOState GEEnv) XmlTree String
    -> IOSLA (XIOState GEEnv) XmlTree String
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
                        IOSLA (XIOState GEEnv) XmlTree String
    -> IOSLA (XIOState GEEnv) XmlTree String
    forall s b c. IOStateArrow s b c -> IOStateArrow s b c
    runInLocalURIContext ( [IOStateArrow GEEnv XmlTree XmlTree]
    -> [IOStateArrow GEEnv XmlTree XmlTree]
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *) n.
    ArrowXml a =>
    [a n XmlTree] -> [a n XmlTree] -> a n XmlTree
    root [String -> String -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *) n.
    ArrowXml a =>
    String -> String -> a n XmlTree
    sattr String
    a_source String
    uri] []         -- uri must be an absolute uri
                                               IOStateArrow GEEnv XmlTree XmlTree
    -> IOSLA (XIOState GEEnv) XmlTree String
    -> IOSLA (XIOState GEEnv) XmlTree String
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>                                  -- abs uri is computed during parameter entity handling
                                               IOStateArrow GEEnv XmlTree XmlTree
    forall s. IOStateArrow s XmlTree XmlTree
    getXmlEntityContents
                                               IOStateArrow GEEnv XmlTree XmlTree
    -> IOSLA (XIOState GEEnv) XmlTree String
    -> IOSLA (XIOState GEEnv) XmlTree String
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
                                               IOSLA (XIOState GEEnv) XmlTree String
    forall s. IOStateArrow s XmlTree String
    processExternalEntityContents
                                             )
                        IOSLA (XIOState GEEnv) XmlTree String
    -> IOSLA (XIOState GEEnv) String String
    -> IOSLA (XIOState GEEnv) XmlTree String
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
                        IOSLA
      (XIOState GEEnv) String (IOSLA (XIOState GEEnv) String String)
    -> IOSLA (XIOState GEEnv) String String
    forall (a :: * -> * -> *) b c. ArrowList a => a b (a b c) -> a b c
    applyA ( (String -> IOSLA (XIOState GEEnv) String String)
    -> IOSLA
         (XIOState GEEnv) String (IOSLA (XIOState GEEnv) String String)
    forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
    arr ((String -> IOSLA (XIOState GEEnv) String String)
     -> IOSLA
          (XIOState GEEnv) String (IOSLA (XIOState GEEnv) String String))
    -> (String -> IOSLA (XIOState GEEnv) String String)
    -> IOSLA
         (XIOState GEEnv) String (IOSLA (XIOState GEEnv) String String)
    forall a b. (a -> b) -> a -> b
    $ \ s :: String
    s -> (String -> GESubstArrow)
    -> String -> IOSLA (XIOState GEEnv) String String
    forall b. (String -> GESubstArrow) -> String -> GEArrow b b
    addEntity (String -> String -> GESubstArrow
    substExternalParsed String
    s) String
    entity )
                      )
              IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
              GESubstArrow
    processGeneralEntity GEContext
    cx RecList
    rl
            where
            processExternalEntityContents   :: IOStateArrow s XmlTree String
            processExternalEntityContents :: IOStateArrow s XmlTree String
    processExternalEntityContents
                = ( ( ( IOSLA (XIOState s) XmlTree XmlTree
    forall (a :: * -> * -> *). ArrowXml a => a XmlTree XmlTree
    documentStatusOk                              -- reading entity succeeded
                        IOSLA (XIOState s) XmlTree XmlTree
    -> IOSLA (XIOState s) XmlTree XmlTree
    -> IOSLA (XIOState s) XmlTree XmlTree
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>                                           -- with content stored in a text node
                        (IOSLA (XIOState s) XmlTree XmlTree
    forall (a :: * -> * -> *) (t :: * -> *) b.
    (ArrowTree a, Tree t) =>
    a (t b) (t b)
    getChildren IOSLA (XIOState s) XmlTree XmlTree
    -> IOSLA (XIOState s) XmlTree XmlTree
    -> IOSLA (XIOState s) XmlTree XmlTree
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>> IOSLA (XIOState s) XmlTree XmlTree
    forall (a :: * -> * -> *). ArrowXml a => a XmlTree XmlTree
    isText)
                      )
                      IOSLA (XIOState s) XmlTree XmlTree
    -> IOSLA (XIOState s) XmlTree XmlTree
    -> IOSLA (XIOState s) XmlTree XmlTree
    forall (a :: * -> * -> *) b c d.
    ArrowIf a =>
    a b c -> a b d -> a b d
    `guards`
                      IOSLA (XIOState s) XmlTree XmlTree
    forall (a :: * -> * -> *) b. ArrowList a => a b b
    this
                    )
                    IOSLA (XIOState s) XmlTree XmlTree
    -> IOSLA (XIOState s) XmlTree XmlTree
    -> IOSLA (XIOState s) XmlTree XmlTree
    forall (a :: * -> * -> *) b c. ArrowIf a => a b c -> a b c -> a b c
    `orElse`
                    String -> IOSLA (XIOState s) XmlTree XmlTree
    forall s b. String -> IOStateArrow s b b
    issueErr ("illegal value for external parsed entity " String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String -> String
    forall a. Show a => a -> String
    show String
    entity)
                  )
                  IOSLA (XIOState s) XmlTree XmlTree
    -> IOStateArrow s XmlTree String -> IOStateArrow s XmlTree String
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
                  IOSLA (XIOState s) XmlTree XmlTree -> IOStateArrow s XmlTree String
    forall (a :: * -> * -> *) n.
    ArrowXml a =>
    a n XmlTree -> a n String
    xshow (IOSLA (XIOState s) XmlTree XmlTree
    forall (a :: * -> * -> *) (t :: * -> *) b.
    (ArrowTree a, Tree t) =>
    a (t b) (t b)
    getChildren IOSLA (XIOState s) XmlTree XmlTree
    -> IOSLA (XIOState s) XmlTree XmlTree
    -> IOSLA (XIOState s) XmlTree XmlTree
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>> IOSLA (XIOState s) XmlTree XmlTree
    forall (a :: * -> * -> *). ArrowXml a => a XmlTree XmlTree
    isText)

        substExternalParsed                                 :: String -> String -> GESubstArrow
        substExternalParsed :: String -> String -> GESubstArrow
    substExternalParsed s :: String
    s entity :: String
    entity ReferenceInContent rl :: RecList
    rl  = String -> RecList -> String -> IOStateArrow GEEnv XmlTree XmlTree
    includedIfValidating String
    s RecList
    rl String
    entity
        substExternalParsed _ entity :: String
    entity ReferenceInAttributeValue _
                                                            = String -> String -> String -> IOStateArrow GEEnv XmlTree XmlTree
    forbidden String
    entity "external parsed general" "in attribute value"
        substExternalParsed _ _      ReferenceInEntityValue _
                                                            = IOStateArrow GEEnv XmlTree XmlTree
    bypassed

        substInternal                                       :: String -> String -> GESubstArrow
        substInternal :: String -> String -> GESubstArrow
    substInternal s :: String
    s entity :: String
    entity ReferenceInContent rl :: RecList
    rl        = String -> RecList -> String -> IOStateArrow GEEnv XmlTree XmlTree
    included          String
    s RecList
    rl String
    entity
        substInternal s :: String
    s entity :: String
    entity ReferenceInAttributeValue rl :: RecList
    rl = String -> RecList -> String -> IOStateArrow GEEnv XmlTree XmlTree
    includedInLiteral String
    s RecList
    rl String
    entity
        substInternal _ _      ReferenceInEntityValue _     = IOStateArrow GEEnv XmlTree XmlTree
    bypassed

        substUnparsed                                       :: String -> GESubstArrow
        substUnparsed :: String -> GESubstArrow
    substUnparsed entity :: String
    entity ReferenceInContent        _    = String -> String -> String -> IOStateArrow GEEnv XmlTree XmlTree
    forbidden String
    entity "unparsed" "content"
        substUnparsed entity :: String
    entity ReferenceInAttributeValue _    = String -> String -> String -> IOStateArrow GEEnv XmlTree XmlTree
    forbidden String
    entity "unparsed" "attribute value"
        substUnparsed entity :: String
    entity ReferenceInEntityValue    _    = String -> String -> String -> IOStateArrow GEEnv XmlTree XmlTree
    forbidden String
    entity "unparsed" "entity value"

                                                                            -- XML 1.0 chapter 4.4.2
        included            :: String -> RecList -> String -> GEArrow XmlTree XmlTree
        included :: String -> RecList -> String -> IOStateArrow GEEnv XmlTree XmlTree
    included s :: String
    s rl :: RecList
    rl entity :: String
    entity
            = Int -> String -> IOStateArrow GEEnv XmlTree XmlTree
    forall s b. Int -> String -> IOStateArrow s b b
    traceMsg 3 ("substituting general entity " String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String -> String
    forall a. Show a => a -> String
    show String
    entity String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ " with value " String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String -> String
    forall a. Show a => a -> String
    show String
    s)
              IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
              String -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *) n. ArrowXml a => String -> a n XmlTree
    txt String
    s
              IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
              String -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *).
    ArrowXml a =>
    String -> a XmlTree XmlTree
    parseXmlEntityValueAsContent ("substituting general entity " String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String -> String
    forall a. Show a => a -> String
    show String
    entity String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ " in contents")
              IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
              IOStateArrow GEEnv XmlTree XmlTree
    forall s. IOStateArrow s XmlTree XmlTree
    filterErrorMsg
              IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
              GESubstArrow
    processGeneralEntity GEContext
    context (String
    entity String -> RecList -> RecList
    forall a. a -> [a] -> [a]
    : RecList
    rl)

                                                                            -- XML 1.0 chapter 4.4.3
        includedIfValidating                :: String -> RecList -> String -> GEArrow XmlTree XmlTree
        includedIfValidating :: String -> RecList -> String -> IOStateArrow GEEnv XmlTree XmlTree
    includedIfValidating
            = String -> RecList -> String -> IOStateArrow GEEnv XmlTree XmlTree
    included
                                                                            -- XML 1.0 chapter 4.4.4
        forbidden           :: String -> String -> String -> GEArrow XmlTree XmlTree
        forbidden :: String -> String -> String -> IOStateArrow GEEnv XmlTree XmlTree
    forbidden entity :: String
    entity msg :: String
    msg cx :: String
    cx
            = String -> IOStateArrow GEEnv XmlTree XmlTree
    forall s b. String -> IOStateArrow s b b
    issueErr ("reference of " String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String
    msg String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String -> String
    forall a. Show a => a -> String
    show String
    entity String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ " forbidden in " String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String
    cx)

                                                                            -- XML 1.0 chapter 4.4.5
        includedInLiteral           :: String -> RecList -> String -> GEArrow XmlTree XmlTree
        includedInLiteral :: String -> RecList -> String -> IOStateArrow GEEnv XmlTree XmlTree
    includedInLiteral s :: String
    s rl :: RecList
    rl entity :: String
    entity
            = String -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *) n. ArrowXml a => String -> a n XmlTree
    txt String
    s
              IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
              String -> IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *).
    ArrowXml a =>
    String -> a XmlTree XmlTree
    parseXmlEntityValueAsAttrValue ("substituting general entity " String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ String -> String
    forall a. Show a => a -> String
    show String
    entity String -> String -> String
    forall a. [a] -> [a] -> [a]
    ++ " in attribute value")
              IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
              IOStateArrow GEEnv XmlTree XmlTree
    forall s. IOStateArrow s XmlTree XmlTree
    filterErrorMsg
              IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    -> IOStateArrow GEEnv XmlTree XmlTree
    forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
    Category cat =>
    cat a b -> cat b c -> cat a c
    >>>
              GESubstArrow
    processGeneralEntity GEContext
    context (String
    entity String -> RecList -> RecList
    forall a. a -> [a] -> [a]
    : RecList
    rl)
                                                                            -- XML 1.0 chapter 4.4.7
        bypassed            :: GEArrow XmlTree XmlTree
        bypassed :: IOStateArrow GEEnv XmlTree XmlTree
    bypassed
            = IOStateArrow GEEnv XmlTree XmlTree
    forall (a :: * -> * -> *) b. ArrowList a => a b b
    this

    -- ------------------------------------------------------------