hxt 8.5.2 → 8.5.4
raw patch · 94 files changed
+11716/−11686 lines, 94 filesdep ~tagsoupPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: tagsoup
API changes (from Hackage documentation)
- Control.Arrow.IOStateListArrow: instance (NFData s) => ArrowNF (IOSLA s)
- Control.Arrow.StateListArrow: instance (NFData s) => ArrowNF (SLA s)
- Data.Tree.NTree.TypeDefs: instance (Eq a) => Eq (NTree a)
- Data.Tree.NTree.TypeDefs: instance (NFData a) => NFData (NTree a)
- Data.Tree.NTree.TypeDefs: instance (Ord a) => Ord (NTree a)
- Data.Tree.NTree.TypeDefs: instance (Read a) => Read (NTree a)
- Data.Tree.NTree.TypeDefs: instance (Show a) => Show (NTree a)
- Text.XML.HXT.Arrow.Pickle.Xml: instance (XmlPickler a) => XmlPickler (Maybe a)
- Text.XML.HXT.Arrow.Pickle.Xml: instance (XmlPickler a) => XmlPickler [a]
- Text.XML.HXT.Arrow.XmlIOStateArrow: instance (NFData us) => NFData (XIOState us)
- Text.XML.HXT.DOM.XmlNode: instance (XmlNode a) => XmlNode (NTree a)
- Text.XML.HXT.DTDValidation.RE: instance (Eq a) => Eq (RE a)
- Text.XML.HXT.DTDValidation.RE: instance (Show a) => Show (RE a)
+ Control.Arrow.IOStateListArrow: instance NFData s => ArrowNF (IOSLA s)
+ Control.Arrow.StateListArrow: instance NFData s => ArrowNF (SLA s)
+ Data.Tree.NTree.TypeDefs: instance Eq a => Eq (NTree a)
+ Data.Tree.NTree.TypeDefs: instance NFData a => NFData (NTree a)
+ Data.Tree.NTree.TypeDefs: instance Ord a => Ord (NTree a)
+ Data.Tree.NTree.TypeDefs: instance Read a => Read (NTree a)
+ Data.Tree.NTree.TypeDefs: instance Show a => Show (NTree a)
+ Text.XML.HXT.Arrow.Pickle.Xml: instance XmlPickler a => XmlPickler (Maybe a)
+ Text.XML.HXT.Arrow.Pickle.Xml: instance XmlPickler a => XmlPickler [a]
+ Text.XML.HXT.Arrow.XmlIOStateArrow: instance NFData us => NFData (XIOState us)
+ Text.XML.HXT.DOM.XmlNode: instance XmlNode a => XmlNode (NTree a)
+ Text.XML.HXT.DTDValidation.RE: instance Eq a => Eq (RE a)
+ Text.XML.HXT.DTDValidation.RE: instance Show a => Show (RE a)
+ Text.XML.HXT.RelaxNG.XmlSchema.RegexMatch: splitRegex :: Regex -> String -> Maybe (String, String)
- Control.Arrow.ArrowIO: arrIO :: (ArrowIO a) => (b -> IO c) -> a b c
+ Control.Arrow.ArrowIO: arrIO :: ArrowIO a => (b -> IO c) -> a b c
- Control.Arrow.ArrowIO: arrIO0 :: (ArrowIO a) => IO c -> a b c
+ Control.Arrow.ArrowIO: arrIO0 :: ArrowIO a => IO c -> a b c
- Control.Arrow.ArrowIO: arrIO2 :: (ArrowIO a) => (b1 -> b2 -> IO c) -> a (b1, b2) c
+ Control.Arrow.ArrowIO: arrIO2 :: ArrowIO a => (b1 -> b2 -> IO c) -> a (b1, b2) c
- Control.Arrow.ArrowIO: arrIO3 :: (ArrowIO a) => (b1 -> b2 -> b3 -> IO c) -> a (b1, (b2, b3)) c
+ Control.Arrow.ArrowIO: arrIO3 :: ArrowIO a => (b1 -> b2 -> b3 -> IO c) -> a (b1, (b2, b3)) c
- Control.Arrow.ArrowIO: arrIO4 :: (ArrowIO a) => (b1 -> b2 -> b3 -> b4 -> IO c) -> a (b1, (b2, (b3, b4))) c
+ Control.Arrow.ArrowIO: arrIO4 :: ArrowIO a => (b1 -> b2 -> b3 -> b4 -> IO c) -> a (b1, (b2, (b3, b4))) c
- Control.Arrow.ArrowIO: class (Arrow a) => ArrowIO a
+ Control.Arrow.ArrowIO: class Arrow a => ArrowIO a
- Control.Arrow.ArrowIO: isIOA :: (ArrowIOIf a) => (b -> IO Bool) -> a b b
+ Control.Arrow.ArrowIO: isIOA :: ArrowIOIf a => (b -> IO Bool) -> a b b
- Control.Arrow.ArrowIf: choiceA :: (ArrowIf a) => [IfThen (a b c) (a b d)] -> a b d
+ Control.Arrow.ArrowIf: choiceA :: ArrowIf a => [IfThen (a b c) (a b d)] -> a b d
- Control.Arrow.ArrowIf: class (ArrowList a) => ArrowIf a
+ Control.Arrow.ArrowIf: class ArrowList a => ArrowIf a
- Control.Arrow.ArrowIf: containing :: (ArrowIf a) => a b c -> a c d -> a b c
+ Control.Arrow.ArrowIf: containing :: ArrowIf a => a b c -> a c d -> a b c
- Control.Arrow.ArrowIf: filterA :: (ArrowIf a) => a b c -> a b b
+ Control.Arrow.ArrowIf: filterA :: ArrowIf a => a b c -> a b b
- Control.Arrow.ArrowIf: guards :: (ArrowIf a) => a b c -> a b d -> a b d
+ Control.Arrow.ArrowIf: guards :: ArrowIf a => a b c -> a b d -> a b d
- Control.Arrow.ArrowIf: guardsP :: (ArrowIf a) => (b -> Bool) -> a b d -> a b d
+ Control.Arrow.ArrowIf: guardsP :: ArrowIf a => (b -> Bool) -> a b d -> a b d
- Control.Arrow.ArrowIf: ifA :: (ArrowIf a) => a b c -> a b d -> a b d -> a b d
+ Control.Arrow.ArrowIf: ifA :: ArrowIf a => a b c -> a b d -> a b d -> a b d
- Control.Arrow.ArrowIf: ifP :: (ArrowIf a) => (b -> Bool) -> a b d -> a b d -> a b d
+ Control.Arrow.ArrowIf: ifP :: ArrowIf a => (b -> Bool) -> a b d -> a b d -> a b d
- Control.Arrow.ArrowIf: neg :: (ArrowIf a) => a b c -> a b b
+ Control.Arrow.ArrowIf: neg :: ArrowIf a => a b c -> a b b
- Control.Arrow.ArrowIf: notContaining :: (ArrowIf a) => a b c -> a c d -> a b c
+ Control.Arrow.ArrowIf: notContaining :: ArrowIf a => a b c -> a c d -> a b c
- Control.Arrow.ArrowIf: orElse :: (ArrowIf a) => a b c -> a b c -> a b c
+ Control.Arrow.ArrowIf: orElse :: ArrowIf a => a b c -> a b c -> a b c
- Control.Arrow.ArrowIf: partitionA :: (ArrowIf a) => a b b -> a [b] ([b], [b])
+ Control.Arrow.ArrowIf: partitionA :: ArrowIf a => a b b -> a [b] ([b], [b])
- Control.Arrow.ArrowIf: spanA :: (ArrowIf a) => a b b -> a [b] ([b], [b])
+ Control.Arrow.ArrowIf: spanA :: ArrowIf a => a b b -> a [b] ([b], [b])
- Control.Arrow.ArrowIf: tagA :: (ArrowIf a) => a b c -> a b (Either b b)
+ Control.Arrow.ArrowIf: tagA :: ArrowIf a => a b c -> a b (Either b b)
- Control.Arrow.ArrowIf: when :: (ArrowIf a) => a b b -> a b c -> a b b
+ Control.Arrow.ArrowIf: when :: ArrowIf a => a b b -> a b c -> a b b
- Control.Arrow.ArrowIf: whenNot :: (ArrowIf a) => a b b -> a b c -> a b b
+ Control.Arrow.ArrowIf: whenNot :: ArrowIf a => a b b -> a b c -> a b b
- Control.Arrow.ArrowIf: whenNotP :: (ArrowIf a) => a b b -> (b -> Bool) -> a b b
+ Control.Arrow.ArrowIf: whenNotP :: ArrowIf a => a b b -> (b -> Bool) -> a b b
- Control.Arrow.ArrowIf: whenP :: (ArrowIf a) => a b b -> (b -> Bool) -> a b b
+ Control.Arrow.ArrowIf: whenP :: ArrowIf a => a b b -> (b -> Bool) -> a b b
- Control.Arrow.ArrowList: ($<$) :: (ArrowList a) => (c -> (a b b)) -> a b c -> a b b
+ Control.Arrow.ArrowList: ($<$) :: ArrowList a => (c -> (a b b)) -> a b c -> a b b
- Control.Arrow.ArrowList: ($<) :: (ArrowList a) => (c -> a b d) -> a b c -> a b d
+ Control.Arrow.ArrowList: ($<) :: ArrowList a => (c -> a b d) -> a b c -> a b d
- Control.Arrow.ArrowList: ($<<) :: (ArrowList a) => (c1 -> c2 -> a b d) -> a b (c1, c2) -> a b d
+ Control.Arrow.ArrowList: ($<<) :: ArrowList a => (c1 -> c2 -> a b d) -> a b (c1, c2) -> a b d
- Control.Arrow.ArrowList: ($<<<) :: (ArrowList a) => (c1 -> c2 -> c3 -> a b d) -> a b (c1, (c2, c3)) -> a b d
+ Control.Arrow.ArrowList: ($<<<) :: ArrowList a => (c1 -> c2 -> c3 -> a b d) -> a b (c1, (c2, c3)) -> a b d
- Control.Arrow.ArrowList: ($<<<<) :: (ArrowList a) => (c1 -> c2 -> c3 -> c4 -> a b d) -> a b (c1, (c2, (c3, c4))) -> a b d
+ Control.Arrow.ArrowList: ($<<<<) :: ArrowList a => (c1 -> c2 -> c3 -> c4 -> a b d) -> a b (c1, (c2, (c3, c4))) -> a b d
- Control.Arrow.ArrowList: (>.) :: (ArrowList a) => a b c -> ([c] -> d) -> a b d
+ Control.Arrow.ArrowList: (>.) :: ArrowList a => a b c -> ([c] -> d) -> a b d
- Control.Arrow.ArrowList: (>>.) :: (ArrowList a) => a b c -> ([c] -> [d]) -> a b d
+ Control.Arrow.ArrowList: (>>.) :: ArrowList a => a b c -> ([c] -> [d]) -> a b d
- Control.Arrow.ArrowList: applyA :: (ArrowList a) => a b (a b c) -> a b c
+ Control.Arrow.ArrowList: applyA :: ArrowList a => a b (a b c) -> a b c
- Control.Arrow.ArrowList: arr2 :: (ArrowList a) => (b1 -> b2 -> c) -> a (b1, b2) c
+ Control.Arrow.ArrowList: arr2 :: ArrowList a => (b1 -> b2 -> c) -> a (b1, b2) c
- Control.Arrow.ArrowList: arr2A :: (ArrowList a) => (b -> a c d) -> a (b, c) d
+ Control.Arrow.ArrowList: arr2A :: ArrowList a => (b -> a c d) -> a (b, c) d
- Control.Arrow.ArrowList: arr2L :: (ArrowList a) => (b -> c -> [d]) -> a (b, c) d
+ Control.Arrow.ArrowList: arr2L :: ArrowList a => (b -> c -> [d]) -> a (b, c) d
- Control.Arrow.ArrowList: arr3 :: (ArrowList a) => (b1 -> b2 -> b3 -> c) -> a (b1, (b2, b3)) c
+ Control.Arrow.ArrowList: arr3 :: ArrowList a => (b1 -> b2 -> b3 -> c) -> a (b1, (b2, b3)) c
- Control.Arrow.ArrowList: arr4 :: (ArrowList a) => (b1 -> b2 -> b3 -> b4 -> c) -> a (b1, (b2, (b3, b4))) c
+ Control.Arrow.ArrowList: arr4 :: ArrowList a => (b1 -> b2 -> b3 -> b4 -> c) -> a (b1, (b2, (b3, b4))) c
- Control.Arrow.ArrowList: arrL :: (ArrowList a) => (b -> [c]) -> a b c
+ Control.Arrow.ArrowList: arrL :: ArrowList a => (b -> [c]) -> a b c
- Control.Arrow.ArrowList: catA :: (ArrowList a) => [a b c] -> a b c
+ Control.Arrow.ArrowList: catA :: ArrowList a => [a b c] -> a b c
- Control.Arrow.ArrowList: constA :: (ArrowList a) => c -> a b c
+ Control.Arrow.ArrowList: constA :: ArrowList a => c -> a b c
- Control.Arrow.ArrowList: constL :: (ArrowList a) => [c] -> a b c
+ Control.Arrow.ArrowList: constL :: ArrowList a => [c] -> a b c
- Control.Arrow.ArrowList: isA :: (ArrowList a) => (b -> Bool) -> a b b
+ Control.Arrow.ArrowList: isA :: ArrowList a => (b -> Bool) -> a b b
- Control.Arrow.ArrowList: listA :: (ArrowList a) => a b c -> a b [c]
+ Control.Arrow.ArrowList: listA :: ArrowList a => a b c -> a b [c]
- Control.Arrow.ArrowList: mergeA :: (ArrowList a) => (a (a1, b1) a1 -> a (a1, b1) b1 -> a (a1, b1) c) -> a (a1, b1) c
+ Control.Arrow.ArrowList: mergeA :: ArrowList a => (a (a1, b1) a1 -> a (a1, b1) b1 -> a (a1, b1) c) -> a (a1, b1) c
- Control.Arrow.ArrowList: none :: (ArrowList a) => a b c
+ Control.Arrow.ArrowList: none :: ArrowList a => a b c
- Control.Arrow.ArrowList: perform :: (ArrowList a) => a b c -> a b b
+ Control.Arrow.ArrowList: perform :: ArrowList a => a b c -> a b b
- Control.Arrow.ArrowList: seqA :: (ArrowList a) => [a b b] -> a b b
+ Control.Arrow.ArrowList: seqA :: ArrowList a => [a b b] -> a b b
- Control.Arrow.ArrowList: single :: (ArrowList a) => a b c -> a b c
+ Control.Arrow.ArrowList: single :: ArrowList a => a b c -> a b c
- Control.Arrow.ArrowList: this :: (ArrowList a) => a b b
+ Control.Arrow.ArrowList: this :: ArrowList a => a b b
- Control.Arrow.ArrowList: unlistA :: (ArrowList a) => a [b] b
+ Control.Arrow.ArrowList: unlistA :: ArrowList a => a [b] b
- Control.Arrow.ArrowList: withDefault :: (ArrowList a) => a b c -> c -> a b c
+ Control.Arrow.ArrowList: withDefault :: ArrowList a => a b c -> c -> a b c
- Control.Arrow.ArrowNF: class (Arrow a) => ArrowNF a
+ Control.Arrow.ArrowNF: class Arrow a => ArrowNF a
- Control.Arrow.ArrowState: accessState :: (ArrowState s a) => (s -> b -> c) -> a b c
+ Control.Arrow.ArrowState: accessState :: ArrowState s a => (s -> b -> c) -> a b c
- Control.Arrow.ArrowState: changeState :: (ArrowState s a) => (s -> b -> s) -> a b b
+ Control.Arrow.ArrowState: changeState :: ArrowState s a => (s -> b -> s) -> a b b
- Control.Arrow.ArrowState: class (Arrow a) => ArrowState s a | a -> s
+ Control.Arrow.ArrowState: class Arrow a => ArrowState s a | a -> s
- Control.Arrow.ArrowState: getState :: (ArrowState s a) => a b s
+ Control.Arrow.ArrowState: getState :: ArrowState s a => a b s
- Control.Arrow.ArrowState: nextState :: (ArrowState s a) => (s -> s) -> a b s
+ Control.Arrow.ArrowState: nextState :: ArrowState s a => (s -> s) -> a b s
- Control.Arrow.ArrowState: setState :: (ArrowState s a) => a s s
+ Control.Arrow.ArrowState: setState :: ArrowState s a => a s s
- Control.Arrow.ListArrow: fromLA :: (ArrowList a) => LA b c -> a b c
+ Control.Arrow.ListArrow: fromLA :: ArrowList a => LA b c -> a b c
- Control.Arrow.StateListArrow: fromSLA :: (ArrowList a) => s -> SLA s b c -> a b c
+ Control.Arrow.StateListArrow: fromSLA :: ArrowList a => s -> SLA s b c -> a b c
- Data.AssocList: addEntries :: (Eq k) => AssocList k v -> AssocList k v -> AssocList k v
+ Data.AssocList: addEntries :: Eq k => AssocList k v -> AssocList k v -> AssocList k v
- Data.AssocList: addEntry :: (Eq k) => k -> v -> AssocList k v -> AssocList k v
+ Data.AssocList: addEntry :: Eq k => k -> v -> AssocList k v -> AssocList k v
- Data.AssocList: delEntries :: (Eq k) => [k] -> AssocList k v -> AssocList k v
+ Data.AssocList: delEntries :: Eq k => [k] -> AssocList k v -> AssocList k v
- Data.AssocList: delEntry :: (Eq k) => k -> AssocList k v -> AssocList k v
+ Data.AssocList: delEntry :: Eq k => k -> AssocList k v -> AssocList k v
- Data.AssocList: hasEntry :: (Eq k) => k -> AssocList k v -> Bool
+ Data.AssocList: hasEntry :: Eq k => k -> AssocList k v -> Bool
- Data.AssocList: lookup1 :: (Eq k) => k -> AssocList k [e] -> [e]
+ Data.AssocList: lookup1 :: Eq k => k -> AssocList k [e] -> [e]
- Data.AssocList: lookupDef :: (Eq k) => v -> k -> AssocList k v -> v
+ Data.AssocList: lookupDef :: Eq k => v -> k -> AssocList k v -> v
- Data.Tree.Class: cardTree :: (Tree t) => t a -> Int
+ Data.Tree.Class: cardTree :: Tree t => t a -> Int
- Data.Tree.Class: changeChildren :: (Tree t) => ([t a] -> [t a]) -> t a -> t a
+ Data.Tree.Class: changeChildren :: Tree t => ([t a] -> [t a]) -> t a -> t a
- Data.Tree.Class: changeNode :: (Tree t) => (a -> a) -> t a -> t a
+ Data.Tree.Class: changeNode :: Tree t => (a -> a) -> t a -> t a
- Data.Tree.Class: depthTree :: (Tree t) => t a -> Int
+ Data.Tree.Class: depthTree :: Tree t => t a -> Int
- Data.Tree.Class: foldTree :: (Tree t) => (a -> [b] -> b) -> t a -> b
+ Data.Tree.Class: foldTree :: Tree t => (a -> [b] -> b) -> t a -> b
- Data.Tree.Class: formatTree :: (Tree t) => (a -> String) -> t a -> String
+ Data.Tree.Class: formatTree :: Tree t => (a -> String) -> t a -> String
- Data.Tree.Class: getChildren :: (Tree t) => t a -> [t a]
+ Data.Tree.Class: getChildren :: Tree t => t a -> [t a]
- Data.Tree.Class: getNode :: (Tree t) => t a -> a
+ Data.Tree.Class: getNode :: Tree t => t a -> a
- Data.Tree.Class: isInner :: (Tree t) => t a -> Bool
+ Data.Tree.Class: isInner :: Tree t => t a -> Bool
- Data.Tree.Class: isLeaf :: (Tree t) => t a -> Bool
+ Data.Tree.Class: isLeaf :: Tree t => t a -> Bool
- Data.Tree.Class: mkLeaf :: (Tree t) => a -> t a
+ Data.Tree.Class: mkLeaf :: Tree t => a -> t a
- Data.Tree.Class: mkTree :: (Tree t) => a -> [t a] -> t a
+ Data.Tree.Class: mkTree :: Tree t => a -> [t a] -> t a
- Data.Tree.Class: nodesTree :: (Tree t) => t a -> [a]
+ Data.Tree.Class: nodesTree :: Tree t => t a -> [a]
- Data.Tree.Class: setChildren :: (Tree t) => [t a] -> t a -> t a
+ Data.Tree.Class: setChildren :: Tree t => [t a] -> t a -> t a
- Data.Tree.Class: setNode :: (Tree t) => a -> t a -> t a
+ Data.Tree.Class: setNode :: Tree t => a -> t a -> t a
- Text.XML.HXT.Arrow.DocumentOutput: encodeDocument' :: (ArrowXml a) => Bool -> String -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.DocumentOutput: encodeDocument' :: ArrowXml a => Bool -> String -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: addDefaultDTDecl :: (ArrowList a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: addDefaultDTDecl :: ArrowList a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: addDoctypeDecl :: (ArrowXml a) => String -> String -> String -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: addDoctypeDecl :: ArrowXml a => String -> String -> String -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: addHeadlineToXmlDoc :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: addHeadlineToXmlDoc :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: addXHtmlDoctypeFrameset :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: addXHtmlDoctypeFrameset :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: addXHtmlDoctypeStrict :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: addXHtmlDoctypeStrict :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: addXHtmlDoctypeTransitional :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: addXHtmlDoctypeTransitional :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: addXmlPi :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: addXmlPi :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: addXmlPiEncoding :: (ArrowXml a) => String -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: addXmlPiEncoding :: ArrowXml a => String -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: canonicalizeAllNodes :: (ArrowList a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: canonicalizeAllNodes :: ArrowList a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: canonicalizeContents :: (ArrowList a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: canonicalizeContents :: ArrowList a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: canonicalizeForXPath :: (ArrowList a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: canonicalizeForXPath :: ArrowList a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: collapseAllXText :: (ArrowList a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: collapseAllXText :: ArrowList a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: collapseXText :: (ArrowList a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: collapseXText :: ArrowList a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: escapeHtmlDoc :: (ArrowList a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: escapeHtmlDoc :: ArrowList a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: escapeXmlDoc :: (ArrowList a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: escapeXmlDoc :: ArrowList a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: hasXmlPi :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: hasXmlPi :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: haskellRepOfXmlDoc :: (ArrowList a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: haskellRepOfXmlDoc :: ArrowList a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: indentDoc :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: indentDoc :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: numberLinesInXmlDoc :: (ArrowList a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: numberLinesInXmlDoc :: ArrowList a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: preventEmptyElements :: (ArrowList a) => [String] -> Bool -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: preventEmptyElements :: ArrowList a => [String] -> Bool -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: rememberDTDAttrl :: (ArrowList a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: rememberDTDAttrl :: ArrowList a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: removeAllComment :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: removeAllComment :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: removeAllWhiteSpace :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: removeAllWhiteSpace :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: removeComment :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: removeComment :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: removeDocWhiteSpace :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: removeDocWhiteSpace :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: removeWhiteSpace :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: removeWhiteSpace :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: transfAllCdata :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: transfAllCdata :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: transfAllCharRef :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: transfAllCharRef :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: transfCdata :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: transfCdata :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: transfCharRef :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: transfCharRef :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: treeRepOfXmlDoc :: (ArrowList a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Edit: treeRepOfXmlDoc :: ArrowList a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Edit: xshowEscapeXml :: (ArrowXml a) => a n XmlTree -> a n String
+ Text.XML.HXT.Arrow.Edit: xshowEscapeXml :: ArrowXml a => a n XmlTree -> a n String
- Text.XML.HXT.Arrow.Namespace: attachNsEnv :: (ArrowXml a) => NsEnv -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Namespace: attachNsEnv :: ArrowXml a => NsEnv -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.Namespace: getNamespaceDecl :: (ArrowXml a) => a XmlTree (String, String)
+ Text.XML.HXT.Arrow.Namespace: getNamespaceDecl :: ArrowXml a => a XmlTree (String, String)
- Text.XML.HXT.Arrow.Namespace: isNamespaceDeclAttr :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Namespace: isNamespaceDeclAttr :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Namespace: processWithNsEnv :: (ArrowXml a) => (NsEnv -> a XmlTree XmlTree) -> NsEnv -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Namespace: processWithNsEnv :: ArrowXml a => (NsEnv -> a XmlTree XmlTree) -> NsEnv -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.Namespace: processWithNsEnvWithoutAttrl :: (ArrowXml a) => (NsEnv -> a XmlTree XmlTree) -> NsEnv -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Namespace: processWithNsEnvWithoutAttrl :: ArrowXml a => (NsEnv -> a XmlTree XmlTree) -> NsEnv -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.Namespace: propagateNamespaces :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Namespace: propagateNamespaces :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Namespace: uniqueNamespaces :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Namespace: uniqueNamespaces :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Namespace: uniqueNamespacesFromDeclAndQNames :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Namespace: uniqueNamespacesFromDeclAndQNames :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Namespace: validateNamespaces :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.Namespace: validateNamespaces :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.ParserInterface: parseHtmlContent :: (ArrowList a) => a String XmlTree
+ Text.XML.HXT.Arrow.ParserInterface: parseHtmlContent :: ArrowList a => a String XmlTree
- Text.XML.HXT.Arrow.ParserInterface: parseHtmlDoc :: (ArrowList a) => a (String, String) XmlTree
+ Text.XML.HXT.Arrow.ParserInterface: parseHtmlDoc :: ArrowList a => a (String, String) XmlTree
- Text.XML.HXT.Arrow.ParserInterface: parseHtmlTagSoup :: (ArrowList a) => Bool -> Bool -> Bool -> Bool -> Bool -> a (String, String) XmlTree
+ Text.XML.HXT.Arrow.ParserInterface: parseHtmlTagSoup :: ArrowList a => Bool -> Bool -> Bool -> Bool -> Bool -> a (String, String) XmlTree
- Text.XML.HXT.Arrow.ParserInterface: parseXmlAttrValue :: (ArrowXml a) => String -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.ParserInterface: parseXmlAttrValue :: ArrowXml a => String -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.ParserInterface: parseXmlContent :: (ArrowXml a) => a String XmlTree
+ Text.XML.HXT.Arrow.ParserInterface: parseXmlContent :: ArrowXml a => a String XmlTree
- Text.XML.HXT.Arrow.ParserInterface: parseXmlDTDEntityValue :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.ParserInterface: parseXmlDTDEntityValue :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.ParserInterface: parseXmlDTDPart :: (ArrowXml a) => a (String, XmlTree) XmlTree
+ Text.XML.HXT.Arrow.ParserInterface: parseXmlDTDPart :: ArrowXml a => a (String, XmlTree) XmlTree
- Text.XML.HXT.Arrow.ParserInterface: parseXmlDTDdecl :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.ParserInterface: parseXmlDTDdecl :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.ParserInterface: parseXmlDTDdeclPart :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.ParserInterface: parseXmlDTDdeclPart :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.ParserInterface: parseXmlDoc :: (ArrowXml a) => a (String, String) XmlTree
+ Text.XML.HXT.Arrow.ParserInterface: parseXmlDoc :: ArrowXml a => a (String, String) XmlTree
- Text.XML.HXT.Arrow.ParserInterface: parseXmlDocEncodingSpec :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.ParserInterface: parseXmlDocEncodingSpec :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.ParserInterface: parseXmlEntityEncodingSpec :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.ParserInterface: parseXmlEntityEncodingSpec :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.ParserInterface: parseXmlGeneralEntityValue :: (ArrowXml a) => String -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.ParserInterface: parseXmlGeneralEntityValue :: ArrowXml a => String -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.ParserInterface: removeEncodingSpec :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.ParserInterface: removeEncodingSpec :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.ParserInterface: substEntityRefs :: (ArrowList a) => [(String, Int)] -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.ParserInterface: substEntityRefs :: ArrowList a => [(String, Int)] -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.ParserInterface: substHtmlEntityRefs :: (ArrowList a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.ParserInterface: substHtmlEntityRefs :: ArrowList a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.ParserInterface: substXmlEntityRefs :: (ArrowList a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.ParserInterface: substXmlEntityRefs :: ArrowList a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.ParserInterface: transformDoc :: (ArrowList a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.ParserInterface: transformDoc :: ArrowList a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.ParserInterface: validateDoc :: (ArrowList a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.ParserInterface: validateDoc :: ArrowList a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.Pickle: checkPickler :: (Eq a) => PU a -> IOStateArrow s a a
+ Text.XML.HXT.Arrow.Pickle: checkPickler :: Eq a => PU a -> IOStateArrow s a a
- Text.XML.HXT.Arrow.Pickle: xpDefault :: (Eq a) => a -> PU a -> PU a
+ Text.XML.HXT.Arrow.Pickle: xpDefault :: Eq a => a -> PU a -> PU a
- Text.XML.HXT.Arrow.Pickle: xpMap :: (Ord k) => String -> String -> PU k -> PU v -> PU (Map k v)
+ Text.XML.HXT.Arrow.Pickle: xpMap :: Ord k => String -> String -> PU k -> PU v -> PU (Map k v)
- Text.XML.HXT.Arrow.Pickle: xpickle :: (XmlPickler a) => PU a
+ Text.XML.HXT.Arrow.Pickle: xpickle :: XmlPickler a => PU a
- Text.XML.HXT.Arrow.Pickle: xpickleVal :: (ArrowXml a) => PU b -> a b XmlTree
+ Text.XML.HXT.Arrow.Pickle: xpickleVal :: ArrowXml a => PU b -> a b XmlTree
- Text.XML.HXT.Arrow.Pickle: xunpickleVal :: (ArrowXml a) => PU b -> a XmlTree b
+ Text.XML.HXT.Arrow.Pickle: xunpickleVal :: ArrowXml a => PU b -> a XmlTree b
- Text.XML.HXT.Arrow.Pickle.Xml: xpDefault :: (Eq a) => a -> PU a -> PU a
+ Text.XML.HXT.Arrow.Pickle.Xml: xpDefault :: Eq a => a -> PU a -> PU a
- Text.XML.HXT.Arrow.Pickle.Xml: xpMap :: (Ord k) => String -> String -> PU k -> PU v -> PU (Map k v)
+ Text.XML.HXT.Arrow.Pickle.Xml: xpMap :: Ord k => String -> String -> PU k -> PU v -> PU (Map k v)
- Text.XML.HXT.Arrow.Pickle.Xml: xpickle :: (XmlPickler a) => PU a
+ Text.XML.HXT.Arrow.Pickle.Xml: xpickle :: XmlPickler a => PU a
- Text.XML.HXT.Arrow.ReadDocument: hread :: (ArrowXml a) => a String XmlTree
+ Text.XML.HXT.Arrow.ReadDocument: hread :: ArrowXml a => a String XmlTree
- Text.XML.HXT.Arrow.ReadDocument: xread :: (ArrowXml a) => a String XmlTree
+ Text.XML.HXT.Arrow.ReadDocument: xread :: ArrowXml a => a String XmlTree
- Text.XML.HXT.Arrow.WriteDocument: prepareContents :: (ArrowXml a) => Attributes -> (Bool -> String -> a XmlTree XmlTree) -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.WriteDocument: prepareContents :: ArrowXml a => Attributes -> (Bool -> String -> a XmlTree XmlTree) -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.WriteDocument: writeDocumentToString :: (ArrowXml a) => Attributes -> a XmlTree String
+ Text.XML.HXT.Arrow.WriteDocument: writeDocumentToString :: ArrowXml a => Attributes -> a XmlTree String
- Text.XML.HXT.Arrow.XmlArrow: (+=) :: (ArrowXml a) => a b XmlTree -> a b XmlTree -> a b XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: (+=) :: ArrowXml a => a b XmlTree -> a b XmlTree -> a b XmlTree
- Text.XML.HXT.Arrow.XmlArrow: addAttr :: (ArrowXml a) => String -> String -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: addAttr :: ArrowXml a => String -> String -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: addAttrl :: (ArrowXml a) => a XmlTree XmlTree -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: addAttrl :: ArrowXml a => a XmlTree XmlTree -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: aelem :: (ArrowXml a) => String -> [a n XmlTree] -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: aelem :: ArrowXml a => String -> [a n XmlTree] -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: attr :: (ArrowXml a) => String -> a n XmlTree -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: attr :: ArrowXml a => String -> a n XmlTree -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: changeAttrName :: (ArrowXml a) => (QName -> QName) -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: changeAttrName :: ArrowXml a => (QName -> QName) -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: changeAttrValue :: (ArrowXml a) => (String -> String) -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: changeAttrValue :: ArrowXml a => (String -> String) -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: changeAttrl :: (ArrowXml a) => (XmlTrees -> XmlTrees -> XmlTrees) -> a XmlTree XmlTree -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: changeAttrl :: ArrowXml a => (XmlTrees -> XmlTrees -> XmlTrees) -> a XmlTree XmlTree -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: changeCmt :: (ArrowXml a) => (String -> String) -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: changeCmt :: ArrowXml a => (String -> String) -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: changeElemName :: (ArrowXml a) => (QName -> QName) -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: changeElemName :: ArrowXml a => (QName -> QName) -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: changePiName :: (ArrowXml a) => (QName -> QName) -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: changePiName :: ArrowXml a => (QName -> QName) -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: changeQName :: (ArrowXml a) => (QName -> QName) -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: changeQName :: ArrowXml a => (QName -> QName) -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: changeText :: (ArrowXml a) => (String -> String) -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: changeText :: ArrowXml a => (String -> String) -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: charRef :: (ArrowXml a) => Int -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: charRef :: ArrowXml a => Int -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: class (ArrowXml a) => ArrowDTD a
+ Text.XML.HXT.Arrow.XmlArrow: class ArrowXml a => ArrowDTD a
- Text.XML.HXT.Arrow.XmlArrow: cmt :: (ArrowXml a) => String -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: cmt :: ArrowXml a => String -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: eelem :: (ArrowXml a) => String -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: eelem :: ArrowXml a => String -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: entityRef :: (ArrowXml a) => String -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: entityRef :: ArrowXml a => String -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: err :: (ArrowXml a) => String -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: err :: ArrowXml a => String -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: fatal :: (ArrowXml a) => String -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: fatal :: ArrowXml a => String -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: getAttrName :: (ArrowXml a) => a XmlTree QName
+ Text.XML.HXT.Arrow.XmlArrow: getAttrName :: ArrowXml a => a XmlTree QName
- Text.XML.HXT.Arrow.XmlArrow: getAttrValue :: (ArrowXml a) => String -> a XmlTree String
+ Text.XML.HXT.Arrow.XmlArrow: getAttrValue :: ArrowXml a => String -> a XmlTree String
- Text.XML.HXT.Arrow.XmlArrow: getAttrValue0 :: (ArrowXml a) => String -> a XmlTree String
+ Text.XML.HXT.Arrow.XmlArrow: getAttrValue0 :: ArrowXml a => String -> a XmlTree String
- Text.XML.HXT.Arrow.XmlArrow: getAttrl :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: getAttrl :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: getCdata :: (ArrowXml a) => a XmlTree String
+ Text.XML.HXT.Arrow.XmlArrow: getCdata :: ArrowXml a => a XmlTree String
- Text.XML.HXT.Arrow.XmlArrow: getCharRef :: (ArrowXml a) => a XmlTree Int
+ Text.XML.HXT.Arrow.XmlArrow: getCharRef :: ArrowXml a => a XmlTree Int
- Text.XML.HXT.Arrow.XmlArrow: getCmt :: (ArrowXml a) => a XmlTree String
+ Text.XML.HXT.Arrow.XmlArrow: getCmt :: ArrowXml a => a XmlTree String
- Text.XML.HXT.Arrow.XmlArrow: getDTDAttrValue :: (ArrowDTD a) => String -> a XmlTree String
+ Text.XML.HXT.Arrow.XmlArrow: getDTDAttrValue :: ArrowDTD a => String -> a XmlTree String
- Text.XML.HXT.Arrow.XmlArrow: getDTDAttrl :: (ArrowXml a) => a XmlTree Attributes
+ Text.XML.HXT.Arrow.XmlArrow: getDTDAttrl :: ArrowXml a => a XmlTree Attributes
- Text.XML.HXT.Arrow.XmlArrow: getDTDPart :: (ArrowXml a) => a XmlTree DTDElem
+ Text.XML.HXT.Arrow.XmlArrow: getDTDPart :: ArrowXml a => a XmlTree DTDElem
- Text.XML.HXT.Arrow.XmlArrow: getElemName :: (ArrowXml a) => a XmlTree QName
+ Text.XML.HXT.Arrow.XmlArrow: getElemName :: ArrowXml a => a XmlTree QName
- Text.XML.HXT.Arrow.XmlArrow: getEntityRef :: (ArrowXml a) => a XmlTree String
+ Text.XML.HXT.Arrow.XmlArrow: getEntityRef :: ArrowXml a => a XmlTree String
- Text.XML.HXT.Arrow.XmlArrow: getErrorLevel :: (ArrowXml a) => a XmlTree Int
+ Text.XML.HXT.Arrow.XmlArrow: getErrorLevel :: ArrowXml a => a XmlTree Int
- Text.XML.HXT.Arrow.XmlArrow: getErrorMsg :: (ArrowXml a) => a XmlTree String
+ Text.XML.HXT.Arrow.XmlArrow: getErrorMsg :: ArrowXml a => a XmlTree String
- Text.XML.HXT.Arrow.XmlArrow: getLocalPart :: (ArrowXml a) => a XmlTree String
+ Text.XML.HXT.Arrow.XmlArrow: getLocalPart :: ArrowXml a => a XmlTree String
- Text.XML.HXT.Arrow.XmlArrow: getName :: (ArrowXml a) => a XmlTree String
+ Text.XML.HXT.Arrow.XmlArrow: getName :: ArrowXml a => a XmlTree String
- Text.XML.HXT.Arrow.XmlArrow: getNamePrefix :: (ArrowXml a) => a XmlTree String
+ Text.XML.HXT.Arrow.XmlArrow: getNamePrefix :: ArrowXml a => a XmlTree String
- Text.XML.HXT.Arrow.XmlArrow: getNamespaceUri :: (ArrowXml a) => a XmlTree String
+ Text.XML.HXT.Arrow.XmlArrow: getNamespaceUri :: ArrowXml a => a XmlTree String
- Text.XML.HXT.Arrow.XmlArrow: getPiContent :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: getPiContent :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: getPiName :: (ArrowXml a) => a XmlTree QName
+ Text.XML.HXT.Arrow.XmlArrow: getPiName :: ArrowXml a => a XmlTree QName
- Text.XML.HXT.Arrow.XmlArrow: getQAttrValue :: (ArrowXml a) => QName -> a XmlTree String
+ Text.XML.HXT.Arrow.XmlArrow: getQAttrValue :: ArrowXml a => QName -> a XmlTree String
- Text.XML.HXT.Arrow.XmlArrow: getQAttrValue0 :: (ArrowXml a) => QName -> a XmlTree String
+ Text.XML.HXT.Arrow.XmlArrow: getQAttrValue0 :: ArrowXml a => QName -> a XmlTree String
- Text.XML.HXT.Arrow.XmlArrow: getQName :: (ArrowXml a) => a XmlTree QName
+ Text.XML.HXT.Arrow.XmlArrow: getQName :: ArrowXml a => a XmlTree QName
- Text.XML.HXT.Arrow.XmlArrow: getText :: (ArrowXml a) => a XmlTree String
+ Text.XML.HXT.Arrow.XmlArrow: getText :: ArrowXml a => a XmlTree String
- Text.XML.HXT.Arrow.XmlArrow: getUniversalName :: (ArrowXml a) => a XmlTree String
+ Text.XML.HXT.Arrow.XmlArrow: getUniversalName :: ArrowXml a => a XmlTree String
- Text.XML.HXT.Arrow.XmlArrow: getUniversalUri :: (ArrowXml a) => a XmlTree String
+ Text.XML.HXT.Arrow.XmlArrow: getUniversalUri :: ArrowXml a => a XmlTree String
- Text.XML.HXT.Arrow.XmlArrow: hasAttr :: (ArrowXml a) => String -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: hasAttr :: ArrowXml a => String -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: hasAttrValue :: (ArrowXml a) => String -> (String -> Bool) -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: hasAttrValue :: ArrowXml a => String -> (String -> Bool) -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: hasDTDAttr :: (ArrowDTD a) => String -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: hasDTDAttr :: ArrowDTD a => String -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: hasLocalPart :: (ArrowXml a) => String -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: hasLocalPart :: ArrowXml a => String -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: hasName :: (ArrowXml a) => String -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: hasName :: ArrowXml a => String -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: hasNamePrefix :: (ArrowXml a) => String -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: hasNamePrefix :: ArrowXml a => String -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: hasNameWith :: (ArrowXml a) => (QName -> Bool) -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: hasNameWith :: ArrowXml a => (QName -> Bool) -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: hasNamespaceUri :: (ArrowXml a) => String -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: hasNamespaceUri :: ArrowXml a => String -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: hasQAttr :: (ArrowXml a) => QName -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: hasQAttr :: ArrowXml a => QName -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: hasQAttrValue :: (ArrowXml a) => QName -> (String -> Bool) -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: hasQAttrValue :: ArrowXml a => QName -> (String -> Bool) -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: hasQName :: (ArrowXml a) => QName -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: hasQName :: ArrowXml a => QName -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: hasText :: (ArrowXml a) => (String -> Bool) -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: hasText :: ArrowXml a => (String -> Bool) -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: isAttr :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: isAttr :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: isCdata :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: isCdata :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: isCharRef :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: isCharRef :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: isCmt :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: isCmt :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: isDTD :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: isDTD :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: isDTDAttlist :: (ArrowDTD a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: isDTDAttlist :: ArrowDTD a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: isDTDCondSect :: (ArrowDTD a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: isDTDCondSect :: ArrowDTD a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: isDTDContent :: (ArrowDTD a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: isDTDContent :: ArrowDTD a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: isDTDDoctype :: (ArrowDTD a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: isDTDDoctype :: ArrowDTD a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: isDTDElement :: (ArrowDTD a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: isDTDElement :: ArrowDTD a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: isDTDEntity :: (ArrowDTD a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: isDTDEntity :: ArrowDTD a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: isDTDName :: (ArrowDTD a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: isDTDName :: ArrowDTD a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: isDTDNotation :: (ArrowDTD a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: isDTDNotation :: ArrowDTD a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: isDTDPERef :: (ArrowDTD a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: isDTDPERef :: ArrowDTD a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: isDTDPEntity :: (ArrowDTD a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: isDTDPEntity :: ArrowDTD a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: isElem :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: isElem :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: isEntityRef :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: isEntityRef :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: isError :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: isError :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: isPi :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: isPi :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: isRoot :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: isRoot :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: isText :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: isText :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: isWhiteSpace :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: isWhiteSpace :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: isXmlPi :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: isXmlPi :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: mkAttr :: (ArrowXml a) => QName -> a n XmlTree -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: mkAttr :: ArrowXml a => QName -> a n XmlTree -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: mkCdata :: (ArrowXml a) => a String XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: mkCdata :: ArrowXml a => a String XmlTree
- Text.XML.HXT.Arrow.XmlArrow: mkCharRef :: (ArrowXml a) => a Int XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: mkCharRef :: ArrowXml a => a Int XmlTree
- Text.XML.HXT.Arrow.XmlArrow: mkCmt :: (ArrowXml a) => a String XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: mkCmt :: ArrowXml a => a String XmlTree
- Text.XML.HXT.Arrow.XmlArrow: mkDTDDoctype :: (ArrowDTD a) => Attributes -> a n XmlTree -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: mkDTDDoctype :: ArrowDTD a => Attributes -> a n XmlTree -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: mkDTDElem :: (ArrowDTD a) => DTDElem -> Attributes -> a n XmlTree -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: mkDTDElem :: ArrowDTD a => DTDElem -> Attributes -> a n XmlTree -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: mkDTDElement :: (ArrowDTD a) => Attributes -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: mkDTDElement :: ArrowDTD a => Attributes -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: mkDTDEntity :: (ArrowDTD a) => Attributes -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: mkDTDEntity :: ArrowDTD a => Attributes -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: mkDTDPEntity :: (ArrowDTD a) => Attributes -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: mkDTDPEntity :: ArrowDTD a => Attributes -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: mkElement :: (ArrowXml a) => QName -> a n XmlTree -> a n XmlTree -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: mkElement :: ArrowXml a => QName -> a n XmlTree -> a n XmlTree -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: mkEntityRef :: (ArrowXml a) => a String XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: mkEntityRef :: ArrowXml a => a String XmlTree
- Text.XML.HXT.Arrow.XmlArrow: mkError :: (ArrowXml a) => Int -> a String XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: mkError :: ArrowXml a => Int -> a String XmlTree
- Text.XML.HXT.Arrow.XmlArrow: mkPi :: (ArrowXml a) => QName -> a n XmlTree -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: mkPi :: ArrowXml a => QName -> a n XmlTree -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: mkText :: (ArrowXml a) => a String XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: mkText :: ArrowXml a => a String XmlTree
- Text.XML.HXT.Arrow.XmlArrow: mkelem :: (ArrowXml a) => String -> [a n XmlTree] -> [a n XmlTree] -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: mkelem :: ArrowXml a => String -> [a n XmlTree] -> [a n XmlTree] -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: mkqelem :: (ArrowXml a) => QName -> [a n XmlTree] -> [a n XmlTree] -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: mkqelem :: ArrowXml a => QName -> [a n XmlTree] -> [a n XmlTree] -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: processAttrl :: (ArrowXml a) => a XmlTree XmlTree -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: processAttrl :: ArrowXml a => a XmlTree XmlTree -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: processTopDownWithAttrl :: (ArrowXml a) => a XmlTree XmlTree -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: processTopDownWithAttrl :: ArrowXml a => a XmlTree XmlTree -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: qattr :: (ArrowXml a) => QName -> a n XmlTree -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: qattr :: ArrowXml a => QName -> a n XmlTree -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: removeAttr :: (ArrowXml a) => String -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: removeAttr :: ArrowXml a => String -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: removeQAttr :: (ArrowXml a) => QName -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: removeQAttr :: ArrowXml a => QName -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: root :: (ArrowXml a) => [a n XmlTree] -> [a n XmlTree] -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: root :: ArrowXml a => [a n XmlTree] -> [a n XmlTree] -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: sattr :: (ArrowXml a) => String -> String -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: sattr :: ArrowXml a => String -> String -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: selem :: (ArrowXml a) => String -> [a n XmlTree] -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: selem :: ArrowXml a => String -> [a n XmlTree] -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: setAttrName :: (ArrowXml a) => QName -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: setAttrName :: ArrowXml a => QName -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: setAttrl :: (ArrowXml a) => a XmlTree XmlTree -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: setAttrl :: ArrowXml a => a XmlTree XmlTree -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: setDTDAttrValue :: (ArrowDTD a) => String -> String -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: setDTDAttrValue :: ArrowDTD a => String -> String -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: setElemName :: (ArrowXml a) => QName -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: setElemName :: ArrowXml a => QName -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: setPiName :: (ArrowXml a) => QName -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: setPiName :: ArrowXml a => QName -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: setQName :: (ArrowXml a) => QName -> a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: setQName :: ArrowXml a => QName -> a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlArrow: spi :: (ArrowXml a) => String -> String -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: spi :: ArrowXml a => String -> String -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: sqattr :: (ArrowXml a) => QName -> String -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: sqattr :: ArrowXml a => QName -> String -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: txt :: (ArrowXml a) => String -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: txt :: ArrowXml a => String -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: warn :: (ArrowXml a) => String -> a n XmlTree
+ Text.XML.HXT.Arrow.XmlArrow: warn :: ArrowXml a => String -> a n XmlTree
- Text.XML.HXT.Arrow.XmlArrow: xshow :: (ArrowXml a) => a n XmlTree -> a n String
+ Text.XML.HXT.Arrow.XmlArrow: xshow :: ArrowXml a => a n XmlTree -> a n String
- Text.XML.HXT.Arrow.XmlIOStateArrow: documentStatusOk :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.Arrow.XmlIOStateArrow: documentStatusOk :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.Arrow.XmlIOStateArrow: expandURI :: (ArrowXml a) => a (String, String) String
+ Text.XML.HXT.Arrow.XmlIOStateArrow: expandURI :: ArrowXml a => a (String, String) String
- Text.XML.HXT.Arrow.XmlIOStateArrow: getFragmentFromURI :: (ArrowList a) => a String String
+ Text.XML.HXT.Arrow.XmlIOStateArrow: getFragmentFromURI :: ArrowList a => a String String
- Text.XML.HXT.Arrow.XmlIOStateArrow: getPathFromURI :: (ArrowList a) => a String String
+ Text.XML.HXT.Arrow.XmlIOStateArrow: getPathFromURI :: ArrowList a => a String String
- Text.XML.HXT.Arrow.XmlIOStateArrow: getPortFromURI :: (ArrowList a) => a String String
+ Text.XML.HXT.Arrow.XmlIOStateArrow: getPortFromURI :: ArrowList a => a String String
- Text.XML.HXT.Arrow.XmlIOStateArrow: getQueryFromURI :: (ArrowList a) => a String String
+ Text.XML.HXT.Arrow.XmlIOStateArrow: getQueryFromURI :: ArrowList a => a String String
- Text.XML.HXT.Arrow.XmlIOStateArrow: getRegNameFromURI :: (ArrowList a) => a String String
+ Text.XML.HXT.Arrow.XmlIOStateArrow: getRegNameFromURI :: ArrowList a => a String String
- Text.XML.HXT.Arrow.XmlIOStateArrow: getSchemeFromURI :: (ArrowList a) => a String String
+ Text.XML.HXT.Arrow.XmlIOStateArrow: getSchemeFromURI :: ArrowList a => a String String
- Text.XML.HXT.Arrow.XmlIOStateArrow: getUserInfoFromURI :: (ArrowList a) => a String String
+ Text.XML.HXT.Arrow.XmlIOStateArrow: getUserInfoFromURI :: ArrowList a => a String String
- Text.XML.HXT.DOM.Util: doubles :: (Eq a) => [a] -> [a]
+ Text.XML.HXT.DOM.Util: doubles :: Eq a => [a] -> [a]
- Text.XML.HXT.DOM.Util: noDoubles :: (Eq a) => [a] -> [a]
+ Text.XML.HXT.DOM.Util: noDoubles :: Eq a => [a] -> [a]
- Text.XML.HXT.DOM.Util: singles :: (Eq a) => [a] -> [a]
+ Text.XML.HXT.DOM.Util: singles :: Eq a => [a] -> [a]
- Text.XML.HXT.DOM.Util: stringAll :: (Eq a) => [a] -> [a] -> [Int]
+ Text.XML.HXT.DOM.Util: stringAll :: Eq a => [a] -> [a] -> [Int]
- Text.XML.HXT.DOM.Util: stringFirst :: (Eq a) => [a] -> [a] -> Maybe Int
+ Text.XML.HXT.DOM.Util: stringFirst :: Eq a => [a] -> [a] -> Maybe Int
- Text.XML.HXT.DOM.Util: stringLast :: (Eq a) => [a] -> [a] -> Maybe Int
+ Text.XML.HXT.DOM.Util: stringLast :: Eq a => [a] -> [a] -> Maybe Int
- Text.XML.HXT.DOM.XmlNode: changeAttrName :: (XmlNode a) => (QName -> QName) -> a -> a
+ Text.XML.HXT.DOM.XmlNode: changeAttrName :: XmlNode a => (QName -> QName) -> a -> a
- Text.XML.HXT.DOM.XmlNode: changeAttrl :: (XmlNode a) => (XmlTrees -> XmlTrees) -> a -> a
+ Text.XML.HXT.DOM.XmlNode: changeAttrl :: XmlNode a => (XmlTrees -> XmlTrees) -> a -> a
- Text.XML.HXT.DOM.XmlNode: changeCmt :: (XmlNode a) => (String -> String) -> a -> a
+ Text.XML.HXT.DOM.XmlNode: changeCmt :: XmlNode a => (String -> String) -> a -> a
- Text.XML.HXT.DOM.XmlNode: changeDTDAttrl :: (XmlNode a) => (Attributes -> Attributes) -> a -> a
+ Text.XML.HXT.DOM.XmlNode: changeDTDAttrl :: XmlNode a => (Attributes -> Attributes) -> a -> a
- Text.XML.HXT.DOM.XmlNode: changeElemName :: (XmlNode a) => (QName -> QName) -> a -> a
+ Text.XML.HXT.DOM.XmlNode: changeElemName :: XmlNode a => (QName -> QName) -> a -> a
- Text.XML.HXT.DOM.XmlNode: changeName :: (XmlNode a) => (QName -> QName) -> a -> a
+ Text.XML.HXT.DOM.XmlNode: changeName :: XmlNode a => (QName -> QName) -> a -> a
- Text.XML.HXT.DOM.XmlNode: changePiName :: (XmlNode a) => (QName -> QName) -> a -> a
+ Text.XML.HXT.DOM.XmlNode: changePiName :: XmlNode a => (QName -> QName) -> a -> a
- Text.XML.HXT.DOM.XmlNode: changeText :: (XmlNode a) => (String -> String) -> a -> a
+ Text.XML.HXT.DOM.XmlNode: changeText :: XmlNode a => (String -> String) -> a -> a
- Text.XML.HXT.DOM.XmlNode: getAttrName :: (XmlNode a) => a -> Maybe QName
+ Text.XML.HXT.DOM.XmlNode: getAttrName :: XmlNode a => a -> Maybe QName
- Text.XML.HXT.DOM.XmlNode: getAttrl :: (XmlNode a) => a -> Maybe XmlTrees
+ Text.XML.HXT.DOM.XmlNode: getAttrl :: XmlNode a => a -> Maybe XmlTrees
- Text.XML.HXT.DOM.XmlNode: getCdata :: (XmlNode a) => a -> Maybe String
+ Text.XML.HXT.DOM.XmlNode: getCdata :: XmlNode a => a -> Maybe String
- Text.XML.HXT.DOM.XmlNode: getCharRef :: (XmlNode a) => a -> Maybe Int
+ Text.XML.HXT.DOM.XmlNode: getCharRef :: XmlNode a => a -> Maybe Int
- Text.XML.HXT.DOM.XmlNode: getCmt :: (XmlNode a) => a -> Maybe String
+ Text.XML.HXT.DOM.XmlNode: getCmt :: XmlNode a => a -> Maybe String
- Text.XML.HXT.DOM.XmlNode: getDTDAttrl :: (XmlNode a) => a -> Maybe Attributes
+ Text.XML.HXT.DOM.XmlNode: getDTDAttrl :: XmlNode a => a -> Maybe Attributes
- Text.XML.HXT.DOM.XmlNode: getDTDPart :: (XmlNode a) => a -> Maybe DTDElem
+ Text.XML.HXT.DOM.XmlNode: getDTDPart :: XmlNode a => a -> Maybe DTDElem
- Text.XML.HXT.DOM.XmlNode: getElemName :: (XmlNode a) => a -> Maybe QName
+ Text.XML.HXT.DOM.XmlNode: getElemName :: XmlNode a => a -> Maybe QName
- Text.XML.HXT.DOM.XmlNode: getEntityRef :: (XmlNode a) => a -> Maybe String
+ Text.XML.HXT.DOM.XmlNode: getEntityRef :: XmlNode a => a -> Maybe String
- Text.XML.HXT.DOM.XmlNode: getErrorLevel :: (XmlNode a) => a -> Maybe Int
+ Text.XML.HXT.DOM.XmlNode: getErrorLevel :: XmlNode a => a -> Maybe Int
- Text.XML.HXT.DOM.XmlNode: getErrorMsg :: (XmlNode a) => a -> Maybe String
+ Text.XML.HXT.DOM.XmlNode: getErrorMsg :: XmlNode a => a -> Maybe String
- Text.XML.HXT.DOM.XmlNode: getLocalPart :: (XmlNode a) => a -> Maybe String
+ Text.XML.HXT.DOM.XmlNode: getLocalPart :: XmlNode a => a -> Maybe String
- Text.XML.HXT.DOM.XmlNode: getName :: (XmlNode a) => a -> Maybe QName
+ Text.XML.HXT.DOM.XmlNode: getName :: XmlNode a => a -> Maybe QName
- Text.XML.HXT.DOM.XmlNode: getNamePrefix :: (XmlNode a) => a -> Maybe String
+ Text.XML.HXT.DOM.XmlNode: getNamePrefix :: XmlNode a => a -> Maybe String
- Text.XML.HXT.DOM.XmlNode: getNamespaceUri :: (XmlNode a) => a -> Maybe String
+ Text.XML.HXT.DOM.XmlNode: getNamespaceUri :: XmlNode a => a -> Maybe String
- Text.XML.HXT.DOM.XmlNode: getPiContent :: (XmlNode a) => a -> Maybe XmlTrees
+ Text.XML.HXT.DOM.XmlNode: getPiContent :: XmlNode a => a -> Maybe XmlTrees
- Text.XML.HXT.DOM.XmlNode: getPiName :: (XmlNode a) => a -> Maybe QName
+ Text.XML.HXT.DOM.XmlNode: getPiName :: XmlNode a => a -> Maybe QName
- Text.XML.HXT.DOM.XmlNode: getQualifiedName :: (XmlNode a) => a -> Maybe String
+ Text.XML.HXT.DOM.XmlNode: getQualifiedName :: XmlNode a => a -> Maybe String
- Text.XML.HXT.DOM.XmlNode: getText :: (XmlNode a) => a -> Maybe String
+ Text.XML.HXT.DOM.XmlNode: getText :: XmlNode a => a -> Maybe String
- Text.XML.HXT.DOM.XmlNode: getUniversalName :: (XmlNode a) => a -> Maybe String
+ Text.XML.HXT.DOM.XmlNode: getUniversalName :: XmlNode a => a -> Maybe String
- Text.XML.HXT.DOM.XmlNode: getUniversalUri :: (XmlNode a) => a -> Maybe String
+ Text.XML.HXT.DOM.XmlNode: getUniversalUri :: XmlNode a => a -> Maybe String
- Text.XML.HXT.DOM.XmlNode: isAttr :: (XmlNode a) => a -> Bool
+ Text.XML.HXT.DOM.XmlNode: isAttr :: XmlNode a => a -> Bool
- Text.XML.HXT.DOM.XmlNode: isCdata :: (XmlNode a) => a -> Bool
+ Text.XML.HXT.DOM.XmlNode: isCdata :: XmlNode a => a -> Bool
- Text.XML.HXT.DOM.XmlNode: isCharRef :: (XmlNode a) => a -> Bool
+ Text.XML.HXT.DOM.XmlNode: isCharRef :: XmlNode a => a -> Bool
- Text.XML.HXT.DOM.XmlNode: isCmt :: (XmlNode a) => a -> Bool
+ Text.XML.HXT.DOM.XmlNode: isCmt :: XmlNode a => a -> Bool
- Text.XML.HXT.DOM.XmlNode: isDTD :: (XmlNode a) => a -> Bool
+ Text.XML.HXT.DOM.XmlNode: isDTD :: XmlNode a => a -> Bool
- Text.XML.HXT.DOM.XmlNode: isElem :: (XmlNode a) => a -> Bool
+ Text.XML.HXT.DOM.XmlNode: isElem :: XmlNode a => a -> Bool
- Text.XML.HXT.DOM.XmlNode: isEntityRef :: (XmlNode a) => a -> Bool
+ Text.XML.HXT.DOM.XmlNode: isEntityRef :: XmlNode a => a -> Bool
- Text.XML.HXT.DOM.XmlNode: isError :: (XmlNode a) => a -> Bool
+ Text.XML.HXT.DOM.XmlNode: isError :: XmlNode a => a -> Bool
- Text.XML.HXT.DOM.XmlNode: isPi :: (XmlNode a) => a -> Bool
+ Text.XML.HXT.DOM.XmlNode: isPi :: XmlNode a => a -> Bool
- Text.XML.HXT.DOM.XmlNode: isRoot :: (XmlNode a) => a -> Bool
+ Text.XML.HXT.DOM.XmlNode: isRoot :: XmlNode a => a -> Bool
- Text.XML.HXT.DOM.XmlNode: isText :: (XmlNode a) => a -> Bool
+ Text.XML.HXT.DOM.XmlNode: isText :: XmlNode a => a -> Bool
- Text.XML.HXT.DOM.XmlNode: mkCdata :: (XmlNode a) => String -> a
+ Text.XML.HXT.DOM.XmlNode: mkCdata :: XmlNode a => String -> a
- Text.XML.HXT.DOM.XmlNode: mkCharRef :: (XmlNode a) => Int -> a
+ Text.XML.HXT.DOM.XmlNode: mkCharRef :: XmlNode a => Int -> a
- Text.XML.HXT.DOM.XmlNode: mkCmt :: (XmlNode a) => String -> a
+ Text.XML.HXT.DOM.XmlNode: mkCmt :: XmlNode a => String -> a
- Text.XML.HXT.DOM.XmlNode: mkEntityRef :: (XmlNode a) => String -> a
+ Text.XML.HXT.DOM.XmlNode: mkEntityRef :: XmlNode a => String -> a
- Text.XML.HXT.DOM.XmlNode: mkError :: (XmlNode a) => Int -> String -> a
+ Text.XML.HXT.DOM.XmlNode: mkError :: XmlNode a => Int -> String -> a
- Text.XML.HXT.DOM.XmlNode: mkPi :: (XmlNode a) => QName -> XmlTrees -> a
+ Text.XML.HXT.DOM.XmlNode: mkPi :: XmlNode a => QName -> XmlTrees -> a
- Text.XML.HXT.DOM.XmlNode: mkText :: (XmlNode a) => String -> a
+ Text.XML.HXT.DOM.XmlNode: mkText :: XmlNode a => String -> a
- Text.XML.HXT.DOM.XmlNode: setAttrName :: (XmlNode a) => QName -> a -> a
+ Text.XML.HXT.DOM.XmlNode: setAttrName :: XmlNode a => QName -> a -> a
- Text.XML.HXT.DOM.XmlNode: setCmt :: (XmlNode a) => String -> a -> a
+ Text.XML.HXT.DOM.XmlNode: setCmt :: XmlNode a => String -> a -> a
- Text.XML.HXT.DOM.XmlNode: setDTDAttrl :: (XmlNode a) => Attributes -> a -> a
+ Text.XML.HXT.DOM.XmlNode: setDTDAttrl :: XmlNode a => Attributes -> a -> a
- Text.XML.HXT.DOM.XmlNode: setElemAttrl :: (XmlNode a) => XmlTrees -> a -> a
+ Text.XML.HXT.DOM.XmlNode: setElemAttrl :: XmlNode a => XmlTrees -> a -> a
- Text.XML.HXT.DOM.XmlNode: setElemName :: (XmlNode a) => QName -> a -> a
+ Text.XML.HXT.DOM.XmlNode: setElemName :: XmlNode a => QName -> a -> a
- Text.XML.HXT.DOM.XmlNode: setName :: (XmlNode a) => QName -> a -> a
+ Text.XML.HXT.DOM.XmlNode: setName :: XmlNode a => QName -> a -> a
- Text.XML.HXT.DOM.XmlNode: setPiName :: (XmlNode a) => QName -> a -> a
+ Text.XML.HXT.DOM.XmlNode: setPiName :: XmlNode a => QName -> a -> a
- Text.XML.HXT.DOM.XmlNode: setText :: (XmlNode a) => String -> a -> a
+ Text.XML.HXT.DOM.XmlNode: setText :: XmlNode a => String -> a -> a
- Text.XML.HXT.DTDValidation.RE: checkRE :: (Show a) => RE a -> String
+ Text.XML.HXT.DTDValidation.RE: checkRE :: Show a => RE a -> String
- Text.XML.HXT.DTDValidation.RE: nullable :: (Show a) => RE a -> Bool
+ Text.XML.HXT.DTDValidation.RE: nullable :: Show a => RE a -> Bool
- Text.XML.HXT.DTDValidation.RE: printRE :: (Show a) => RE a -> String
+ Text.XML.HXT.DTDValidation.RE: printRE :: Show a => RE a -> String
- Text.XML.HXT.DTDValidation.TypeDefs: hasDTDAttrValue :: (ArrowDTD a) => String -> (String -> Bool) -> a XmlTree XmlTree
+ Text.XML.HXT.DTDValidation.TypeDefs: hasDTDAttrValue :: ArrowDTD a => String -> (String -> Bool) -> a XmlTree XmlTree
- Text.XML.HXT.DTDValidation.TypeDefs: isAttlistOfElement :: (ArrowDTD a) => String -> a XmlTree XmlTree
+ Text.XML.HXT.DTDValidation.TypeDefs: isAttlistOfElement :: ArrowDTD a => String -> a XmlTree XmlTree
- Text.XML.HXT.DTDValidation.TypeDefs: isDefaultAttrKind :: (ArrowDTD a) => a XmlTree XmlTree
+ Text.XML.HXT.DTDValidation.TypeDefs: isDefaultAttrKind :: ArrowDTD a => a XmlTree XmlTree
- Text.XML.HXT.DTDValidation.TypeDefs: isEmptyElement :: (ArrowDTD a) => a XmlTree XmlTree
+ Text.XML.HXT.DTDValidation.TypeDefs: isEmptyElement :: ArrowDTD a => a XmlTree XmlTree
- Text.XML.HXT.DTDValidation.TypeDefs: isEnumAttrType :: (ArrowDTD a) => a XmlTree XmlTree
+ Text.XML.HXT.DTDValidation.TypeDefs: isEnumAttrType :: ArrowDTD a => a XmlTree XmlTree
- Text.XML.HXT.DTDValidation.TypeDefs: isFixedAttrKind :: (ArrowDTD a) => a XmlTree XmlTree
+ Text.XML.HXT.DTDValidation.TypeDefs: isFixedAttrKind :: ArrowDTD a => a XmlTree XmlTree
- Text.XML.HXT.DTDValidation.TypeDefs: isIdAttrType :: (ArrowDTD a) => a XmlTree XmlTree
+ Text.XML.HXT.DTDValidation.TypeDefs: isIdAttrType :: ArrowDTD a => a XmlTree XmlTree
- Text.XML.HXT.DTDValidation.TypeDefs: isIdRefAttrType :: (ArrowDTD a) => a XmlTree XmlTree
+ Text.XML.HXT.DTDValidation.TypeDefs: isIdRefAttrType :: ArrowDTD a => a XmlTree XmlTree
- Text.XML.HXT.DTDValidation.TypeDefs: isMixedContentElement :: (ArrowDTD a) => a XmlTree XmlTree
+ Text.XML.HXT.DTDValidation.TypeDefs: isMixedContentElement :: ArrowDTD a => a XmlTree XmlTree
- Text.XML.HXT.DTDValidation.TypeDefs: isNotationAttrType :: (ArrowDTD a) => a XmlTree XmlTree
+ Text.XML.HXT.DTDValidation.TypeDefs: isNotationAttrType :: ArrowDTD a => a XmlTree XmlTree
- Text.XML.HXT.DTDValidation.TypeDefs: isRequiredAttrKind :: (ArrowDTD a) => a XmlTree XmlTree
+ Text.XML.HXT.DTDValidation.TypeDefs: isRequiredAttrKind :: ArrowDTD a => a XmlTree XmlTree
- Text.XML.HXT.DTDValidation.TypeDefs: isUnparsedEntity :: (ArrowDTD a) => a XmlTree XmlTree
+ Text.XML.HXT.DTDValidation.TypeDefs: isUnparsedEntity :: ArrowDTD a => a XmlTree XmlTree
- Text.XML.HXT.DTDValidation.XmlRE: checkRE :: (Show a) => RE a -> String
+ Text.XML.HXT.DTDValidation.XmlRE: checkRE :: Show a => RE a -> String
- Text.XML.HXT.DTDValidation.XmlRE: printRE :: (Show a) => RE a -> String
+ Text.XML.HXT.DTDValidation.XmlRE: printRE :: Show a => RE a -> String
- Text.XML.HXT.RelaxNG.BasicArrows: checkRngName :: (ArrowXml a) => [String] -> a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: checkRngName :: ArrowXml a => [String] -> a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: getRngAttrAttribute :: (ArrowXml a) => a XmlTree String
+ Text.XML.HXT.RelaxNG.BasicArrows: getRngAttrAttribute :: ArrowXml a => a XmlTree String
- Text.XML.HXT.RelaxNG.BasicArrows: getRngAttrCombine :: (ArrowXml a) => a XmlTree String
+ Text.XML.HXT.RelaxNG.BasicArrows: getRngAttrCombine :: ArrowXml a => a XmlTree String
- Text.XML.HXT.RelaxNG.BasicArrows: getRngAttrDatatypeLibrary :: (ArrowXml a) => a XmlTree String
+ Text.XML.HXT.RelaxNG.BasicArrows: getRngAttrDatatypeLibrary :: ArrowXml a => a XmlTree String
- Text.XML.HXT.RelaxNG.BasicArrows: getRngAttrDescr :: (ArrowXml a) => a XmlTree String
+ Text.XML.HXT.RelaxNG.BasicArrows: getRngAttrDescr :: ArrowXml a => a XmlTree String
- Text.XML.HXT.RelaxNG.BasicArrows: getRngAttrHref :: (ArrowXml a) => a XmlTree String
+ Text.XML.HXT.RelaxNG.BasicArrows: getRngAttrHref :: ArrowXml a => a XmlTree String
- Text.XML.HXT.RelaxNG.BasicArrows: getRngAttrName :: (ArrowXml a) => a XmlTree String
+ Text.XML.HXT.RelaxNG.BasicArrows: getRngAttrName :: ArrowXml a => a XmlTree String
- Text.XML.HXT.RelaxNG.BasicArrows: getRngAttrNs :: (ArrowXml a) => a XmlTree String
+ Text.XML.HXT.RelaxNG.BasicArrows: getRngAttrNs :: ArrowXml a => a XmlTree String
- Text.XML.HXT.RelaxNG.BasicArrows: getRngAttrType :: (ArrowXml a) => a XmlTree String
+ Text.XML.HXT.RelaxNG.BasicArrows: getRngAttrType :: ArrowXml a => a XmlTree String
- Text.XML.HXT.RelaxNG.BasicArrows: hasRngAttrAttribute :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: hasRngAttrAttribute :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: hasRngAttrCombine :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: hasRngAttrCombine :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: hasRngAttrDatatypeLibrary :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: hasRngAttrDatatypeLibrary :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: hasRngAttrHref :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: hasRngAttrHref :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: hasRngAttrName :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: hasRngAttrName :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: hasRngAttrNs :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: hasRngAttrNs :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: hasRngAttrType :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: hasRngAttrType :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: hasRngName :: (ArrowXml a) => String -> a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: hasRngName :: ArrowXml a => String -> a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isAttributeListGroupInterleaveOneOrMore :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isAttributeListGroupInterleaveOneOrMore :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isAttributeRef :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isAttributeRef :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isAttributeRefTextListGroupInterleaveOneOrMoreEmpty :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isAttributeRefTextListGroupInterleaveOneOrMoreEmpty :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isAttributeRefTextListInterleave :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isAttributeRefTextListInterleave :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isChoiceGroupInterleave :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isChoiceGroupInterleave :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isChoiceGroupInterleaveOneOrMore :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isChoiceGroupInterleaveOneOrMore :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isDefineOneOrMoreZeroOrMoreOptionalListMixed :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isDefineOneOrMoreZeroOrMoreOptionalListMixed :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isExternalRefInclude :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isExternalRefInclude :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isGroupInterleave :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isGroupInterleave :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isNameAnyNameNsName :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isNameAnyNameNsName :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isNameNsName :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isNameNsName :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isNameNsNameValue :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isNameNsNameValue :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngAnyName :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngAnyName :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngAttrAttribute :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngAttrAttribute :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngAttrCombine :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngAttrCombine :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngAttrDatatypeLibrary :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngAttrDatatypeLibrary :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngAttrHref :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngAttrHref :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngAttrName :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngAttrName :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngAttrNs :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngAttrNs :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngAttrType :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngAttrType :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngAttribute :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngAttribute :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngChoice :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngChoice :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngCombine :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngCombine :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngData :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngData :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngDefine :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngDefine :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngDiv :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngDiv :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngElement :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngElement :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngEmpty :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngEmpty :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngExcept :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngExcept :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngExternalRef :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngExternalRef :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngGrammar :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngGrammar :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngGroup :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngGroup :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngInclude :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngInclude :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngInterleave :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngInterleave :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngList :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngList :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngMixed :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngMixed :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngName :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngName :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngNotAllowed :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngNotAllowed :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngNsName :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngNsName :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngOneOrMore :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngOneOrMore :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngOptional :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngOptional :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngParam :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngParam :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngParentRef :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngParentRef :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngRef :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngRef :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngRelaxError :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngRelaxError :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngStart :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngStart :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngText :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngText :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngType :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngType :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngValue :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngValue :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: isRngZeroOrMore :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: isRngZeroOrMore :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: mkRngChoice :: (ArrowXml a) => a n XmlTree -> a n XmlTree -> a n XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: mkRngChoice :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: mkRngDefine :: (ArrowXml a) => a n XmlTree -> a n XmlTree -> a n XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: mkRngDefine :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: mkRngElement :: (ArrowXml a) => String -> a n XmlTree -> a n XmlTree -> a n XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: mkRngElement :: ArrowXml a => String -> a n XmlTree -> a n XmlTree -> a n XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: mkRngEmpty :: (ArrowXml a) => a n XmlTree -> a n XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: mkRngEmpty :: ArrowXml a => a n XmlTree -> a n XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: mkRngGrammar :: (ArrowXml a) => a n XmlTree -> a n XmlTree -> a n XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: mkRngGrammar :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: mkRngGroup :: (ArrowXml a) => a n XmlTree -> a n XmlTree -> a n XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: mkRngGroup :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: mkRngInterleave :: (ArrowXml a) => a n XmlTree -> a n XmlTree -> a n XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: mkRngInterleave :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: mkRngName :: (ArrowXml a) => a n XmlTree -> a n XmlTree -> a n XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: mkRngName :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: mkRngNotAllowed :: (ArrowXml a) => a n XmlTree -> a n XmlTree -> a n XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: mkRngNotAllowed :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: mkRngOneOrMore :: (ArrowXml a) => a n XmlTree -> a n XmlTree -> a n XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: mkRngOneOrMore :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: mkRngRef :: (ArrowXml a) => a n XmlTree -> a n XmlTree -> a n XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: mkRngRef :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: mkRngRelaxError :: (ArrowXml a) => a n XmlTree -> a n XmlTree -> a n XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: mkRngRelaxError :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: mkRngStart :: (ArrowXml a) => a n XmlTree -> a n XmlTree -> a n XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: mkRngStart :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: mkRngText :: (ArrowXml a) => a n XmlTree -> a n XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: mkRngText :: ArrowXml a => a n XmlTree -> a n XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: noOfChildren :: (ArrowXml a) => (Int -> Bool) -> a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: noOfChildren :: ArrowXml a => (Int -> Bool) -> a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: setRngName :: (ArrowXml a) => String -> a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: setRngName :: ArrowXml a => String -> a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: setRngNameDiv :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: setRngNameDiv :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.BasicArrows: setRngNameRef :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.BasicArrows: setRngNameRef :: ArrowXml a => a XmlTree XmlTree
- Text.XML.HXT.RelaxNG.Schema: relaxSchemaArrow :: (ArrowList a) => a b XmlTree
+ Text.XML.HXT.RelaxNG.Schema: relaxSchemaArrow :: ArrowList a => a b XmlTree
- Text.XML.HXT.RelaxNG.SchemaGrammar: relaxSchemaArrow :: (ArrowList a) => a b XmlTree
+ Text.XML.HXT.RelaxNG.SchemaGrammar: relaxSchemaArrow :: ArrowList a => a b XmlTree
- Text.XML.HXT.RelaxNG.Validation: normalizeForRelaxValidation :: (ArrowXml a) => a XmlTree XmlTree
+ Text.XML.HXT.RelaxNG.Validation: normalizeForRelaxValidation :: ArrowXml a => a XmlTree XmlTree
Files
- LICENCE +0/−9
- LICENSE +9/−0
- examples/arrows/hparser/Makefile +2/−0
- examples/arrows/hparser/lousy.html +3/−3
- hxt.cabal +24/−14
- src/Control/Arrow/ArrowIO.hs +10/−10
- src/Control/Arrow/ArrowIf.hs +45/−45
- src/Control/Arrow/ArrowList.hs +54/−54
- src/Control/Arrow/ArrowNF.hs +4/−4
- src/Control/Arrow/ArrowState.hs +12/−12
- src/Control/Arrow/ArrowTree.hs +119/−119
- src/Control/Arrow/IOListArrow.hs +51/−51
- src/Control/Arrow/IOStateListArrow.hs +79/−79
- src/Control/Arrow/ListArrow.hs +33/−33
- src/Control/Arrow/ListArrows.hs +4/−4
- src/Control/Arrow/StateListArrow.hs +82/−82
- src/Data/AssocList.hs +18/−18
- src/Data/Atom.hs +32/−32
- src/Data/Tree/Class.hs +20/−20
- src/Data/Tree/NTree/TypeDefs.hs +37/−37
- src/Text/XML/HXT/Arrow.hs +3/−3
- src/Text/XML/HXT/Arrow/DTDProcessing.hs +318/−318
- src/Text/XML/HXT/Arrow/DocumentInput.hs +234/−234
- src/Text/XML/HXT/Arrow/DocumentOutput.hs +106/−106
- src/Text/XML/HXT/Arrow/Edit.hs +281/−281
- src/Text/XML/HXT/Arrow/GeneralEntitySubstitution.hs +213/−213
- src/Text/XML/HXT/Arrow/Namespace.hs +183/−183
- src/Text/XML/HXT/Arrow/ParserInterface.hs +59/−59
- src/Text/XML/HXT/Arrow/Pickle.hs +61/−61
- src/Text/XML/HXT/Arrow/Pickle/DTD.hs +148/−148
- src/Text/XML/HXT/Arrow/Pickle/Schema.hs +121/−121
- src/Text/XML/HXT/Arrow/Pickle/Xml.hs +219/−219
- src/Text/XML/HXT/Arrow/ProcessDocument.hs +102/−102
- src/Text/XML/HXT/Arrow/ReadDocument.hs +159/−159
- src/Text/XML/HXT/Arrow/WriteDocument.hs +63/−63
- src/Text/XML/HXT/Arrow/XmlArrow.hs +258/−258
- src/Text/XML/HXT/Arrow/XmlIOStateArrow.hs +283/−283
- src/Text/XML/HXT/Arrow/XmlRegex.hs +145/−145
- src/Text/XML/HXT/DOM/FormatXmlTree.hs +17/−17
- src/Text/XML/HXT/DOM/Interface.hs +4/−4
- src/Text/XML/HXT/DOM/IsoLatinTables.hs +14/−14
- src/Text/XML/HXT/DOM/MimeTypeDefaults.hs +581/−581
- src/Text/XML/HXT/DOM/MimeTypes.hs +52/−52
- src/Text/XML/HXT/DOM/QualifiedName.hs +4/−4
- src/Text/XML/HXT/DOM/ShowXml.hs +118/−118
- src/Text/XML/HXT/DOM/TypeDefs.hs +69/−69
- src/Text/XML/HXT/DOM/UTF8Decoding.hs +4/−4
- src/Text/XML/HXT/DOM/Unicode.hs +190/−190
- src/Text/XML/HXT/DOM/Util.hs +86/−86
- src/Text/XML/HXT/DOM/XmlKeywords.hs +166/−166
- src/Text/XML/HXT/DOM/XmlNode.hs +213/−213
- src/Text/XML/HXT/DOM/XmlOptions.hs +71/−71
- src/Text/XML/HXT/DTDValidation/AttributeValueValidation.hs +63/−63
- src/Text/XML/HXT/DTDValidation/DTDValidation.hs +238/−238
- src/Text/XML/HXT/DTDValidation/DocTransformation.hs +53/−53
- src/Text/XML/HXT/DTDValidation/DocValidation.hs +183/−183
- src/Text/XML/HXT/DTDValidation/IdValidation.hs +90/−90
- src/Text/XML/HXT/DTDValidation/RE.hs +98/−98
- src/Text/XML/HXT/DTDValidation/TypeDefs.hs +68/−68
- src/Text/XML/HXT/DTDValidation/Validation.hs +30/−30
- src/Text/XML/HXT/DTDValidation/XmlRE.hs +17/−17
- src/Text/XML/HXT/IO/GetFILE.hs +66/−66
- src/Text/XML/HXT/IO/GetHTTPLibCurl.hs +155/−155
- src/Text/XML/HXT/Parser/HtmlParsec.hs +219/−219
- src/Text/XML/HXT/Parser/ProtocolHandlerUtil.hs +21/−21
- src/Text/XML/HXT/Parser/TagSoup.hs +327/−312
- src/Text/XML/HXT/Parser/XhtmlEntities.hs +252/−252
- src/Text/XML/HXT/Parser/XmlCharParser.hs +19/−19
- src/Text/XML/HXT/Parser/XmlDTDParser.hs +245/−245
- src/Text/XML/HXT/Parser/XmlDTDTokenParser.hs +31/−31
- src/Text/XML/HXT/Parser/XmlEntities.hs +7/−7
- src/Text/XML/HXT/Parser/XmlParsec.hs +223/−223
- src/Text/XML/HXT/Parser/XmlTokenParser.hs +115/−115
- src/Text/XML/HXT/RelaxNG.hs +0/−0
- src/Text/XML/HXT/RelaxNG/BasicArrows.hs +157/−157
- src/Text/XML/HXT/RelaxNG/CreatePattern.hs +70/−70
- src/Text/XML/HXT/RelaxNG/DataTypeLibMysql.hs +64/−64
- src/Text/XML/HXT/RelaxNG/DataTypeLibUtils.hs +132/−132
- src/Text/XML/HXT/RelaxNG/DataTypeLibraries.hs +33/−33
- src/Text/XML/HXT/RelaxNG/DataTypes.hs +76/−76
- src/Text/XML/HXT/RelaxNG/PatternFunctions.hs +16/−16
- src/Text/XML/HXT/RelaxNG/PatternToString.hs +54/−54
- src/Text/XML/HXT/RelaxNG/Schema.hs +26/−26
- src/Text/XML/HXT/RelaxNG/SchemaGrammar.hs +26/−26
- src/Text/XML/HXT/RelaxNG/Simplification.hs +2249/−2249
- src/Text/XML/HXT/RelaxNG/Unicode/Blocks.hs +197/−197
- src/Text/XML/HXT/RelaxNG/Unicode/CharProps.hs +36/−36
- src/Text/XML/HXT/RelaxNG/Utils.hs +23/−23
- src/Text/XML/HXT/RelaxNG/Validation.hs +135/−135
- src/Text/XML/HXT/RelaxNG/Validator.hs +75/−75
- src/Text/XML/HXT/RelaxNG/XmlSchema/DataTypeLibW3C.hs +306/−306
- src/Text/XML/HXT/RelaxNG/XmlSchema/Regex.hs +188/−188
- src/Text/XML/HXT/RelaxNG/XmlSchema/RegexMatch.hs +46/−43
- src/Text/XML/HXT/RelaxNG/XmlSchema/RegexParser.hs +104/−104
− LICENCE
@@ -1,9 +0,0 @@-The MIT License--Copyright (c) 2005 Uwe Schmidt, Martin Schmidt, Torben Kuseler--Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:--The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.--THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ LICENSE view
@@ -0,0 +1,9 @@+The MIT License++Copyright (c) 2005 Uwe Schmidt, Martin Schmidt, Torben Kuseler++Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
examples/arrows/hparser/Makefile view
@@ -140,6 +140,8 @@ test6 : @echo "===> tagsoup parsing examples" ; echo ; sleep 2+ @echo "===> lousy HTML document" ; echo ; sleep 2+ $(prog) --tagsoup --parse-html lousy.html @echo "===> www.w3c.org homepage (valid XHTML)" ; echo ; sleep 2 $(prog) --tagsoup http://www.w3c.org/ @echo "===> same again with removed whitespace and tree output" ; echo ; sleep 2
examples/arrows/hparser/lousy.html view
@@ -9,9 +9,9 @@ <h2>html <p>some text and a &xxx; <p>more text- ' ' '+ ' ' ' &yyy &unknown;- A+ A B A Ä </p@@ -32,6 +32,6 @@ Schmidt</a></address> <!-- Created: Tue Apr 29 16:07:57 CEST 2003 --> <!-- hhmts start -->-Last modified: Mon Feb 18 13:56:28 CET 2008+Last modified: Tue Aug 17 15:56:59 CEST 2010 <!-- hhmts end --> </html>
hxt.cabal view
@@ -1,17 +1,27 @@ -- arch-tag: Haskell XML Toolbox main description file-name: hxt-version: 8.5.2-license: OtherLicense-license-file: LICENCE-maintainer: Uwe Schmidt <uwe@fh-wedel.de>-stability: stable-category: XML-synopsis: A collection of tools for processing XML with Haskell. -description: The Haskell XML Toolbox bases on the ideas of HaXml and HXML, but introduces a more general approach for processing XML with Haskell. The Haskell XML Toolbox uses a generic data model for representing XML documents, including the DTD subset and the document subset, in Haskell. It contains a validating XML parser, a HTML parser, namespace support, an XPath expression evaluator, an XSLT library, a RelaxNG schema validator and funtions for serialization and deserialization of user defined data. The library make extensive use of the arrow approach for processing XML. Since version 8.5 XPath and XSLT have been moved to separate packages hxt-xpath and hxt-xslt.-homepage: http://www.fh-wedel.de/~si/HXmlToolbox/index.html-copyright: Copyright (c) 2005-2010 Uwe Schmidt-build-type: Simple-cabal-version: >=1.6+Name: hxt+Version: 8.5.4+Synopsis: A collection of tools for processing XML with Haskell. +Description: The Haskell XML Toolbox bases on the ideas of HaXml and HXML,+ but introduces a more general approach for processing XML with Haskell.+ The Haskell XML Toolbox uses a generic data model for representing XML documents,+ including the DTD subset and the document subset, in Haskell.+ It contains a validating XML parser, a HTML parser, namespace support,+ an XPath expression evaluator, an XSLT library, a RelaxNG schema validator+ and funtions for serialization and deserialization of user defined data.+ The library makes extensive use of the arrow approach for processing XML.+ Since version 8.5 XPath and XSLT have been moved to separate packages hxt-xpath and hxt-xslt,+ serialisation is in package hxt-binary+License: OtherLicense+License-file: LICENSE+Author: Uwe Schmidt, Martin Schmidt, Torben Kuseler+Maintainer: Uwe Schmidt <uwe@fh-wedel.de>+Stability: Stable+Category: XML+Homepage: http://www.fh-wedel.de/~si/HXmlToolbox/index.html+Copyright: Copyright (c) 2005-2010 Uwe Schmidt+Build-type: Simple+Cabal-version: >=1.6 extra-source-files: examples/arrows/absurls/AbsURIs.hs@@ -173,5 +183,5 @@ network >= 2.1 && < 3, deepseq >= 1.1 && < 2, bytestring >= 0.9 && < 1,- tagsoup >= 0.8 && < 0.9,+ tagsoup >= 0.10 && < 0.11, curl >= 1.3 && < 2
src/Control/Arrow/ArrowIO.hs view
@@ -29,32 +29,32 @@ class Arrow a => ArrowIO a where -- | construct an arrow from an IO action- arrIO :: (b -> IO c) -> a b c+ arrIO :: (b -> IO c) -> a b c -- | construct an arrow from an IO action without any parameter- arrIO0 :: IO c -> a b c- arrIO0 f = arrIO (const f)+ arrIO0 :: IO c -> a b c+ arrIO0 f = arrIO (const f) -- | construction of a 2 argument arrow from a binary IO action -- | -- | example: @ a1 &&& a2 >>> arr2 f @ - arrIO2 :: (b1 -> b2 -> IO c) -> a (b1, b2) c- arrIO2 f = arrIO (\ ~(x1, x2) -> f x1 x2)+ arrIO2 :: (b1 -> b2 -> IO c) -> a (b1, b2) c+ arrIO2 f = arrIO (\ ~(x1, x2) -> f x1 x2) -- | construction of a 3 argument arrow from a 3-ary IO action -- | -- | example: @ a1 &&& a2 &&& a3 >>> arr3 f @ - arrIO3 :: (b1 -> b2 -> b3 -> IO c) -> a (b1, (b2, b3)) c- arrIO3 f = arrIO (\ ~(x1, ~(x2, x3)) -> f x1 x2 x3)+ arrIO3 :: (b1 -> b2 -> b3 -> IO c) -> a (b1, (b2, b3)) c+ arrIO3 f = arrIO (\ ~(x1, ~(x2, x3)) -> f x1 x2 x3) -- | construction of a 4 argument arrow from a 4-ary IO action -- | -- | example: @ a1 &&& a2 &&& a3 &&& a4 >>> arr4 f @ - arrIO4 :: (b1 -> b2 -> b3 -> b4 -> IO c) -> a (b1, (b2, (b3, b4))) c- arrIO4 f = arrIO (\ ~(x1, ~(x2, ~(x3, x4))) -> f x1 x2 x3 x4)+ arrIO4 :: (b1 -> b2 -> b3 -> b4 -> IO c) -> a (b1, (b2, (b3, b4))) c+ arrIO4 f = arrIO (\ ~(x1, ~(x2, ~(x3, x4))) -> f x1 x2 x3 x4) -- | the interface for converting an IO predicate into a list arrow@@ -66,6 +66,6 @@ -- if the predicate holds, the single list containing the input is returned, else the empty list, -- similar to 'Control.Arrow.ArrowList.isA' - isIOA :: (b -> IO Bool) -> a b b+ isIOA :: (b -> IO Bool) -> a b b -- ------------------------------------------------------------
src/Control/Arrow/ArrowIf.hs view
@@ -43,84 +43,84 @@ -- | if lifted to arrows - ifA :: a b c -> a b d -> a b d -> a b d+ ifA :: a b c -> a b d -> a b d -> a b d -- | shortcut: @ ifP p = ifA (isA p) @ - ifP :: (b -> Bool) -> a b d -> a b d -> a b d- ifP p = ifA (isA p)+ ifP :: (b -> Bool) -> a b d -> a b d -> a b d+ ifP p = ifA (isA p) -- | negation: @ neg f = ifA f none this @ - neg :: a b c -> a b b- neg f = ifA f none this+ neg :: a b c -> a b b+ neg f = ifA f none this -- | @ f \`when\` g @ : when the predicate g holds, f is applied, else the identity filter this - when :: a b b -> a b c -> a b b- f `when` g = ifA g f this+ when :: a b b -> a b c -> a b b+ f `when` g = ifA g f this -- | shortcut: @ f \`whenP\` p = f \`when\` (isA p) @ - whenP :: a b b -> (b -> Bool) -> a b b- f `whenP` g = ifP g f this+ whenP :: a b b -> (b -> Bool) -> a b b+ f `whenP` g = ifP g f this -- | @ f \`whenNot\` g @ : when the predicate g does not hold, f is applied, else the identity filter this - whenNot :: a b b -> a b c -> a b b- f `whenNot` g = ifA g this f+ whenNot :: a b b -> a b c -> a b b+ f `whenNot` g = ifA g this f -- | like 'whenP' - whenNotP :: a b b -> (b -> Bool) -> a b b- f `whenNotP` g = ifP g this f+ whenNotP :: a b b -> (b -> Bool) -> a b b+ f `whenNotP` g = ifP g this f -- | @ g \`guards\` f @ : when the predicate g holds, f is applied, else none - guards :: a b c -> a b d -> a b d- f `guards` g = ifA f g none+ guards :: a b c -> a b d -> a b d+ f `guards` g = ifA f g none -- | like 'whenP' - guardsP :: (b -> Bool) -> a b d -> a b d- f `guardsP` g = ifP f g none+ guardsP :: (b -> Bool) -> a b d -> a b d+ f `guardsP` g = ifP f g none -- | shortcut for @ f `guards` this @ - filterA :: a b c -> a b b- filterA f = ifA f this none+ filterA :: a b c -> a b b+ filterA f = ifA f this none -- | @ f \`containing\` g @ : keep only those results from f for which g holds -- -- definition: @ f \`containing\` g = f >>> g \`guards\` this @ - containing :: a b c -> a c d -> a b c- f `containing` g = f >>> g `guards` this+ containing :: a b c -> a c d -> a b c+ f `containing` g = f >>> g `guards` this -- | @ f \`notContaining\` g @ : keep only those results from f for which g does not hold -- -- definition: @ f \`notContaining\` g = f >>> ifA g none this @ - notContaining :: a b c -> a c d -> a b c- f `notContaining` g = f >>> ifA g none this+ notContaining :: a b c -> a c d -> a b c+ f `notContaining` g = f >>> ifA g none this -- | @ f \`orElse\` g @ : directional choice: if f succeeds, the result of f is the result, else g is applied- orElse :: a b c -> a b c -> a b c+ orElse :: a b c -> a b c -> a b c -- | generalisation of 'orElse' for multi way branches like in case expressions. -- -- An auxiliary data type 'IfThen' with an infix constructor ':->' is used for writing multi way branches -- -- example: @ choiceA [ p1 :-> e1, p2 :-> e2, this :-> default ] @- choiceA :: [IfThen (a b c) (a b d)] -> a b d- choiceA = foldr ifA' none- where- ifA' (g :-> f) = ifA g f+ choiceA :: [IfThen (a b c) (a b d)] -> a b d+ choiceA = foldr ifA' none+ where+ ifA' (g :-> f) = ifA g f -- | tag a value with Left or Right, if arrow has success, input is tagged with Left, else with Right- tagA :: a b c -> a b (Either b b)- tagA p = ifA p (arr Left) (arr Right)+ tagA :: a b c -> a b (Either b b)+ tagA p = ifA p (arr Left) (arr Right) -- | split a list value with an arrow and returns a pair of lists.@@ -128,31 +128,31 @@ -- -- example: @ runLA (spanA (isA (\/= \'-\'))) \"abc-def\" @ gives @ [(\"abc\",\"-def\")] @ as result - spanA :: a b b -> a [b] ([b],[b])- spanA p = ifA ( arrL (take 1) >>> p )- ( arr head &&& (arr tail >>> spanA p)- >>>- arr (\ ~(x, ~(xs,ys)) -> (x : xs, ys))- )+ spanA :: a b b -> a [b] ([b],[b])+ spanA p = ifA ( arrL (take 1) >>> p )+ ( arr head &&& (arr tail >>> spanA p)+ >>>+ arr (\ ~(x, ~(xs,ys)) -> (x : xs, ys))+ ) ( arr (\ l -> ([],l)) ) -- | partition a list of values into a pair of lists -- -- This is the arrow Version of 'Data.List.partition' - partitionA :: a b b -> a [b] ([b],[b])- partitionA p = listA ( arrL id >>> tagA p )- >>^- ( (\ ~(l1, l2) -> (unTag l1, unTag l2) ) . partition (isLeft) )- where- isLeft (Left _) = True- isLeft _ = False- unTag = map (either id id)+ partitionA :: a b b -> a [b] ([b],[b])+ partitionA p = listA ( arrL id >>> tagA p )+ >>^+ ( (\ ~(l1, l2) -> (unTag l1, unTag l2) ) . partition (isLeft) )+ where+ isLeft (Left _) = True+ isLeft _ = False+ unTag = map (either id id) -- ------------------------------------------------------------ -- | an auxiliary data type for 'choiceA' -data IfThen a b = a :-> b+data IfThen a b = a :-> b -- ------------------------------------------------------------
src/Control/Arrow/ArrowList.hs view
@@ -48,50 +48,50 @@ -- | -- | example: @ a1 &&& a2 >>> arr2 f @ - arr2 :: (b1 -> b2 -> c) -> a (b1, b2) c- arr2 = arr . uncurry+ arr2 :: (b1 -> b2 -> c) -> a (b1, b2) c+ arr2 = arr . uncurry -- | construction of a 3 argument arrow from a 3-ary function -- | -- | example: @ a1 &&& a2 &&& a3 >>> arr3 f @ - arr3 :: (b1 -> b2 -> b3 -> c) -> a (b1, (b2, b3)) c- arr3 f = arr (\ ~(x1, ~(x2, x3)) -> f x1 x2 x3)+ arr3 :: (b1 -> b2 -> b3 -> c) -> a (b1, (b2, b3)) c+ arr3 f = arr (\ ~(x1, ~(x2, x3)) -> f x1 x2 x3) -- | construction of a 4 argument arrow from a 4-ary function -- | -- | example: @ a1 &&& a2 &&& a3 &&& a4 >>> arr4 f @ - arr4 :: (b1 -> b2 -> b3 -> b4 -> c) -> a (b1, (b2, (b3, b4))) c- arr4 f = arr (\ ~(x1, ~(x2, ~(x3, x4))) -> f x1 x2 x3 x4)+ arr4 :: (b1 -> b2 -> b3 -> b4 -> c) -> a (b1, (b2, (b3, b4))) c+ arr4 f = arr (\ ~(x1, ~(x2, ~(x3, x4))) -> f x1 x2 x3 x4) -- | construction of a 2 argument arrow from a singe argument arrow - arr2A :: (b -> a c d) -> a (b, c) d+ arr2A :: (b -> a c d) -> a (b, c) d -- | constructor for a list arrow from a function with a list as result - arrL :: (b -> [c]) -> a b c+ arrL :: (b -> [c]) -> a b c -- | constructor for a list arrow with 2 arguments - arr2L :: (b -> c -> [d]) -> a (b, c) d- arr2L = arrL . uncurry+ arr2L :: (b -> c -> [d]) -> a (b, c) d+ arr2L = arrL . uncurry -- | constructor for a const arrow: @ constA = arr . const @ - constA :: c -> a b c- constA = arr . const+ constA :: c -> a b c+ constA = arr . const -- | constructor for a const arrow: @ constL = arrL . const @ - constL :: [c] -> a b c- constL = arrL . const+ constL :: [c] -> a b c+ constL = arrL . const -- | builds an arrow from a predicate. -- If the predicate holds, the single list containing the input is returned, else the empty list - isA :: (b -> Bool) -> a b b+ isA :: (b -> Bool) -> a b b -- | combinator for converting the result of a list arrow into another list --@@ -99,12 +99,12 @@ -- -- example: @ foo >>. take 1 @ constructs a deterministic version of foo by deleting all further results - (>>.) :: a b c -> ([c] -> [d]) -> a b d+ (>>.) :: a b c -> ([c] -> [d]) -> a b d -- | combinator for converting the result of an arrow into a single element result - (>.) :: a b c -> ([c] -> d ) -> a b d- af >. f = af >>. ((:[]) . f)+ (>.) :: a b c -> ([c] -> d ) -> a b d+ af >. f = af >>. ((:[]) . f) -- | combinator for converting an arrow into a determinstic version with all results collected in a single element list --@@ -118,8 +118,8 @@ -- > -- > collectAndSort collect = listA collect >>> arrL sort - listA :: a b c -> a b [c]- listA af = af >>. (:[])+ listA :: a b c -> a b [c]+ listA af = af >>. (:[]) -- | the inverse of 'listA' --@@ -127,25 +127,25 @@ -- -- unlistA is defined as @ arrL id @ - unlistA :: a [b] b- unlistA = arrL id+ unlistA :: a [b] b+ unlistA = arrL id -- | the identity arrow, alias for returnA - this :: a b b- this = returnA+ this :: a b b+ this = returnA -- | the zero arrow, alias for zeroArrow - none :: a b c- none = zeroArrow+ none :: a b c+ none = zeroArrow -- | converts an arrow, that may fail, into an arrow that always succeeds -- -- example: @ withDefault none \"abc\" @ is equivalent to @ constA \"abc\" @ - withDefault :: a b c -> c -> a b c- withDefault a d = a >>. \ x -> if null x then [d] else x+ withDefault :: a b c -> c -> a b c+ withDefault a d = a >>. \ x -> if null x then [d] else x -- | makes a list arrow deterministic, the number of results is at most 1 --@@ -161,8 +161,8 @@ -- > (constA "y" -- > <+> this ) ) "x" == ["y"] - single :: a b c -> a b c- single f = f >>. take 1+ single :: a b c -> a b c+ single f = f >>. take 1 -- | compute an arrow from the input and apply the arrow to this input --@@ -176,7 +176,7 @@ -- -- see also: '$<', '$<<', '$<<<', '$<<<<', '$<$' - applyA :: a b (a b c) -> a b c+ applyA :: a b (a b c) -> a b c applyA f = (f &&& this) >>> app -- | compute the parameter for an arrow with extra parameters from the input@@ -210,8 +210,8 @@ -- -- see also: 'applyA', '$<<', '$<<<', '$<<<<', '$<$' - ($<) :: (c -> a b d) -> a b c -> a b d- g $< f = applyA (f >>> arr g)+ ($<) :: (c -> a b d) -> a b c -> a b d+ g $< f = applyA (f >>> arr g) -- | binary version of '$<' --@@ -226,8 +226,8 @@ -- > runLA ( infixString $<< constA "y" -- > &&& (constA "z" <+> this) ) "x" = ["yxz", "yxx"] - ($<<) :: (c1 -> c2 -> a b d) -> a b (c1, c2) -> a b d- f $<< g = applyA (g >>> arr2 f)+ ($<<) :: (c1 -> c2 -> a b d) -> a b (c1, c2) -> a b d+ f $<< g = applyA (g >>> arr2 f) -- | version of '$<' for arrows with 3 extra parameters --@@ -235,8 +235,8 @@ -- -- > f $<<< g1 &&& g2 &&& g3 - ($<<<) :: (c1 -> c2 -> c3 -> a b d) -> a b (c1, (c2, c3)) -> a b d- f $<<< g = applyA (g >>> arr3 f)+ ($<<<) :: (c1 -> c2 -> c3 -> a b d) -> a b (c1, (c2, c3)) -> a b d+ f $<<< g = applyA (g >>> arr3 f) -- | version of '$<' for arrows with 4 extra parameters --@@ -244,8 +244,8 @@ -- -- > f $<<<< g1 &&& g2 &&& g3 &&& g4 - ($<<<<) :: (c1 -> c2 -> c3 -> c4 -> a b d) -> a b (c1, (c2, (c3, c4))) -> a b d- f $<<<< g = applyA (g >>> arr4 f)+ ($<<<<) :: (c1 -> c2 -> c3 -> c4 -> a b d) -> a b (c1, (c2, (c3, c4))) -> a b d+ f $<<<< g = applyA (g >>> arr4 f) -- | compute the parameter for an arrow @f@ with an extra parameter by an arrow @g@ -- and apply all the results from @g@ sequentially to the input@@ -293,14 +293,14 @@ -- > g2 :: a b c2 -- > -- > f :: (c1, c2) -> a b b- -- > f (x1, x2) = ... x1 ... x2 ... + -- > f (x1, x2) = ... x1 ... x2 ... -- > -- > f $<$ g1 &&& g2 -- -- see also: 'applyA', '$<' - ($<$) :: (c -> (a b b)) -> a b c -> a b b- g $<$ f = applyA (listA (f >>> arr g) >>> arr seqA)+ ($<$) :: (c -> (a b b)) -> a b c -> a b b+ g $<$ f = applyA (listA (f >>> arr g) >>> arr seqA) -- | merge the result pairs of an arrow with type @a a1 (b1, b2)@ -- by combining the tuple components with the @op@ arrow@@ -309,38 +309,38 @@ -- -- > a1 :: a String (XmlTree, XmlTree) -- > a1 = selem "foo" [this >>> mkText]- -- > &&&- -- > selem "bar" [arr (++"0") >>> mkText]- -- > + -- > &&&+ -- > selem "bar" [arr (++"0") >>> mkText]+ -- > -- > runLA (a1 >>> mergeA (<+>) >>> xshow this) "42" == ["<foo>42</foo>","<bar>420</bar>"] -- > runLA (a1 >>> mergeA (+=) >>> xshow this) "42" == ["<foo>42<bar>420</bar></foo>"] -- -- see also: 'applyA', '$<' and '+=' in class 'Text.XML.HXT.Arrow.ArrowXml' - mergeA :: (a (a1, b1) a1 -> a (a1, b1) b1 -> a (a1, b1) c) ->- a (a1, b1) c- mergeA op = (\ x -> arr fst `op` constA (snd x)) $< this+ mergeA :: (a (a1, b1) a1 -> a (a1, b1) b1 -> a (a1, b1) c) ->+ a (a1, b1) c+ mergeA op = (\ x -> arr fst `op` constA (snd x)) $< this -- | useful only for arrows with side effects: perform applies an arrow to the input -- ignores the result and returns the input -- -- example: @ ... >>> perform someTraceArrow >>> ... @ - perform :: a b c -> a b b- perform f = listA f &&& this >>> arr snd+ perform :: a b c -> a b b+ perform f = listA f &&& this >>> arr snd -- | generalization of arrow combinator '<+>' -- -- definition: @ catA = foldl (\<+\>) none @ - catA :: [a b c] -> a b c- catA = foldl (<+>) none+ catA :: [a b c] -> a b c+ catA = foldl (<+>) none -- | generalization of arrow combinator '>>>' -- -- definition: @ seqA = foldl (>>>) this @ - seqA :: [a b b] -> a b b- seqA = foldl (>>>) this+ seqA :: [a b b] -> a b b+ seqA = foldl (>>>) this -- ------------------------------------------------------------
src/Control/Arrow/ArrowNF.hs view
@@ -28,11 +28,11 @@ -- and validation of a document, all DTD stuff is not longer in use and can be -- recycled by the GC. -strictA :: (Arrow a, NFData b) => a b b-strictA = arr $ \ x -> deepseq x x+strictA :: (Arrow a, NFData b) => a b b+strictA = arr $ \ x -> deepseq x x class (Arrow a) => ArrowNF a where- rnfA :: (NFData c) => a b c -> a b c- rnfA f = f >>> strictA+ rnfA :: (NFData c) => a b c -> a b c+ rnfA f = f >>> strictA -- ------------------------------------------------------------
src/Control/Arrow/ArrowState.hs view
@@ -37,25 +37,25 @@ -- for computing a new state from the old and the arrow input. -- Result is the arrow input - changeState :: (s -> b -> s) -> a b b+ changeState :: (s -> b -> s) -> a b b -- | access the state with a function using the arrow input -- as data for selecting state components. - accessState :: (s -> b -> c) -> a b c+ accessState :: (s -> b -> c) -> a b c -- | read the complete state, ignore arrow input --- -- definition: @ getState = accessState (\\ s x -> s) @ + -- definition: @ getState = accessState (\\ s x -> s) @ - getState :: a b s- getState = accessState (\ s _x -> s)+ getState :: a b s+ getState = accessState (\ s _x -> s) -- | overwrite the old state -- -- definition: @ setState = changeState (\\ s x -> x) @- setState :: a s s- setState = changeState (\ _s x -> x) -- changeState (const id)+ setState :: a s s+ setState = changeState (\ _s x -> x) -- changeState (const id) -- | change state (and ignore input) and return new state --@@ -68,13 +68,13 @@ -- > newId = nextState (+1) -- > >>> -- > arr (('#':) . show)- -- > + -- > -- > runSLA 0 (newId <+> newId <+> newId) undefined -- > = ["#1", "#2", "#3"] - nextState :: (s -> s) -> a b s- nextState sf = changeState (\s -> const (sf s))- >>>- getState+ nextState :: (s -> s) -> a b s+ nextState sf = changeState (\s -> const (sf s))+ >>>+ getState -- ------------------------------------------------------------
src/Control/Arrow/ArrowTree.hs view
@@ -44,45 +44,45 @@ -- | construct a leaf - mkLeaf :: Tree t => b -> a c (t b)- mkLeaf = constA . T.mkLeaf+ mkLeaf :: Tree t => b -> a c (t b)+ mkLeaf = constA . T.mkLeaf -- | construct an inner node - mkTree :: Tree t => b -> [t b] -> a c (t b)- mkTree n = constA . T.mkTree n+ mkTree :: Tree t => b -> [t b] -> a c (t b)+ mkTree n = constA . T.mkTree n -- | select the children of the root of a tree - getChildren :: Tree t => a (t b) (t b)- getChildren = arrL T.getChildren+ getChildren :: Tree t => a (t b) (t b)+ getChildren = arrL T.getChildren -- | select the attribute of the root of a tree - getNode :: Tree t => a (t b) b- getNode = arr T.getNode+ getNode :: Tree t => a (t b) b+ getNode = arr T.getNode -- | substitute the children of the root of a tree - setChildren :: Tree t => [t b] -> a (t b) (t b)- setChildren cs = arr (T.setChildren cs)+ setChildren :: Tree t => [t b] -> a (t b) (t b)+ setChildren cs = arr (T.setChildren cs) -- | substitute the attribute of the root of a tree - setNode :: Tree t => b -> a (t b) (t b)- setNode n = arr (T.setNode n)+ setNode :: Tree t => b -> a (t b) (t b)+ setNode n = arr (T.setNode n) -- | edit the children of the root of a tree - changeChildren :: Tree t => ([t b] -> [t b]) -> a (t b) (t b)- changeChildren csf = arr (T.changeChildren csf)+ changeChildren :: Tree t => ([t b] -> [t b]) -> a (t b) (t b)+ changeChildren csf = arr (T.changeChildren csf) -- | edit the attribute of the root of a tree - changeNode :: Tree t => (b -> b) -> a (t b) (t b)- changeNode nf = arr (T.changeNode nf)+ changeNode :: Tree t => (b -> b) -> a (t b) (t b)+ changeNode nf = arr (T.changeNode nf) - -- compound arrows+ -- compound arrows -- | apply an arrow element wise to all children of the root of a tree -- collect these results and substitute the children with this result@@ -91,12 +91,12 @@ -- -- example: @ processChildren (none \`when\` isCmt) @ removes all children, for which isCmt holds - processChildren :: Tree t => a (t b) (t b) -> a (t b) (t b)- processChildren f = arr T.getNode- &&&- listA (arrL T.getChildren >>> f) -- new children, deterministic filter: single element result- >>>- arr2 T.mkTree+ processChildren :: Tree t => a (t b) (t b) -> a (t b) (t b)+ processChildren f = arr T.getNode+ &&&+ listA (arrL T.getChildren >>> f) -- new children, deterministic filter: single element result+ >>>+ arr2 T.mkTree -- | similar to processChildren, but the new children are computed by processing -- the whole input tree@@ -104,12 +104,12 @@ -- example: @ replaceChildren (deep isText) @ selects all subtrees for which isText holds -- and substitutes the children component of the root node with this list - replaceChildren :: Tree t => a (t b) (t b) -> a (t b) (t b)- replaceChildren f = arr T.getNode- &&&- listA f -- compute new children- >>>- arr2 T.mkTree+ replaceChildren :: Tree t => a (t b) (t b) -> a (t b) (t b)+ replaceChildren f = arr T.getNode+ &&&+ listA f -- compute new children+ >>>+ arr2 T.mkTree -- | -- pronounced \"slash\", meaning g inside f@@ -120,10 +120,10 @@ -- -- This expression selects -- all \"h1\" elements in the \"body\" element of an \"html\" element, an expression, that- -- corresponds 1-1 to the XPath selection path \"html\/body\/h1\" + -- corresponds 1-1 to the XPath selection path \"html\/body\/h1\" - (/>) :: Tree t => a b (t c) -> a (t c) d -> a b d- f /> g = f >>> getChildren >>> g+ (/>) :: Tree t => a b (t c) -> a (t c) d -> a b d+ f /> g = f >>> getChildren >>> g -- | -- pronounced \"double slash\", meaning g arbitrarily deep inside f@@ -138,8 +138,8 @@ -- to the XPath selection path \"html\/\/table\". The latter on matches all table elements -- even nested ones, but @\/\/>@ gives in many cases the appropriate functionality. - (//>) :: Tree t => a b (t c) -> a (t c) d -> a b d- f //> g = f >>> getChildren >>> deep g+ (//>) :: Tree t => a b (t c) -> a (t c) d -> a b d+ f //> g = f >>> getChildren >>> deep g -- |@@ -147,8 +147,8 @@ -- -- defined as @ f \<\/ g = f \`containing\` (getChildren >>> g) @ - (</) :: Tree t => a (t b) (t b) -> a (t b) (t b) -> a (t b) (t b)- f </ g = f `containing` (getChildren >>> g)+ (</) :: Tree t => a (t b) (t b) -> a (t b) (t b) -> a (t b) (t b)+ f </ g = f `containing` (getChildren >>> g) -- | recursively searches a whole tree for subtrees, for which a predicate holds.@@ -159,10 +159,10 @@ -- example: @ deep isHtmlTable @ selects all top level table elements in a document -- (with an appropriate definition for isHtmlTable) but no tables occuring within a table cell. - deep :: Tree t => a (t b) c -> a (t b) c- deep f = f -- success when applying f- `orElse`- (getChildren >>> deep f) -- seach children+ deep :: Tree t => a (t b) c -> a (t b) c+ deep f = f -- success when applying f+ `orElse`+ (getChildren >>> deep f) -- seach children -- | recursively searches a whole tree for subrees, for which a predicate holds.@@ -171,10 +171,10 @@ -- example: @ deepest isHtmlTable @ selects all innermost table elements in a document -- but no table elements containing tables. See 'deep' and 'multi' for other search strategies. - deepest :: Tree t => a (t b) c -> a (t b) c- deepest f = (getChildren >>> deepest f) -- seach children- `orElse`- f -- no success: apply f to root+ deepest :: Tree t => a (t b) c -> a (t b) c+ deepest f = (getChildren >>> deepest f) -- seach children+ `orElse`+ f -- no success: apply f to root -- | recursively searches a whole tree for subtrees, for which a predicate holds.@@ -183,10 +183,10 @@ -- -- example: @ multy isHtmlTable @ selects all table elements, even nested ones. - multi :: Tree t => a (t b) c -> a (t b) c- multi f = f -- combine result for root- <+>- (getChildren >>> multi f) -- with result for all descendants+ multi :: Tree t => a (t b) c -> a (t b) c+ multi f = f -- combine result for root+ <+>+ (getChildren >>> multi f) -- with result for all descendants -- | recursively transforms a whole tree by applying an arrow to all subtrees, -- this is done bottom up depth first, leaves first, root as last tree@@ -194,19 +194,19 @@ -- example: @ processBottomUp (getChildren \`when\` isHtmlFont) @ removes all font tags in a HTML document, even nested ones -- (with an appropriate definition of isHtmlFont) - processBottomUp :: Tree t => a (t b) (t b) -> a (t b) (t b)- processBottomUp f = processChildren (processBottomUp f) -- process all descendants first- >>>- f -- then process root+ processBottomUp :: Tree t => a (t b) (t b) -> a (t b) (t b)+ processBottomUp f = processChildren (processBottomUp f) -- process all descendants first+ >>>+ f -- then process root -- | similar to 'processBottomUp', but recursively transforms a whole tree by applying an arrow to all subtrees -- with a top down depth first traversal strategie. In many cases 'processBottomUp' and 'processTopDown' -- give same results. - processTopDown :: Tree t => a (t b) (t b) -> a (t b) (t b)- processTopDown f = f -- first process root- >>>- processChildren (processTopDown f) -- then process all descendants of new root+ processTopDown :: Tree t => a (t b) (t b) -> a (t b) (t b)+ processTopDown f = f -- first process root+ >>>+ processChildren (processTopDown f) -- then process all descendants of new root -- | recursively transforms a whole tree by applying an arrow to all subtrees,@@ -214,12 +214,12 @@ -- leaves are transformed first processBottomUpWhenNot- :: Tree t => a (t b) (t b) -> a (t b) (t b) -> a (t b) (t b)+ :: Tree t => a (t b) (t b) -> a (t b) (t b) -> a (t b) (t b) processBottomUpWhenNot f p- = ( processChildren (processBottomUpWhenNot f p)- >>>- f- ) `whenNot` p+ = ( processChildren (processBottomUpWhenNot f p)+ >>>+ f+ ) `whenNot` p -- | recursively transforms a whole tree by applying an arrow to all subtrees, -- but transformation stops when a tree is successfully transformed.@@ -228,11 +228,11 @@ -- example: @ processTopDownUntil (isHtmlTable \`guards\` tranformTable) @ -- transforms all top level table elements into something else, but inner tables remain unchanged - processTopDownUntil :: Tree t => a (t b) (t b) -> a (t b) (t b)+ processTopDownUntil :: Tree t => a (t b) (t b) -> a (t b) (t b) processTopDownUntil f- = f- `orElse`- processChildren (processTopDownUntil f)+ = f+ `orElse`+ processChildren (processTopDownUntil f) -- | computes a list of trees by applying an arrow to the input -- and inserts this list in front of index i in the list of children@@ -240,78 +240,78 @@ -- example: @ insertChildrenAt 0 (deep isCmt) @ selects all subtrees for which isCmt holds -- and copies theses in front of the existing children - insertChildrenAt :: Tree t => Int -> a (t b) (t b) -> a (t b) (t b)+ insertChildrenAt :: Tree t => Int -> a (t b) (t b) -> a (t b) (t b) insertChildrenAt i f- = listA f &&& this >>> arr2 insertAt- where- insertAt newcs- = T.changeChildren (\ cs -> let- (cs1, cs2) = splitAt i cs- in- cs1 ++ newcs ++ cs2- )+ = listA f &&& this >>> arr2 insertAt+ where+ insertAt newcs+ = T.changeChildren (\ cs -> let+ (cs1, cs2) = splitAt i cs+ in+ cs1 ++ newcs ++ cs2+ ) -- | similar to 'insertChildrenAt', but the insertion position is searched with a predicate - insertChildrenAfter :: Tree t => a (t b) (t b) -> a (t b) (t b) -> a (t b) (t b)+ insertChildrenAfter :: Tree t => a (t b) (t b) -> a (t b) (t b) -> a (t b) (t b) insertChildrenAfter p f- = replaceChildren- ( ( ( listA getChildren- >>>- spanA p- )- &&&- listA f- )- >>> arr2L (\ (xs1, xs2) xs -> xs1 ++ xs ++ xs2)- )- + = replaceChildren+ ( ( ( listA getChildren+ >>>+ spanA p+ )+ &&&+ listA f+ )+ >>> arr2L (\ (xs1, xs2) xs -> xs1 ++ xs ++ xs2)+ )+ -- | an arrow for inserting a whole subtree with some holes in it (a template) -- into a document. The holes can be filled with contents from the input. -- -- Example --- -- > insertTreeTemplateTest :: ArrowXml a => a b XmlTree+ -- > insertTreeTemplateTest :: ArrowXml a => a b XmlTree -- > insertTreeTemplateTest -- > = doc -- > >>>- -- > insertTemplate template pattern+ -- > insertTreeTemplate template pattern -- > where- -- > doc -- the input data- -- > = constA "<x><y>The Title</y><z>The content</z></x>"- -- > >>> xread- -- > template -- the output template with 2 holes: xxx and yyy- -- > = constA "<html><head><title>xxx</title></head><body><h1>yyy</h1></body></html>"- -- > >>> xread+ -- > doc -- the input data+ -- > = constA "<x><y>The Title</y><z>The content</z></x>"+ -- > >>> xread+ -- > template -- the output template with 2 holes: xxx and yyy+ -- > = constA "<html><head><title>xxx</title></head><body><h1>yyy</h1></body></html>"+ -- > >>> xread -- > pattern- -- > = [ hasText (== "xxx") -- fill the xxx hole with the input contents from element "x/y"- -- > :-> ( getChildren >>> hasName "y" >>> deep isText )- -- > - -- > , hasText (== "yyy") -- fill the yyy hole with the input contents from element "x/z"- -- > :-> ( getChildren >>> hasName "z" >>> getChildren )- -- > ]+ -- > = [ hasText (== "xxx") -- fill the xxx hole with the input contents from element "x/y"+ -- > :-> ( getChildren >>> hasName "y" >>> deep isText )+ -- >+ -- > , hasText (== "yyy") -- fill the yyy hole with the input contents from element "x/z"+ -- > :-> ( getChildren >>> hasName "z" >>> getChildren )+ -- > ] -- -- computes the XML tree for the following document -- -- > "<html><head><title>The Title</title></head><body><h1>The content</h1></body></html>" - insertTreeTemplate :: Tree t =>- a (t b) (t b) -> -- the the template- [IfThen (a (t b) c) (a (t b) (t b))] -> -- the list of nodes in the template to be substituted- a (t b) (t b)+ insertTreeTemplate :: Tree t =>+ a (t b) (t b) -> -- the the template+ [IfThen (a (t b) c) (a (t b) (t b))] -> -- the list of nodes in the template to be substituted+ a (t b) (t b) insertTreeTemplate template choices- = insertTree $< this- where- insertTree t- = template -- swap input and template- >>>- processTemplate- where- processTemplate- = choiceA choices' -- check whether node is a "hole" within the template- `orElse`- processChildren processTemplate -- else descent into template tree- choices'- = map feedTree choices -- modify choices, such that the input is feed into the action arrows- feedTree (cond :-> action)- = cond :-> (constA t >>> action) -- the real input becomes the input at the holes+ = insertTree $< this+ where+ insertTree t+ = template -- swap input and template+ >>>+ processTemplate+ where+ processTemplate+ = choiceA choices' -- check whether node is a "hole" within the template+ `orElse`+ processChildren processTemplate -- else descent into template tree+ choices'+ = map feedTree choices -- modify choices, such that the input is feed into the action arrows+ feedTree (cond :-> action)+ = cond :-> (constA t >>> action) -- the real input becomes the input at the holes
src/Control/Arrow/IOListArrow.hs view
@@ -41,92 +41,92 @@ instance Category IOLA where id = IOLA $ return . (:[]) - IOLA g . IOLA f = IOLA $ \ x -> do- ys <- f x- zs <- sequence . map g $ ys- return (concat zs)+ IOLA g . IOLA f = IOLA $ \ x -> do+ ys <- f x+ zs <- sequence . map g $ ys+ return (concat zs) instance Arrow IOLA where- arr f = IOLA $ \ x -> return [f x]+ arr f = IOLA $ \ x -> return [f x] - first (IOLA f) = IOLA $ \ ~(x1, x2) -> do- ys1 <- f x1- return [ (y1, x2) | y1 <- ys1 ]+ first (IOLA f) = IOLA $ \ ~(x1, x2) -> do+ ys1 <- f x1+ return [ (y1, x2) | y1 <- ys1 ] -- just for efficiency- second (IOLA g) = IOLA $ \ ~(x1, x2) -> do- ys2 <- g x2- return [ (x1, y2) | y2 <- ys2 ]+ second (IOLA g) = IOLA $ \ ~(x1, x2) -> do+ ys2 <- g x2+ return [ (x1, y2) | y2 <- ys2 ] -- just for efficiency- IOLA f *** IOLA g = IOLA $ \ ~(x1, x2) -> do- ys1 <- f x1- ys2 <- g x2- return [ (y1, y2) | y1 <- ys1, y2 <- ys2 ]+ IOLA f *** IOLA g = IOLA $ \ ~(x1, x2) -> do+ ys1 <- f x1+ ys2 <- g x2+ return [ (y1, y2) | y1 <- ys1, y2 <- ys2 ] -- just for efficiency- IOLA f &&& IOLA g = IOLA $ \ x -> do- ys1 <- f x- ys2 <- g x- return [ (y1, y2) | y1 <- ys1, y2 <- ys2 ]+ IOLA f &&& IOLA g = IOLA $ \ x -> do+ ys1 <- f x+ ys2 <- g x+ return [ (y1, y2) | y1 <- ys1, y2 <- ys2 ] instance ArrowZero IOLA where- zeroArrow = IOLA $ const (return [])+ zeroArrow = IOLA $ const (return []) instance ArrowPlus IOLA where- IOLA f <+> IOLA g = IOLA $ \ x -> do- rs1 <- f x- rs2 <- g x- return (rs1 ++ rs2)+ IOLA f <+> IOLA g = IOLA $ \ x -> do+ rs1 <- f x+ rs2 <- g x+ return (rs1 ++ rs2) instance ArrowChoice IOLA where- left (IOLA f) = IOLA $ either- (\ x -> f x >>= (\ y -> return (map Left y)))+ left (IOLA f) = IOLA $ either+ (\ x -> f x >>= (\ y -> return (map Left y))) (return . (:[]) . Right)- right (IOLA f) = IOLA $ either+ right (IOLA f) = IOLA $ either (return . (:[]) . Left)- (\ x -> f x >>= (\ y -> return (map Right y)))+ (\ x -> f x >>= (\ y -> return (map Right y))) instance ArrowApply IOLA where- app = IOLA $ \ (IOLA f, x) -> f x+ app = IOLA $ \ (IOLA f, x) -> f x instance ArrowList IOLA where- arrL f = IOLA $ \ x -> return (f x)- arr2A f = IOLA $ \ ~(x, y) -> runIOLA (f x) y- constA c = IOLA $ const (return [c])- isA p = IOLA $ \x -> return (if p x then [x] else [])- IOLA f >>. g = IOLA $ \x -> do- ys <- f x- return (g ys)+ arrL f = IOLA $ \ x -> return (f x)+ arr2A f = IOLA $ \ ~(x, y) -> runIOLA (f x) y+ constA c = IOLA $ const (return [c])+ isA p = IOLA $ \x -> return (if p x then [x] else [])+ IOLA f >>. g = IOLA $ \x -> do+ ys <- f x+ return (g ys) instance ArrowIf IOLA where- ifA (IOLA p) ta ea = IOLA $ \x -> do- res <- p x- runIOLA (if null res then ea else ta) x+ ifA (IOLA p) ta ea = IOLA $ \x -> do+ res <- p x+ runIOLA (if null res then ea else ta) x (IOLA f) `orElse` g- = IOLA $ \x -> do- res <- f x- if null res then runIOLA g x else return res+ = IOLA $ \x -> do+ res <- f x+ if null res then runIOLA g x else return res instance ArrowIO IOLA where- arrIO cmd = IOLA $ \x -> do- res <- cmd x- return [res]+ arrIO cmd = IOLA $ \x -> do+ res <- cmd x+ return [res] instance ArrowIOIf IOLA where- isIOA p = IOLA $ \x -> do- res <- p x- return (if res then [x] else [])+ isIOA p = IOLA $ \x -> do+ res <- p x+ return (if res then [x] else []) instance ArrowTree IOLA instance ArrowNF IOLA where- rnfA (IOLA f) = IOLA $ \ x -> do- res <- f x- deepseq res $ return res+ rnfA (IOLA f) = IOLA $ \ x -> do+ res <- f x+ deepseq res $ return res -- ------------------------------------------------------------
src/Control/Arrow/IOStateListArrow.hs view
@@ -45,114 +45,114 @@ newtype IOSLA s a b = IOSLA { runIOSLA :: s -> a -> IO (s, [b]) } instance Category (IOSLA s) where- id = IOSLA $ \ s x -> return (s, [x]) -- don't defined id = arr id, this gives loops during optimization+ id = IOSLA $ \ s x -> return (s, [x]) -- don't defined id = arr id, this gives loops during optimization - IOSLA g . IOSLA f = IOSLA $ \ s x -> do- (s1, ys) <- f s x- sequence' s1 ys- where- sequence' s' [] = return (s', [])- sequence' s' (x':xs') = do- (s1', ys') <- g s' x'- (s2', zs') <- sequence' s1' xs'- return (s2', ys' ++ zs')+ IOSLA g . IOSLA f = IOSLA $ \ s x -> do+ (s1, ys) <- f s x+ sequence' s1 ys+ where+ sequence' s' [] = return (s', [])+ sequence' s' (x':xs') = do+ (s1', ys') <- g s' x'+ (s2', zs') <- sequence' s1' xs'+ return (s2', ys' ++ zs') instance Arrow (IOSLA s) where- arr f = IOSLA $ \ s x -> return (s, [f x])+ arr f = IOSLA $ \ s x -> return (s, [f x]) - first (IOSLA f) = IOSLA $ \ s (x1, x2) -> do- (s', ys1) <- f s x1- return (s', [ (y1, x2) | y1 <- ys1 ])+ first (IOSLA f) = IOSLA $ \ s (x1, x2) -> do+ (s', ys1) <- f s x1+ return (s', [ (y1, x2) | y1 <- ys1 ]) -- just for efficiency- second (IOSLA g) = IOSLA $ \ s (x1, x2) -> do- (s', ys2) <- g s x2- return (s', [ (x1, y2) | y2 <- ys2 ])+ second (IOSLA g) = IOSLA $ \ s (x1, x2) -> do+ (s', ys2) <- g s x2+ return (s', [ (x1, y2) | y2 <- ys2 ]) -- just for efficiency- IOSLA f *** IOSLA g = IOSLA $ \ s (x1, x2) -> do- (s1, ys1) <- f s x1- (s2, ys2) <- g s1 x2- return (s2, [ (y1, y2) | y1 <- ys1, y2 <- ys2 ])+ IOSLA f *** IOSLA g = IOSLA $ \ s (x1, x2) -> do+ (s1, ys1) <- f s x1+ (s2, ys2) <- g s1 x2+ return (s2, [ (y1, y2) | y1 <- ys1, y2 <- ys2 ]) -- just for efficiency- IOSLA f &&& IOSLA g = IOSLA $ \ s x -> do- (s1, ys1) <- f s x- (s2, ys2) <- g s1 x- return (s2, [ (y1, y2) | y1 <- ys1, y2 <- ys2 ])+ IOSLA f &&& IOSLA g = IOSLA $ \ s x -> do+ (s1, ys1) <- f s x+ (s2, ys2) <- g s1 x+ return (s2, [ (y1, y2) | y1 <- ys1, y2 <- ys2 ]) instance ArrowZero (IOSLA s) where- zeroArrow = IOSLA $ \ s -> const (return (s, []))+ zeroArrow = IOSLA $ \ s -> const (return (s, [])) instance ArrowPlus (IOSLA s) where- IOSLA f <+> IOSLA g = IOSLA $ \ s x -> do- (s1, rs1) <- f s x- (s2, rs2) <- g s1 x- return (s2, rs1 ++ rs2)+ IOSLA f <+> IOSLA g = IOSLA $ \ s x -> do+ (s1, rs1) <- f s x+ (s2, rs2) <- g s1 x+ return (s2, rs1 ++ rs2) instance ArrowChoice (IOSLA s) where- left (IOSLA f) = IOSLA $ \ s -> either- (\ x -> do- (s1, y) <- f s x- return (s1, map Left y)- )+ left (IOSLA f) = IOSLA $ \ s -> either+ (\ x -> do+ (s1, y) <- f s x+ return (s1, map Left y)+ ) (\ x -> return (s, [Right x])) - right (IOSLA f) = IOSLA $ \ s -> either+ right (IOSLA f) = IOSLA $ \ s -> either (\ x -> return (s, [Left x]))- (\ x -> do- (s1, y) <- f s x- return (s1, map Right y)- )+ (\ x -> do+ (s1, y) <- f s x+ return (s1, map Right y)+ ) instance ArrowApply (IOSLA s) where- app = IOSLA $ \ s (IOSLA f, x) -> f s x+ app = IOSLA $ \ s (IOSLA f, x) -> f s x instance ArrowList (IOSLA s) where- arrL f = IOSLA $ \ s x -> return (s, (f x))- arr2A f = IOSLA $ \ s (x, y) -> runIOSLA (f x) s y- constA c = IOSLA $ \ s -> const (return (s, [c]))- isA p = IOSLA $ \ s x -> return (s, if p x then [x] else [])- IOSLA f >>. g = IOSLA $ \ s x -> do- (s1, ys) <- f s x- return (s1, g ys)+ arrL f = IOSLA $ \ s x -> return (s, (f x))+ arr2A f = IOSLA $ \ s (x, y) -> runIOSLA (f x) s y+ constA c = IOSLA $ \ s -> const (return (s, [c]))+ isA p = IOSLA $ \ s x -> return (s, if p x then [x] else [])+ IOSLA f >>. g = IOSLA $ \ s x -> do+ (s1, ys) <- f s x+ return (s1, g ys) -- just for efficency- perform (IOSLA f) = IOSLA $ \ s x -> do- (s1, _ys) <- f s x- return (s1, [x])+ perform (IOSLA f) = IOSLA $ \ s x -> do+ (s1, _ys) <- f s x+ return (s1, [x]) instance ArrowIf (IOSLA s) where- ifA (IOSLA p) ta ea = IOSLA $ \ s x -> do- (s1, res) <- p s x- runIOSLA ( if null res- then ea- else ta- ) s1 x+ ifA (IOSLA p) ta ea = IOSLA $ \ s x -> do+ (s1, res) <- p s x+ runIOSLA ( if null res+ then ea+ else ta+ ) s1 x (IOSLA f) `orElse` g- = IOSLA $ \ s x -> do- r@(s1, res) <- f s x- if null res- then runIOSLA g s1 x- else return r+ = IOSLA $ \ s x -> do+ r@(s1, res) <- f s x+ if null res+ then runIOSLA g s1 x+ else return r instance ArrowIO (IOSLA s) where- arrIO cmd = IOSLA $ \ s x -> do- res <- cmd x- return (s, [res])+ arrIO cmd = IOSLA $ \ s x -> do+ res <- cmd x+ return (s, [res]) instance ArrowIOIf (IOSLA s) where- isIOA p = IOSLA $ \ s x -> do- res <- p x- return (s, if res then [x] else [])+ isIOA p = IOSLA $ \ s x -> do+ res <- p x+ return (s, if res then [x] else []) instance ArrowState s (IOSLA s) where- changeState cf = IOSLA $ \ s x -> let s' = cf s x in return (seq s' s', [x])- accessState af = IOSLA $ \ s x -> return (s, [af s x])+ changeState cf = IOSLA $ \ s x -> let s' = cf s x in return (seq s' s', [x])+ accessState af = IOSLA $ \ s x -> return (s, [af s x]) -- ------------------------------------------------------------ @@ -162,11 +162,11 @@ -- This is uesful, when running predefined IO arrows, e.g. for document input, -- in a context with a more complex state component. -liftSt :: IOSLA s1 b c -> IOSLA (s1, s2) b c+liftSt :: IOSLA s1 b c -> IOSLA (s1, s2) b c liftSt (IOSLA f) = IOSLA $ \ (s1, s2) x -> do- (s1', ys) <- f s1 x- return ((s1', s2), ys)+ (s1', ys) <- f s1 x+ return ((s1', s2), ys) -- |@@ -176,19 +176,19 @@ -- This is useful, when running an arrow with an extra environment component, e.g. -- for namespace handling in XML. -runSt :: s2 -> IOSLA (s1, s2) b c -> IOSLA s1 b c+runSt :: s2 -> IOSLA (s1, s2) b c -> IOSLA s1 b c runSt s2 (IOSLA f) = IOSLA $ \ s1 x -> do- ((s1', _s2'), ys) <- f (s1, s2) x- return (s1', ys)+ ((s1', _s2'), ys) <- f (s1, s2) x+ return (s1', ys) -- ------------------------------------------------------------ instance ArrowTree (IOSLA s) instance (NFData s) => ArrowNF (IOSLA s) where- rnfA (IOSLA f) = IOSLA $ \ s x -> do- res <- f s x- deepseq res $ return res+ rnfA (IOSLA f) = IOSLA $ \ s x -> do+ res <- f s x+ deepseq res $ return res -- ------------------------------------------------------------
src/Control/Arrow/ListArrow.hs view
@@ -43,67 +43,67 @@ instance Category LA where id = LA $ (:[])- LA g . LA f = LA $ concatMap g . f+ LA g . LA f = LA $ concatMap g . f instance Arrow LA where- arr f = LA $ \ x -> [f x]- first (LA f) = LA $ \ ~(x1, x2) -> [ (y1, x2) | y1 <- f x1 ]+ arr f = LA $ \ x -> [f x]+ first (LA f) = LA $ \ ~(x1, x2) -> [ (y1, x2) | y1 <- f x1 ] -- just for efficiency - second (LA g) = LA $ \ ~(x1, x2) -> [ (x1, y2) | y2 <- g x2 ]- LA f *** LA g = LA $ \ ~(x1, x2) -> [ (y1, y2) | y1 <- f x1, y2 <- g x2]- LA f &&& LA g = LA $ \ x -> [ (y1, y2) | y1 <- f x , y2 <- g x ]+ second (LA g) = LA $ \ ~(x1, x2) -> [ (x1, y2) | y2 <- g x2 ]+ LA f *** LA g = LA $ \ ~(x1, x2) -> [ (y1, y2) | y1 <- f x1, y2 <- g x2]+ LA f &&& LA g = LA $ \ x -> [ (y1, y2) | y1 <- f x , y2 <- g x ] instance ArrowZero LA where- zeroArrow = LA $ const []+ zeroArrow = LA $ const [] instance ArrowPlus LA where- LA f <+> LA g = LA $ \ x -> f x ++ g x+ LA f <+> LA g = LA $ \ x -> f x ++ g x instance ArrowChoice LA where- left (LA f) = LA $ either (map Left . f) ((:[]) . Right)- right (LA f) = LA $ either ((:[]) . Left) (map Right . f)- LA f +++ LA g = LA $ either (map Left . f) (map Right . g)- LA f ||| LA g = LA $ either f g+ left (LA f) = LA $ either (map Left . f) ((:[]) . Right)+ right (LA f) = LA $ either ((:[]) . Left) (map Right . f)+ LA f +++ LA g = LA $ either (map Left . f) (map Right . g)+ LA f ||| LA g = LA $ either f g instance ArrowApply LA where- app = LA $ \ (LA f, x) -> f x+ app = LA $ \ (LA f, x) -> f x instance ArrowList LA where- arrL = LA- arr2A f = LA $ \ ~(x, y) -> runLA (f x) y- isA p = LA $ \ x -> if p x then [x] else []- LA f >>. g = LA $ g . f- withDefault a d = a >>. \ x -> if null x then [d] else x+ arrL = LA+ arr2A f = LA $ \ ~(x, y) -> runLA (f x) y+ isA p = LA $ \ x -> if p x then [x] else []+ LA f >>. g = LA $ g . f+ withDefault a d = a >>. \ x -> if null x then [d] else x instance ArrowIf LA where- ifA (LA p) t e = LA $ \ x -> runLA ( if null (p x)- then e- else t- ) x+ ifA (LA p) t e = LA $ \ x -> runLA ( if null (p x)+ then e+ else t+ ) x (LA f) `orElse` (LA g)- = LA $ \ x -> ( let- res = f x- in- if null res- then g x- else res- )+ = LA $ \ x -> ( let+ res = f x+ in+ if null res+ then g x+ else res+ ) spanA p = LA $ (:[]) . span (not . null . runLA p) - partitionA p = LA $ (:[]) . partition (not . null . runLA p)+ partitionA p = LA $ (:[]) . partition (not . null . runLA p) instance ArrowTree LA instance ArrowNF LA where- rnfA (LA f) = LA $ \ x -> let res = f x+ rnfA (LA f) = LA $ \ x -> let res = f x in deepseq res res @@ -112,8 +112,8 @@ -- | conversion of pure list arrows into other possibly more complex -- list arrows -fromLA :: ArrowList a => LA b c -> a b c-fromLA f = arrL (runLA f)+fromLA :: ArrowList a => LA b c -> a b c+fromLA f = arrL (runLA f) -- ------------------------------------------------------------
src/Control/Arrow/ListArrows.hs view
@@ -16,7 +16,7 @@ -- ------------------------------------------------------------ module Control.Arrow.ListArrows- ( module Control.Arrow -- arrow classes+ ( module Control.Arrow -- arrow classes , module Control.Arrow.ArrowList , module Control.Arrow.ArrowIf , module Control.Arrow.ArrowNF@@ -24,14 +24,14 @@ , module Control.Arrow.ArrowTree , module Control.Arrow.ArrowIO - , module Control.Arrow.ListArrow -- arrow types+ , module Control.Arrow.ListArrow -- arrow types , module Control.Arrow.StateListArrow , module Control.Arrow.IOListArrow , module Control.Arrow.IOStateListArrow ) where -import Control.Arrow -- arrow classes+import Control.Arrow -- arrow classes import Control.Arrow.ArrowList import Control.Arrow.ArrowIf import Control.Arrow.ArrowNF@@ -39,7 +39,7 @@ import Control.Arrow.ArrowTree import Control.Arrow.ArrowIO -import Control.Arrow.ListArrow -- arrow types+import Control.Arrow.ListArrow -- arrow types import Control.Arrow.StateListArrow import Control.Arrow.IOListArrow import Control.Arrow.IOStateListArrow
src/Control/Arrow/StateListArrow.hs view
@@ -45,122 +45,122 @@ instance Category (SLA s) where id = SLA $ \ s x -> (s, [x]) - SLA g . SLA f = SLA $ \ s x -> let- ~(s1, ys) = f s x- sequence' s' []- = (s', [])- sequence' s' (x':xs')- = let- ~(s1', ys') = g s' x'- ~(s2', zs') = sequence' s1' xs'- in- (s2', ys' ++ zs')- in- sequence' s1 ys- + SLA g . SLA f = SLA $ \ s x -> let+ ~(s1, ys) = f s x+ sequence' s' []+ = (s', [])+ sequence' s' (x':xs')+ = let+ ~(s1', ys') = g s' x'+ ~(s2', zs') = sequence' s1' xs'+ in+ (s2', ys' ++ zs')+ in+ sequence' s1 ys+ instance Arrow (SLA s) where- arr f = SLA $ \ s x -> (s, [f x])+ arr f = SLA $ \ s x -> (s, [f x]) - first (SLA f) = SLA $ \ s ~(x1, x2) -> let- ~(s', ys1) = f s x1- in- (s', [ (y1, x2) | y1 <- ys1 ])+ first (SLA f) = SLA $ \ s ~(x1, x2) -> let+ ~(s', ys1) = f s x1+ in+ (s', [ (y1, x2) | y1 <- ys1 ]) -- just for efficiency- second (SLA g) = SLA $ \ s ~(x1, x2) -> let- ~(s', ys2) = g s x2- in- (s', [ (x1, y2) | y2 <- ys2 ])+ second (SLA g) = SLA $ \ s ~(x1, x2) -> let+ ~(s', ys2) = g s x2+ in+ (s', [ (x1, y2) | y2 <- ys2 ]) -- just for efficiency- SLA f *** SLA g = SLA $ \ s ~(x1, x2) -> let- ~(s1, ys1) = f s x1- ~(s2, ys2) = g s1 x2- in- (s2, [ (y1, y2) | y1 <- ys1, y2 <- ys2 ])+ SLA f *** SLA g = SLA $ \ s ~(x1, x2) -> let+ ~(s1, ys1) = f s x1+ ~(s2, ys2) = g s1 x2+ in+ (s2, [ (y1, y2) | y1 <- ys1, y2 <- ys2 ]) -- just for efficiency- SLA f &&& SLA g = SLA $ \ s x -> let- ~(s1, ys1) = f s x- ~(s2, ys2) = g s1 x- in- (s2, [ (y1, y2) | y1 <- ys1, y2 <- ys2 ])+ SLA f &&& SLA g = SLA $ \ s x -> let+ ~(s1, ys1) = f s x+ ~(s2, ys2) = g s1 x+ in+ (s2, [ (y1, y2) | y1 <- ys1, y2 <- ys2 ]) instance ArrowZero (SLA s) where- zeroArrow = SLA $ \ s -> const (s, [])+ zeroArrow = SLA $ \ s -> const (s, []) instance ArrowPlus (SLA s) where- SLA f <+> SLA g = SLA $ \ s x -> let- ~(s1, rs1) = f s x- ~(s2, rs2) = g s1 x- in- (s2, rs1 ++ rs2)+ SLA f <+> SLA g = SLA $ \ s x -> let+ ~(s1, rs1) = f s x+ ~(s2, rs2) = g s1 x+ in+ (s2, rs1 ++ rs2) instance ArrowChoice (SLA s) where- left (SLA f) = SLA $ \ s -> let- lf x = (s1, map Left y)- where- ~(s1, y) = f s x+ left (SLA f) = SLA $ \ s -> let+ lf x = (s1, map Left y)+ where+ ~(s1, y) = f s x rf x = (s, [Right x])- in- either lf rf+ in+ either lf rf - right (SLA f) = SLA $ \ s -> let- lf x = (s, [Left x])- rf x = (s1, map Right y)- where- ~(s1, y) = f s x- in- either lf rf+ right (SLA f) = SLA $ \ s -> let+ lf x = (s, [Left x])+ rf x = (s1, map Right y)+ where+ ~(s1, y) = f s x+ in+ either lf rf instance ArrowApply (SLA s) where- app = SLA $ \ s (SLA f, x) -> f s x+ app = SLA $ \ s (SLA f, x) -> f s x instance ArrowList (SLA s) where- arrL f = SLA $ \ s x -> (s, (f x))- arr2A f = SLA $ \ s ~(x, y) -> runSLA (f x) s y- constA c = SLA $ \ s -> const (s, [c])- isA p = SLA $ \ s x -> (s, if p x then [x] else [])- SLA f >>. g = SLA $ \ s x -> let- ~(s1, ys) = f s x- in- (s1, g ys)+ arrL f = SLA $ \ s x -> (s, (f x))+ arr2A f = SLA $ \ s ~(x, y) -> runSLA (f x) s y+ constA c = SLA $ \ s -> const (s, [c])+ isA p = SLA $ \ s x -> (s, if p x then [x] else [])+ SLA f >>. g = SLA $ \ s x -> let+ ~(s1, ys) = f s x+ in+ (s1, g ys) -- just for efficency- perform (SLA f) = SLA $ \ s x -> let- ~(s1, _ys) = f s x- in- (s1, [x])+ perform (SLA f) = SLA $ \ s x -> let+ ~(s1, _ys) = f s x+ in+ (s1, [x]) instance ArrowIf (SLA s) where- ifA (SLA p) ta ea = SLA $ \ s x -> let- ~(s1, res) = p s x- in- runSLA ( if null res- then ea- else ta- ) s1 x+ ifA (SLA p) ta ea = SLA $ \ s x -> let+ ~(s1, res) = p s x+ in+ runSLA ( if null res+ then ea+ else ta+ ) s1 x (SLA f) `orElse` g- = SLA $ \ s x -> let- r@(s1, res) = f s x- in- if null res- then runSLA g s1 x- else r+ = SLA $ \ s x -> let+ r@(s1, res) = f s x+ in+ if null res+ then runSLA g s1 x+ else r instance ArrowState s (SLA s) where- changeState cf = SLA $ \ s x -> (cf s x, [x])- accessState af = SLA $ \ s x -> (s, [af s x])+ changeState cf = SLA $ \ s x -> (cf s x, [x])+ accessState af = SLA $ \ s x -> (s, [af s x]) instance ArrowTree (SLA s) instance (NFData s) => ArrowNF (SLA s) where- rnfA (SLA f) = SLA $ \ s x -> let res = f s x+ rnfA (SLA f) = SLA $ \ s x -> let res = f s x in deepseq res res @@ -178,8 +178,8 @@ -- runs a state arrow with initial state 0 (e..g. an Int) within -- another arrow sequence -fromSLA :: ArrowList a => s -> SLA s b c -> a b c-fromSLA s f = arrL (snd . (runSLA f s))+fromSLA :: ArrowList a => s -> SLA s b c -> a b c+fromSLA s f = arrL (snd . (runSLA f s)) -- ------------------------------------------------------------
src/Data/AssocList.hs view
@@ -13,48 +13,48 @@ type AssocList k v = [(k, v)] --- lookup = lookup from Prelude+-- lookup = lookup from Prelude -- | lookup with default value -lookupDef :: Eq k => v -> k -> AssocList k v -> v-lookupDef d k = fromMaybe d . lookup k+lookupDef :: Eq k => v -> k -> AssocList k v -> v+lookupDef d k = fromMaybe d . lookup k -- | lookup with empty list (empty string) as default value -lookup1 :: Eq k => k -> AssocList k [e] -> [e]-lookup1 k = fromMaybe [] . lookup k+lookup1 :: Eq k => k -> AssocList k [e] -> [e]+lookup1 k = fromMaybe [] . lookup k -- | test for existence of a key -hasEntry :: Eq k => k -> AssocList k v -> Bool-hasEntry k = isJust . lookup k+hasEntry :: Eq k => k -> AssocList k v -> Bool+hasEntry k = isJust . lookup k -- | add an entry, remove an existing entry before adding the new one at the top of the list, addEntry is strict -addEntry :: Eq k => k -> v -> AssocList k v -> AssocList k v-addEntry k v l = ( (k,v) : ) $! delEntry k l+addEntry :: Eq k => k -> v -> AssocList k v -> AssocList k v+addEntry k v l = ( (k,v) : ) $! delEntry k l -- let l' = delEntry k l in seq l' ((k, v) : l') -- | add a whole list of entries with 'addEntry' -addEntries :: Eq k => AssocList k v -> AssocList k v -> AssocList k v-addEntries = foldr (.) id . map (uncurry addEntry) . reverse+addEntries :: Eq k => AssocList k v -> AssocList k v -> AssocList k v+addEntries = foldr (.) id . map (uncurry addEntry) . reverse -- | delete an entry, delEntry is strict-delEntry :: Eq k => k -> AssocList k v -> AssocList k v-delEntry _ [] = []+delEntry :: Eq k => k -> AssocList k v -> AssocList k v+delEntry _ [] = [] delEntry k (x@(k1,_) : rest)- | k == k1 = rest- | otherwise = ( x : ) $! delEntry k rest+ | k == k1 = rest+ | otherwise = ( x : ) $! delEntry k rest --- delEntry k = filter ((/= k) . fst)+-- delEntry k = filter ((/= k) . fst) -- | delete a list of entries with 'delEntry' -delEntries :: Eq k => [k] -> AssocList k v -> AssocList k v-delEntries = foldl (.) id . map delEntry+delEntries :: Eq k => [k] -> AssocList k v -> AssocList k v+delEntries = foldl (.) id . map delEntry -- -----------------------------------------------------------------------------
src/Data/Atom.hs view
@@ -54,9 +54,9 @@ module Data.Atom ( -- * Atom objects- Atom, -- instance (Eq, Ord, Read, Show)- newAtom, -- :: String -> Atom- share -- :: String -> String+ Atom, -- instance (Eq, Ord, Read, Show)+ newAtom, -- :: String -> Atom+ share -- :: String -> String ) where import Control.Concurrent.MVar@@ -64,75 +64,75 @@ import Data.ByteString.Internal ( toForeignPtr, c2w, w2c ) import Data.ByteString ( ByteString, pack, unpack )-import qualified Data.Map as M+import qualified Data.Map as M import Data.Typeable import System.IO.Unsafe ( unsafePerformIO ) -import Text.XML.HXT.DOM.Unicode ( unicodeToUtf8 )-import Text.XML.HXT.DOM.UTF8Decoding ( decodeUtf8 )+import Text.XML.HXT.DOM.Unicode ( unicodeToUtf8 )+import Text.XML.HXT.DOM.UTF8Decoding ( decodeUtf8 ) -- ------------------------------------------------------------ -type Atoms = M.Map ByteString ByteString+type Atoms = M.Map ByteString ByteString -newtype Atom = A { bs :: ByteString }+newtype Atom = A { bs :: ByteString } deriving (Typeable) -- ------------------------------------------------------------ -- | the internal cache for the strings -theAtoms :: MVar Atoms-theAtoms = unsafePerformIO (newMVar M.empty)+theAtoms :: MVar Atoms+theAtoms = unsafePerformIO (newMVar M.empty) {-# NOINLINE theAtoms #-} -- | insert a bytestring into the atom cache -insertAtom :: ByteString -> Atoms -> (Atoms, Atom)-insertAtom s m = maybe (M.insert s s m, A s)+insertAtom :: ByteString -> Atoms -> (Atoms, Atom)+insertAtom s m = maybe (M.insert s s m, A s) (\ s' -> (m, A s'))- .- M.lookup s $ m+ .+ M.lookup s $ m -- | creation of an @Atom@ from a @String@ -newAtom :: String -> Atom-newAtom = unsafePerformIO . newAtom'+newAtom :: String -> Atom+newAtom = unsafePerformIO . newAtom' {-# NOINLINE newAtom #-} -- | The internal operation running in the IO monad-newAtom' :: String -> IO Atom-newAtom' s = do- m <- takeMVar theAtoms- let (m', a) = insertAtom (pack. map c2w . unicodeToUtf8 $ s) m- putMVar theAtoms m'- return a+newAtom' :: String -> IO Atom+newAtom' s = do+ m <- takeMVar theAtoms+ let (m', a) = insertAtom (pack. map c2w . unicodeToUtf8 $ s) m+ putMVar theAtoms m'+ return a -- | Insert a @String@ into the atom cache and convert the atom back into a @String@. -- -- locically @share == id@ holds, but internally equal strings share the same memory. -share :: String -> String-share = show . newAtom+share :: String -> String+share = show . newAtom instance Eq Atom where- a1 == a2 = fp1 == fp2- where- (fp1, _, _) = toForeignPtr . bs $ a1- (fp2, _, _) = toForeignPtr . bs $ a2+ a1 == a2 = fp1 == fp2+ where+ (fp1, _, _) = toForeignPtr . bs $ a1+ (fp2, _, _) = toForeignPtr . bs $ a2 instance Ord Atom where compare a1 a2- | a1 == a2 = EQ- | otherwise = compare (bs a1) (bs a2)+ | a1 == a2 = EQ+ | otherwise = compare (bs a1) (bs a2) instance Read Atom where readsPrec p str = [ (newAtom x, y) | (x, y) <- readsPrec p str ] instance Show Atom where- show = fst . decodeUtf8 . map w2c . unpack . bs- -- show = show . toForeignPtr . bs -- for debug only+ show = fst . decodeUtf8 . map w2c . unpack . bs+ -- show = show . toForeignPtr . bs -- for debug only instance NFData Atom where
src/Data/Tree/Class.hs view
@@ -22,71 +22,71 @@ class Tree t where -- | tree construction: a new tree is constructed by a node attribute and a list of children- mkTree :: a -> [t a] -> t a+ mkTree :: a -> [t a] -> t a -- | leaf construction: leafs don't have any children -- -- definition: @ mkLeaf n = mkTree n [] @ - mkLeaf :: a -> t a- mkLeaf n = mkTree n []+ mkLeaf :: a -> t a+ mkLeaf n = mkTree n [] -- | leaf test: list of children empty? - isLeaf :: t a -> Bool- isLeaf = null . getChildren+ isLeaf :: t a -> Bool+ isLeaf = null . getChildren -- | innner node test: @ not . isLeaf @ - isInner :: t a -> Bool- isInner = not . isLeaf+ isInner :: t a -> Bool+ isInner = not . isLeaf -- | select node attribute - getNode :: t a -> a+ getNode :: t a -> a -- | select children - getChildren :: t a -> [t a]+ getChildren :: t a -> [t a] -- | edit node attribute - changeNode :: (a -> a) -> t a -> t a+ changeNode :: (a -> a) -> t a -> t a -- | edit children - changeChildren :: ([t a] -> [t a]) -> t a -> t a+ changeChildren :: ([t a] -> [t a]) -> t a -> t a -- | substitute node: @ setNode n = changeNode (const n) @ - setNode :: a -> t a -> t a- setNode n = changeNode (const n)+ setNode :: a -> t a -> t a+ setNode n = changeNode (const n) -- | substitute children: @ setChildren cl = changeChildren (const cl) @ - setChildren :: [t a] -> t a -> t a- setChildren cl = changeChildren (const cl)+ setChildren :: [t a] -> t a -> t a+ setChildren cl = changeChildren (const cl) -- | fold for trees - foldTree :: (a -> [b] -> b) -> t a -> b+ foldTree :: (a -> [b] -> b) -> t a -> b -- | all nodes of a tree - nodesTree :: t a -> [a]+ nodesTree :: t a -> [a] -- | depth of a tree - depthTree :: t a -> Int+ depthTree :: t a -> Int -- | number of nodes in a tree - cardTree :: t a -> Int+ cardTree :: t a -> Int -- | format tree for readable trace output -- -- a /graphical/ representation of the tree in text format - formatTree :: (a -> String) -> t a -> String+ formatTree :: (a -> String) -> t a -> String -- ------------------------------------------------------------
src/Data/Tree/NTree/TypeDefs.hs view
@@ -38,76 +38,76 @@ -- -- NTree implements Eq, Ord, Show and Read -data NTree a = NTree a (NTrees a)+data NTree a = NTree a (NTrees a) deriving (Eq, Ord, Show, Read, Typeable) -- | shortcut for a sequence of n-ary trees -type NTrees a = [NTree a]+type NTrees a = [NTree a] -- ------------------------------------------------------------ instance (NFData a) => NFData (NTree a) where- rnf (NTree n cl) = rnf n `seq` rnf cl+ rnf (NTree n cl) = rnf n `seq` rnf cl -- | NTree implements class Functor instance Functor NTree where- fmap f ~(NTree n cl) = NTree (f n) (map (fmap f) cl)+ fmap f ~(NTree n cl) = NTree (f n) (map (fmap f) cl) -- | Implementation of "Data.Tree.Class" interface for rose trees instance Tree NTree where- mkTree n cl = NTree n cl+ mkTree n cl = NTree n cl - getNode ~(NTree n _ ) = n- getChildren ~(NTree _ cl) = cl+ getNode ~(NTree n _ ) = n+ getChildren ~(NTree _ cl) = cl - changeNode cf ~(NTree n cl) = NTree (cf n) cl- changeChildren cf ~(NTree n cl) = NTree n (cf cl)+ changeNode cf ~(NTree n cl) = NTree (cf n) cl+ changeChildren cf ~(NTree n cl) = NTree n (cf cl) - foldTree f ~(NTree n cs) = f n (map (foldTree f) cs)+ foldTree f ~(NTree n cs) = f n (map (foldTree f) cs) - nodesTree = foldTree (\ n rs -> n : concat rs)- depthTree = foldTree (\ _ rs -> 1 + maximum (0 : rs))- cardTree = foldTree (\ _ rs -> 1 + sum rs)- formatTree nf n = formatNTreeF nf (showString "---") (showString " ") n ""+ nodesTree = foldTree (\ n rs -> n : concat rs)+ depthTree = foldTree (\ _ rs -> 1 + maximum (0 : rs))+ cardTree = foldTree (\ _ rs -> 1 + sum rs)+ formatTree nf n = formatNTreeF nf (showString "---") (showString " ") n "" -- ------------------------------------------------------------ -- | -- convert a tree into a pseudo graphical string reprsentation -formatNTreeF :: (node -> String) -> (String -> String) -> (String -> String) -> NTree node -> String -> String+formatNTreeF :: (node -> String) -> (String -> String) -> (String -> String) -> NTree node -> String -> String formatNTreeF node2String pf1 pf2 (NTree n l) = formatNode . formatChildren pf2 l where- formatNode = pf1 . foldr (.) id (map trNL (node2String n)) . showNL- trNL '\n' = showNL . pf2- trNL c = showChar c- showNL = showChar '\n'+ formatNode = pf1 . foldr (.) id (map trNL (node2String n)) . showNL+ trNL '\n' = showNL . pf2+ trNL c = showChar c+ showNL = showChar '\n' formatChildren _ []- = id+ = id formatChildren pf (t:ts)- | null ts- = pfl'- . formatTr pf2' t- | otherwise- = pfl'- . formatTr pf1' t- . formatChildren pf ts- where- pf0' = pf . showString indent1- pf1' = pf . showString indent2- pf2' = pf . showString indent3- pfl' = pf . showString indent4- formatTr = formatNTreeF node2String pf0'- indent1 = "+---"- indent2 = "| "- indent3 = " "- indent4 = "|\n"+ | null ts+ = pfl'+ . formatTr pf2' t+ | otherwise+ = pfl'+ . formatTr pf1' t+ . formatChildren pf ts+ where+ pf0' = pf . showString indent1+ pf1' = pf . showString indent2+ pf2' = pf . showString indent3+ pfl' = pf . showString indent4+ formatTr = formatNTreeF node2String pf0'+ indent1 = "+---"+ indent2 = "| "+ indent3 = " "+ indent4 = "|\n" -- eof ------------------------------------------------------------
src/Text/XML/HXT/Arrow.hs view
@@ -41,9 +41,9 @@ ) where -import Control.Arrow.ListArrows -- arrow classes+import Control.Arrow.ListArrows -- arrow classes -import Data.Atom () -- import this explicitly+import Data.Atom () -- import this explicitly import Text.XML.HXT.DOM.Interface import Text.XML.HXT.Arrow.DocumentInput@@ -57,7 +57,7 @@ import Text.XML.HXT.Arrow.WriteDocument import Text.XML.HXT.Arrow.XmlArrow import Text.XML.HXT.Arrow.XmlIOStateArrow-import Text.XML.HXT.Arrow.XmlRegex () -- import this explicitly+import Text.XML.HXT.Arrow.XmlRegex () -- import this explicitly import Text.XML.HXT.Version
src/Text/XML/HXT/Arrow/DTDProcessing.hs view
@@ -25,7 +25,7 @@ ) where -import Control.Arrow -- arrow classes+import Control.Arrow -- arrow classes import Control.Arrow.ArrowList import Control.Arrow.ArrowIf import Control.Arrow.ArrowTree@@ -63,36 +63,36 @@ -- ------------------------------------------------------------ -- -data DTDPart = Internal- | External- deriving (Eq)+data DTDPart = Internal+ | External+ deriving (Eq) -type RecList = [String]+type RecList = [String] -type DTDStateArrow b c = IOStateArrow PEEnv b c+type DTDStateArrow b c = IOStateArrow PEEnv b c -- ------------------------------------------------------------ -newtype PEEnv = PEEnv (M.Map String XmlTree)+newtype PEEnv = PEEnv (M.Map String XmlTree) -emptyPeEnv :: PEEnv-emptyPeEnv = PEEnv M.empty+emptyPeEnv :: PEEnv+emptyPeEnv = PEEnv M.empty -lookupPeEnv :: String -> PEEnv -> Maybe XmlTree+lookupPeEnv :: String -> PEEnv -> Maybe XmlTree lookupPeEnv k (PEEnv env) = M.lookup k env -addPeEntry :: String -> XmlTree -> PEEnv -> PEEnv+addPeEntry :: String -> XmlTree -> PEEnv -> PEEnv addPeEntry k a (PEEnv env) = PEEnv $ M.insert k a env -getPeValue :: DTDStateArrow String XmlTree+getPeValue :: DTDStateArrow String XmlTree getPeValue = (this &&& getUserState) >>> arrL (\ (n, env) -> maybeToList . lookupPeEnv n $ env) -addPe :: String -> DTDStateArrow XmlTree XmlTree+addPe :: String -> DTDStateArrow XmlTree XmlTree addPe n = traceMsg 2 ("substParamEntity: add entity " ++ show n ++ " to env") >>>@@ -111,402 +111,402 @@ -- -- input tree must represent a complete document including root node -processDTD :: IOStateArrow s XmlTree XmlTree+processDTD :: IOStateArrow s XmlTree XmlTree processDTD = runInLocalURIContext ( processRoot- >>>- traceTree- >>>- traceSource- )+ >>>+ traceTree+ >>>+ traceSource+ ) `when` ( isRoot >>> getChildren ) where - processRoot :: IOStateArrow s XmlTree XmlTree+ processRoot :: IOStateArrow s XmlTree XmlTree processRoot- = ( traceMsg 1 ("processDTD: process parameter entities")- >>>- setParamString a_standalone ""- >>>- ( addDocType- `whenNot`- ( getChildren >>> isDTDDoctype )- )- >>>- processChildren substParamEntities- >>>- setDocumentStatusFromSystemState "in XML DTD processing"- )+ = ( traceMsg 1 ("processDTD: process parameter entities")+ >>>+ setParamString a_standalone ""+ >>>+ ( addDocType+ `whenNot`+ ( getChildren >>> isDTDDoctype )+ )+ >>>+ processChildren substParamEntities+ >>>+ setDocumentStatusFromSystemState "in XML DTD processing"+ ) `when`- documentStatusOk- where- addDocType- = replaceChildren ( (getChildren >>> isXmlPi)- <+>- mkDTDDoctype [] none- <+>- (getChildren >>> neg isXmlPi)- )+ documentStatusOk+ where+ addDocType+ = replaceChildren ( (getChildren >>> isXmlPi)+ <+>+ mkDTDDoctype [] none+ <+>+ (getChildren >>> neg isXmlPi)+ ) -substParamEntities :: IOStateArrow s XmlTree XmlTree+substParamEntities :: IOStateArrow s XmlTree XmlTree substParamEntities = withOtherUserState emptyPeEnv processParamEntities `when` isDTDDoctype where - processParamEntities :: DTDStateArrow XmlTree XmlTree+ processParamEntities :: DTDStateArrow XmlTree XmlTree processParamEntities- = mergeEntities $<<< ( listA processPredef- &&&- listA processInt- &&&- listA (runInLocalURIContext processExt)- )- where- mergeEntities dtdPre dtdInt dtdExt- = replaceChildren (arrL $ const $ foldl1 mergeDTDs [dtdPre, dtdInt, dtdExt])+ = mergeEntities $<<< ( listA processPredef+ &&&+ listA processInt+ &&&+ listA (runInLocalURIContext processExt)+ )+ where+ mergeEntities dtdPre dtdInt dtdExt+ = replaceChildren (arrL $ const $ foldl1 mergeDTDs [dtdPre, dtdInt, dtdExt]) - processPredef- = predefDTDPart >>> substParamEntity Internal []+ processPredef+ = predefDTDPart >>> substParamEntity Internal [] - processInt- = getChildren >>> substParamEntity Internal []+ processInt+ = getChildren >>> substParamEntity Internal [] - processExt- = externalDTDPart >>> substParamEntity External []+ processExt+ = externalDTDPart >>> substParamEntity External [] - mergeDTDs :: XmlTrees -> XmlTrees -> XmlTrees- mergeDTDs dtdInt dtdExt- = dtdInt ++ (filter (filterDTDNodes dtdInt) dtdExt)+ mergeDTDs :: XmlTrees -> XmlTrees -> XmlTrees+ mergeDTDs dtdInt dtdExt+ = dtdInt ++ (filter (filterDTDNodes dtdInt) dtdExt) - filterDTDNodes :: XmlTrees -> XmlTree -> Bool- filterDTDNodes dtdPart t- = not (any (filterDTDNode t) dtdPart)+ filterDTDNodes :: XmlTrees -> XmlTree -> Bool+ filterDTDNodes dtdPart t+ = not (any (filterDTDNode t) dtdPart) - filterDTDNode :: XmlTree -> XmlTree -> Bool+ filterDTDNode :: XmlTree -> XmlTree -> Bool - filterDTDNode t1 t2- = fromMaybe False $- do- dp1 <- XN.getDTDPart t1- dp2 <- XN.getDTDPart t2- al1 <- XN.getDTDAttrl t1- al2 <- XN.getDTDAttrl t2- return ( dp1 == dp2- &&- ( dp1 `elem` [ELEMENT, NOTATION, ENTITY, ATTLIST] )- &&- ( lookup a_name al1 == lookup a_name al2 )- &&- ( dp1 /= ATTLIST- ||- lookup a_value al1 == lookup a_value al2- )- )+ filterDTDNode t1 t2+ = fromMaybe False $+ do+ dp1 <- XN.getDTDPart t1+ dp2 <- XN.getDTDPart t2+ al1 <- XN.getDTDAttrl t1+ al2 <- XN.getDTDAttrl t2+ return ( dp1 == dp2+ &&+ ( dp1 `elem` [ELEMENT, NOTATION, ENTITY, ATTLIST] )+ &&+ ( lookup a_name al1 == lookup a_name al2 )+ &&+ ( dp1 /= ATTLIST+ ||+ lookup a_value al1 == lookup a_value al2+ )+ ) -substParamEntity :: DTDPart -> RecList -> DTDStateArrow XmlTree XmlTree+substParamEntity :: DTDPart -> RecList -> DTDStateArrow XmlTree XmlTree substParamEntity loc recList = choiceA- [ isDTDEntity :-> ( traceDTD "ENTITY declaration before DTD declaration parsing"- >>>- processChildren (substPeRefsInDTDdecl recList)- >>>- parseXmlDTDdecl- >>>- substRefsInEntityValue- >>>- processEntityDecl- >>>- traceDTD "ENTITY declaration after DTD declaration parsing"- )+ [ isDTDEntity :-> ( traceDTD "ENTITY declaration before DTD declaration parsing"+ >>>+ processChildren (substPeRefsInDTDdecl recList)+ >>>+ parseXmlDTDdecl+ >>>+ substRefsInEntityValue+ >>>+ processEntityDecl+ >>>+ traceDTD "ENTITY declaration after DTD declaration parsing"+ ) , ( isDTDElement- <+>- isDTDAttlist- <+>- isDTDNotation- ) :-> ( traceDTD "DTD declaration before PE substitution"- >>>- processChildren (substPeRefsInDTDdecl recList)- >>>- parseXmlDTDdecl- >>>- traceDTD "DTD declaration after DTD declaration parsing"- )- , isDTDPERef :-> substPeRefsInDTDpart recList+ <+>+ isDTDAttlist+ <+>+ isDTDNotation+ ) :-> ( traceDTD "DTD declaration before PE substitution"+ >>>+ processChildren (substPeRefsInDTDdecl recList)+ >>>+ parseXmlDTDdecl+ >>>+ traceDTD "DTD declaration after DTD declaration parsing"+ )+ , isDTDPERef :-> substPeRefsInDTDpart recList - , isDTDCondSect :-> ( if loc == Internal- then issueErr "conditional sections in internal part of the DTD is not allowed"- else evalCondSect $< getDTDAttrValue a_value- )- , isCmt :-> none- , this :-> this+ , isDTDCondSect :-> ( if loc == Internal+ then issueErr "conditional sections in internal part of the DTD is not allowed"+ else evalCondSect $< getDTDAttrValue a_value+ )+ , isCmt :-> none+ , this :-> this ] where- processEntityDecl :: DTDStateArrow XmlTree XmlTree+ processEntityDecl :: DTDStateArrow XmlTree XmlTree processEntityDecl- = choiceA- [ isDTDEntity :-> ( ifA (hasDTDAttr k_system)- processExternalEntity- processInternalEntity- )- , isDTDPEntity- :-> ( processParamEntity $< getDTDAttrValue a_name )- , this :-> none- ]- where- processExternalEntity :: DTDStateArrow XmlTree XmlTree -- processing external entities is delayed until first usage- processExternalEntity -- only the current base uri must be remembered- = setDTDAttrValue a_url $< ( getDTDAttrValue k_system >>> mkAbsURI )+ = choiceA+ [ isDTDEntity :-> ( ifA (hasDTDAttr k_system)+ processExternalEntity+ processInternalEntity+ )+ , isDTDPEntity+ :-> ( processParamEntity $< getDTDAttrValue a_name )+ , this :-> none+ ]+ where+ processExternalEntity :: DTDStateArrow XmlTree XmlTree -- processing external entities is delayed until first usage+ processExternalEntity -- only the current base uri must be remembered+ = setDTDAttrValue a_url $< ( getDTDAttrValue k_system >>> mkAbsURI ) - processInternalEntity :: DTDStateArrow XmlTree XmlTree -- just combine all parts of the entity value- processInternalEntity -- into one string- = replaceChildren (xshow getChildren >>> mkText)+ processInternalEntity :: DTDStateArrow XmlTree XmlTree -- just combine all parts of the entity value+ processInternalEntity -- into one string+ = replaceChildren (xshow getChildren >>> mkText) - processParamEntity :: String -> DTDStateArrow XmlTree XmlTree- processParamEntity peName- = ifA (constA peName >>> getPeValue)- ( issueWarn ("parameter entity " ++ show peName ++ " already defined") )- ( ( ifA ( hasDTDAttr k_system ) -- is external param entity ?- ( runInLocalURIContext getExternalParamEntityValue )- ( replaceChildren (xshow getChildren >>> mkText) ) -- just combine all parts of the entity value into one string- )+ processParamEntity :: String -> DTDStateArrow XmlTree XmlTree+ processParamEntity peName+ = ifA (constA peName >>> getPeValue)+ ( issueWarn ("parameter entity " ++ show peName ++ " already defined") )+ ( ( ifA ( hasDTDAttr k_system ) -- is external param entity ?+ ( runInLocalURIContext getExternalParamEntityValue )+ ( replaceChildren (xshow getChildren >>> mkText) ) -- just combine all parts of the entity value into one string+ ) >>> addPe peName- )+ ) - substPERef :: String -> DTDStateArrow XmlTree XmlTree+ substPERef :: String -> DTDStateArrow XmlTree XmlTree substPERef pn- = choiceA- [ isInternalRef :-> issueErr ("a parameter entity reference of " ++ show pn ++ " occurs in the internal subset of the DTD")- , isUndefinedRef :-> issueErr ("parameter entity " ++ show pn ++ " not found (forward reference?)")- , this :-> substPE- ]- `when`- isDTDPERef- where- isInternalRef = isA (const (loc == Internal))- peVal = constA pn >>> getPeValue- isUndefinedRef = neg peVal- substPE- = replaceChildren (peVal >>> getChildren) -- store PE value in children component- >>>- ( ( setBase $< (peVal >>> getDTDAttrValue a_url) ) -- store base uri for external refs- `orElse`- this- )- where- setBase uri = setDTDAttrValue a_url uri+ = choiceA+ [ isInternalRef :-> issueErr ("a parameter entity reference of " ++ show pn ++ " occurs in the internal subset of the DTD")+ , isUndefinedRef :-> issueErr ("parameter entity " ++ show pn ++ " not found (forward reference?)")+ , this :-> substPE+ ]+ `when`+ isDTDPERef+ where+ isInternalRef = isA (const (loc == Internal))+ peVal = constA pn >>> getPeValue+ isUndefinedRef = neg peVal+ substPE+ = replaceChildren (peVal >>> getChildren) -- store PE value in children component+ >>>+ ( ( setBase $< (peVal >>> getDTDAttrValue a_url) ) -- store base uri for external refs+ `orElse`+ this+ )+ where+ setBase uri = setDTDAttrValue a_url uri - substRefsInEntityValue :: DTDStateArrow XmlTree XmlTree+ substRefsInEntityValue :: DTDStateArrow XmlTree XmlTree substRefsInEntityValue- = ( ( processChildren ( transfCharRef- >>>- substPeRefsInValue []- )- )- `whenNot`- hasDTDAttr k_system -- only apply for internal entities- )- `when` - ( isDTDEntity <+> isDTDPEntity ) -- only apply for entity declarations+ = ( ( processChildren ( transfCharRef+ >>>+ substPeRefsInValue []+ )+ )+ `whenNot`+ hasDTDAttr k_system -- only apply for internal entities+ )+ `when`+ ( isDTDEntity <+> isDTDPEntity ) -- only apply for entity declarations - substPeRefsInDTDpart :: RecList -> DTDStateArrow XmlTree XmlTree+ substPeRefsInDTDpart :: RecList -> DTDStateArrow XmlTree XmlTree substPeRefsInDTDpart rl- = recursionCheck "DTD part" rl subst- where- subst :: RecList -> String -> DTDStateArrow XmlTree XmlTree- subst recl pn- = substPERef pn- >>>- traceDTD "substPeRefsInDTDdecl: before parseXmlDTDPart"- >>>- ( runInPeContext ( getChildren- >>>- ( (constA ("parameter entity: " ++ pn)) &&& this )- >>>- parseXmlDTDPart- >>>- traceDTD "substPeRefsInDTDpart: after parseXmlDTDPart"- >>>- substParamEntity loc (pn : recl)- )- `when`- isDTDPERef- )+ = recursionCheck "DTD part" rl subst+ where+ subst :: RecList -> String -> DTDStateArrow XmlTree XmlTree+ subst recl pn+ = substPERef pn+ >>>+ traceDTD "substPeRefsInDTDdecl: before parseXmlDTDPart"+ >>>+ ( runInPeContext ( getChildren+ >>>+ ( (constA ("parameter entity: " ++ pn)) &&& this )+ >>>+ parseXmlDTDPart+ >>>+ traceDTD "substPeRefsInDTDpart: after parseXmlDTDPart"+ >>>+ substParamEntity loc (pn : recl)+ )+ `when`+ isDTDPERef+ ) - substPeRefsInDTDdecl :: RecList -> DTDStateArrow XmlTree XmlTree+ substPeRefsInDTDdecl :: RecList -> DTDStateArrow XmlTree XmlTree substPeRefsInDTDdecl rl- = recursionCheck "DTD declaration" rl subst- where- subst :: RecList -> String -> DTDStateArrow XmlTree XmlTree- subst recl pn- = substPERef pn- >>>- traceDTD "substPeRefsInDTDdecl: before parseXmlDTDdeclPart"- >>>- ( runInPeContext ( parseXmlDTDdeclPart- >>>- traceDTD "substPeRefsInDTDdecl: after parseXmlDTDdeclPart"- >>>- processChildren ( substPeRefsInDTDdecl (pn : recl) )- )- `when`- isDTDPERef- )+ = recursionCheck "DTD declaration" rl subst+ where+ subst :: RecList -> String -> DTDStateArrow XmlTree XmlTree+ subst recl pn+ = substPERef pn+ >>>+ traceDTD "substPeRefsInDTDdecl: before parseXmlDTDdeclPart"+ >>>+ ( runInPeContext ( parseXmlDTDdeclPart+ >>>+ traceDTD "substPeRefsInDTDdecl: after parseXmlDTDdeclPart"+ >>>+ processChildren ( substPeRefsInDTDdecl (pn : recl) )+ )+ `when`+ isDTDPERef+ ) - substPeRefsInValue :: RecList -> DTDStateArrow XmlTree XmlTree+ substPeRefsInValue :: RecList -> DTDStateArrow XmlTree XmlTree substPeRefsInValue rl- = recursionCheck "entity value" rl subst- where- subst :: RecList -> String -> DTDStateArrow XmlTree XmlTree- subst recl pn- = substPERef pn- >>>- parseXmlDTDEntityValue- >>>- transfCharRef- >>>- substPeRefsInValue (pn : recl)+ = recursionCheck "entity value" rl subst+ where+ subst :: RecList -> String -> DTDStateArrow XmlTree XmlTree+ subst recl pn+ = substPERef pn+ >>>+ parseXmlDTDEntityValue+ >>>+ transfCharRef+ >>>+ substPeRefsInValue (pn : recl) - substPeRefsInCondSect :: RecList -> DTDStateArrow XmlTree XmlTree+ substPeRefsInCondSect :: RecList -> DTDStateArrow XmlTree XmlTree substPeRefsInCondSect rl- = recursionCheck "conditional section" rl subst- where- subst :: RecList -> String -> DTDStateArrow XmlTree XmlTree- subst recl pn- = substPERef pn- >>>- traceDTD "substPeRefsInCondSect: parseXmlDTDdeclPart"- >>>- runInPeContext ( parseXmlDTDdeclPart- >>>- traceDTD "substPeRefsInCondSect: after parseXmlDTDdeclPart"- >>>- processChildren ( substPeRefsInCondSect (pn : recl) )- )+ = recursionCheck "conditional section" rl subst+ where+ subst :: RecList -> String -> DTDStateArrow XmlTree XmlTree+ subst recl pn+ = substPERef pn+ >>>+ traceDTD "substPeRefsInCondSect: parseXmlDTDdeclPart"+ >>>+ runInPeContext ( parseXmlDTDdeclPart+ >>>+ traceDTD "substPeRefsInCondSect: after parseXmlDTDdeclPart"+ >>>+ processChildren ( substPeRefsInCondSect (pn : recl) )+ ) - recursionCheck :: String -> RecList -> (RecList -> String -> DTDStateArrow XmlTree XmlTree) -> DTDStateArrow XmlTree XmlTree+ recursionCheck :: String -> RecList -> (RecList -> String -> DTDStateArrow XmlTree XmlTree) -> DTDStateArrow XmlTree XmlTree recursionCheck wher rl subst- = ( recusiveSubst $< getDTDAttrValue a_peref )- `when`- isDTDPERef- where- recusiveSubst name- | name `elem` rl- = issueErr ("recursive call of parameter entity " ++ show name ++ " in " ++ wher)+ = ( recusiveSubst $< getDTDAttrValue a_peref )+ `when`+ isDTDPERef+ where+ recusiveSubst name+ | name `elem` rl+ = issueErr ("recursive call of parameter entity " ++ show name ++ " in " ++ wher) | otherwise- = subst rl name+ = subst rl name - runInPeContext :: DTDStateArrow XmlTree XmlTree -> DTDStateArrow XmlTree XmlTree+ runInPeContext :: DTDStateArrow XmlTree XmlTree -> DTDStateArrow XmlTree XmlTree runInPeContext f- = ( runWithNewBase $< getDTDAttrValue a_url )- `orElse`- f- where- runWithNewBase base- = runInLocalURIContext- ( perform (constA base >>> setBaseURI)- >>>- f- )+ = ( runWithNewBase $< getDTDAttrValue a_url )+ `orElse`+ f+ where+ runWithNewBase base+ = runInLocalURIContext+ ( perform (constA base >>> setBaseURI)+ >>>+ f+ ) - evalCondSect :: String -> DTDStateArrow XmlTree XmlTree+ evalCondSect :: String -> DTDStateArrow XmlTree XmlTree evalCondSect content- = traceDTD "evalCondSect: process conditional section"- >>>- processChildren (substPeRefsInCondSect [])- >>>- parseXmlDTDdecl- >>>- ( hasText (== k_include)- `guards`- ( ( constA "conditional section" &&& txt content )- >>>- parseXmlDTDPart- >>>- traceMsg 2 "evalCond: include DTD part"- >>>- substParamEntity External recList- )- )+ = traceDTD "evalCondSect: process conditional section"+ >>>+ processChildren (substPeRefsInCondSect [])+ >>>+ parseXmlDTDdecl+ >>>+ ( hasText (== k_include)+ `guards`+ ( ( constA "conditional section" &&& txt content )+ >>>+ parseXmlDTDPart+ >>>+ traceMsg 2 "evalCond: include DTD part"+ >>>+ substParamEntity External recList+ )+ ) -predefDTDPart :: DTDStateArrow XmlTree XmlTree+predefDTDPart :: DTDStateArrow XmlTree XmlTree predefDTDPart = ( constA "predefined entities"- &&&- ( constA predefinedEntities >>> mkText)+ &&&+ ( constA predefinedEntities >>> mkText) ) >>> parseXmlDTDPart where- predefinedEntities :: String+ predefinedEntities :: String predefinedEntities- = concat [ "<!ENTITY lt '&#60;'>"- , "<!ENTITY gt '>'>"- , "<!ENTITY amp '&#38;'>"- , "<!ENTITY apos '''>"- , "<!ENTITY quot '"'>"- ]+ = concat [ "<!ENTITY lt '&#60;'>"+ , "<!ENTITY gt '>'>"+ , "<!ENTITY amp '&#38;'>"+ , "<!ENTITY apos '''>"+ , "<!ENTITY quot '"'>"+ ] -externalDTDPart :: DTDStateArrow XmlTree XmlTree+externalDTDPart :: DTDStateArrow XmlTree XmlTree externalDTDPart = isDTDDoctype `guards` ( hasDTDAttr k_system- `guards`- ( getExternalDTDPart $< getDTDAttrValue k_system )+ `guards`+ ( getExternalDTDPart $< getDTDAttrValue k_system ) ) -getExternalDTDPart :: String -> DTDStateArrow XmlTree XmlTree+getExternalDTDPart :: String -> DTDStateArrow XmlTree XmlTree getExternalDTDPart src = root [sattr a_source src] [] >>> getXmlEntityContents >>> replaceChildren ( ( constA src &&& getChildren )- >>>- parseXmlDTDPart- )+ >>>+ parseXmlDTDPart+ ) >>> traceDoc "processExternalDTD: parsing DTD part done" >>> getChildren -getExternalParamEntityValue :: DTDStateArrow XmlTree XmlTree+getExternalParamEntityValue :: DTDStateArrow XmlTree XmlTree getExternalParamEntityValue = isDTDPEntity `guards` ( setEntityValue $<<< ( getDTDAttrl- &&&- listA ( getEntityValue $< getDTDAttrl )- &&&- getBaseURI- )+ &&&+ listA ( getEntityValue $< getDTDAttrl )+ &&&+ getBaseURI+ ) ) where- getEntityValue :: Attributes -> DTDStateArrow XmlTree XmlTree+ getEntityValue :: Attributes -> DTDStateArrow XmlTree XmlTree getEntityValue al- = root [sattr a_source (lookup1 k_system al){- <+> catA (map (uncurry sattr) al)-}] []- >>>- getXmlEntityContents- >>>- traceMsg 2 "getExternalParamEntityValue: contents read"+ = root [sattr a_source (lookup1 k_system al){- <+> catA (map (uncurry sattr) al)-}] [] >>>- getChildren+ getXmlEntityContents+ >>>+ traceMsg 2 "getExternalParamEntityValue: contents read"+ >>>+ getChildren - setEntityValue :: Attributes -> XmlTrees -> String -> DTDStateArrow XmlTree XmlTree+ setEntityValue :: Attributes -> XmlTrees -> String -> DTDStateArrow XmlTree XmlTree setEntityValue al res base- | null res- = issueErr ("illegal external parameter entity value for entity %" ++ peName ++";")- | otherwise- = mkDTDElem PENTITY ((a_url, base) : al) (arrL $ const res)- where- peName = lookup1 a_name al+ | null res+ = issueErr ("illegal external parameter entity value for entity %" ++ peName ++";")+ | otherwise+ = mkDTDElem PENTITY ((a_url, base) : al) (arrL $ const res)+ where+ peName = lookup1 a_name al -traceDTD :: String -> DTDStateArrow XmlTree XmlTree-traceDTD msg = traceMsg 3 msg >>> traceTree+traceDTD :: String -> DTDStateArrow XmlTree XmlTree+traceDTD msg = traceMsg 3 msg >>> traceTree -- ------------------------------------------------------------
src/Text/XML/HXT/Arrow/DocumentInput.hs view
@@ -25,59 +25,59 @@ ) where -import Control.Arrow -- arrow classes+import Control.Arrow -- arrow classes import Control.Arrow.ArrowList import Control.Arrow.ArrowIf import Control.Arrow.ArrowTree import Control.Arrow.ArrowIO import Control.Arrow.ListArrow -import Data.List ( isPrefixOf )+import Data.List ( isPrefixOf ) -import System.FilePath ( takeExtension )+import System.FilePath ( takeExtension ) -import Text.XML.HXT.DOM.Unicode ( getDecodingFct- , guessEncoding- , normalizeNL- )+import Text.XML.HXT.DOM.Unicode ( getDecodingFct+ , guessEncoding+ , normalizeNL+ ) -import qualified Text.XML.HXT.IO.GetFILE as FILE-import qualified Text.XML.HXT.IO.GetHTTPLibCurl as LibCURL+import qualified Text.XML.HXT.IO.GetFILE as FILE+import qualified Text.XML.HXT.IO.GetHTTPLibCurl as LibCURL import Text.XML.HXT.DOM.Interface -import Text.XML.HXT.Arrow.ParserInterface ( parseXmlDocEncodingSpec- , parseXmlEntityEncodingSpec- , removeEncodingSpec- )+import Text.XML.HXT.Arrow.ParserInterface ( parseXmlDocEncodingSpec+ , parseXmlEntityEncodingSpec+ , removeEncodingSpec+ ) import Text.XML.HXT.Arrow.XmlArrow import Text.XML.HXT.Arrow.XmlIOStateArrow -- ---------------------------------------------------------- -protocolHandlers :: AssocList String (IOStateArrow s XmlTree XmlTree)+protocolHandlers :: AssocList String (IOStateArrow s XmlTree XmlTree) protocolHandlers- = [ ("file", getFileContents)- , ("http", getHttpContents)- , ("stdin", getStdinContents)+ = [ ("file", getFileContents)+ , ("http", getHttpContents)+ , ("stdin", getStdinContents) ] -getProtocolHandler :: IOStateArrow s String (IOStateArrow s XmlTree XmlTree)+getProtocolHandler :: IOStateArrow s String (IOStateArrow s XmlTree XmlTree) getProtocolHandler = arr (\ s -> lookupDef getUnsupported s protocolHandlers) -getUnsupported :: IOStateArrow s XmlTree XmlTree+getUnsupported :: IOStateArrow s XmlTree XmlTree getUnsupported = perform ( getAttrValue a_source- >>>- arr (("unsupported protocol in URI " ++) . show)- >>>- applyA (arr issueFatal)- )+ >>>+ arr (("unsupported protocol in URI " ++) . show)+ >>>+ applyA (arr issueFatal)+ ) >>> setDocumentStatusFromSystemState "accessing documents"- -getStringContents :: IOStateArrow s XmlTree XmlTree++getStringContents :: IOStateArrow s XmlTree XmlTree getStringContents = setCont $< getAttrValue a_source >>>@@ -86,59 +86,59 @@ addAttr transferStatus "200" where setCont contents- = replaceChildren (txt contents')- >>>- addAttr transferURI (take 7 contents) -- the "string:" prefix is stored, this is required by setBaseURIFromDoc- >>>- addAttr a_source (show . prefix 48 $ contents') -- a quoted prefix of the content, max 48 chars is taken as source name- where- contents' = drop (length stringProtocol) contents- prefix l s- | length s' > l = take (l - 3) s' ++ "..."- | otherwise = s'- where- s' = take (l + 1) s+ = replaceChildren (txt contents')+ >>>+ addAttr transferURI (take 7 contents) -- the "string:" prefix is stored, this is required by setBaseURIFromDoc+ >>>+ addAttr a_source (show . prefix 48 $ contents') -- a quoted prefix of the content, max 48 chars is taken as source name+ where+ contents' = drop (length stringProtocol) contents+ prefix l s+ | length s' > l = take (l - 3) s' ++ "..."+ | otherwise = s'+ where+ s' = take (l + 1) s -getFileContents :: IOStateArrow s XmlTree XmlTree+getFileContents :: IOStateArrow s XmlTree XmlTree getFileContents = applyA ( ( ( getAttrValue a_strict_input- >>>- arr isTrueValue- )- &&&- ( getAttrValue transferURI- >>>- getPathFromURI- )- )- >>>- traceValue 2 (\ (b, f) -> "read file " ++ show f ++ " (strict input = " ++ show b ++ ")")- >>>- arrIO (uncurry FILE.getCont)- >>>- ( arr (uncurry addError) -- io error occured- |||- arr addTxtContent -- content read- )- )+ >>>+ arr isTrueValue+ )+ &&&+ ( getAttrValue transferURI+ >>>+ getPathFromURI+ )+ )+ >>>+ traceValue 2 (\ (b, f) -> "read file " ++ show f ++ " (strict input = " ++ show b ++ ")")+ >>>+ arrIO (uncurry FILE.getCont)+ >>>+ ( arr (uncurry addError) -- io error occured+ |||+ arr addTxtContent -- content read+ )+ ) >>> addMimeType -getStdinContents :: IOStateArrow s XmlTree XmlTree+getStdinContents :: IOStateArrow s XmlTree XmlTree getStdinContents = applyA ( getAttrValue a_strict_input- >>>- arr isTrueValue- >>>- arrIO FILE.getStdinCont- >>>- ( arr (uncurry addError) -- io error occured- |||- arr addTxtContent -- content read- )- )+ >>>+ arr isTrueValue+ >>>+ arrIO FILE.getStdinCont+ >>>+ ( arr (uncurry addError) -- io error occured+ |||+ arr addTxtContent -- content read+ )+ ) -addError :: [(String, String)] -> String -> IOStateArrow s XmlTree XmlTree+addError :: [(String, String)] -> String -> IOStateArrow s XmlTree XmlTree addError al e = issueFatal e >>>@@ -146,19 +146,19 @@ >>> setDocumentStatusFromSystemState "accessing documents" -addMimeType :: IOStateArrow s XmlTree XmlTree+addMimeType :: IOStateArrow s XmlTree XmlTree addMimeType = addMime $< ( getAttrValue transferURI- >>>- ( uriToMime $< getSysParam xio_mimeTypes )- )+ >>>+ ( uriToMime $< getSysParam xio_mimeTypes )+ ) where addMime mt- = addAttr transferMimeType mt+ = addAttr transferMimeType mt uriToMime mtt- = arr $ ( \ uri -> extensionToMimeType (drop 1 . takeExtension $ uri) mtt )+ = arr $ ( \ uri -> extensionToMimeType (drop 1 . takeExtension $ uri) mtt ) -addTxtContent :: String -> IOStateArrow s XmlTree XmlTree+addTxtContent :: String -> IOStateArrow s XmlTree XmlTree addTxtContent c = replaceChildren (txt c) >>>@@ -166,101 +166,101 @@ >>> addAttr transferStatus "200" -getHttpContents :: IOStateArrow s XmlTree XmlTree+getHttpContents :: IOStateArrow s XmlTree XmlTree getHttpContents = getCont $<< ( getAttrValue transferURI- &&&- ( ( getAttrlAsAssoc -- get all attributes of root node- &&&- getAllParamsString -- get all system params- )- >>^ uncurry addEntries -- merge them, attributes overwrite system params- )- )+ &&&+ ( ( getAttrlAsAssoc -- get all attributes of root node+ &&&+ getAllParamsString -- get all system params+ )+ >>^ uncurry addEntries -- merge them, attributes overwrite system params+ )+ ) where- getAttrlAsAssoc -- get the attributes as assoc list- = listA ( getAttrl- >>> ( getName- &&&- xshow getChildren- )- )+ getAttrlAsAssoc -- get the attributes as assoc list+ = listA ( getAttrl+ >>> ( getName+ &&&+ xshow getChildren+ )+ ) getCont uri options- = applyA ( ( traceMsg 2 ( "get HTTP via libcurl, uri=" ++ show uri ++ " options=" ++ show options )- >>>- arrIO0 ( LibCURL.getCont options uri )- )- >>>- ( arr (uncurry addError)- |||- arr addContent- )- )+ = applyA ( ( traceMsg 2 ( "get HTTP via libcurl, uri=" ++ show uri ++ " options=" ++ show options )+ >>>+ arrIO0 ( LibCURL.getCont options uri )+ )+ >>>+ ( arr (uncurry addError)+ |||+ arr addContent+ )+ ) - addContent :: (AssocList String String, String) -> IOStateArrow s XmlTree XmlTree+ addContent :: (AssocList String String, String) -> IOStateArrow s XmlTree XmlTree addContent (al, c)- = replaceChildren (txt c)- >>>- seqA (map (uncurry addAttr) al)+ = replaceChildren (txt c)+ >>>+ seqA (map (uncurry addAttr) al) -getURIContents :: IOStateArrow s XmlTree XmlTree+getURIContents :: IOStateArrow s XmlTree XmlTree getURIContents = getContentsFromString `orElse` getContentsFromDoc where getContentsFromString- = ( getAttrValue a_source- >>>- isA (isPrefixOf stringProtocol)- )- `guards`- getStringContents- + = ( getAttrValue a_source+ >>>+ isA (isPrefixOf stringProtocol)+ )+ `guards`+ getStringContents+ getContentsFromDoc- = ( ( addTransferURI $< getBaseURI- >>>- getCont- )- `when`- ( setAbsURI $< ( getAttrValue a_source- >>^- ( \ src-> (if null src then "stdin:" else src) ) -- empty document name -> read from stdin- )- )- )+ = ( ( addTransferURI $< getBaseURI+ >>>+ getCont+ )+ `when`+ ( setAbsURI $< ( getAttrValue a_source+ >>^+ ( \ src-> (if null src then "stdin:" else src) ) -- empty document name -> read from stdin+ )+ )+ ) >>> setDocumentStatusFromSystemState "getURIContents" setAbsURI src- = ifA ( constA src >>> changeBaseURI )- this- ( issueFatal ("illegal URI : " ++ show src) )+ = ifA ( constA src >>> changeBaseURI )+ this+ ( issueFatal ("illegal URI : " ++ show src) ) addTransferURI uri- = addAttr transferURI uri+ = addAttr transferURI uri getCont- = applyA ( getBaseURI -- compute the handler and call it- >>>- traceValue 2 (("getURIContents: reading " ++) . show)- >>>- getSchemeFromURI- >>>- getProtocolHandler- )- `orElse`- this -- don't change tree, when no handler can be found- -setBaseURIFromDoc :: IOStateArrow s XmlTree XmlTree+ = applyA ( getBaseURI -- compute the handler and call it+ >>>+ traceValue 2 (("getURIContents: reading " ++) . show)+ >>>+ getSchemeFromURI+ >>>+ getProtocolHandler+ )+ `orElse`+ this -- don't change tree, when no handler can be found++setBaseURIFromDoc :: IOStateArrow s XmlTree XmlTree setBaseURIFromDoc = perform ( getAttrValue transferURI- >>>- isA (isPrefixOf stringProtocol) -- do not change base URI when reading from a string- >>>- setBaseURI- )+ >>>+ isA (isPrefixOf stringProtocol) -- do not change base URI when reading from a string+ >>>+ setBaseURI+ ) {- | Read the content of a document.@@ -285,13 +285,13 @@ -} -getXmlContents :: IOStateArrow s XmlTree XmlTree+getXmlContents :: IOStateArrow s XmlTree XmlTree getXmlContents = getXmlContents' parseXmlDocEncodingSpec >>> setBaseURIFromDoc -getXmlEntityContents :: IOStateArrow s XmlTree XmlTree+getXmlEntityContents :: IOStateArrow s XmlTree XmlTree getXmlEntityContents = getXmlContents' parseXmlEntityEncodingSpec >>>@@ -299,72 +299,72 @@ >>> setBaseURIFromDoc -getXmlContents' :: IOStateArrow s XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree+getXmlContents' :: IOStateArrow s XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree getXmlContents' parseEncodingSpec = ( getURIContents- >>>- choiceA- [ isXmlHtmlDoc :-> ( parseEncodingSpec- >>>- filterErrorMsg- >>>- decodeDocument- )- , isTextDoc :-> decodeDocument- , this :-> this- ]- >>>- perform ( getAttrValue transferURI- >>>- traceValue 1 (("getXmlContents: content read and decoded for " ++) . show)- )- >>>- traceTree- >>>- traceSource+ >>>+ choiceA+ [ isXmlHtmlDoc :-> ( parseEncodingSpec+ >>>+ filterErrorMsg+ >>>+ decodeDocument+ )+ , isTextDoc :-> decodeDocument+ , this :-> this+ ]+ >>>+ perform ( getAttrValue transferURI+ >>>+ traceValue 1 (("getXmlContents: content read and decoded for " ++) . show)+ )+ >>>+ traceTree+ >>>+ traceSource ) `when` isRoot -isMimeDoc :: (String -> Bool) -> IOStateArrow s XmlTree XmlTree-isMimeDoc isMT = fromLA $- ( ( getAttrValue transferMimeType >>^ stringToLower )- >>>- isA (\ t -> null t || isMT t)- )- `guards` this+isMimeDoc :: (String -> Bool) -> IOStateArrow s XmlTree XmlTree+isMimeDoc isMT = fromLA $+ ( ( getAttrValue transferMimeType >>^ stringToLower )+ >>>+ isA (\ t -> null t || isMT t)+ )+ `guards` this -isTextDoc, isXmlHtmlDoc :: IOStateArrow s XmlTree XmlTree+isTextDoc, isXmlHtmlDoc :: IOStateArrow s XmlTree XmlTree -isTextDoc = isMimeDoc isTextMimeType+isTextDoc = isMimeDoc isTextMimeType -isXmlHtmlDoc = isMimeDoc (\ mt -> isHtmlMimeType mt || isXmlMimeType mt)+isXmlHtmlDoc = isMimeDoc (\ mt -> isHtmlMimeType mt || isXmlMimeType mt) -- ------------------------------------------------------------ -getEncoding :: IOStateArrow s XmlTree String+getEncoding :: IOStateArrow s XmlTree String getEncoding- = catA [ xshow getChildren -- 1. guess: guess encoding by looking at the first few bytes- >>>- arr guessEncoding- , getAttrValue transferEncoding -- 2. guess: take the transfer encoding- , getAttrValue a_encoding -- 3. guess: take encoding parameter in root node- , getParamString a_encoding -- 4. guess: take encoding parameter in global state- , constA utf8 -- default : utf8- ]- >. (head . filter (not . null)) -- make the filter deterministic: take 1. entry from list of guesses+ = catA [ xshow getChildren -- 1. guess: guess encoding by looking at the first few bytes+ >>>+ arr guessEncoding+ , getAttrValue transferEncoding -- 2. guess: take the transfer encoding+ , getAttrValue a_encoding -- 3. guess: take encoding parameter in root node+ , getParamString a_encoding -- 4. guess: take encoding parameter in global state+ , constA utf8 -- default : utf8+ ]+ >. (head . filter (not . null)) -- make the filter deterministic: take 1. entry from list of guesses -getTextEncoding :: IOStateArrow s XmlTree String+getTextEncoding :: IOStateArrow s XmlTree String getTextEncoding- = catA [ getAttrValue transferEncoding -- 1. guess: take the transfer encoding- , getAttrValue a_encoding -- 2. guess: take encoding parameter in root node- , getParamString a_encoding -- 3. guess: take encoding parameter in global state- , constA isoLatin1 -- default : no encoding- ]- >. (head . filter (not . null)) -- make the filter deterministic: take 1. entry from list of guesses+ = catA [ getAttrValue transferEncoding -- 1. guess: take the transfer encoding+ , getAttrValue a_encoding -- 2. guess: take encoding parameter in root node+ , getParamString a_encoding -- 3. guess: take encoding parameter in global state+ , constA isoLatin1 -- default : no encoding+ ]+ >. (head . filter (not . null)) -- make the filter deterministic: take 1. entry from list of guesses -decodeDocument :: IOStateArrow s XmlTree XmlTree+decodeDocument :: IOStateArrow s XmlTree XmlTree decodeDocument = choiceA [ ( isRoot >>> isXmlHtmlDoc ) :-> ( decodeArr normalizeNL $< getEncoding )@@ -372,43 +372,43 @@ , this :-> this ] where- decodeArr :: (String -> String) -> String -> IOStateArrow s XmlTree XmlTree+ decodeArr :: (String -> String) -> String -> IOStateArrow s XmlTree XmlTree decodeArr normalizeNewline enc- = maybe notFound found . getDecodingFct $ enc- where- found df- = traceMsg 2 ("decodeDocument: encoding is " ++ show enc)- >>>- ( decodeText df $< getAttrValue a_ignore_encoding_errors )- >>>- addAttr transferEncoding enc+ = maybe notFound found . getDecodingFct $ enc+ where+ found df+ = traceMsg 2 ("decodeDocument: encoding is " ++ show enc)+ >>>+ ( decodeText df $< getAttrValue a_ignore_encoding_errors )+ >>>+ addAttr transferEncoding enc - notFound- = issueFatal ("encoding scheme not supported: " ++ show enc)- >>>- setDocumentStatusFromSystemState "decoding document"+ notFound+ = issueFatal ("encoding scheme not supported: " ++ show enc)+ >>>+ setDocumentStatusFromSystemState "decoding document" - decodeText df ignoreErrs- = processChildren- ( getText -- get the document content- >>> arr df -- decode the text, result is (string, [errMsg])- >>> ( ( (fst >>> normalizeNewline) -- take decoded string, normalize newline and build text node- ^>> mkText- )- <+>- ( if isTrueValue ignoreErrs- then none -- encoding errors are ignored- else- ( arrL snd -- take the error messages- >>>- arr ((enc ++) . (" encoding error" ++)) -- prefix with enc error- >>>- applyA (arr issueErr) -- build issueErr arrow and apply- >>>- none -- neccessary for type match with <+>- )- )- )- )- + decodeText df ignoreErrs+ = processChildren+ ( getText -- get the document content+ >>> arr df -- decode the text, result is (string, [errMsg])+ >>> ( ( (fst >>> normalizeNewline) -- take decoded string, normalize newline and build text node+ ^>> mkText+ )+ <+>+ ( if isTrueValue ignoreErrs+ then none -- encoding errors are ignored+ else+ ( arrL snd -- take the error messages+ >>>+ arr ((enc ++) . (" encoding error" ++)) -- prefix with enc error+ >>>+ applyA (arr issueErr) -- build issueErr arrow and apply+ >>>+ none -- neccessary for type match with <+>+ )+ )+ )+ )+ -- ------------------------------------------------------------
src/Text/XML/HXT/Arrow/DocumentOutput.hs view
@@ -24,183 +24,183 @@ ) where -import Control.Arrow -- arrow classes+import Control.Arrow -- arrow classes import Control.Arrow.ArrowList import Control.Arrow.ArrowIf import Control.Arrow.ArrowTree import Control.Arrow.ArrowIO import Control.Arrow.ListArrow -import Text.XML.HXT.DOM.Unicode ( getOutputEncodingFct )+import Text.XML.HXT.DOM.Unicode ( getOutputEncodingFct ) import Text.XML.HXT.DOM.Interface import Text.XML.HXT.Arrow.XmlArrow import Text.XML.HXT.Arrow.XmlIOStateArrow -import Text.XML.HXT.Arrow.Edit ( addHeadlineToXmlDoc- , addXmlPi- , addXmlPiEncoding- , indentDoc- , numberLinesInXmlDoc- , treeRepOfXmlDoc- )+import Text.XML.HXT.Arrow.Edit ( addHeadlineToXmlDoc+ , addXmlPi+ , addXmlPiEncoding+ , indentDoc+ , numberLinesInXmlDoc+ , treeRepOfXmlDoc+ ) -import System.IO ( Handle- , IOMode(..)- , openFile- , openBinaryFile+import System.IO ( Handle+ , IOMode(..)+ , openFile+ , openBinaryFile , hSetBinaryMode- , hPutStrLn- , hClose- , stdout- )+ , hPutStrLn+ , hClose+ , stdout+ ) -import System.IO.Error ( try )+import System.IO.Error ( try ) -- ------------------------------------------------------------ -- -- output arrows -putXmlDocument :: Bool -> String -> IOStateArrow s XmlTree XmlTree+putXmlDocument :: Bool -> String -> IOStateArrow s XmlTree XmlTree putXmlDocument textMode dst = perform ( xshow getChildren- >>>- arrIO (\ s -> try ( hPutDocument (\h -> hPutStrLn h s)))- >>>- ( ( traceMsg 1 ("io error, document not written to " ++ outFile)- >>>- arr show >>> mkError c_fatal- >>>- filterErrorMsg- )- |||- ( traceMsg 2 ("document written to " ++ outFile)- >>>- none- )- )- )+ >>>+ arrIO (\ s -> try ( hPutDocument (\h -> hPutStrLn h s)))+ >>>+ ( ( traceMsg 1 ("io error, document not written to " ++ outFile)+ >>>+ arr show >>> mkError c_fatal+ >>>+ filterErrorMsg+ )+ |||+ ( traceMsg 2 ("document written to " ++ outFile)+ >>>+ none+ )+ )+ ) where- isStdout = null dst || dst == "-"+ isStdout = null dst || dst == "-" - outFile = if isStdout- then "stdout"- else show dst+ outFile = if isStdout+ then "stdout"+ else show dst - hPutDocument :: (Handle -> IO ()) -> IO ()+ hPutDocument :: (Handle -> IO ()) -> IO () hPutDocument action- | isStdout- = do+ | isStdout+ = do hSetBinaryMode stdout (not textMode) action stdout hSetBinaryMode stdout False- | otherwise- = do- handle <- ( if textMode- then openFile- else openBinaryFile- ) dst WriteMode- action handle- hClose handle+ | otherwise+ = do+ handle <- ( if textMode+ then openFile+ else openBinaryFile+ ) dst WriteMode+ action handle+ hClose handle -- | -- write the tree representation of a document to a file -putXmlTree :: String -> IOStateArrow s XmlTree XmlTree+putXmlTree :: String -> IOStateArrow s XmlTree XmlTree putXmlTree dst = perform ( treeRepOfXmlDoc- >>>- addHeadlineToXmlDoc- >>>- putXmlDocument True dst- )+ >>>+ addHeadlineToXmlDoc+ >>>+ putXmlDocument True dst+ ) -- | -- write a document with indentaion and line numers -putXmlSource :: String -> IOStateArrow s XmlTree XmlTree+putXmlSource :: String -> IOStateArrow s XmlTree XmlTree putXmlSource dst = perform ( (this ) `whenNot` isRoot- >>>- indentDoc- >>>- numberLinesInXmlDoc- >>>- addHeadlineToXmlDoc- >>>- putXmlDocument True dst- )+ >>>+ indentDoc+ >>>+ numberLinesInXmlDoc+ >>>+ addHeadlineToXmlDoc+ >>>+ putXmlDocument True dst+ ) -- ------------------------------------------------------------ -getEncodingParam :: IOStateArrow s XmlTree String+getEncodingParam :: IOStateArrow s XmlTree String getEncodingParam- = catA [ getParamString a_output_encoding -- 4. guess: take output encoding parameter from global state- , getParamString a_encoding -- 5. guess: take encoding parameter from global state- , constA utf8 -- default : utf8+ = catA [ getParamString a_output_encoding -- 4. guess: take output encoding parameter from global state+ , getParamString a_encoding -- 5. guess: take encoding parameter from global state+ , constA utf8 -- default : utf8 ] >. (head . filter (not . null)) -getOutputEncoding :: String -> IOStateArrow s XmlTree String+getOutputEncoding :: String -> IOStateArrow s XmlTree String getOutputEncoding defaultEnc = getEC $< getEncodingParam where getEC enc' = fromLA $ getOutputEncoding' defaultEnc enc' -encodeDocument :: Bool -> String -> IOStateArrow s XmlTree XmlTree+encodeDocument :: Bool -> String -> IOStateArrow s XmlTree XmlTree encodeDocument supressXmlPi defaultEnc = encode $< getOutputEncoding defaultEnc where encode enc = traceMsg 2 ("encodeDocument: encoding is " ++ show enc)- >>>+ >>> ( encodeDocument' supressXmlPi enc `orElse` ( issueFatal ("encoding scheme not supported: " ++ show enc)- >>>- setDocumentStatusFromSystemState "encoding document"+ >>>+ setDocumentStatusFromSystemState "encoding document" ) ) -- ------------------------------------------------------------ -getOutputEncoding' :: String -> String -> LA XmlTree String+getOutputEncoding' :: String -> String -> LA XmlTree String getOutputEncoding' defaultEnc defaultEnc2- = catA [ getChildren -- 1. guess: evaluate <?xml ... encoding="..."?>- >>>- ( ( isPi >>> hasName t_xml )- `guards`- getAttrValue a_encoding- )- , constA defaultEnc -- 2. guess: explicit parameter, may be ""- , getAttrValue a_output_encoding -- 3. guess: take output encoding parameter in root node- , constA defaultEnc2 -- default : UNICODE or utf8- ]- >. (head . filter (not . null)) -- make the filter deterministic: take 1. entry from list of guesses+ = catA [ getChildren -- 1. guess: evaluate <?xml ... encoding="..."?>+ >>>+ ( ( isPi >>> hasName t_xml )+ `guards`+ getAttrValue a_encoding+ )+ , constA defaultEnc -- 2. guess: explicit parameter, may be ""+ , getAttrValue a_output_encoding -- 3. guess: take output encoding parameter in root node+ , constA defaultEnc2 -- default : UNICODE or utf8+ ]+ >. (head . filter (not . null)) -- make the filter deterministic: take 1. entry from list of guesses -encodeDocument' :: ArrowXml a => Bool -> String -> a XmlTree XmlTree+encodeDocument' :: ArrowXml a => Bool -> String -> a XmlTree XmlTree encodeDocument' supressXmlPi defaultEnc = fromLA (encode $< getOutputEncoding' defaultEnc utf8) where- encode :: String -> LA XmlTree XmlTree+ encode :: String -> LA XmlTree XmlTree encode encodingScheme = case getOutputEncodingFct encodingScheme of- Nothing -> none- Just ef -> ( if supressXmlPi- then processChildren (none `when` isXmlPi)- else ( addXmlPi- >>>- addXmlPiEncoding encodingScheme- )- )- >>>- replaceChildren ( xshow getChildren- >>>- arr ef- >>>- mkText- )- >>>- addAttr a_output_encoding encodingScheme+ Nothing -> none+ Just ef -> ( if supressXmlPi+ then processChildren (none `when` isXmlPi)+ else ( addXmlPi+ >>>+ addXmlPiEncoding encodingScheme+ )+ )+ >>>+ replaceChildren ( xshow getChildren+ >>>+ arr ef+ >>>+ mkText+ )+ >>>+ addAttr a_output_encoding encodingScheme -- ------------------------------------------------------------
src/Text/XML/HXT/Arrow/Edit.hs view
@@ -34,7 +34,7 @@ , indentDoc , numberLinesInXmlDoc , preventEmptyElements- + , removeComment , removeAllComment , removeWhiteSpace@@ -64,19 +64,19 @@ import Control.Arrow.ArrowList import Control.Arrow.ArrowIf import Control.Arrow.ArrowTree-import Control.Arrow.ListArrow+import Control.Arrow.ListArrow import Text.XML.HXT.Arrow.XmlArrow import Text.XML.HXT.DOM.Interface-import qualified Text.XML.HXT.DOM.XmlNode as XN-import Text.XML.HXT.DOM.Unicode ( isXmlSpaceChar )-import Text.XML.HXT.DOM.FormatXmlTree ( formatXmlTree )+import qualified Text.XML.HXT.DOM.XmlNode as XN+import Text.XML.HXT.DOM.Unicode ( isXmlSpaceChar )+import Text.XML.HXT.DOM.FormatXmlTree ( formatXmlTree ) import Text.XML.HXT.Parser.HtmlParsec ( emptyHtmlTags )-import Text.XML.HXT.Parser.XmlEntities ( xmlEntities )-import Text.XML.HXT.Parser.XhtmlEntities ( xhtmlEntities )+import Text.XML.HXT.Parser.XmlEntities ( xmlEntities )+import Text.XML.HXT.Parser.XhtmlEntities ( xhtmlEntities ) import Data.List ( isPrefixOf )-import qualified Data.Map as M+import qualified Data.Map as M import Data.Maybe -- ------------------------------------------------------------@@ -100,30 +100,30 @@ -- -- see 'canonicalizeAllNodes' and 'canonicalizeForXPath' -canonicalizeTree' :: LA XmlTree XmlTree -> LA XmlTree XmlTree+canonicalizeTree' :: LA XmlTree XmlTree -> LA XmlTree XmlTree canonicalizeTree' toBeRemoved = processChildren (none `when` isText) >>> processBottomUp canonicalize1Node where- canonicalize1Node :: LA XmlTree XmlTree+ canonicalize1Node :: LA XmlTree XmlTree canonicalize1Node- = (deep isPi `when` isDTD) -- remove DTD parts, except PIs- >>>- (none `when` toBeRemoved) -- remove unintersting nodes- >>>- ( processAttrl ( processChildren transfCharRef- >>>- collapseXText- )- `when` isElem- )- >>>- transfCdata -- CDATA -> text- >>>- transfCharRef -- Char refs -> text- >>>- collapseXText -- combine text+ = (deep isPi `when` isDTD) -- remove DTD parts, except PIs+ >>>+ (none `when` toBeRemoved) -- remove unintersting nodes+ >>>+ ( processAttrl ( processChildren transfCharRef+ >>>+ collapseXText+ )+ `when` isElem+ )+ >>>+ transfCdata -- CDATA -> text+ >>>+ transfCharRef -- Char refs -> text+ >>>+ collapseXText -- combine text -- |@@ -145,13 +145,13 @@ -- -- - Special characters in attribute values and character content are replaced by character references -canonicalizeAllNodes :: ArrowList a => a XmlTree XmlTree+canonicalizeAllNodes :: ArrowList a => a XmlTree XmlTree canonicalizeAllNodes = fromLA $- canonicalizeTree' ( isCmt -- remove comment- <+>- isXmlPi -- remove xml declaration- )+ canonicalizeTree' ( isCmt -- remove comment+ <+>+ isXmlPi -- remove xml declaration+ ) -- | -- Canonicalize a tree for XPath@@ -159,7 +159,7 @@ -- -- see 'canonicalizeAllNodes' -canonicalizeForXPath :: ArrowList a => a XmlTree XmlTree+canonicalizeForXPath :: ArrowList a => a XmlTree XmlTree canonicalizeForXPath = fromLA $ canonicalizeTree' isXmlPi@@ -173,49 +173,49 @@ -- -- see 'canonicalizeAllNodes' -canonicalizeContents :: ArrowList a => a XmlTree XmlTree+canonicalizeContents :: ArrowList a => a XmlTree XmlTree canonicalizeContents = fromLA $ processBottomUp canonicalize1Node where- canonicalize1Node :: LA XmlTree XmlTree+ canonicalize1Node :: LA XmlTree XmlTree canonicalize1Node- = ( processAttrl ( processChildren transfCharRef- >>>- collapseXText- )- `when` isElem- )- >>>- transfCdata -- CDATA -> text- >>>- transfCharRef -- Char refs -> text- >>>- collapseXText -- combine text+ = ( processAttrl ( processChildren transfCharRef+ >>>+ collapseXText+ )+ `when` isElem+ )+ >>>+ transfCdata -- CDATA -> text+ >>>+ transfCharRef -- Char refs -> text+ >>>+ collapseXText -- combine text -- ------------------------------------------------------------ -collapseXText' :: LA XmlTree XmlTree+collapseXText' :: LA XmlTree XmlTree collapseXText' = replaceChildren ( listA getChildren >>> arrL (foldr mergeText' []) ) where- mergeText' :: XmlTree -> XmlTrees -> XmlTrees+ mergeText' :: XmlTree -> XmlTrees -> XmlTrees mergeText' t1 (t2 : ts2)- | XN.isText t1 && XN.isText t2- = let- s1 = fromJust . XN.getText $ t1- s2 = fromJust . XN.getText $ t2- t = XN.mkText (s1 ++ s2)- in- t : ts2+ | XN.isText t1 && XN.isText t2+ = let+ s1 = fromJust . XN.getText $ t1+ s2 = fromJust . XN.getText $ t2+ t = XN.mkText (s1 ++ s2)+ in+ t : ts2 mergeText' t1 ts- = t1 : ts+ = t1 : ts -- | -- Collects sequences of text nodes in the list of children of a node into one single text node. -- This is useful, e.g. after char and entity reference substitution -collapseXText :: ArrowList a => a XmlTree XmlTree+collapseXText :: ArrowList a => a XmlTree XmlTree collapseXText = fromLA $ collapseXText'@@ -226,7 +226,7 @@ -- -- see also : 'collapseXText' -collapseAllXText :: ArrowList a => a XmlTree XmlTree+collapseAllXText :: ArrowList a => a XmlTree XmlTree collapseAllXText = fromLA $ processBottomUp collapseXText'@@ -243,8 +243,8 @@ -- -- > xshowEscape f >>> xread == f -xshowEscapeXml :: ArrowXml a => a n XmlTree -> a n String-xshowEscapeXml f = xshow (f >>> escapeXmlDoc)+xshowEscapeXml :: ArrowXml a => a n XmlTree -> a n String+xshowEscapeXml f = xshow (f >>> escapeXmlDoc) -- ------------------------------------------------------------ @@ -252,50 +252,50 @@ -- escape XmlText, -- transform all special XML chars into char- or entity- refs -type EntityRefTable = M.Map Int String+type EntityRefTable = M.Map Int String xmlEntityRefTable- , xhtmlEntityRefTable :: EntityRefTable+ , xhtmlEntityRefTable :: EntityRefTable xmlEntityRefTable = buildEntityRefTable $ xmlEntities xhtmlEntityRefTable = buildEntityRefTable $ xhtmlEntities -buildEntityRefTable :: [(String, Int)] -> EntityRefTable-buildEntityRefTable = M.fromList . map (\ (x,y) -> (y,x) )+buildEntityRefTable :: [(String, Int)] -> EntityRefTable+buildEntityRefTable = M.fromList . map (\ (x,y) -> (y,x) ) -escapeText'' :: (Char -> XmlTree) -> (Char -> Bool) -> XmlTree -> XmlTrees+escapeText'' :: (Char -> XmlTree) -> (Char -> Bool) -> XmlTree -> XmlTrees escapeText'' escChar isEsc t = maybe [t] escape' . XN.getText $ t where- escape' "" = [t] -- empty text nodes remain empty text nodes- escape' s = escape s -- they do not disapear+ escape' "" = [t] -- empty text nodes remain empty text nodes+ escape' s = escape s -- they do not disapear escape ""- = []+ = [] escape (c:s1)- | isEsc c- = escChar c : escape s1+ | isEsc c+ = escChar c : escape s1 escape s- = XN.mkText s1 : escape s2- where- (s1, s2) = break isEsc s+ = XN.mkText s1 : escape s2+ where+ (s1, s2) = break isEsc s {--escapeCharRef :: Char -> XmlTree-escapeCharRef = XN.mkCharRef . fromEnum+escapeCharRef :: Char -> XmlTree+escapeCharRef = XN.mkCharRef . fromEnum -} -escapeEntityRef :: EntityRefTable -> Char -> XmlTree+escapeEntityRef :: EntityRefTable -> Char -> XmlTree escapeEntityRef entityTable c = maybe (XN.mkCharRef c') XN.mkEntityRef . M.lookup c' $ entityTable where c' = fromEnum c -escapeXmlEntityRef :: Char -> XmlTree-escapeXmlEntityRef = escapeEntityRef xmlEntityRefTable+escapeXmlEntityRef :: Char -> XmlTree+escapeXmlEntityRef = escapeEntityRef xmlEntityRefTable -escapeHtmlEntityRef :: Char -> XmlTree-escapeHtmlEntityRef = escapeEntityRef xhtmlEntityRefTable+escapeHtmlEntityRef :: Char -> XmlTree+escapeHtmlEntityRef = escapeEntityRef xhtmlEntityRefTable -- ------------------------------------------------------------ @@ -306,12 +306,12 @@ -- in attribute values also \', \", \>, \\n, \\r and \\t are converted into entity or char references, -- in comments nothing is converted (see XML standard 2.4, useful e.g. for JavaScript). -escapeXmlDoc :: ArrowList a => a XmlTree XmlTree+escapeXmlDoc :: ArrowList a => a XmlTree XmlTree escapeXmlDoc = fromLA $ escapeDoc escXmlText escXmlAttrValue where escXmlText- = arrL $ escapeText'' escapeXmlEntityRef (`elem` "<&") -- no escape for ", ' and > required: XML standard 2.4+ = arrL $ escapeText'' escapeXmlEntityRef (`elem` "<&") -- no escape for ", ' and > required: XML standard 2.4 escXmlAttrValue = arrL $ escapeText'' escapeXmlEntityRef (`elem` "<>\"\'&\n\r\t") @@ -325,62 +325,62 @@ -- ------------------------------------------------------------ -escapeHtmlDoc :: ArrowList a => a XmlTree XmlTree+escapeHtmlDoc :: ArrowList a => a XmlTree XmlTree escapeHtmlDoc = fromLA $ escapeDoc escHtmlText escHtmlAttrValue where escHtmlText- = arrL $ escapeText'' escapeHtmlEntityRef isHtmlTextEsc+ = arrL $ escapeText'' escapeHtmlEntityRef isHtmlTextEsc escHtmlAttrValue = arrL $ escapeText'' escapeHtmlEntityRef isHtmlAttrEsc isHtmlTextEsc c- = c >= toEnum(128) || ( c `elem` "<&" )+ = c >= toEnum(128) || ( c `elem` "<&" ) isHtmlAttrEsc c- = c >= toEnum(128) || ( c `elem` "<>\"\'&\n\r\t" )+ = c >= toEnum(128) || ( c `elem` "<>\"\'&\n\r\t" ) -- ------------------------------------------------------------ -escapeDoc :: LA XmlTree XmlTree -> LA XmlTree XmlTree -> LA XmlTree XmlTree+escapeDoc :: LA XmlTree XmlTree -> LA XmlTree XmlTree -> LA XmlTree XmlTree escapeDoc escText escAttr = escape where escape- = choiceA- [ isElem :-> ( processChildren escape- >>>- processAttrl escVal- )- , isText :-> escText- -- , isCmt :-> escCmt- , isDTD :-> processTopDown escDTD- , this :-> this- ]+ = choiceA+ [ isElem :-> ( processChildren escape+ >>>+ processAttrl escVal+ )+ , isText :-> escText+ -- , isCmt :-> escCmt+ , isDTD :-> processTopDown escDTD+ , this :-> this+ ] escVal = processChildren escAttr escDTD = escVal `when` ( isDTDEntity <+> isDTDPEntity ) -- ------------------------------------------------------------ -preventEmptyElements :: ArrowList a => [String] -> Bool -> a XmlTree XmlTree+preventEmptyElements :: ArrowList a => [String] -> Bool -> a XmlTree XmlTree preventEmptyElements ns isHtml = fromLA $ insertDummyElem where isNoneEmpty | not (null ns) = hasNameWith (localPart >>> (`elem` ns))- | isHtml = hasNameWith (localPart >>> (`notElem` emptyHtmlTags))- | otherwise = this+ | isHtml = hasNameWith (localPart >>> (`notElem` emptyHtmlTags))+ | otherwise = this insertDummyElem- = processBottomUp- ( replaceChildren (txt "")- `when`- ( isElem- >>>- isNoneEmpty- >>>- neg getChildren- )- )+ = processBottomUp+ ( replaceChildren (txt "")+ `when`+ ( isElem+ >>>+ isNoneEmpty+ >>>+ neg getChildren+ )+ ) -- ------------------------------------------------------------ @@ -390,30 +390,30 @@ -- Useful for debugging and trace output. -- see also : 'treeRepOfXmlDoc', 'numberLinesInXmlDoc' -haskellRepOfXmlDoc :: ArrowList a => a XmlTree XmlTree+haskellRepOfXmlDoc :: ArrowList a => a XmlTree XmlTree haskellRepOfXmlDoc = fromLA $ root [getAttrl] [show ^>> mkText] -- | -- convert a document into a text and add line numbers to the text representation.--- +-- -- Result is a root node with a single text node as child. -- Useful for debugging and trace output. -- see also : 'haskellRepOfXmlDoc', 'treeRepOfXmlDoc' -numberLinesInXmlDoc :: ArrowList a => a XmlTree XmlTree+numberLinesInXmlDoc :: ArrowList a => a XmlTree XmlTree numberLinesInXmlDoc = fromLA $ processChildren (changeText numberLines) where- numberLines :: String -> String+ numberLines :: String -> String numberLines str- = concat $- zipWith (\ n l -> lineNr n ++ l ++ "\n") [1..] (lines str)- where- lineNr :: Int -> String- lineNr n = (reverse (take 6 (reverse (show n) ++ replicate 6 ' '))) ++ " "+ = concat $+ zipWith (\ n l -> lineNr n ++ l ++ "\n") [1..] (lines str)+ where+ lineNr :: Int -> String+ lineNr n = (reverse (take 6 (reverse (show n) ++ replicate 6 ' '))) ++ " " -- | -- convert a document into a text representation in tree form.@@ -421,44 +421,44 @@ -- Useful for debugging and trace output. -- see also : 'haskellRepOfXmlDoc', 'numberLinesInXmlDoc' -treeRepOfXmlDoc :: ArrowList a => a XmlTree XmlTree+treeRepOfXmlDoc :: ArrowList a => a XmlTree XmlTree treeRepOfXmlDoc = fromLA $ root [getAttrl] [formatXmlTree ^>> mkText] -addHeadlineToXmlDoc :: ArrowXml a => a XmlTree XmlTree+addHeadlineToXmlDoc :: ArrowXml a => a XmlTree XmlTree addHeadlineToXmlDoc = fromLA $ ( addTitle $< (getAttrValue a_source >>^ formatTitle) ) where addTitle str- = replaceChildren ( txt str <+> getChildren <+> txt "\n" )+ = replaceChildren ( txt str <+> getChildren <+> txt "\n" ) formatTitle str- = "\n" ++ headline ++ "\n" ++ underline ++ "\n\n"- where- headline = "content of: " ++ str+ = "\n" ++ headline ++ "\n" ++ underline ++ "\n\n"+ where+ headline = "content of: " ++ str underline = map (const '=') headline -- ------------------------------------------------------------ -removeComment' :: LA XmlTree XmlTree-removeComment' = none `when` isCmt+removeComment' :: LA XmlTree XmlTree+removeComment' = none `when` isCmt -- | -- remove Comments: @none `when` isCmt@ -removeComment :: ArrowXml a => a XmlTree XmlTree-removeComment = fromLA $ removeComment'+removeComment :: ArrowXml a => a XmlTree XmlTree+removeComment = fromLA $ removeComment' -- | -- remove all comments recursively -removeAllComment :: ArrowXml a => a XmlTree XmlTree-removeAllComment = fromLA $ processBottomUp removeComment'+removeAllComment :: ArrowXml a => a XmlTree XmlTree+removeAllComment = fromLA $ processBottomUp removeComment' -- ---------- -removeWhiteSpace' :: LA XmlTree XmlTree-removeWhiteSpace' = none `when` isWhiteSpace+removeWhiteSpace' :: LA XmlTree XmlTree+removeWhiteSpace' = none `when` isWhiteSpace -- | -- simple filter for removing whitespace.@@ -468,8 +468,8 @@ -- -- see also : 'removeAllWhiteSpace', 'removeDocWhiteSpace' -removeWhiteSpace :: ArrowXml a => a XmlTree XmlTree-removeWhiteSpace = fromLA $ removeWhiteSpace'+removeWhiteSpace :: ArrowXml a => a XmlTree XmlTree+removeWhiteSpace = fromLA $ removeWhiteSpace' -- | -- simple recursive filter for removing all whitespace.@@ -479,8 +479,8 @@ -- -- see also : 'removeWhiteSpace', 'removeDocWhiteSpace' -removeAllWhiteSpace :: ArrowXml a => a XmlTree XmlTree-removeAllWhiteSpace = fromLA $ processBottomUp removeWhiteSpace'+removeAllWhiteSpace :: ArrowXml a => a XmlTree XmlTree+removeAllWhiteSpace = fromLA $ processBottomUp removeWhiteSpace' -- | -- filter for removing all not significant whitespace.@@ -499,28 +499,28 @@ -- -- see also : 'indentDoc', 'removeAllWhiteSpace' -removeDocWhiteSpace :: ArrowXml a => a XmlTree XmlTree-removeDocWhiteSpace = fromLA $ removeRootWhiteSpace+removeDocWhiteSpace :: ArrowXml a => a XmlTree XmlTree+removeDocWhiteSpace = fromLA $ removeRootWhiteSpace -removeRootWhiteSpace :: LA XmlTree XmlTree+removeRootWhiteSpace :: LA XmlTree XmlTree removeRootWhiteSpace = processChildren processRootElement `when` isRoot where- processRootElement :: LA XmlTree XmlTree+ processRootElement :: LA XmlTree XmlTree processRootElement- = removeWhiteSpace >>> processChild- where- processChild- = choiceA [ isDTD- :-> removeAllWhiteSpace -- whitespace in DTD is redundant- , this- :-> replaceChildren ( getChildren- >>. indentTrees insertNothing False 1- )- ]+ = removeWhiteSpace >>> processChild+ where+ processChild+ = choiceA [ isDTD+ :-> removeAllWhiteSpace -- whitespace in DTD is redundant+ , this+ :-> replaceChildren ( getChildren+ >>. indentTrees insertNothing False 1+ )+ ] -- ------------------------------------------------------------ @@ -544,37 +544,37 @@ -- -- see also : 'removeDocWhiteSpace' -indentDoc :: ArrowXml a => a XmlTree XmlTree-indentDoc = fromLA $- ( ( isRoot `guards` indentRoot )- `orElse`- (root [] [this] >>> indentRoot >>> getChildren)- )+indentDoc :: ArrowXml a => a XmlTree XmlTree+indentDoc = fromLA $+ ( ( isRoot `guards` indentRoot )+ `orElse`+ (root [] [this] >>> indentRoot >>> getChildren)+ ) -- ------------------------------------------------------------ -indentRoot :: LA XmlTree XmlTree-indentRoot = processChildren indentRootChildren+indentRoot :: LA XmlTree XmlTree+indentRoot = processChildren indentRootChildren where indentRootChildren- = removeText >>> indentChild >>> insertNL- where- removeText = none `when` isText- insertNL = this <+> txt "\n"- indentChild = ( replaceChildren- ( getChildren- >>.- indentTrees (insertIndentation 2) False 1- )- `whenNot` isDTD- )+ = removeText >>> indentChild >>> insertNL+ where+ removeText = none `when` isText+ insertNL = this <+> txt "\n"+ indentChild = ( replaceChildren+ ( getChildren+ >>.+ indentTrees (insertIndentation 2) False 1+ )+ `whenNot` isDTD+ ) -- ------------------------------------------------------------ -- -- copied from EditFilter and rewritten for arrows -- to remove dependency to the filter module -indentTrees :: (Int -> LA XmlTree XmlTree) -> Bool -> Int -> XmlTrees -> XmlTrees+indentTrees :: (Int -> LA XmlTree XmlTree) -> Bool -> Int -> XmlTrees -> XmlTrees indentTrees _ _ _ [] = [] indentTrees indentFilter preserveSpace level ts@@ -583,136 +583,136 @@ indentRest rs where runLAs f l- = runLA (constL l >>> f) undefined+ = runLA (constL l >>> f) undefined (ls, rs)- = break XN.isElem ts+ = break XN.isElem ts - isSignificant :: Bool+ isSignificant :: Bool isSignificant- = preserveSpace- ||- (not . null . runLAs isSignificantPart) ls+ = preserveSpace+ ||+ (not . null . runLAs isSignificantPart) ls - isSignificantPart :: LA XmlTree XmlTree+ isSignificantPart :: LA XmlTree XmlTree isSignificantPart- = catA- [ isText `guards` neg isWhiteSpace- , isCdata- , isCharRef- , isEntityRef- ]+ = catA+ [ isText `guards` neg isWhiteSpace+ , isCdata+ , isCharRef+ , isEntityRef+ ] - lsf :: LA XmlTree XmlTree+ lsf :: LA XmlTree XmlTree lsf- | isSignificant- = this- | otherwise- = (none `when` isWhiteSpace)+ | isSignificant+ = this+ | otherwise+ = (none `when` isWhiteSpace) >>> (indentFilter level <+> this) - indentRest :: XmlTrees -> XmlTrees+ indentRest :: XmlTrees -> XmlTrees indentRest []- | isSignificant- = []- | otherwise- = runLA (indentFilter (level - 1)) undefined+ | isSignificant+ = []+ | otherwise+ = runLA (indentFilter (level - 1)) undefined indentRest (t':ts')- = runLA ( ( indentElem- >>>- lsf- )- `when` isElem- ) t'+ = runLA ( ( indentElem+ >>>+ lsf+ )+ `when` isElem+ ) t' ++- ( if null ts'- then indentRest- else indentTrees indentFilter preserveSpace level- ) ts'- where- indentElem- = replaceChildren ( getChildren- >>.- indentChildren- )+ ( if null ts'+ then indentRest+ else indentTrees indentFilter preserveSpace level+ ) ts'+ where+ indentElem+ = replaceChildren ( getChildren+ >>.+ indentChildren+ ) - xmlSpaceAttrValue :: String- xmlSpaceAttrValue- = concat . runLA (getAttrValue "xml:space") $ t'+ xmlSpaceAttrValue :: String+ xmlSpaceAttrValue+ = concat . runLA (getAttrValue "xml:space") $ t' - preserveSpace' :: Bool- preserveSpace'- = ( fromMaybe preserveSpace- .- lookup xmlSpaceAttrValue- ) [ ("preserve", True)- , ("default", False)- ]+ preserveSpace' :: Bool+ preserveSpace'+ = ( fromMaybe preserveSpace+ .+ lookup xmlSpaceAttrValue+ ) [ ("preserve", True)+ , ("default", False)+ ] - indentChildren :: XmlTrees -> XmlTrees- indentChildren cs'- | all (maybe False (all isXmlSpaceChar) . XN.getText) cs'- = []- | otherwise- = indentTrees indentFilter preserveSpace' (level + 1) cs'+ indentChildren :: XmlTrees -> XmlTrees+ indentChildren cs'+ | all (maybe False (all isXmlSpaceChar) . XN.getText) cs'+ = []+ | otherwise+ = indentTrees indentFilter preserveSpace' (level + 1) cs' - + -- filter for indenting elements -insertIndentation :: Int -> Int -> LA a XmlTree+insertIndentation :: Int -> Int -> LA a XmlTree insertIndentation indentWidth level = txt ('\n' : replicate (level * indentWidth) ' ') -- filter for removing all whitespace -insertNothing :: Int -> LA a XmlTree-insertNothing _ = none+insertNothing :: Int -> LA a XmlTree+insertNothing _ = none -- ------------------------------------------------------------ -transfCdata' :: LA XmlTree XmlTree-transfCdata' = (getCdata >>> mkText) `when` isCdata+transfCdata' :: LA XmlTree XmlTree+transfCdata' = (getCdata >>> mkText) `when` isCdata -- | -- converts a CDATA section node into a normal text node -transfCdata :: ArrowXml a => a XmlTree XmlTree-transfCdata = fromLA $- transfCdata'+transfCdata :: ArrowXml a => a XmlTree XmlTree+transfCdata = fromLA $+ transfCdata' -- | -- converts CDATA sections in whole document tree into normal text nodes -transfAllCdata :: ArrowXml a => a XmlTree XmlTree-transfAllCdata = fromLA $- processBottomUp transfCdata'- +transfAllCdata :: ArrowXml a => a XmlTree XmlTree+transfAllCdata = fromLA $+ processBottomUp transfCdata'+ -- -transfCharRef' :: LA XmlTree XmlTree-transfCharRef' = ( getCharRef >>> arr (\ i -> [toEnum i]) >>> mkText )- `when`- isCharRef+transfCharRef' :: LA XmlTree XmlTree+transfCharRef' = ( getCharRef >>> arr (\ i -> [toEnum i]) >>> mkText )+ `when`+ isCharRef -- | -- converts character references to normal text -transfCharRef :: ArrowXml a => a XmlTree XmlTree-transfCharRef = fromLA $- transfCharRef'+transfCharRef :: ArrowXml a => a XmlTree XmlTree+transfCharRef = fromLA $+ transfCharRef' -- | -- recursively converts all character references to normal text -transfAllCharRef :: ArrowXml a => a XmlTree XmlTree-transfAllCharRef = fromLA $- processBottomUp transfCharRef'+transfAllCharRef :: ArrowXml a => a XmlTree XmlTree+transfAllCharRef = fromLA $+ processBottomUp transfCharRef' -- ------------------------------------------------------------ -rememberDTDAttrl :: ArrowList a => a XmlTree XmlTree+rememberDTDAttrl :: ArrowList a => a XmlTree XmlTree rememberDTDAttrl = fromLA $ ( ( addDTDAttrl $< ( getChildren >>> isDTDDoctype >>> getDTDAttrl ) )@@ -723,7 +723,7 @@ addDTDAttrl al = seqA . map (uncurry addAttr) . map (first (dtdPrefix ++)) $ al -addDefaultDTDecl :: ArrowList a => a XmlTree XmlTree+addDefaultDTDecl :: ArrowList a => a XmlTree XmlTree addDefaultDTDecl = fromLA $ ( addDTD $< listA (getAttrl >>> (getName &&& xshow getChildren) >>> hasDtdPrefix) )@@ -740,53 +740,53 @@ <+> txt "\n" <+>- ( getChildren >>> (none `when` isDTDDoctype) ) -- remove old DTD stuff+ ( getChildren >>> (none `when` isDTDDoctype) ) -- remove old DTD stuff ) -- ------------------------------------------------------------ -hasXmlPi :: ArrowXml a => a XmlTree XmlTree+hasXmlPi :: ArrowXml a => a XmlTree XmlTree hasXmlPi = fromLA ( getChildren- >>>- isPi- >>>- hasName t_xml+ >>>+ isPi+ >>>+ hasName t_xml ) -- | add an \<?xml version=\"1.0\"?\> processing instruction -- if it's not already there -addXmlPi :: ArrowXml a => a XmlTree XmlTree+addXmlPi :: ArrowXml a => a XmlTree XmlTree addXmlPi = fromLA ( insertChildrenAt 0 ( ( mkPi (mkSNsName t_xml) none- >>>- addAttr a_version "1.0"- )- <+>- txt "\n"- )- `whenNot`- hasXmlPi+ >>>+ addAttr a_version "1.0"+ )+ <+>+ txt "\n"+ )+ `whenNot`+ hasXmlPi ) -- | add an encoding spec to the \<?xml version=\"1.0\"?\> processing instruction -addXmlPiEncoding :: ArrowXml a => String -> a XmlTree XmlTree+addXmlPiEncoding :: ArrowXml a => String -> a XmlTree XmlTree addXmlPiEncoding enc = fromLA $ processChildren ( addAttr a_encoding enc- `when`- ( isPi >>> hasName t_xml )- )+ `when`+ ( isPi >>> hasName t_xml )+ ) -- | add an XHTML strict doctype declaration to a document addXHtmlDoctypeStrict , addXHtmlDoctypeTransitional- , addXHtmlDoctypeFrameset :: ArrowXml a => a XmlTree XmlTree+ , addXHtmlDoctypeFrameset :: ArrowXml a => a XmlTree XmlTree -- | add an XHTML strict doctype declaration to a document @@ -807,19 +807,19 @@ -- -- The arguments are the root element name, the PUBLIC id and the SYSTEM id -addDoctypeDecl :: ArrowXml a => String -> String -> String -> a XmlTree XmlTree+addDoctypeDecl :: ArrowXml a => String -> String -> String -> a XmlTree XmlTree addDoctypeDecl rootElem public system = fromLA $ replaceChildren ( mkDTDDoctype ( ( if null public then id else ( (k_public, public) : ) )- .- ( if null system then id else ( (k_system, system) : ) )- $ [ (a_name, rootElem) ]- ) none- <+>- txt "\n"- <+>- getChildren+ .+ ( if null system then id else ( (k_system, system) : ) )+ $ [ (a_name, rootElem) ]+ ) none+ <+>+ txt "\n"+ <+>+ getChildren ) -- ------------------------------------------------------------
src/Text/XML/HXT/Arrow/GeneralEntitySubstitution.hs view
@@ -20,7 +20,7 @@ ( processGeneralEntities ) where -import Control.Arrow -- arrow classes+import Control.Arrow -- arrow classes import Control.Arrow.ArrowList import Control.Arrow.ArrowIf import Control.Arrow.ArrowTree@@ -55,27 +55,27 @@ = ReferenceInContent | ReferenceInAttributeValue | ReferenceInEntityValue- -- or OccursInAttributeValue -- not used during substitution but during validation- -- or ReferenceInDTD -- not used: syntax check detects errors+ -- 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 GESubstArrow = GEContext -> RecList -> GEArrow XmlTree XmlTree -type GEArrow b c = IOStateArrow GEEnv b c+type GEArrow b c = IOStateArrow GEEnv b c -type RecList = [String]+type RecList = [String] -- ------------------------------------------------------------ -newtype GEEnv = GEEnv (M.Map String GESubstArrow)+newtype GEEnv = GEEnv (M.Map String GESubstArrow) -emptyGeEnv :: GEEnv-emptyGeEnv = GEEnv M.empty+emptyGeEnv :: GEEnv+emptyGeEnv = GEEnv M.empty -lookupGeEnv :: String -> GEEnv -> Maybe GESubstArrow+lookupGeEnv :: String -> GEEnv -> Maybe GESubstArrow lookupGeEnv k (GEEnv env) = M.lookup k env -addGeEntry :: String -> GESubstArrow -> GEEnv -> GEEnv+addGeEntry :: String -> GESubstArrow -> GEEnv -> GEEnv addGeEntry k a (GEEnv env) = GEEnv $ M.insert k a env @@ -86,258 +86,258 @@ -- -- input: a complete document tree including root node -processGeneralEntities :: IOStateArrow s XmlTree XmlTree+processGeneralEntities :: IOStateArrow s XmlTree XmlTree processGeneralEntities = ( traceMsg 1 "processGeneralEntities: collect and substitute general entities"- >>>- withOtherUserState emptyGeEnv (processChildren (processGeneralEntity ReferenceInContent []))- >>>- setDocumentStatusFromSystemState "in general entity processing"- >>>- traceTree- >>>- traceSource+ >>>+ withOtherUserState emptyGeEnv (processChildren (processGeneralEntity ReferenceInContent []))+ >>>+ setDocumentStatusFromSystemState "in general entity processing"+ >>>+ traceTree+ >>>+ traceSource ) `when` documentStatusOk - -processGeneralEntity :: GESubstArrow++processGeneralEntity :: GESubstArrow processGeneralEntity context recl- = choiceA [ isElem :-> ( processAttrl (processChildren substEntitiesInAttrValue)- >>>- processChildren (processGeneralEntity context recl)- )- , isDTDDoctype :-> processChildren (processGeneralEntity context recl)- , isDTDEntity :-> addEntityDecl- , isDTDAttlist :-> substEntitiesInAttrDefaultValue- , isEntityRef :-> substEntityRef- , this :-> this- ]+ = choiceA [ isElem :-> ( processAttrl (processChildren substEntitiesInAttrValue)+ >>>+ processChildren (processGeneralEntity context recl)+ )+ , isDTDDoctype :-> processChildren (processGeneralEntity context recl)+ , isDTDEntity :-> addEntityDecl+ , isDTDAttlist :-> substEntitiesInAttrDefaultValue+ , isEntityRef :-> substEntityRef+ , this :-> this+ ] where- addEntityDecl :: GEArrow XmlTree XmlTree+ addEntityDecl :: GEArrow XmlTree XmlTree addEntityDecl- = perform ( choiceA [ isIntern :-> addInternalEntity -- don't change sequence of cases- , isExtern :-> addExternalEntity- , isUnparsed :-> addUnparsedEntity- ]- )- where- isIntern = none `when` hasDTDAttr k_system- isExtern = none `when` hasDTDAttr k_ndata- isUnparsed = this+ = perform ( choiceA [ isIntern :-> addInternalEntity -- don't change sequence of cases+ , isExtern :-> addExternalEntity+ , isUnparsed :-> addUnparsedEntity+ ]+ )+ where+ isIntern = none `when` hasDTDAttr k_system+ isExtern = none `when` hasDTDAttr k_ndata+ isUnparsed = this - addInternalEntity :: GEArrow XmlTree b+ addInternalEntity :: GEArrow XmlTree b addInternalEntity- = ( ( getDTDAttrValue a_name- >>>- traceValue 2 (("processGeneralEntity: general entity definition for " ++) . show)- )- &&&- xshow (getChildren >>> isText)- )+ = ( ( getDTDAttrValue a_name+ >>>+ traceValue 2 (("processGeneralEntity: general entity definition for " ++) . show)+ )+ &&&+ xshow (getChildren >>> isText)+ ) >>>- applyA ( arr2 $ \ entity str ->- listA ( ( ( txt str- >>>- parseXmlGeneralEntityValue ("general internal entity" ++ show entity)- >>>- filterErrorMsg- )- `orElse` txt ""- )- >>>- processGeneralEntity ReferenceInEntityValue (entity : recl)- )- >>>- applyA (arr $ \ ts -> insertEntity (substInternal ts) entity)- )- >>>- none+ applyA ( arr2 $ \ entity str ->+ listA ( ( ( txt str+ >>>+ parseXmlGeneralEntityValue ("general internal entity" ++ show entity)+ >>>+ filterErrorMsg+ )+ `orElse` txt ""+ )+ >>>+ processGeneralEntity ReferenceInEntityValue (entity : recl)+ )+ >>>+ applyA (arr $ \ ts -> insertEntity (substInternal ts) entity)+ )+ >>>+ none - addExternalEntity :: GEArrow XmlTree b+ addExternalEntity :: GEArrow XmlTree b addExternalEntity- = ( ( getDTDAttrValue a_name- >>>- traceValue 2 (("processGeneralEntity: external entity definition for " ++) . show)+ = ( ( getDTDAttrValue a_name+ >>>+ traceValue 2 (("processGeneralEntity: external entity definition for " ++) . show) )- &&&- getDTDAttrValue a_url -- the absolute URL, not the relative in attr: k_system- )- >>>- applyA (arr2 $ \ entity uri -> insertEntity (substExternalParsed1Time uri) entity)- >>>- none+ &&&+ getDTDAttrValue a_url -- the absolute URL, not the relative in attr: k_system+ )+ >>>+ applyA (arr2 $ \ entity uri -> insertEntity (substExternalParsed1Time uri) entity)+ >>>+ none - addUnparsedEntity :: GEArrow XmlTree b+ addUnparsedEntity :: GEArrow XmlTree b addUnparsedEntity- = getDTDAttrValue a_name- >>>- traceValue 2 (("processGeneralEntity: unparsed entity definition for " ++) . show)+ = getDTDAttrValue a_name >>>- applyA (arr (insertEntity substUnparsed))- >>>- none+ traceValue 2 (("processGeneralEntity: unparsed entity definition for " ++) . show)+ >>>+ applyA (arr (insertEntity substUnparsed))+ >>>+ none - insertEntity :: (String -> GESubstArrow) -> String -> GEArrow b b+ insertEntity :: (String -> GESubstArrow) -> String -> GEArrow b b insertEntity fct entity- = ( getUserState- >>>- applyA (arr checkDefined)- )- `guards`- addEntity fct entity- where- checkDefined geEnv- = maybe ok alreadyDefined . lookupGeEnv entity $ geEnv- where- ok = this- alreadyDefined _- = issueWarn ("entity " ++ show entity ++ " already defined, repeated definition ignored")+ = ( getUserState+ >>>+ applyA (arr checkDefined)+ )+ `guards`+ addEntity fct entity+ where+ checkDefined geEnv+ = maybe ok alreadyDefined . lookupGeEnv entity $ geEnv+ where+ ok = this+ alreadyDefined _+ = issueWarn ("entity " ++ show entity ++ " already defined, repeated definition ignored") - addEntity :: (String -> GESubstArrow) -> String -> GEArrow b b+ addEntity :: (String -> GESubstArrow) -> String -> GEArrow b b addEntity fct entity- = changeUserState ins- where- ins _ geEnv = addGeEntry entity (fct entity) geEnv+ = changeUserState ins+ where+ ins _ geEnv = addGeEntry entity (fct entity) geEnv - substEntitiesInAttrDefaultValue :: GEArrow XmlTree XmlTree+ substEntitiesInAttrDefaultValue :: GEArrow XmlTree XmlTree substEntitiesInAttrDefaultValue- = applyA ( xshow ( getDTDAttrValue a_default -- parse the default value- >>> -- substitute entities- mkText -- and convert value into a string- >>>- parseXmlAttrValue "default value of attribute"- >>>- filterErrorMsg- >>>- substEntitiesInAttrValue- )- >>> arr (setDTDAttrValue a_default)- )+ = applyA ( xshow ( getDTDAttrValue a_default -- parse the default value+ >>> -- substitute entities+ mkText -- and convert value into a string+ >>>+ parseXmlAttrValue "default value of attribute"+ >>>+ filterErrorMsg+ >>>+ substEntitiesInAttrValue+ )+ >>> arr (setDTDAttrValue a_default)+ ) `when` hasDTDAttr a_default - substEntitiesInAttrValue :: GEArrow XmlTree XmlTree+ substEntitiesInAttrValue :: GEArrow XmlTree XmlTree substEntitiesInAttrValue- = ( processGeneralEntity ReferenceInAttributeValue recl- `when`- isEntityRef- )+ = ( processGeneralEntity ReferenceInAttributeValue recl+ `when`+ isEntityRef+ ) >>>- changeText normalizeWhiteSpace- >>>- transfCharRef- where- normalizeWhiteSpace = map ( \c -> if c `elem` "\n\t\r" then ' ' else c )+ changeText normalizeWhiteSpace+ >>>+ transfCharRef+ where+ normalizeWhiteSpace = map ( \c -> if c `elem` "\n\t\r" then ' ' else c ) - substEntityRef :: GEArrow XmlTree XmlTree+ substEntityRef :: GEArrow XmlTree XmlTree substEntityRef- = applyA ( ( ( getEntityRef -- get the entity name and the env- >>> -- and compute the arrow to be applied- traceValue 2 (("processGeneralEntity: entity reference for entity " ++) . show)- >>>- traceMsg 3 ("recursion list = " ++ show recl)- )- &&&- getUserState- ) >>>- arr2 substA- )- `orElse` this- where- substA :: String -> GEEnv -> GEArrow XmlTree XmlTree- substA entity geEnv- = maybe entityNotFound entityFound . lookupGeEnv entity $ geEnv- where- errMsg msg- = issueErr msg+ = applyA ( ( ( getEntityRef -- get the entity name and the env+ >>> -- and compute the arrow to be applied+ traceValue 2 (("processGeneralEntity: entity reference for entity " ++) . show)+ >>>+ traceMsg 3 ("recursion list = " ++ show recl)+ )+ &&&+ getUserState+ ) >>>+ arr2 substA+ )+ `orElse` this+ where+ substA :: String -> GEEnv -> GEArrow XmlTree XmlTree+ substA entity geEnv+ = maybe entityNotFound entityFound . lookupGeEnv entity $ geEnv+ where+ errMsg msg+ = issueErr msg - entityNotFound- = errMsg ("general entity reference \"&" ++ entity ++ ";\" not processed, no definition found, (forward reference?)")+ entityNotFound+ = errMsg ("general entity reference \"&" ++ entity ++ ";\" not processed, no definition found, (forward reference?)") - entityFound fct- | entity `elem` recl- = errMsg ("general entity reference \"&" ++ entity ++ ";\" not processed, cyclic definition")- | otherwise- = fct context recl+ entityFound fct+ | entity `elem` recl+ = errMsg ("general entity reference \"&" ++ entity ++ ";\" not processed, cyclic definition")+ | otherwise+ = fct context recl - substExternalParsed1Time :: String -> String -> GESubstArrow+ substExternalParsed1Time :: String -> String -> GESubstArrow substExternalParsed1Time uri entity cx rl- = perform ( traceMsg 2 ("substExternalParsed1Time: read and parse external parsed entity " ++ show entity)- >>>- runInLocalURIContext ( root [sattr a_source uri] [] -- uri must be an absolute uri- >>> -- abs uri is computed during parameter entity handling- listA ( getXmlEntityContents- >>>- processExternalEntityContents- )- )- >>>- applyA ( arr $ \ ts -> addEntity (substExternalParsed ts) entity )- )- >>>- processGeneralEntity cx rl- where- processExternalEntityContents :: IOStateArrow s XmlTree XmlTree- processExternalEntityContents- = ( ( documentStatusOk -- reading entity succeeded- >>> -- with content stored in a text node- (getChildren >>> isText)- )- `guards`- ( getChildren- >>>- parseXmlGeneralEntityValue ("external parsed entity " ++ show entity)- >>>- filterErrorMsg- )- )- `orElse`- issueErr ("illegal value for external parsed entity " ++ show entity)+ = perform ( traceMsg 2 ("substExternalParsed1Time: read and parse external parsed entity " ++ show entity)+ >>>+ runInLocalURIContext ( root [sattr a_source uri] [] -- uri must be an absolute uri+ >>> -- abs uri is computed during parameter entity handling+ listA ( getXmlEntityContents+ >>>+ processExternalEntityContents+ )+ )+ >>>+ applyA ( arr $ \ ts -> addEntity (substExternalParsed ts) entity )+ )+ >>>+ processGeneralEntity cx rl+ where+ processExternalEntityContents :: IOStateArrow s XmlTree XmlTree+ processExternalEntityContents+ = ( ( documentStatusOk -- reading entity succeeded+ >>> -- with content stored in a text node+ (getChildren >>> isText)+ )+ `guards`+ ( getChildren+ >>>+ parseXmlGeneralEntityValue ("external parsed entity " ++ show entity)+ >>>+ filterErrorMsg+ )+ )+ `orElse`+ issueErr ("illegal value for external parsed entity " ++ show entity) - substExternalParsed :: XmlTrees -> String -> GESubstArrow- substExternalParsed ts entity ReferenceInContent rl = includedIfValidating ts rl entity- substExternalParsed _ entity ReferenceInAttributeValue _+ substExternalParsed :: XmlTrees -> String -> GESubstArrow+ substExternalParsed ts entity ReferenceInContent rl = includedIfValidating ts rl entity+ substExternalParsed _ entity ReferenceInAttributeValue _ = forbidden entity "external parsed general" "in attribute value"- substExternalParsed _ _ ReferenceInEntityValue _+ substExternalParsed _ _ ReferenceInEntityValue _ = bypassed - substInternal :: XmlTrees -> String -> GESubstArrow- substInternal ts entity ReferenceInContent rl = included ts rl entity+ substInternal :: XmlTrees -> String -> GESubstArrow+ substInternal ts entity ReferenceInContent rl = included ts rl entity substInternal ts entity ReferenceInAttributeValue rl= includedInLiteral ts rl entity- substInternal _ _ ReferenceInEntityValue _ = bypassed+ substInternal _ _ ReferenceInEntityValue _ = bypassed - substUnparsed :: String -> GESubstArrow- substUnparsed entity ReferenceInContent _ = forbidden entity "unparsed" "content"- substUnparsed entity ReferenceInAttributeValue _ = forbidden entity "unparsed" "attribute value"- substUnparsed entity ReferenceInEntityValue _ = forbidden entity "unparsed" "entity value"+ substUnparsed :: String -> GESubstArrow+ substUnparsed entity ReferenceInContent _ = forbidden entity "unparsed" "content"+ substUnparsed entity ReferenceInAttributeValue _ = forbidden entity "unparsed" "attribute value"+ substUnparsed entity ReferenceInEntityValue _ = forbidden entity "unparsed" "entity value" - -- XML 1.0 chapter 4.4.2- included :: XmlTrees -> RecList -> String -> GEArrow XmlTree XmlTree+ -- XML 1.0 chapter 4.4.2+ included :: XmlTrees -> RecList -> String -> GEArrow XmlTree XmlTree included ts rl entity- = arrL (const ts)- >>>- processGeneralEntity context (entity : rl)+ = arrL (const ts)+ >>>+ processGeneralEntity context (entity : rl) - -- XML 1.0 chapter 4.4.3- includedIfValidating :: XmlTrees -> RecList -> String -> GEArrow XmlTree XmlTree+ -- XML 1.0 chapter 4.4.3+ includedIfValidating :: XmlTrees -> RecList -> String -> GEArrow XmlTree XmlTree includedIfValidating- = included+ = included - -- XML 1.0 chapter 4.4.4- forbidden :: String -> String -> String -> GEArrow XmlTree XmlTree+ -- XML 1.0 chapter 4.4.4+ forbidden :: String -> String -> String -> GEArrow XmlTree XmlTree forbidden entity msg cx- = issueErr ("reference of " ++ msg ++ show entity ++ " forbidden in " ++ cx)+ = issueErr ("reference of " ++ msg ++ show entity ++ " forbidden in " ++ cx) - -- XML 1.0 chapter 4.4.5- includedInLiteral :: XmlTrees -> RecList -> String -> GEArrow XmlTree XmlTree+ -- XML 1.0 chapter 4.4.5+ includedInLiteral :: XmlTrees -> RecList -> String -> GEArrow XmlTree XmlTree includedInLiteral- = included+ = included - -- XML 1.0 chapter 4.4.7- bypassed :: GEArrow XmlTree XmlTree+ -- XML 1.0 chapter 4.4.7+ bypassed :: GEArrow XmlTree XmlTree bypassed- = this+ = this -- ------------------------------------------------------------
src/Text/XML/HXT/Arrow/Namespace.hs view
@@ -31,7 +31,7 @@ ) where -import Control.Arrow -- arrow classes+import Control.Arrow -- arrow classes import Control.Arrow.ArrowList import Control.Arrow.ArrowIf import Control.Arrow.ArrowTree@@ -40,16 +40,16 @@ import Text.XML.HXT.DOM.Interface import Text.XML.HXT.Arrow.XmlArrow -import Data.Maybe ( isNothing- , fromJust- )-import Data.List ( nub )+import Data.Maybe ( isNothing+ , fromJust+ )+import Data.List ( nub ) -- ------------------------------------------------------------ -- | test whether an attribute node contains an XML Namespace declaration -isNamespaceDeclAttr :: ArrowXml a => a XmlTree XmlTree+isNamespaceDeclAttr :: ArrowXml a => a XmlTree XmlTree isNamespaceDeclAttr = fromLA $ (getAttrName >>> isA isNameSpaceName) `guards` this@@ -58,19 +58,19 @@ -- an attribute tree with a namespace declaration (see 'isNamespaceDeclAttr') -- for all other nodes this arrow fails -getNamespaceDecl :: ArrowXml a => a XmlTree (String, String)+getNamespaceDecl :: ArrowXml a => a XmlTree (String, String) getNamespaceDecl = fromLA $ isNamespaceDeclAttr >>> ( ( getAttrName- >>>- arr getNsPrefix- )- &&& xshow getChildren+ >>>+ arr getNsPrefix+ )+ &&& xshow getChildren ) where- getNsPrefix = drop 6 . qualifiedName -- drop "xmlns:"+ getNsPrefix = drop 6 . qualifiedName -- drop "xmlns:" -- ------------------------------------------------------------ @@ -78,7 +78,7 @@ -- -- apply 'getNamespaceDecl' to a whole XmlTree -collectNamespaceDecl :: LA XmlTree (String, String)+collectNamespaceDecl :: LA XmlTree (String, String) collectNamespaceDecl = multi getAttrl >>> getNamespaceDecl -- | collect all (namePrefix, namespaceUri) pairs from a tree@@ -88,7 +88,7 @@ -- namespace cleanup, e.g. for documents generated with XSLT. It can be used -- together with 'collectNamespaceDecl' to 'cleanupNamespaces' -collectPrefixUriPairs :: LA XmlTree (String, String)+collectPrefixUriPairs :: LA XmlTree (String, String) collectPrefixUriPairs = multi (isElem <+> getAttrl <+> isPi) >>>@@ -96,16 +96,16 @@ >>> arrL getPrefixUri where- getPrefixUri :: QName -> [(String, String)]+ getPrefixUri :: QName -> [(String, String)] getPrefixUri n- | null uri = []- | px == a_xmlns- ||- px == a_xml = [] -- these ones are reserved an predefined- | otherwise = [(namePrefix n, uri)]- where- uri = namespaceUri n- px = namePrefix n+ | null uri = []+ | px == a_xmlns+ ||+ px == a_xml = [] -- these ones are reserved an predefined+ | otherwise = [(namePrefix n, uri)]+ where+ uri = namespaceUri n+ px = namePrefix n -- ------------------------------------------------------------ @@ -113,7 +113,7 @@ -- -- Calls 'cleanupNamespaces' with 'collectNamespaceDecl' -uniqueNamespaces :: ArrowXml a => a XmlTree XmlTree+uniqueNamespaces :: ArrowXml a => a XmlTree XmlTree uniqueNamespaces = fromLA $ cleanupNamespaces collectNamespaceDecl@@ -123,7 +123,7 @@ -- useful for cleanup of namespaces in generated documents. -- Calls 'cleanupNamespaces' with @ collectNamespaceDecl \<+> collectPrefixUriPairs @ -uniqueNamespacesFromDeclAndQNames :: ArrowXml a => a XmlTree XmlTree+uniqueNamespacesFromDeclAndQNames :: ArrowXml a => a XmlTree XmlTree uniqueNamespacesFromDeclAndQNames = fromLA $ cleanupNamespaces (collectNamespaceDecl <+> collectPrefixUriPairs)@@ -132,58 +132,58 @@ -- -- The parameter is used for collecting namespace uris and prefixes from the input tree -cleanupNamespaces :: LA XmlTree (String, String) -> LA XmlTree XmlTree+cleanupNamespaces :: LA XmlTree (String, String) -> LA XmlTree XmlTree cleanupNamespaces collectNamespaces = renameNamespaces $< (listA collectNamespaces >>^ (toNsEnv >>> nub)) where renameNamespaces :: NsEnv -> LA XmlTree XmlTree renameNamespaces env- = processBottomUp- ( processAttrl- ( ( none `when` isNamespaceDeclAttr ) -- remove all namespace declarations- >>>- changeQName renamePrefix -- update namespace prefix of attribute names, if namespace uri is set- )- >>>- changeQName renamePrefix -- update namespace prefix of element names- )- >>>- attachEnv env1 -- all all namespaces as attributes to the root node attribute list- where- renamePrefix :: QName -> QName- renamePrefix n- | isNullXName uri = n- | isNothing newPx = n- | otherwise = setNamePrefix' (fromJust newPx) n- where- uri = namespaceUri' n- newPx = lookup uri revEnv1- + = processBottomUp+ ( processAttrl+ ( ( none `when` isNamespaceDeclAttr ) -- remove all namespace declarations+ >>>+ changeQName renamePrefix -- update namespace prefix of attribute names, if namespace uri is set+ )+ >>>+ changeQName renamePrefix -- update namespace prefix of element names+ )+ >>>+ attachEnv env1 -- all all namespaces as attributes to the root node attribute list+ where+ renamePrefix :: QName -> QName+ renamePrefix n+ | isNullXName uri = n+ | isNothing newPx = n+ | otherwise = setNamePrefix' (fromJust newPx) n+ where+ uri = namespaceUri' n+ newPx = lookup uri revEnv1+ revEnv1 = map (\ (x, y) -> (y, x)) env1 - env1 :: NsEnv- env1 = newEnv [] uris+ env1 :: NsEnv+ env1 = newEnv [] uris - uris :: [XName]- uris = nub . map snd $ env+ uris :: [XName]+ uris = nub . map snd $ env - genPrefixes :: [XName]+ genPrefixes :: [XName] genPrefixes = map (newXName . ("ns" ++) . show) [(0::Int)..] - newEnv :: NsEnv -> [XName] -> NsEnv- newEnv env' []- = env'+ newEnv :: NsEnv -> [XName] -> NsEnv+ newEnv env' []+ = env' - newEnv env' (uri:rest)- = newEnv env'' rest- where- env'' = (prefix, uri) : env'- prefix- = head (filter notAlreadyUsed $ preferedPrefixes ++ genPrefixes)- preferedPrefixes- = map fst . filter ((==uri).snd) $ env- notAlreadyUsed s- = isNothing . lookup s $ env'+ newEnv env' (uri:rest)+ = newEnv env'' rest+ where+ env'' = (prefix, uri) : env'+ prefix+ = head (filter notAlreadyUsed $ preferedPrefixes ++ genPrefixes)+ preferedPrefixes+ = map fst . filter ((==uri).snd) $ env+ notAlreadyUsed s+ = isNothing . lookup s $ env' -- ------------------------------------------------------------ @@ -194,29 +194,29 @@ -- The namespace environment is implemented as a 'Data.AssocList.AssocList'. -- Processing of attributes can be controlled by a boolean parameter -processWithNsEnv1 :: ArrowXml a => Bool -> (NsEnv -> a XmlTree XmlTree) -> NsEnv -> a XmlTree XmlTree+processWithNsEnv1 :: ArrowXml a => Bool -> (NsEnv -> a XmlTree XmlTree) -> NsEnv -> a XmlTree XmlTree processWithNsEnv1 withAttr f env- = ifA isElem -- the test is just an optimization- ( processWithExtendedEnv $< arr (extendEnv env) ) -- only element nodes contain namespace declarations+ = ifA isElem -- the test is just an optimization+ ( processWithExtendedEnv $< arr (extendEnv env) ) -- only element nodes contain namespace declarations ( processWithExtendedEnv env ) where processWithExtendedEnv env'- = f env' -- apply the env filter- >>>- ( ( if withAttr- then processAttrl (f env') -- apply the env to all attributes- else this- )- >>>- processChildren (processWithNsEnv f env') -- apply the env recursively to all children- )- `when` isElem -- attrl and children only need processing for elem nodes+ = f env' -- apply the env filter+ >>>+ ( ( if withAttr+ then processAttrl (f env') -- apply the env to all attributes+ else this+ )+ >>>+ processChildren (processWithNsEnv f env') -- apply the env recursively to all children+ )+ `when` isElem -- attrl and children only need processing for elem nodes - extendEnv :: NsEnv -> XmlTree -> NsEnv+ extendEnv :: NsEnv -> XmlTree -> NsEnv extendEnv env' t'- = addEntries (toNsEnv newDecls) env'- where- newDecls = runLA ( getAttrl >>> getNamespaceDecl ) t'+ = addEntries (toNsEnv newDecls) env'+ where+ newDecls = runLA ( getAttrl >>> getNamespaceDecl ) t' -- ------------------------------------------------------------ @@ -225,16 +225,16 @@ -- -- The namespace environment is implemented as a 'Data.AssocList.AssocList' -processWithNsEnv :: ArrowXml a => (NsEnv -> a XmlTree XmlTree) -> NsEnv -> a XmlTree XmlTree-processWithNsEnv = processWithNsEnv1 True+processWithNsEnv :: ArrowXml a => (NsEnv -> a XmlTree XmlTree) -> NsEnv -> a XmlTree XmlTree+processWithNsEnv = processWithNsEnv1 True -- | process all element nodes of a document tree with an arrow, containing always the -- valid namespace environment as extra parameter. Attribute lists are not processed. -- -- See also: 'processWithNsEnv' -processWithNsEnvWithoutAttrl :: ArrowXml a => (NsEnv -> a XmlTree XmlTree) -> NsEnv -> a XmlTree XmlTree-processWithNsEnvWithoutAttrl = processWithNsEnv1 False+processWithNsEnvWithoutAttrl :: ArrowXml a => (NsEnv -> a XmlTree XmlTree) -> NsEnv -> a XmlTree XmlTree+processWithNsEnvWithoutAttrl = processWithNsEnv1 False -- ----------------------------------------------------------------------------- @@ -243,29 +243,29 @@ -- This arrow is useful for document processing, that requires access to all namespace -- declarations at any element node, but which cannot be done with a simple 'processWithNsEnv'. -attachNsEnv :: ArrowXml a => NsEnv -> a XmlTree XmlTree+attachNsEnv :: ArrowXml a => NsEnv -> a XmlTree XmlTree attachNsEnv initialEnv = fromLA $ processWithNsEnvWithoutAttrl attachEnv initialEnv where -attachEnv :: NsEnv -> LA XmlTree XmlTree+attachEnv :: NsEnv -> LA XmlTree XmlTree attachEnv env = ( processAttrl (none `when` isNamespaceDeclAttr)- >>>- addAttrl (catA nsAttrl)+ >>>+ addAttrl (catA nsAttrl) ) `when` isElem where- nsAttrl :: [LA XmlTree XmlTree]- nsAttrl = map nsDeclToAttr env+ nsAttrl :: [LA XmlTree XmlTree]+ nsAttrl = map nsDeclToAttr env - nsDeclToAttr :: (XName, XName) -> LA XmlTree XmlTree+ nsDeclToAttr :: (XName, XName) -> LA XmlTree XmlTree nsDeclToAttr (n, uri)- = mkAttr qn (txt (show uri))- where- qn :: QName- qn | isNullXName n = mkQName' nullXName xmlnsXName xmlnsNamespaceXName- | otherwise = mkQName' xmlnsXName n xmlnsNamespaceXName+ = mkAttr qn (txt (show uri))+ where+ qn :: QName+ qn | isNullXName n = mkQName' nullXName xmlnsXName xmlnsNamespaceXName+ | otherwise = mkQName' xmlnsXName n xmlnsNamespaceXName -- ----------------------------------------------------------------------------- @@ -277,39 +277,39 @@ -- -- The arrow may be applied repeatedly if neccessary. -propagateNamespaces :: ArrowXml a => a XmlTree XmlTree-propagateNamespaces = fromLA $- propagateNamespaceEnv [ (xmlXName, xmlNamespaceXName)- , (xmlnsXName, xmlnsNamespaceXName)- ]+propagateNamespaces :: ArrowXml a => a XmlTree XmlTree+propagateNamespaces = fromLA $+ propagateNamespaceEnv [ (xmlXName, xmlNamespaceXName)+ , (xmlnsXName, xmlnsNamespaceXName)+ ] -- | -- attaches the namespace info given by the namespace table -- to a tag node and its attributes and children. -propagateNamespaceEnv :: NsEnv -> LA XmlTree XmlTree+propagateNamespaceEnv :: NsEnv -> LA XmlTree XmlTree propagateNamespaceEnv = processWithNsEnv addNamespaceUri where- addNamespaceUri :: NsEnv -> LA XmlTree XmlTree+ addNamespaceUri :: NsEnv -> LA XmlTree XmlTree addNamespaceUri env'- = choiceA [ isElem :-> changeElemName (setNamespace env')- , isAttr :-> attachNamespaceUriToAttr env'- , isPi :-> changePiName (setNamespace env')- , this :-> this- ]+ = choiceA [ isElem :-> changeElemName (setNamespace env')+ , isAttr :-> attachNamespaceUriToAttr env'+ , isPi :-> changePiName (setNamespace env')+ , this :-> this+ ] - attachNamespaceUriToAttr :: NsEnv -> LA XmlTree XmlTree+ attachNamespaceUriToAttr :: NsEnv -> LA XmlTree XmlTree attachNamespaceUriToAttr attrEnv- = ( ( getQName >>> isA (not . null . namePrefix) )- `guards`- changeAttrName (setNamespace attrEnv)- )+ = ( ( getQName >>> isA (not . null . namePrefix) )+ `guards`+ changeAttrName (setNamespace attrEnv)+ ) `orElse`- ( changeAttrName (const xmlnsQN)- `when`- hasName a_xmlns- )+ ( changeAttrName (const xmlnsQN)+ `when`+ hasName a_xmlns+ ) -- ----------------------------------------------------------------------------- @@ -320,96 +320,96 @@ -- Predicates 'isWellformedQName', 'isWellformedQualifiedName', 'isDeclaredNamespace' -- and 'isWellformedNSDecl' are applied to the appropriate elements and attributes. -validateNamespaces :: ArrowXml a => a XmlTree XmlTree-validateNamespaces = fromLA validateNamespaces1+validateNamespaces :: ArrowXml a => a XmlTree XmlTree+validateNamespaces = fromLA validateNamespaces1 -validateNamespaces1 :: LA XmlTree XmlTree+validateNamespaces1 :: LA XmlTree XmlTree validateNamespaces1- = choiceA [ isRoot :-> ( getChildren >>> validateNamespaces1 ) -- root is correct by definition- , this :-> multi validate1Namespaces- ]+ = choiceA [ isRoot :-> ( getChildren >>> validateNamespaces1 ) -- root is correct by definition+ , this :-> multi validate1Namespaces+ ] -- | -- a single node for namespace constrains. -validate1Namespaces :: LA XmlTree XmlTree+validate1Namespaces :: LA XmlTree XmlTree validate1Namespaces = choiceA- [ isElem :-> catA [ ( getQName >>> isA ( not . isWellformedQName )- )- `guards` nsError (\ n -> "element name " ++ show n ++ " is not a wellformed qualified name" )+ [ isElem :-> catA [ ( getQName >>> isA ( not . isWellformedQName )+ )+ `guards` nsError (\ n -> "element name " ++ show n ++ " is not a wellformed qualified name" ) - , ( getQName >>> isA ( not . isDeclaredNamespace )- )- `guards` nsError (\ n -> "namespace for prefix in element name " ++ show n ++ " is undefined" )+ , ( getQName >>> isA ( not . isDeclaredNamespace )+ )+ `guards` nsError (\ n -> "namespace for prefix in element name " ++ show n ++ " is undefined" ) - , doubleOcc $< ( (getAttrl >>> getUniversalName) >>. doubles )+ , doubleOcc $< ( (getAttrl >>> getUniversalName) >>. doubles ) - , getAttrl >>> validate1Namespaces- ]+ , getAttrl >>> validate1Namespaces+ ] - , isAttr :-> catA [ ( getQName >>> isA ( not . isWellformedQName )- )- `guards` nsError (\ n -> "attribute name " ++ show n ++ " is not a wellformed qualified name" )+ , isAttr :-> catA [ ( getQName >>> isA ( not . isWellformedQName )+ )+ `guards` nsError (\ n -> "attribute name " ++ show n ++ " is not a wellformed qualified name" ) - , ( getQName >>> isA ( not . isDeclaredNamespace )- )- `guards` nsError (\ n -> "namespace for prefix in attribute name " ++ show n ++ " is undefined" )+ , ( getQName >>> isA ( not . isDeclaredNamespace )+ )+ `guards` nsError (\ n -> "namespace for prefix in attribute name " ++ show n ++ " is undefined" ) - , ( hasNamePrefix a_xmlns >>> xshow getChildren >>> isA null- )- `guards` nsError (\ n -> "namespace value of namespace declaration for " ++ show n ++ " has no value" )+ , ( hasNamePrefix a_xmlns >>> xshow getChildren >>> isA null+ )+ `guards` nsError (\ n -> "namespace value of namespace declaration for " ++ show n ++ " has no value" ) , ( getQName >>> isA (not . isWellformedNSDecl )- )- `guards` nsError (\ n -> "illegal namespace declaration for name " ++ n ++ " starting with reserved prefix " ++ show "xml" )- ]+ )+ `guards` nsError (\ n -> "illegal namespace declaration for name " ++ n ++ " starting with reserved prefix " ++ show "xml" )+ ] - , isDTD :-> catA [ isDTDDoctype <+> isDTDAttlist <+> isDTDElement <+> isDTDName- >>>- getDTDAttrValue a_name- >>>- ( isA (not . isWellformedQualifiedName)- `guards`- nsErr (\ n -> "a DTD part contains a not wellformed qualified Name: " ++ show n)- )+ , isDTD :-> catA [ isDTDDoctype <+> isDTDAttlist <+> isDTDElement <+> isDTDName+ >>>+ getDTDAttrValue a_name+ >>>+ ( isA (not . isWellformedQualifiedName)+ `guards`+ nsErr (\ n -> "a DTD part contains a not wellformed qualified Name: " ++ show n)+ ) - , isDTDAttlist- >>>- getDTDAttrValue a_value- >>>- ( isA (not . isWellformedQualifiedName)- `guards`- nsErr (\ n -> "an ATTLIST declaration contains as attribute name a not wellformed qualified Name: " ++ show n)- )+ , isDTDAttlist+ >>>+ getDTDAttrValue a_value+ >>>+ ( isA (not . isWellformedQualifiedName)+ `guards`+ nsErr (\ n -> "an ATTLIST declaration contains as attribute name a not wellformed qualified Name: " ++ show n)+ ) , isDTDEntity <+> isDTDPEntity <+> isDTDNotation- >>>- getDTDAttrValue a_name- >>>- ( isA (not . isNCName)+ >>>+ getDTDAttrValue a_name+ >>>+ ( isA (not . isNCName) `guards`- nsErr (\ n -> "an entity or notation declaration contains a not wellformed NCName: " ++ show n)- )- ]- , isPi :-> catA [ getName- >>>- ( isA (not . isNCName)- `guards`- nsErr (\ n -> "a PI contains a not wellformed NCName: " ++ show n)- )- ]+ nsErr (\ n -> "an entity or notation declaration contains a not wellformed NCName: " ++ show n)+ )+ ]+ , isPi :-> catA [ getName+ >>>+ ( isA (not . isNCName)+ `guards`+ nsErr (\ n -> "a PI contains a not wellformed NCName: " ++ show n)+ )+ ] ] where- nsError :: (String -> String) -> LA XmlTree XmlTree+ nsError :: (String -> String) -> LA XmlTree XmlTree nsError msg- = (getQName >>> arr show) >>> nsErr msg+ = (getQName >>> arr show) >>> nsErr msg - nsErr :: (String -> String) -> LA String XmlTree- nsErr msg = arr msg >>> mkError c_err+ nsErr :: (String -> String) -> LA String XmlTree+ nsErr msg = arr msg >>> mkError c_err - doubleOcc :: String -> LA XmlTree XmlTree+ doubleOcc :: String -> LA XmlTree XmlTree doubleOcc an- = nsError (\ n -> "multiple occurences of universal name for attributes of tag " ++ show n ++ " : " ++ show an )+ = nsError (\ n -> "multiple occurences of universal name for attributes of tag " ++ show n ++ " : " ++ show an ) -- ------------------------------------------------------------
src/Text/XML/HXT/Arrow/ParserInterface.hs view
@@ -13,80 +13,80 @@ import Control.Arrow.ArrowTree import Control.Arrow.ListArrow -import Text.XML.HXT.Parser.XmlEntities ( xmlEntities )+import Text.XML.HXT.Parser.XmlEntities ( xmlEntities ) import Text.XML.HXT.Parser.XhtmlEntities( xhtmlEntities ) import Text.XML.HXT.DOM.Interface import Text.XML.HXT.Arrow.XmlArrow -import qualified Text.XML.HXT.Parser.TagSoup as TS+import qualified Text.XML.HXT.Parser.TagSoup as TS import qualified Text.XML.HXT.Parser.HtmlParsec as HP import qualified Text.XML.HXT.Parser.XmlParsec as XP-import qualified Text.XML.HXT.Parser.XmlDTDParser as DP+import qualified Text.XML.HXT.Parser.XmlDTDParser as DP import qualified Text.XML.HXT.DTDValidation.Validation as VA -- ------------------------------------------------------------ -parseXmlDoc :: ArrowXml a => a (String, String) XmlTree-parseXmlDoc = arr2L XP.parseXmlDocument+parseXmlDoc :: ArrowXml a => a (String, String) XmlTree+parseXmlDoc = arr2L XP.parseXmlDocument -parseXmlDTDPart :: ArrowXml a => a (String, XmlTree) XmlTree-parseXmlDTDPart = arr2L XP.parseXmlDTDPart+parseXmlDTDPart :: ArrowXml a => a (String, XmlTree) XmlTree+parseXmlDTDPart = arr2L XP.parseXmlDTDPart -parseXmlContent :: ArrowXml a => a String XmlTree-parseXmlContent = arrL XP.xread+parseXmlContent :: ArrowXml a => a String XmlTree+parseXmlContent = arrL XP.xread parseXmlEntityEncodingSpec , parseXmlDocEncodingSpec- , removeEncodingSpec :: ArrowXml a => a XmlTree XmlTree+ , removeEncodingSpec :: ArrowXml a => a XmlTree XmlTree -parseXmlDocEncodingSpec = arrL XP.parseXmlDocEncodingSpec-parseXmlEntityEncodingSpec = arrL XP.parseXmlEntityEncodingSpec+parseXmlDocEncodingSpec = arrL XP.parseXmlDocEncodingSpec+parseXmlEntityEncodingSpec = arrL XP.parseXmlEntityEncodingSpec -removeEncodingSpec = arrL XP.removeEncodingSpec+removeEncodingSpec = arrL XP.removeEncodingSpec -parseXmlDTDdeclPart :: ArrowXml a => a XmlTree XmlTree-parseXmlDTDdeclPart = arrL DP.parseXmlDTDdeclPart+parseXmlDTDdeclPart :: ArrowXml a => a XmlTree XmlTree+parseXmlDTDdeclPart = arrL DP.parseXmlDTDdeclPart -parseXmlDTDdecl :: ArrowXml a => a XmlTree XmlTree-parseXmlDTDdecl = arrL DP.parseXmlDTDdecl+parseXmlDTDdecl :: ArrowXml a => a XmlTree XmlTree+parseXmlDTDdecl = arrL DP.parseXmlDTDdecl -parseXmlDTDEntityValue :: ArrowXml a => a XmlTree XmlTree-parseXmlDTDEntityValue = arrL DP.parseXmlDTDEntityValue+parseXmlDTDEntityValue :: ArrowXml a => a XmlTree XmlTree+parseXmlDTDEntityValue = arrL DP.parseXmlDTDEntityValue -parseXmlAttrValue :: ArrowXml a => String -> a XmlTree XmlTree-parseXmlAttrValue context = arrL (XP.parseXmlAttrValue context)+parseXmlAttrValue :: ArrowXml a => String -> a XmlTree XmlTree+parseXmlAttrValue context = arrL (XP.parseXmlAttrValue context) -parseXmlGeneralEntityValue :: ArrowXml a => String -> a XmlTree XmlTree+parseXmlGeneralEntityValue :: ArrowXml a => String -> a XmlTree XmlTree parseXmlGeneralEntityValue context- = arrL (XP.parseXmlGeneralEntityValue context)+ = arrL (XP.parseXmlGeneralEntityValue context) -- ------------------------------------------------------------ -parseHtmlDoc :: ArrowList a => a (String, String) XmlTree-parseHtmlDoc = arr2L HP.parseHtmlDocument+parseHtmlDoc :: ArrowList a => a (String, String) XmlTree+parseHtmlDoc = arr2L HP.parseHtmlDocument -parseHtmlContent :: ArrowList a => a String XmlTree-parseHtmlContent = arrL HP.parseHtmlContent+parseHtmlContent :: ArrowList a => a String XmlTree+parseHtmlContent = arrL HP.parseHtmlContent -parseHtmlTagSoup :: ArrowList a => Bool -> Bool -> Bool -> Bool -> Bool -> a (String, String) XmlTree+parseHtmlTagSoup :: ArrowList a => Bool -> Bool -> Bool -> Bool -> Bool -> a (String, String) XmlTree parseHtmlTagSoup withNamespaces withWarnings preserveCmt removeWS asHtml- = arr2L (TS.parseHtmlTagSoup withNamespaces withWarnings preserveCmt removeWS asHtml)+ = arr2L (TS.parseHtmlTagSoup withNamespaces withWarnings preserveCmt removeWS asHtml) -- ------------------------------------------------------------ -validateDoc :: ArrowList a => a XmlTree XmlTree-validateDoc = fromLA ( VA.validate- `when`- VA.getDTDSubset -- validate only when DTD decl is present- )+validateDoc :: ArrowList a => a XmlTree XmlTree+validateDoc = fromLA ( VA.validate+ `when`+ VA.getDTDSubset -- validate only when DTD decl is present+ ) -transformDoc :: ArrowList a => a XmlTree XmlTree-transformDoc = fromLA VA.transform+transformDoc :: ArrowList a => a XmlTree XmlTree+transformDoc = fromLA VA.transform -- old stuff--- validateDoc = arrL VA.validate--- transformDoc = arrL VA.transform+-- validateDoc = arrL VA.validate+-- transformDoc = arrL VA.transform -- ------------------------------------------------------------ @@ -98,38 +98,38 @@ -- -- Unknown entity refs remain unchanged -substHtmlEntityRefs :: ArrowList a => a XmlTree XmlTree-substHtmlEntityRefs = substEntityRefs xhtmlEntities+substHtmlEntityRefs :: ArrowList a => a XmlTree XmlTree+substHtmlEntityRefs = substEntityRefs xhtmlEntities -- | substitution of the five predefined XMT entities, works like 'substHtmlEntityRefs' -substXmlEntityRefs :: ArrowList a => a XmlTree XmlTree-substXmlEntityRefs = substEntityRefs xmlEntities+substXmlEntityRefs :: ArrowList a => a XmlTree XmlTree+substXmlEntityRefs = substEntityRefs xmlEntities -- | the entity substitution arrow called from 'substXmlEntityRefs' and 'substHtmlEntityRefs' -substEntityRefs :: ArrowList a => [(String, Int)] -> a XmlTree XmlTree+substEntityRefs :: ArrowList a => [(String, Int)] -> a XmlTree XmlTree substEntityRefs entities = fromLA substEntities where- substEntities :: LA XmlTree XmlTree+ substEntities :: LA XmlTree XmlTree substEntities- = choiceA- [ isEntityRef :-> ( substEntity $< getEntityRef )- , isElem :-> ( processAttrl (processChildren substEntities)- >>>- processChildren substEntities- )- , this :-> this- ]- where- substEntity en- = case (lookup en entities) of- Just i- -> txt [toEnum i] -- constA i >>> mkCharRef- Nothing- -> this+ = choiceA+ [ isEntityRef :-> ( substEntity $< getEntityRef )+ , isElem :-> ( processAttrl (processChildren substEntities)+ >>>+ processChildren substEntities+ )+ , this :-> this+ ]+ where+ substEntity en+ = case (lookup en entities) of+ Just i+ -> txt [toEnum i] -- constA i >>> mkCharRef+ Nothing+ -> this -- ------------------------------------------------------------
src/Text/XML/HXT/Arrow/Pickle.hs view
@@ -37,7 +37,7 @@ -- ------------------------------------------------------------ module Text.XML.HXT.Arrow.Pickle- ( xpickleDocument -- from this module Text.XML.HXT.Arrow.Pickle+ ( xpickleDocument -- from this module Text.XML.HXT.Arrow.Pickle , xunpickleDocument , xpickleWriteDTD , xpickleDTD@@ -123,26 +123,26 @@ -- An option evaluated by this arrow is 'a_addDTD'. -- If 'a_addDTD' is set ('v_1'), the pickler DTD is added as an inline DTD into the document. -xpickleDocument :: PU a -> Attributes -> String -> IOStateArrow s a XmlTree+xpickleDocument :: PU a -> Attributes -> String -> IOStateArrow s a XmlTree xpickleDocument xp al dest = xpickleVal xp >>> traceMsg 1 "xpickleVal applied" >>> ( if lookup1 a_addDTD al == v_1- then replaceChildren ( (constA undefined >>> xpickleDTD xp >>> getChildren)- <+>- getChildren- )- else this+ then replaceChildren ( (constA undefined >>> xpickleDTD xp >>> getChildren)+ <+>+ getChildren+ )+ else this ) >>> writeDocument al dest -- | Option for generating and adding DTD when document is pickled -a_addDTD :: String-a_addDTD = "addDTD"+a_addDTD :: String+a_addDTD = "addDTD" -- | read an arbitray value from an XML document --@@ -154,34 +154,34 @@ -- when applied with the appropriate options. When during pickling indentation is switched on, -- the whitespace must be removed during unpickling. -xunpickleDocument :: PU a -> Attributes -> String -> IOStateArrow s b a+xunpickleDocument :: PU a -> Attributes -> String -> IOStateArrow s b a xunpickleDocument xp al src- = readDocument al src- >>>- traceMsg 1 ("xunpickleVal for " ++ show src ++ " started")- >>>- xunpickleVal xp- >>>- traceMsg 1 ("xunpickleVal for " ++ show src ++ " finished")+ = readDocument al src+ >>>+ traceMsg 1 ("xunpickleVal for " ++ show src ++ " started")+ >>>+ xunpickleVal xp+ >>>+ traceMsg 1 ("xunpickleVal for " ++ show src ++ " finished") -- | Write out the DTD generated out of a pickler. Calls 'xpicklerDTD' -xpickleWriteDTD :: PU b -> Attributes -> String -> IOStateArrow s b XmlTree-xpickleWriteDTD xp al dest- = xpickleDTD xp- >>>- writeDocument al dest+xpickleWriteDTD :: PU b -> Attributes -> String -> IOStateArrow s b XmlTree+xpickleWriteDTD xp al dest+ = xpickleDTD xp+ >>>+ writeDocument al dest -- | The arrow for generating the DTD out of a pickler -- -- A DTD is generated from a pickler and check for consistency. -- Errors concerning the DTD are issued. -xpickleDTD :: PU b -> IOStateArrow s b XmlTree-xpickleDTD xp = root [] [ constL (thePicklerDTD xp)- >>>- filterErrorMsg- ]+xpickleDTD :: PU b -> IOStateArrow s b XmlTree+xpickleDTD xp = root [] [ constL (thePicklerDTD xp)+ >>>+ filterErrorMsg+ ] -- | An arrow for checking picklers --@@ -194,50 +194,50 @@ -- -- If the check succeeds, the arrow works like this, else it fails. -checkPickler :: Eq a => PU a -> IOStateArrow s a a-checkPickler xp = ( ( ( ( xpickleVal xp- >>>- replaceChildren ( (constA undefined >>> xpickleDTD xp >>> getChildren)- <+>- getChildren- )- >>>- writeDocumentToString []- >>>- readFromString [(a_validate, v_1)]- >>>- ( xunpickleVal xp- `orElse`- ( issueErr "unpickling the document failed"- >>>- none- )- )- )- &&& - this- )- >>> isA (uncurry (==))- )- `guards` this- )- `orElse` issueErr "pickle/unpickle combinators failed"+checkPickler :: Eq a => PU a -> IOStateArrow s a a+checkPickler xp = ( ( ( ( xpickleVal xp+ >>>+ replaceChildren ( (constA undefined >>> xpickleDTD xp >>> getChildren)+ <+>+ getChildren+ )+ >>>+ writeDocumentToString []+ >>>+ readFromString [(a_validate, v_1)]+ >>>+ ( xunpickleVal xp+ `orElse`+ ( issueErr "unpickling the document failed"+ >>>+ none+ )+ )+ )+ &&&+ this+ )+ >>> isA (uncurry (==))+ )+ `guards` this+ )+ `orElse` issueErr "pickle/unpickle combinators failed" -- | The arrow version of the pickler function -xpickleVal :: ArrowXml a => PU b -> a b XmlTree-xpickleVal xp = arr (pickleDoc xp)+xpickleVal :: ArrowXml a => PU b -> a b XmlTree+xpickleVal xp = arr (pickleDoc xp) -- | The arrow version of the unpickler function -xunpickleVal :: ArrowXml a => PU b -> a XmlTree b-xunpickleVal xp = arrL (maybeToList . unpickleDoc xp)+xunpickleVal :: ArrowXml a => PU b -> a XmlTree b+xunpickleVal xp = arrL (maybeToList . unpickleDoc xp) -- | Compute the associated DTD of a pickler -thePicklerDTD :: PU b -> XmlTrees-thePicklerDTD = dtdDescrToXml . dtdDescr . theSchema+thePicklerDTD :: PU b -> XmlTrees+thePicklerDTD = dtdDescrToXml . dtdDescr . theSchema -- ------------------------------------------------------------
src/Text/XML/HXT/Arrow/Pickle/DTD.hs view
@@ -30,27 +30,27 @@ -- ------------------------------------------------------------ -data DTDdescr = DTDdescr Name Schemas [(Name,Schemas)]+data DTDdescr = DTDdescr Name Schemas [(Name,Schemas)] instance Show DTDdescr where show (DTDdescr n es as)- = "root element: " ++ n ++ "\n"- ++- "elements:\n"- ++- concatMap ((++ "\n") .show) es- ++- "attributes:\n"- ++- concatMap ((++ "\n") . showAttr) as- where- showAttr (n1, sc) = n1 ++ ": " ++ show sc+ = "root element: " ++ n ++ "\n"+ +++ "elements:\n"+ +++ concatMap ((++ "\n") .show) es+ +++ "attributes:\n"+ +++ concatMap ((++ "\n") . showAttr) as+ where+ showAttr (n1, sc) = n1 ++ ": " ++ show sc -- ------------------------------------------------------------ -- | convert a DTD descr into XmlTrees -dtdDescrToXml :: DTDdescr -> XmlTrees+dtdDescrToXml :: DTDdescr -> XmlTrees dtdDescrToXml (DTDdescr rt es as) = checkErr (null rt) "no unique root element found in pickler DTD, add an \"xpElem\" pickler" ++@@ -61,61 +61,61 @@ concatMap (uncurry checkAttrModell) as ++ [ XN.mkDTDElem DOCTYPE docAttrs ( concatMap elemDTD es1- ++- concatMap (uncurry attrDTDs) as- ) ]+ +++ concatMap (uncurry attrDTDs) as+ ) ] where- es1 = filter isScElem es- - docAttrs = [(a_name, if null rt then "no-unique-root-element-found" else rt)]+ es1 = filter isScElem es + docAttrs = [(a_name, if null rt then "no-unique-root-element-found" else rt)]+ elemDTD (Element n sc)- | lookup1 a_type al == "unknown"- = cl- | otherwise- = [ XN.mkDTDElem ELEMENT ((a_name, n) : al) cl ]- where- (al, cl) = scContToXml sc+ | lookup1 a_type al == "unknown"+ = cl+ | otherwise+ = [ XN.mkDTDElem ELEMENT ((a_name, n) : al) cl ]+ where+ (al, cl) = scContToXml sc elemDTD _- = error "illegal case in elemDTD"+ = error "illegal case in elemDTD" - attrDTDs en = concatMap (attrDTD en)+ attrDTDs en = concatMap (attrDTD en) attrDTD en (Attribute an sc)- = [ XN.mkDTDElem ATTLIST ((a_name, en) : (a_value, an) : al) cl ]- where- (al, cl) = scAttrToXml sc- attrDTD _ _ = error "illegal case in attrDTD"+ = [ XN.mkDTDElem ATTLIST ((a_name, en) : (a_value, an) : al) cl ]+ where+ (al, cl) = scAttrToXml sc+ attrDTD _ _ = error "illegal case in attrDTD" -checkAttrModell :: Name -> Schemas -> XmlTrees-checkAttrModell n = concatMap (checkAM n)+checkAttrModell :: Name -> Schemas -> XmlTrees+checkAttrModell n = concatMap (checkAM n) -checkAM :: Name -> Schema -> XmlTrees-checkAM en (Attribute an sc) = checkAMC en an sc-checkAM _ _ = []+checkAM :: Name -> Schema -> XmlTrees+checkAM en (Attribute an sc) = checkAMC en an sc+checkAM _ _ = [] -checkAMC :: Name -> Name -> Schema -> XmlTrees-checkAMC _en _an (CharData _) = []+checkAMC :: Name -> Name -> Schema -> XmlTrees+checkAMC _en _an (CharData _) = [] checkAMC en an sc- | isScCharData sc = []+ | isScCharData sc = [] | isScList sc && (sc_1 sc == scNmtoken)- = []- | isScOpt sc = checkAMC en an (sc_1 sc)- | otherwise = foundErr- ( "weird attribute type found for attribute "- ++ show an- ++ " for element "- ++ show en- ++ "\n\t(internal structure: " ++ show sc ++ ")"- ++ "\n\thint: create an element instead of an attribute for "- ++ show an- )+ = []+ | isScOpt sc = checkAMC en an (sc_1 sc)+ | otherwise = foundErr+ ( "weird attribute type found for attribute "+ ++ show an+ ++ " for element "+ ++ show en+ ++ "\n\t(internal structure: " ++ show sc ++ ")"+ ++ "\n\thint: create an element instead of an attribute for "+ ++ show an+ ) -- checkContentModell1 n sc = foundErr (n ++ " : " ++ show sc) ++ checkContentModell n sc -checkContentModell :: Name -> Schema -> XmlTrees+checkContentModell :: Name -> Schema -> XmlTrees checkContentModell _ Any = []@@ -132,13 +132,13 @@ checkContentModell n (Seq scs) = checkErr pcDataInCM ( "PCDATA found in a sequence spec in the content modell for "- ++ show n- ++ "\n\thint: create an element for this data"+ ++ show n+ ++ "\n\thint: create an element for this data" ) ++ checkErr somethingElseInCM ( "something weired found in a sequence spec in the content modell for "- ++ show n+ ++ show n ) ++ concatMap (checkContentModell n) scs@@ -149,17 +149,17 @@ checkContentModell n (Alt scs) = checkErr mixedCM ( "PCDATA mixed up with illegal content spec in mixed contents for "- ++ show n- ++ "\n\thint: create an element for this data"+ ++ show n+ ++ "\n\thint: create an element for this data" ) ++ concatMap (checkContentModell n) scs where mixedCM- | any isScCharData scs- = any (not . isScElemRef) . filter (not . isScCharData) $ scs- | otherwise- = False+ | any isScCharData scs+ = any (not . isScElemRef) . filter (not . isScCharData) $ scs+ | otherwise+ = False checkContentModell _ (Rep _ _ (ElemRef _)) = []@@ -173,99 +173,99 @@ checkContentModell n (Rep _ _ _) = foundErr ( "illegal content spec found for "- ++ show n+ ++ show n ) checkContentModell _ _ = [] -scContToXml :: Schema -> (Attributes, XmlTrees)+scContToXml :: Schema -> (Attributes, XmlTrees) -scContToXml Any = ( [(a_type, v_any)], [] )-scContToXml (CharData _) = ( [(a_type, v_pcdata)], [] )-scContToXml (Seq []) = ( [(a_type, v_empty)], [] )-scContToXml sc@(ElemRef _) = scContToXml (Seq [sc])-scContToXml sc@(Seq _) = ( [(a_type, v_children)]- , scCont [] sc- )+scContToXml Any = ( [(a_type, v_any)], [] )+scContToXml (CharData _) = ( [(a_type, v_pcdata)], [] )+scContToXml (Seq []) = ( [(a_type, v_empty)], [] )+scContToXml sc@(ElemRef _) = scContToXml (Seq [sc])+scContToXml sc@(Seq _) = ( [(a_type, v_children)]+ , scCont [] sc+ ) scContToXml sc@(Alt sc1)- | isMixed sc1 = ( [(a_type, v_mixed)]- , scCont [ (a_modifier, "*") ] sc- )- | otherwise = ( [(a_type, v_children)]- , scCont [] sc- ) + | isMixed sc1 = ( [(a_type, v_mixed)]+ , scCont [ (a_modifier, "*") ] sc+ )+ | otherwise = ( [(a_type, v_children)]+ , scCont [] sc+ ) where- isMixed = not . null . filter isScCharData-scContToXml sc@(Rep _ _ _) = ( [(a_type, v_children)]- , scCont [] sc- )-scContToXml _sc = ( [(a_type, v_any)] -- default: everything is allowed- , []- )+ isMixed = not . null . filter isScCharData+scContToXml sc@(Rep _ _ _) = ( [(a_type, v_children)]+ , scCont [] sc+ )+scContToXml _sc = ( [(a_type, v_any)] -- default: everything is allowed+ , []+ ) -scWrap :: Schema -> Schema-scWrap sc@(Alt _) = sc-scWrap sc@(Seq _) = sc-scWrap sc@(Rep _ _ _) = sc-scWrap sc = Seq [sc]+scWrap :: Schema -> Schema+scWrap sc@(Alt _) = sc+scWrap sc@(Seq _) = sc+scWrap sc@(Rep _ _ _) = sc+scWrap sc = Seq [sc] -scCont :: Attributes -> Schema -> XmlTrees-scCont al (Seq scs) = scConts ((a_kind, v_seq ) : al) scs-scCont al (Alt scs) = scConts ((a_kind, v_choice) : al) scs-scCont al (Rep 0 (-1) sc) = scCont ((a_modifier, "*") : al) (scWrap sc)-scCont al (Rep 1 (-1) sc) = scCont ((a_modifier, "+") : al) (scWrap sc)-scCont al (Rep 0 1 sc) = scCont ((a_modifier, "?") : al) (scWrap sc)-scCont al (ElemRef n) = [XN.mkDTDElem NAME ((a_name, n) : al) []]-scCont _ (CharData _) = [XN.mkDTDElem NAME [(a_name, "#PCDATA")] []]-scCont _ _sc = [XN.mkDTDElem NAME [(a_name, "bad-content-spec")] []] -- error case+scCont :: Attributes -> Schema -> XmlTrees+scCont al (Seq scs) = scConts ((a_kind, v_seq ) : al) scs+scCont al (Alt scs) = scConts ((a_kind, v_choice) : al) scs+scCont al (Rep 0 (-1) sc) = scCont ((a_modifier, "*") : al) (scWrap sc)+scCont al (Rep 1 (-1) sc) = scCont ((a_modifier, "+") : al) (scWrap sc)+scCont al (Rep 0 1 sc) = scCont ((a_modifier, "?") : al) (scWrap sc)+scCont al (ElemRef n) = [XN.mkDTDElem NAME ((a_name, n) : al) []]+scCont _ (CharData _) = [XN.mkDTDElem NAME [(a_name, "#PCDATA")] []]+scCont _ _sc = [XN.mkDTDElem NAME [(a_name, "bad-content-spec")] []] -- error case -scConts :: Attributes -> Schemas -> XmlTrees-scConts al scs = [XN.mkDTDElem CONTENT al (concatMap (scCont []) scs)]+scConts :: Attributes -> Schemas -> XmlTrees+scConts al scs = [XN.mkDTDElem CONTENT al (concatMap (scCont []) scs)] -scAttrToXml :: Schema -> (Attributes, XmlTrees)+scAttrToXml :: Schema -> (Attributes, XmlTrees) scAttrToXml sc- | isScFixed sc = ( [ (a_kind, k_fixed)- , (a_type, k_cdata)- , (a_default, (xsdParam xsd_enumeration sc))- ]- , [])- | isScEnum sc = ( [ (a_kind, k_required)- , (a_type, k_enumeration)- ]- , map (\ n -> XN.mkDTDElem NAME [(a_name, n)] []) enums- )- | isScCharData sc = ( [ (a_kind, k_required)- , (a_type, d_type)- ]- , [])- | isScOpt sc = (addEntry a_kind k_implied al, cl)- | isScList sc = (addEntry a_type k_nmtokens al, cl)- | otherwise = ( [ (a_kind, k_fixed)- , (a_default, "bad-attribute-type: " ++ show sc)- ]- , [] )+ | isScFixed sc = ( [ (a_kind, k_fixed)+ , (a_type, k_cdata)+ , (a_default, (xsdParam xsd_enumeration sc))+ ]+ , [])+ | isScEnum sc = ( [ (a_kind, k_required)+ , (a_type, k_enumeration)+ ]+ , map (\ n -> XN.mkDTDElem NAME [(a_name, n)] []) enums+ )+ | isScCharData sc = ( [ (a_kind, k_required)+ , (a_type, d_type)+ ]+ , [])+ | isScOpt sc = (addEntry a_kind k_implied al, cl)+ | isScList sc = (addEntry a_type k_nmtokens al, cl)+ | otherwise = ( [ (a_kind, k_fixed)+ , (a_default, "bad-attribute-type: " ++ show sc)+ ]+ , [] ) where- (al, cl) = scAttrToXml (sc_1 sc)+ (al, cl) = scAttrToXml (sc_1 sc) d_type- | sc == scNmtoken = k_nmtoken- | otherwise = k_cdata- enums = words . xsdParam xsd_enumeration $ sc+ | sc == scNmtoken = k_nmtoken+ | otherwise = k_cdata+ enums = words . xsdParam xsd_enumeration $ sc -checkErr :: Bool -> String -> XmlTrees-checkErr True s = [XN.mkError c_err s]-checkErr _ _ = []+checkErr :: Bool -> String -> XmlTrees+checkErr True s = [XN.mkError c_err s]+checkErr _ _ = [] -foundErr :: String -> XmlTrees-foundErr = checkErr True+foundErr :: String -> XmlTrees+foundErr = checkErr True -- ------------------------------------------------------------ -- | convert a pickler schema into a DTD descr -dtdDescr :: Schema -> DTDdescr+dtdDescr :: Schema -> DTDdescr dtdDescr sc = DTDdescr rt es1 as where@@ -274,32 +274,32 @@ as = filter (not. null . snd) . concatMap attrDec $ es rt = fromMaybe "" . elemName $ sc -elementDeclarations :: Schema -> Schemas-elementDeclarations sc = elemRefs . elementDecs [] $ [sc]+elementDeclarations :: Schema -> Schemas+elementDeclarations sc = elemRefs . elementDecs [] $ [sc] -elementDecs :: Schemas -> Schemas -> Schemas+elementDecs :: Schemas -> Schemas -> Schemas elementDecs es [] = es elementDecs es (s:ss) = elementDecs (elemDecs s) ss where- elemDecs (Seq scs) = elementDecs es scs- elemDecs (Alt scs) = elementDecs es scs- elemDecs (Rep _ _ sc) = elemDecs sc+ elemDecs (Seq scs) = elementDecs es scs+ elemDecs (Alt scs) = elementDecs es scs+ elemDecs (Rep _ _ sc) = elemDecs sc elemDecs e@(Element n sc)- | n `elem` elemNames es = es- | otherwise = elementDecs (e:es) [sc]- elemDecs _ = es+ | n `elem` elemNames es = es+ | otherwise = elementDecs (e:es) [sc]+ elemDecs _ = es -elemNames :: Schemas -> [Name]+elemNames :: Schemas -> [Name] elemNames = concatMap (maybeToList . elemName) -elemName :: Schema -> Maybe Name+elemName :: Schema -> Maybe Name elemName (Element n _) = Just n elemName _ = Nothing -elemRefs :: Schemas -> Schemas-elemRefs = map elemRef+elemRefs :: Schemas -> Schemas+elemRefs = map elemRef where elemRef (Element n sc) = Element n (pruneElem sc) elemRef sc = sc@@ -309,16 +309,16 @@ pruneElem (Rep l u sc) = Rep l u (pruneElem sc) pruneElem sc = sc -attrDec :: Schema -> [(Name, Schemas)]+attrDec :: Schema -> [(Name, Schemas)] attrDec (Element n sc) = [(n, attrDecs sc)] where- attrDecs a@(Attribute _ _) = [a]- attrDecs (Seq scs) = concatMap attrDecs scs- attrDecs _ = []-attrDec _ = []+ attrDecs a@(Attribute _ _) = [a]+ attrDecs (Seq scs) = concatMap attrDecs scs+ attrDecs _ = []+attrDec _ = [] -remAttrDec :: Schema -> Schema+remAttrDec :: Schema -> Schema remAttrDec (Element n sc) = Element n (remA sc) where
src/Text/XML/HXT/Arrow/Pickle/Schema.hs view
@@ -32,101 +32,101 @@ -- | The datatype for modelling the structure of an -data Schema = Any- | Seq { sc_l :: [Schema]- }- | Alt { sc_l :: [Schema]- }- | Rep { sc_lb :: Int- , sc_ub :: Int- , sc_1 :: Schema- }- | Element { sc_n :: Name- , sc_1 :: Schema- }- | Attribute { sc_n :: Name- , sc_1 :: Schema- }- | ElemRef { sc_n :: Name- }- | CharData { sc_dt :: DataTypeDescr- }- deriving (Eq, Show)+data Schema = Any+ | Seq { sc_l :: [Schema]+ }+ | Alt { sc_l :: [Schema]+ }+ | Rep { sc_lb :: Int+ , sc_ub :: Int+ , sc_1 :: Schema+ }+ | Element { sc_n :: Name+ , sc_1 :: Schema+ }+ | Attribute { sc_n :: Name+ , sc_1 :: Schema+ }+ | ElemRef { sc_n :: Name+ }+ | CharData { sc_dt :: DataTypeDescr+ }+ deriving (Eq, Show) -type Name = String-type Schemas = [Schema]+type Name = String+type Schemas = [Schema] -data DataTypeDescr = DTDescr { dtLib :: String- , dtName :: String- , dtParams :: Attributes- }- deriving (Show)+data DataTypeDescr = DTDescr { dtLib :: String+ , dtName :: String+ , dtParams :: Attributes+ }+ deriving (Show) instance Eq DataTypeDescr where x1 == x2 = dtLib x1 == dtLib x2- &&- dtName x1 == dtName x2- &&- sort (dtParams x1) == sort (dtParams x2)+ &&+ dtName x1 == dtName x2+ &&+ sort (dtParams x1) == sort (dtParams x2) -- ------------------------------------------------------------ -- | test: is schema a simple XML Schema datatype -isScXsd :: (String -> Bool) -> Schema -> Bool+isScXsd :: (String -> Bool) -> Schema -> Bool isScXsd p (CharData (DTDescr lib n _ps))- = lib == w3cNS- &&- p n-isScXsd _ _ = False+ = lib == w3cNS+ &&+ p n+isScXsd _ _ = False -- | test: is type a fixed value attribute type -isScFixed :: Schema -> Bool-isScFixed sc = isScXsd (== xsd_string) sc- &&- ((== 1) . length . words . xsdParam xsd_enumeration) sc+isScFixed :: Schema -> Bool+isScFixed sc = isScXsd (== xsd_string) sc+ &&+ ((== 1) . length . words . xsdParam xsd_enumeration) sc -isScEnum :: Schema -> Bool-isScEnum sc = isScXsd (== xsd_string) sc- &&- (not . null . xsdParam xsd_enumeration) sc+isScEnum :: Schema -> Bool+isScEnum sc = isScXsd (== xsd_string) sc+ &&+ (not . null . xsdParam xsd_enumeration) sc -isScElem :: Schema -> Bool-isScElem (Element _ _) = True-isScElem _ = False+isScElem :: Schema -> Bool+isScElem (Element _ _) = True+isScElem _ = False -isScAttr :: Schema -> Bool+isScAttr :: Schema -> Bool isScAttr (Attribute _ _)= True-isScAttr _ = False+isScAttr _ = False -isScElemRef :: Schema -> Bool-isScElemRef (ElemRef _) = True-isScElemRef _ = False+isScElemRef :: Schema -> Bool+isScElemRef (ElemRef _) = True+isScElemRef _ = False -isScCharData :: Schema -> Bool+isScCharData :: Schema -> Bool isScCharData (CharData _)= True-isScCharData _ = False+isScCharData _ = False -isScSARE :: Schema -> Bool-isScSARE (Seq _) = True-isScSARE (Alt _) = True-isScSARE (Rep _ _ _) = True-isScSARE (ElemRef _) = True-isScSARE _ = False+isScSARE :: Schema -> Bool+isScSARE (Seq _) = True+isScSARE (Alt _) = True+isScSARE (Rep _ _ _) = True+isScSARE (ElemRef _) = True+isScSARE _ = False -isScList :: Schema -> Bool-isScList (Rep 0 (-1) _) = True-isScList _ = False+isScList :: Schema -> Bool+isScList (Rep 0 (-1) _) = True+isScList _ = False -isScOpt :: Schema -> Bool-isScOpt (Rep 0 1 _) = True-isScOpt _ = False+isScOpt :: Schema -> Bool+isScOpt (Rep 0 1 _) = True+isScOpt _ = False -- | access an attribute of a descr of an atomic type -xsdParam :: String -> Schema -> String+xsdParam :: String -> Schema -> String xsdParam n (CharData dtd) = lookup1 n (dtParams dtd) xsdParam _ _ = ""@@ -139,83 +139,83 @@ -- -- predefined xsd data types for representation of DTD types -scDT :: String -> String -> Attributes -> Schema-scDT l n rl = CharData $ DTDescr l n rl+scDT :: String -> String -> Attributes -> Schema+scDT l n rl = CharData $ DTDescr l n rl -scDTxsd :: String -> Attributes -> Schema-scDTxsd = scDT w3cNS+scDTxsd :: String -> Attributes -> Schema+scDTxsd = scDT w3cNS -scString :: Schema-scString = scDTxsd xsd_string []+scString :: Schema+scString = scDTxsd xsd_string [] -scString1 :: Schema-scString1 = scDTxsd xsd_string [(xsd_minLength, "1")]+scString1 :: Schema+scString1 = scDTxsd xsd_string [(xsd_minLength, "1")] -scFixed :: String -> Schema-scFixed v = scDTxsd xsd_string [(xsd_enumeration, v)]+scFixed :: String -> Schema+scFixed v = scDTxsd xsd_string [(xsd_enumeration, v)] -scEnum :: [String] -> Schema-scEnum vs = scFixed (unwords vs)+scEnum :: [String] -> Schema+scEnum vs = scFixed (unwords vs) -scNmtoken :: Schema-scNmtoken = scDTxsd xsd_NCName []+scNmtoken :: Schema+scNmtoken = scDTxsd xsd_NCName [] -scNmtokens :: Schema-scNmtokens = scList scNmtoken+scNmtokens :: Schema+scNmtokens = scList scNmtoken -- ------------------------------------------------------------ -scEmpty :: Schema-scEmpty = Seq []+scEmpty :: Schema+scEmpty = Seq [] -scSeq :: Schema -> Schema -> Schema-scSeq (Seq []) sc2 = sc2-scSeq sc1 (Seq []) = sc1-scSeq (Seq scs1) (Seq scs2) = Seq (scs1 ++ scs2) -- prevent nested Seq expr-scSeq (Seq scs1) sc2 = Seq (scs1 ++ [sc2])-scSeq sc1 (Seq scs2) = Seq (sc1 : scs2)-scSeq sc1 sc2 = Seq [sc1,sc2]+scSeq :: Schema -> Schema -> Schema+scSeq (Seq []) sc2 = sc2+scSeq sc1 (Seq []) = sc1+scSeq (Seq scs1) (Seq scs2) = Seq (scs1 ++ scs2) -- prevent nested Seq expr+scSeq (Seq scs1) sc2 = Seq (scs1 ++ [sc2])+scSeq sc1 (Seq scs2) = Seq (sc1 : scs2)+scSeq sc1 sc2 = Seq [sc1,sc2] -scSeqs :: [Schema] -> Schema-scSeqs = foldl scSeq scEmpty+scSeqs :: [Schema] -> Schema+scSeqs = foldl scSeq scEmpty -scNull :: Schema-scNull = Alt []+scNull :: Schema+scNull = Alt [] -scAlt :: Schema -> Schema -> Schema-scAlt (Alt []) sc2 = sc2-scAlt sc1 (Alt []) = sc1-scAlt (Alt scs1) (Alt scs2) = Alt (scs1 ++ scs2) -- prevent nested Alt expr-scAlt (Alt scs1) sc2 = Alt (scs1 ++ [sc2])-scAlt sc1 (Alt scs2) = Alt (sc1 : scs2)-scAlt sc1 sc2 = Alt [sc1,sc2]+scAlt :: Schema -> Schema -> Schema+scAlt (Alt []) sc2 = sc2+scAlt sc1 (Alt []) = sc1+scAlt (Alt scs1) (Alt scs2) = Alt (scs1 ++ scs2) -- prevent nested Alt expr+scAlt (Alt scs1) sc2 = Alt (scs1 ++ [sc2])+scAlt sc1 (Alt scs2) = Alt (sc1 : scs2)+scAlt sc1 sc2 = Alt [sc1,sc2] -scAlts :: [Schema] -> Schema-scAlts = foldl scAlt scNull+scAlts :: [Schema] -> Schema+scAlts = foldl scAlt scNull -scOption :: Schema -> Schema-scOption (Seq []) = scEmpty-scOption (Attribute n sc2) = Attribute n (scOption sc2)+scOption :: Schema -> Schema+scOption (Seq []) = scEmpty+scOption (Attribute n sc2) = Attribute n (scOption sc2) scOption sc1- | sc1 == scString1 = scString- | otherwise = scOpt sc1+ | sc1 == scString1 = scString+ | otherwise = scOpt sc1 -scList :: Schema -> Schema-scList = scRep 0 (-1)+scList :: Schema -> Schema+scList = scRep 0 (-1) -scList1 :: Schema -> Schema-scList1 = scRep 1 (-1)+scList1 :: Schema -> Schema+scList1 = scRep 1 (-1) -scOpt :: Schema -> Schema-scOpt = scRep 0 1+scOpt :: Schema -> Schema+scOpt = scRep 0 1 -scRep :: Int -> Int -> Schema -> Schema+scRep :: Int -> Int -> Schema -> Schema scRep l u sc1 = Rep l u sc1 -scElem :: String -> Schema -> Schema-scElem n sc1 = Element n sc1+scElem :: String -> Schema -> Schema+scElem n sc1 = Element n sc1 -scAttr :: String -> Schema -> Schema-scAttr n sc1 = Attribute n sc1+scAttr :: String -> Schema -> Schema+scAttr n sc1 = Attribute n sc1 -- ------------------------------------------------------------
src/Text/XML/HXT/Arrow/Pickle/Xml.hs view
@@ -39,7 +39,7 @@ where import Data.Maybe-import Data.Map (Map)+import Data.Map (Map) import qualified Data.Map as M import Text.XML.HXT.DOM.Interface@@ -53,39 +53,39 @@ -- ------------------------------------------------------------ -data St = St { attributes :: [XmlTree]- , contents :: [XmlTree]- }+data St = St { attributes :: [XmlTree]+ , contents :: [XmlTree]+ } -data PU a = PU { appPickle :: (a, St) -> St- , appUnPickle :: St -> (Maybe a, St)- , theSchema :: Schema- }+data PU a = PU { appPickle :: (a, St) -> St+ , appUnPickle :: St -> (Maybe a, St)+ , theSchema :: Schema+ } -emptySt :: St-emptySt = St { attributes = []- , contents = []- }+emptySt :: St+emptySt = St { attributes = []+ , contents = []+ } -addAtt :: XmlTree -> St -> St-addAtt x s = s {attributes = x : attributes s}+addAtt :: XmlTree -> St -> St+addAtt x s = s {attributes = x : attributes s} -addCont :: XmlTree -> St -> St-addCont x s = s {contents = x : contents s}+addCont :: XmlTree -> St -> St+addCont x s = s {contents = x : contents s} -dropCont :: St -> St-dropCont s = s { contents = drop 1 (contents s) }+dropCont :: St -> St+dropCont s = s { contents = drop 1 (contents s) } -getAtt :: QName -> St -> Maybe XmlTree+getAtt :: QName -> St -> Maybe XmlTree getAtt qn s = listToMaybe $ runLA ( arrL attributes- >>>- isAttr >>> hasQName qn- ) s+ >>>+ isAttr >>> hasQName qn+ ) s -getCont :: St -> Maybe XmlTree-getCont s = listToMaybe . contents $ s+getCont :: St -> Maybe XmlTree+getCont s = listToMaybe . contents $ s -- ------------------------------------------------------------ @@ -94,7 +94,7 @@ -- The pickler, first parameter, controls the conversion process. -- Result is a complete document tree including a root node -pickleDoc :: PU a -> a -> XmlTree+pickleDoc :: PU a -> a -> XmlTree pickleDoc p v = XN.mkRoot (attributes st) (contents st) where@@ -111,11 +111,11 @@ unpickleDoc :: PU a -> XmlTree -> Maybe a unpickleDoc p t | XN.isRoot t- = fst . appUnPickle p $ St { attributes = fromJust . XN.getAttrl $ t- , contents = XN.getChildren t- }+ = fst . appUnPickle p $ St { attributes = fromJust . XN.getAttrl $ t+ , contents = XN.getChildren t+ } | otherwise- = unpickleDoc p (XN.mkRoot [] [t])+ = unpickleDoc p (XN.mkRoot [] [t]) -- ------------------------------------------------------------ @@ -123,37 +123,37 @@ -- -- Encodes nothing, fails always during unpickling -xpZero :: PU a-xpZero = PU { appPickle = snd- , appUnPickle = \ s -> (Nothing, s)- , theSchema = scNull- }+xpZero :: PU a+xpZero = PU { appPickle = snd+ , appUnPickle = \ s -> (Nothing, s)+ , theSchema = scNull+ } -- unit pickler -xpUnit :: PU ()-xpUnit = xpLift ()+xpUnit :: PU ()+xpUnit = xpLift () -- | Lift a value to a pickler -- -- When pickling, nothing is encoded, when unpickling, the given value is inserted. -- This pickler always succeeds. -xpLift :: a -> PU a-xpLift x = PU { appPickle = snd- , appUnPickle = \ s -> (Just x, s)- , theSchema = scEmpty- }+xpLift :: a -> PU a+xpLift x = PU { appPickle = snd+ , appUnPickle = \ s -> (Just x, s)+ , theSchema = scEmpty+ } -- | Lift a Maybe value to a pickler. -- -- @Nothing@ is mapped to the zero pickler, @Just x@ is pickled with @xpLift x@. -xpLiftMaybe :: Maybe a -> PU a-xpLiftMaybe v = (xpLiftMaybe' v) { theSchema = scOption scEmpty }+xpLiftMaybe :: Maybe a -> PU a+xpLiftMaybe v = (xpLiftMaybe' v) { theSchema = scOption scEmpty } where- xpLiftMaybe' Nothing = xpZero- xpLiftMaybe' (Just x) = xpLift x+ xpLiftMaybe' Nothing = xpZero+ xpLiftMaybe' (Just x) = xpLift x -- | pickle\/unpickle combinator for sequence and choice.@@ -164,25 +164,25 @@ -- -- The schema must be attached later, e.g. in xpPair or other higher level combinators -xpCondSeq :: PU b -> (b -> a) -> PU a -> (a -> PU b) -> PU b+xpCondSeq :: PU b -> (b -> a) -> PU a -> (a -> PU b) -> PU b xpCondSeq pd f pa k = PU { appPickle = ( \ (b, s) ->- let- a = f b- pb = k a- in- appPickle pa (a, (appPickle pb (b, s)))- )- , appUnPickle = ( \ s ->- let- (a, s') = appUnPickle pa s- in- case a of- Nothing -> appUnPickle pd s- Just a' -> appUnPickle (k a') s'- )- , theSchema = undefined- }+ let+ a = f b+ pb = k a+ in+ appPickle pa (a, (appPickle pb (b, s)))+ )+ , appUnPickle = ( \ s ->+ let+ (a, s') = appUnPickle pa s+ in+ case a of+ Nothing -> appUnPickle pd s+ Just a' -> appUnPickle (k a') s'+ )+ , theSchema = undefined+ } -- | Combine two picklers sequentially.@@ -190,8 +190,8 @@ -- If the first fails during -- unpickling, the whole unpickler fails -xpSeq :: (b -> a) -> PU a -> (a -> PU b) -> PU b-xpSeq = xpCondSeq xpZero+xpSeq :: (b -> a) -> PU a -> (a -> PU b) -> PU b+xpSeq = xpCondSeq xpZero -- | combine tow picklers with a choice@@ -200,32 +200,32 @@ -- When during unpickling the first one fails, -- an alternative pickler (first argument) is applied. -- This pickler is only used as combinator for unpickling.- -xpChoice :: PU b -> PU a -> (a -> PU b) -> PU b-xpChoice pb = xpCondSeq pb undefined +xpChoice :: PU b -> PU a -> (a -> PU b) -> PU b+xpChoice pb = xpCondSeq pb undefined + -- | map value into another domain and apply pickler there -- -- One of the most often used picklers. -xpWrap :: (a -> b, b -> a) -> PU a -> PU b-xpWrap (i, j) pa = (xpSeq j pa (xpLift . i)) { theSchema = theSchema pa }+xpWrap :: (a -> b, b -> a) -> PU a -> PU b+xpWrap (i, j) pa = (xpSeq j pa (xpLift . i)) { theSchema = theSchema pa } -- | like 'xpWrap', but if the inverse mapping is undefined, the unpickler fails -- -- Map a value into another domain. If the inverse mapping is -- undefined (Nothing), the unpickler fails -xpWrapMaybe :: (a -> Maybe b, b -> a) -> PU a -> PU b-xpWrapMaybe (i, j) pa = (xpSeq j pa (xpLiftMaybe . i)) { theSchema = theSchema pa }+xpWrapMaybe :: (a -> Maybe b, b -> a) -> PU a -> PU b+xpWrapMaybe (i, j) pa = (xpSeq j pa (xpLiftMaybe . i)) { theSchema = theSchema pa } -- | pickle a pair of values sequentially -- -- Used for pairs or together with wrap for pickling -- algebraic data types with two components -xpPair :: PU a -> PU b -> PU (a, b)+xpPair :: PU a -> PU b -> PU (a, b) xpPair pa pb = ( xpSeq fst pa (\ a -> xpSeq snd pb (\ b ->@@ -234,7 +234,7 @@ -- | Like 'xpPair' but for triples -xpTriple :: PU a -> PU b -> PU c -> PU (a, b, c)+xpTriple :: PU a -> PU b -> PU c -> PU (a, b, c) xpTriple pa pb pc = xpWrap (toTriple, fromTriple) (xpPair pa (xpPair pb pc)) where@@ -243,7 +243,7 @@ -- | Like 'xpPair' and 'xpTriple' but for 4-tuples -xp4Tuple :: PU a -> PU b -> PU c -> PU d -> PU (a, b, c, d)+xp4Tuple :: PU a -> PU b -> PU c -> PU d -> PU (a, b, c, d) xp4Tuple pa pb pc pd = xpWrap (toQuad, fromQuad) (xpPair pa (xpPair pb (xpPair pc pd))) where@@ -252,7 +252,7 @@ -- | Like 'xpPair' and 'xpTriple' but for 5-tuples -xp5Tuple :: PU a -> PU b -> PU c -> PU d -> PU e -> PU (a, b, c, d, e)+xp5Tuple :: PU a -> PU b -> PU c -> PU d -> PU e -> PU (a, b, c, d, e) xp5Tuple pa pb pc pd pe = xpWrap (toQuint, fromQuint) (xpPair pa (xpPair pb (xpPair pc (xpPair pd pe)))) where@@ -261,7 +261,7 @@ -- | Like 'xpPair' and 'xpTriple' but for 6-tuples -xp6Tuple :: PU a -> PU b -> PU c -> PU d -> PU e -> PU f -> PU (a, b, c, d, e, f)+xp6Tuple :: PU a -> PU b -> PU c -> PU d -> PU e -> PU f -> PU (a, b, c, d, e, f) xp6Tuple pa pb pc pd pe pf = xpWrap (toSix, fromSix) (xpPair pa (xpPair pb (xpPair pc (xpPair pd (xpPair pe pf))))) where@@ -274,8 +274,8 @@ -- For pickling empty strings use 'xpText0'. If the text has a more -- specific datatype than xsd:string, use 'xpTextDT' -xpText :: PU String-xpText = xpTextDT scString1+xpText :: PU String+xpText = xpTextDT scString1 -- | Pickle a string into an XML text node --@@ -284,18 +284,18 @@ -- In 'Text.XML.HXT.Arrow.Pickle.Schema' there are some more functions for creating -- simple datatype descriptions. -xpTextDT :: Schema -> PU String+xpTextDT :: Schema -> PU String xpTextDT sc = PU { appPickle = \ (s, st) -> addCont (XN.mkText s) st- , appUnPickle = \ st -> fromMaybe (Nothing, st) (unpickleString st)- , theSchema = sc- }+ , appUnPickle = \ st -> fromMaybe (Nothing, st) (unpickleString st)+ , theSchema = sc+ } where unpickleString st- = do- t <- getCont st- s <- XN.getText t- return (Just s, dropCont st)+ = do+ t <- getCont st+ s <- XN.getText t+ return (Just s, dropCont st) -- | Pickle a possibly empty string into an XML node. --@@ -305,14 +305,14 @@ -- So the empty text node becomes nothing, and the pickler must deliver an empty string, -- if there is no text node in the document. -xpText0 :: PU String-xpText0 = xpText0DT scString1+xpText0 :: PU String+xpText0 = xpText0DT scString1 -- | Pickle a possibly empty string with a datatype description into an XML node. -- -- Like 'xpText0' but with extra Parameter for datatype description as in 'xpTextDT'. -xpText0DT :: Schema -> PU String+xpText0DT :: Schema -> PU String xpText0DT sc = xpWrap (fromMaybe "", emptyToNothing) $ xpOption $ xpTextDT sc where@@ -326,16 +326,16 @@ -- One of the most often used pimitive picklers. Applicable for all -- types which are instances of @Read@ and @Show@ -xpPrim :: (Read a, Show a) => PU a+xpPrim :: (Read a, Show a) => PU a xpPrim = xpWrapMaybe (readMaybe, show) xpText where- readMaybe :: Read a => String -> Maybe a+ readMaybe :: Read a => String -> Maybe a readMaybe str- = val (reads str)- where- val [(x,"")] = Just x- val _ = Nothing+ = val (reads str)+ where+ val [(x,"")] = Just x+ val _ = Nothing -- ------------------------------------------------------------ @@ -343,23 +343,23 @@ -- -- Usefull for components of type XmlTree in other data structures -xpTree :: PU XmlTree-xpTree = PU { appPickle = \ (s, st) -> addCont s st- , appUnPickle = \ st -> fromMaybe (Nothing, st) (unpickleTree st)- , theSchema = Any- }+xpTree :: PU XmlTree+xpTree = PU { appPickle = \ (s, st) -> addCont s st+ , appUnPickle = \ st -> fromMaybe (Nothing, st) (unpickleTree st)+ , theSchema = Any+ } where unpickleTree st- = do- t <- getCont st- return (Just t, dropCont st)+ = do+ t <- getCont st+ return (Just t, dropCont st) --- | Pickle a whole list of XmlTrees by just adding the list, unpickle is done by taking all element contens.+-- | Pickle a whole list of XmlTrees by just adding the list, unpickle is done by taking all element contents. ----- This pickler should always combined with 'xpElem' for taking the whole contents of an element.+-- This pickler should always be combined with 'xpElem' for taking the whole contents of an element. -xpTrees :: PU [XmlTree]-xpTrees = (xpList xpTree) { theSchema = Any }+xpTrees :: PU [XmlTree]+xpTrees = (xpList xpTree) { theSchema = Any } -- | Pickle a string representing XML contents by inserting the tree representation into the XML document. --@@ -368,7 +368,7 @@ -- this function will escape all XML special chars, such that pickling the value back becomes save. -- Pickling is done with 'Text.XML.HXT.Arrow.ReadDocument.xread' -xpXmlText :: PU String+xpXmlText :: PU String xpXmlText = xpWrap ( showXML, readXML ) $ xpTrees where@@ -382,30 +382,30 @@ -- -- The default pickler for Maybe types -xpOption :: PU a -> PU (Maybe a)+xpOption :: PU a -> PU (Maybe a) xpOption pa = PU { appPickle = ( \ (a, st) ->- case a of- Nothing -> st- Just x -> appPickle pa (x, st)- )+ case a of+ Nothing -> st+ Just x -> appPickle pa (x, st)+ ) - , appUnPickle = appUnPickle $- xpChoice (xpLift Nothing) pa (xpLift . Just)+ , appUnPickle = appUnPickle $+ xpChoice (xpLift Nothing) pa (xpLift . Just) , theSchema = scOption (theSchema pa)- }+ } -- | Optional conversion with default value -- -- The default value is not encoded in the XML document, -- during unpickling the default value is inserted if the pickler fails -xpDefault :: (Eq a) => a -> PU a -> PU a+xpDefault :: (Eq a) => a -> PU a -> PU a xpDefault df = xpWrap ( fromMaybe df- , \ x -> if x == df then Nothing else Just x- ) .+ , \ x -> if x == df then Nothing else Just x+ ) . xpOption -- ------------------------------------------------------------@@ -416,35 +416,35 @@ -- The standard pickler for lists. Can also be used in combination with 'xpWrap' -- for constructing set and map picklers -xpList :: PU a -> PU [a]+xpList :: PU a -> PU [a] xpList pa = PU { appPickle = ( \ (a, st) ->- case a of- [] -> st- _:_ -> appPickle pc (a, st)- )- , appUnPickle = appUnPickle $+ case a of+ [] -> st+ _:_ -> appPickle pc (a, st)+ )+ , appUnPickle = appUnPickle $ xpChoice (xpLift []) pa- (\ x -> xpSeq id (xpList pa) (\xs -> xpLift (x:xs)))+ (\ x -> xpSeq id (xpList pa) (\xs -> xpLift (x:xs))) - , theSchema = scList (theSchema pa)- }+ , theSchema = scList (theSchema pa)+ } where pc = xpSeq head pa (\ x ->- xpSeq tail (xpList pa) (\ xs ->- xpLift (x:xs)))+ xpSeq tail (xpList pa) (\ xs ->+ xpLift (x:xs))) -- | Encoding of a none empty list of values -- -- Attention: when calling this pickler with an empty list, -- an internal error \"head of empty list is raised\". -xpList1 :: PU a -> PU [a]+xpList1 :: PU a -> PU [a] xpList1 pa = ( xpWrap (\ (x, xs) -> x : xs- ,\ (x : xs) -> (x, xs)- ) $- xpPair pa (xpList pa)+ ,\ (x : xs) -> (x, xs)+ ) $+ xpPair pa (xpList pa) ) { theSchema = scList1 (theSchema pa) } -- ------------------------------------------------------------@@ -456,11 +456,11 @@ -- the key is encoded as an attribute named by the 2. argument, -- the 3. arg is the pickler for the keys, the last one for the values -xpMap :: Ord k => String -> String -> PU k -> PU v -> PU (Map k v)+xpMap :: Ord k => String -> String -> PU k -> PU v -> PU (Map k v) xpMap en an xpk xpv = xpWrap ( M.fromList- , M.toList- ) $+ , M.toList+ ) $ xpList $ xpElem en $ xpPair ( xpAttr an $ xpk ) xpv@@ -473,21 +473,21 @@ -- Every constructor is mapped to an index into the list of picklers. -- The index is used only during pickling, not during unpickling, there the 1. match is taken -xpAlt :: (a -> Int) -> [PU a] -> PU a+xpAlt :: (a -> Int) -> [PU a] -> PU a xpAlt tag ps = PU { appPickle = ( \ (a, st) ->- let- pa = ps !! (tag a)- in- appPickle pa (a, st)- )- , appUnPickle = appUnPickle $- ( case ps of- [] -> xpZero- pa:ps1 -> xpChoice (xpAlt tag ps1) pa xpLift- )- , theSchema = scAlts (map theSchema ps)- }+ let+ pa = ps !! (tag a)+ in+ appPickle pa (a, st)+ )+ , appUnPickle = appUnPickle $+ ( case ps of+ [] -> xpZero+ pa:ps1 -> xpChoice (xpAlt tag ps1) pa xpLift+ )+ , theSchema = scAlts (map theSchema ps)+ } -- ------------------------------------------------------------ @@ -504,36 +504,36 @@ -- -- > <number>42</number> -xpElemQN :: QName -> PU a -> PU a+xpElemQN :: QName -> PU a -> PU a xpElemQN qn pa = PU { appPickle = ( \ (a, st) ->- let- st' = appPickle pa (a, emptySt)- in- addCont (XN.mkElement qn (attributes st') (contents st')) st- )- , appUnPickle = \ st -> fromMaybe (Nothing, st) (unpickleElement st)- , theSchema = scElem (qualifiedName qn) (theSchema pa)- }+ let+ st' = appPickle pa (a, emptySt)+ in+ addCont (XN.mkElement qn (attributes st') (contents st')) st+ )+ , appUnPickle = \ st -> fromMaybe (Nothing, st) (unpickleElement st)+ , theSchema = scElem (qualifiedName qn) (theSchema pa)+ } where unpickleElement st- = do- t <- getCont st- n <- XN.getElemName t- if n /= qn- then fail ("element name " ++ show n ++ " does not match" ++ show qn)- else do- let cs = XN.getChildren t- al <- XN.getAttrl t- res <- fst . appUnPickle pa $ St {attributes = al, contents = cs}- return (Just res, dropCont st)+ = do+ t <- getCont st+ n <- XN.getElemName t+ if n /= qn+ then fail ("element name " ++ show n ++ " does not match" ++ show qn)+ else do+ let cs = XN.getChildren t+ al <- XN.getAttrl t+ res <- fst . appUnPickle pa $ St {attributes = al, contents = cs}+ return (Just res, dropCont st) -- | convenient Pickler for xpElemQN -- -- > xpElem n = xpElemQN (mkName n) -xpElem :: String -> PU a -> PU a-xpElem = xpElemQN . mkName+xpElem :: String -> PU a -> PU a+xpElem = xpElemQN . mkName -- ------------------------------------------------------------ @@ -560,35 +560,35 @@ -- > (xpElemWithAttrValue "attr" "name" "key2" $ xpText0) -- > (xpElemWithAttrValue "attr" "name" "key3" $ xpickle) -xpElemWithAttrValue :: String -> String -> String -> PU a -> PU a+xpElemWithAttrValue :: String -> String -> String -> PU a -> PU a xpElemWithAttrValue name an av pa = PU { appPickle = ( \ (a, st) ->- let- st' = appPickle pa' (a, emptySt)- in- addCont (XN.mkElement (mkName name) (attributes st') (contents st')) st- )- , appUnPickle = \ st -> fromMaybe (Nothing, st) (unpickleElement st)- , theSchema = scElem name (theSchema pa')- }+ let+ st' = appPickle pa' (a, emptySt)+ in+ addCont (XN.mkElement (mkName name) (attributes st') (contents st')) st+ )+ , appUnPickle = \ st -> fromMaybe (Nothing, st) (unpickleElement st)+ , theSchema = scElem name (theSchema pa')+ } where pa' = xpAddFixedAttr an av $ pa noMatch = null . runLA ( isElem- >>>- hasName name- >>>- hasAttrValue an (==av)- )+ >>>+ hasName name+ >>>+ hasAttrValue an (==av)+ ) unpickleElement st- = do- t <- getCont st- if noMatch t- then fail "element name or attr value does not match"- else do- let cs = XN.getChildren t- al <- XN.getAttrl t- res <- fst . appUnPickle pa $ St {attributes = al, contents = cs}- return (Just res, dropCont st)+ = do+ t <- getCont st+ if noMatch t+ then fail "element name or attr value does not match"+ else do+ let cs = XN.getChildren t+ al <- XN.getAttrl t+ res <- fst . appUnPickle pa $ St {attributes = al, contents = cs}+ return (Just res, dropCont st) -- ------------------------------------------------------------ @@ -596,56 +596,56 @@ -- -- The attribute is inserted in the surrounding element constructed by the 'xpElem' pickler -xpAttrQN :: QName -> PU a -> PU a+xpAttrQN :: QName -> PU a -> PU a xpAttrQN qn pa = PU { appPickle = ( \ (a, st) ->- let- st' = appPickle pa (a, emptySt)- in- addAtt (XN.mkAttr qn (contents st')) st- )- , appUnPickle = \ st -> fromMaybe (Nothing, st) (unpickleAttr st)- , theSchema = scAttr (qualifiedName qn) (theSchema pa)- }+ let+ st' = appPickle pa (a, emptySt)+ in+ addAtt (XN.mkAttr qn (contents st')) st+ )+ , appUnPickle = \ st -> fromMaybe (Nothing, st) (unpickleAttr st)+ , theSchema = scAttr (qualifiedName qn) (theSchema pa)+ } where unpickleAttr st- = do- a <- getAtt qn st- let av = XN.getChildren a- res <- fst . appUnPickle pa $ St {attributes = [], contents = av}- return (Just res, st) -- attribute is not removed from attribute list,- -- attributes are selected by name+ = do+ a <- getAtt qn st+ let av = XN.getChildren a+ res <- fst . appUnPickle pa $ St {attributes = [], contents = av}+ return (Just res, st) -- attribute is not removed from attribute list,+ -- attributes are selected by name -- | convenient Pickler for xpAttrQN -- -- > xpAttr n = xpAttrQN (mkName n) -xpAttr :: String -> PU a -> PU a-xpAttr = xpAttrQN . mkName+xpAttr :: String -> PU a -> PU a+xpAttr = xpAttrQN . mkName -- | Add an optional attribute for an optional value (Maybe a). -xpAttrImplied :: String -> PU a -> PU (Maybe a)+xpAttrImplied :: String -> PU a -> PU (Maybe a) xpAttrImplied name pa = xpOption $ xpAttr name pa -xpAttrFixed :: String -> String -> PU ()+xpAttrFixed :: String -> String -> PU () xpAttrFixed name val = ( xpWrapMaybe ( \ v -> if v == val then Just () else Nothing- , const val- ) $- xpAttr name xpText+ , const val+ ) $+ xpAttr name xpText ) { theSchema = scAttr name (scFixed val) } -- | Add an attribute with a fixed value. -- -- Useful e.g. to declare namespaces. Is implemented by 'xpAttrFixed' -xpAddFixedAttr :: String -> String -> PU a -> PU a+xpAddFixedAttr :: String -> String -> PU a -> PU a xpAddFixedAttr name val pa = xpWrap ( snd- , (,) ()- ) $+ , (,) ()+ ) $ xpPair (xpAttrFixed name val) pa -- ------------------------------------------------------------
src/Text/XML/HXT/Arrow/ProcessDocument.hs view
@@ -26,7 +26,7 @@ ) where -import Control.Arrow -- arrow classes+import Control.Arrow -- arrow classes import Control.Arrow.ArrowList import Control.Arrow.ArrowIf import Control.Arrow.ArrowTree@@ -67,7 +67,7 @@ -- ------------------------------------------------------------ -{- | +{- | XML parser Input tree must be a root tree with a text tree as child containing the document to be parsed.@@ -86,36 +86,36 @@ This parser is useful for applications processing correct XML documents. -} -parseXmlDocument :: Bool -> IOStateArrow s XmlTree XmlTree+parseXmlDocument :: Bool -> IOStateArrow s XmlTree XmlTree parseXmlDocument validate = ( replaceChildren ( ( getAttrValue a_source- &&&- xshow getChildren- )- >>>- parseXmlDoc- >>>- filterErrorMsg- )- >>>- setDocumentStatusFromSystemState "parse XML document"- >>>- processDTD- >>>- processGeneralEntities- >>>- transfAllCharRef- >>>- ( if validate- then validateDocument- else this- )+ &&&+ xshow getChildren+ )+ >>>+ parseXmlDoc+ >>>+ filterErrorMsg+ )+ >>>+ setDocumentStatusFromSystemState "parse XML document"+ >>>+ processDTD+ >>>+ processGeneralEntities+ >>>+ transfAllCharRef+ >>>+ ( if validate+ then validateDocument+ else this+ ) ) `when` documentStatusOk -- ------------------------------------------------------------ -{- | +{- | HTML parser Input tree must be a root tree with a text tree as child containing the document to be parsed.@@ -129,57 +129,57 @@ -} -parseHtmlDocument :: Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> IOStateArrow s XmlTree XmlTree+parseHtmlDocument :: Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> IOStateArrow s XmlTree XmlTree parseHtmlDocument withTagSoup withNamespaces warnings preserveCmt removeWhitespace asHtml = ( perform ( getAttrValue a_source >>> traceValue 1 (("parseHtmlDoc: parse HTML document " ++) . show) )- >>>- replaceChildren ( ( getAttrValue a_source -- get source name- &&&- xshow getChildren- ) -- get string to be parsed- >>>- parseHtml- )- >>>- removeWarnings- >>>- setDocumentStatusFromSystemState "parse HTML document"- >>>- traceTree- >>>- traceSource- >>>- perform ( getAttrValue a_source- >>>- traceValue 1 (\ src -> "parse HTML document " ++ show src ++ " finished")- )+ >>>+ replaceChildren ( ( getAttrValue a_source -- get source name+ &&&+ xshow getChildren+ ) -- get string to be parsed+ >>>+ parseHtml+ )+ >>>+ removeWarnings+ >>>+ setDocumentStatusFromSystemState "parse HTML document"+ >>>+ traceTree+ >>>+ traceSource+ >>>+ perform ( getAttrValue a_source+ >>>+ traceValue 1 (\ src -> "parse HTML document " ++ show src ++ " finished")+ ) ) `when` documentStatusOk where parseHtml- | withTagSoup = traceMsg 1 ("parse document with tagsoup " ++- ( if asHtml then "HT" else "X" ) ++ "ML parser"- )- >>>- parseHtmlTagSoup withNamespaces warnings preserveCmt removeWhitespace asHtml+ | withTagSoup = traceMsg 1 ("parse document with tagsoup " +++ ( if asHtml then "HT" else "X" ) ++ "ML parser"+ )+ >>>+ parseHtmlTagSoup withNamespaces warnings preserveCmt removeWhitespace asHtml - | otherwise = traceMsg 1 ("parse document with parsec HTML parser")- >>>- parseHtmlDoc -- run parser- >>>- substHtmlEntityRefs -- substitute entity refs+ | otherwise = traceMsg 1 ("parse document with parsec HTML parser")+ >>>+ parseHtmlDoc -- run parser+ >>>+ substHtmlEntityRefs -- substitute entity refs removeWarnings- | withTagSoup- &&- not warnings = this- | otherwise = processTopDownWithAttrl- ( if warnings -- remove warnings inserted by parser and entity subst- then filterErrorMsg- else ( none- `when`- isError- )- )+ | withTagSoup+ &&+ not warnings = this+ | otherwise = processTopDownWithAttrl+ ( if warnings -- remove warnings inserted by parser and entity subst+ then filterErrorMsg+ else ( none+ `when`+ isError+ )+ ) -- ------------------------------------------------------------ @@ -198,28 +198,28 @@ -} -validateDocument :: IOStateArrow s XmlTree XmlTree+validateDocument :: IOStateArrow s XmlTree XmlTree validateDocument = ( traceMsg 1 "validating document"- >>>- perform ( validateDoc- >>>- filterErrorMsg- )- >>>- setDocumentStatusFromSystemState "document validation"- >>>- transformDoc- >>>- traceMsg 1 "document validated"- >>>- traceSource- >>>- traceTree+ >>>+ perform ( validateDoc+ >>>+ filterErrorMsg+ )+ >>>+ setDocumentStatusFromSystemState "document validation"+ >>>+ transformDoc+ >>>+ traceMsg 1 "document validated"+ >>>+ traceSource+ >>>+ traceTree ) `when` documentStatusOk- + -- ------------------------------------------------------------ {- | Namespace propagation@@ -237,22 +237,22 @@ -} -propagateAndValidateNamespaces :: IOStateArrow s XmlTree XmlTree+propagateAndValidateNamespaces :: IOStateArrow s XmlTree XmlTree propagateAndValidateNamespaces = ( traceMsg 1 "propagating namespaces"- >>>- propagateNamespaces- >>>- traceDoc "propagating namespaces done"- >>>- traceMsg 1 "validating namespaces"- >>>- ( setDocumentStatusFromSystemState "namespace propagation"- `when`- ( validateNamespaces >>> perform filterErrorMsg )- )- >>>- traceMsg 1 "namespace validation finished"+ >>>+ propagateNamespaces+ >>>+ traceDoc "propagating namespaces done"+ >>>+ traceMsg 1 "validating namespaces"+ >>>+ ( setDocumentStatusFromSystemState "namespace propagation"+ `when`+ ( validateNamespaces >>> perform filterErrorMsg )+ )+ >>>+ traceMsg 1 "namespace validation finished" ) `when` documentStatusOk@@ -269,14 +269,14 @@ For supported protocols see 'Text.XML.HXT.Arrow.DocumentInput.getXmlContents' -} -getDocumentContents :: Attributes -> String -> IOStateArrow s b XmlTree+getDocumentContents :: Attributes -> String -> IOStateArrow s b XmlTree getDocumentContents options src = root [] [] >>> addAttr a_source src >>>- seqA (map (uncurry addAttr) options) -- add all options to doc root- >>> -- e.g. getXmlContents needs some of these+ seqA (map (uncurry addAttr) options) -- add all options to doc root+ >>> -- e.g. getXmlContents needs some of these traceMsg 1 ("readDocument: start processing document " ++ show src) >>> getXmlContents
src/Text/XML/HXT/Arrow/ReadDocument.hs view
@@ -28,28 +28,28 @@ import Control.Arrow.ListArrows -import Data.Char ( isDigit )+import Data.Char ( isDigit ) import Text.XML.HXT.DOM.Interface import Text.XML.HXT.Arrow.XmlArrow import Text.XML.HXT.Arrow.XmlIOStateArrow -import Text.XML.HXT.Arrow.Edit ( canonicalizeAllNodes- , canonicalizeForXPath- , canonicalizeContents+import Text.XML.HXT.Arrow.Edit ( canonicalizeAllNodes+ , canonicalizeForXPath+ , canonicalizeContents , rememberDTDAttrl- , removeDocWhiteSpace- )+ , removeDocWhiteSpace+ ) import Text.XML.HXT.Arrow.ParserInterface- -import Text.XML.HXT.Arrow.ProcessDocument ( getDocumentContents- , parseXmlDocument- , parseHtmlDocument- , propagateAndValidateNamespaces- ) -import Text.XML.HXT.RelaxNG.Validator ( validateDocumentWithRelaxSchema )+import Text.XML.HXT.Arrow.ProcessDocument ( getDocumentContents+ , parseXmlDocument+ , parseHtmlDocument+ , propagateAndValidateNamespaces+ ) +import Text.XML.HXT.RelaxNG.Validator ( validateDocumentWithRelaxSchema )+ -- ------------------------------------------------------------ {- |@@ -65,12 +65,12 @@ - 'a_parse_by_mimetype' : select the parser by the mime type of the document (pulled out of the HTTP header). When the mime type is set to \"text\/html\"- the HTML parser (parsec or tagsoup) is taken, when it\'s set to- \"text\/xml\" or \"text\/xhtml\" the XML parser (parsec or tagsoup) is taken.- If the mime type is something else no further processing is performed,- the contents is given back to the application in form of a single text node.- If the default document encoding ('a_encoding') is set to isoLatin1, this even enables processing- of arbitray binary data.+ the HTML parser (parsec or tagsoup) is taken, when it\'s set to+ \"text\/xml\" or \"text\/xhtml\" the XML parser (parsec or tagsoup) is taken.+ If the mime type is something else no further processing is performed,+ the contents is given back to the application in form of a single text node.+ If the default document encoding ('a_encoding') is set to isoLatin1, this even enables processing+ of arbitray binary data. - 'a_validate' : validate document againsd DTD (default), else skip validation @@ -107,7 +107,7 @@ - 'a_strict_input' : file input is done strictly using the 'Data.ByteString' input functions. This ensures correct closing of files, especially when working with the tagsoup parser and not processing the whole input data. Default is off. The @ByteString@ input usually is not faster than the buildin @hGetContents@- for strings.+ for strings. - 'a_options_curl' : deprecated but for compatibility reasons still supported. More options passed to the curl binding.@@ -117,7 +117,7 @@ - 'a_encoding' : default document encoding ('utf8', 'isoLatin1', 'usAscii', 'iso8859_2', ... , 'iso8859_16', ...). Only XML, HTML and text documents are decoded, default decoding for XML\/HTML is utf8, for text iso latin1 (no decoding).- The whole content is returned in a single text node.+ The whole content is returned in a single text node. - 'a_mime_types' : set the mime type table for file input with given file. The format of this config file must be in the syntax of a debian linux \"mime.types\" config file @@ -137,7 +137,7 @@ > readDocument [ ] "test.xml" -reads and validates a document \"test.xml\", no namespace propagation, only canonicalization is performed +reads and validates a document \"test.xml\", no namespace propagation, only canonicalization is performed > readDocument [ (a_validate, "0") > , (a_encoding, isoLatin1)@@ -182,10 +182,10 @@ for minimal complete examples see 'Text.XML.HXT.Arrow.WriteDocument.writeDocument' and 'runX', the main starting point for running an XML arrow. -} -readDocument :: Attributes -> String -> IOStateArrow s b XmlTree+readDocument :: Attributes -> String -> IOStateArrow s b XmlTree readDocument userOptions src = case getTraceLev of- Nothing -> readDocument' userOptions src+ Nothing -> readDocument' userOptions src Just l -> withTraceLevel l $ readDocument' userOptions src where getTraceLev = do@@ -194,7 +194,7 @@ then return (read s) else fail "not a number" -readDocument' :: Attributes -> String -> IOStateArrow s b XmlTree+readDocument' :: Attributes -> String -> IOStateArrow s b XmlTree readDocument' userOptions src = loadMineTypes (lookup1 a_mime_types userOptions) >>>@@ -209,157 +209,157 @@ traceTree where options- = addEntries userOptions defaultOptions+ = addEntries userOptions defaultOptions defaultOptions- = [ ( a_parse_html, v_0 )- , ( a_tagsoup, v_0 )- , ( a_strict_input, v_0 )- , ( a_validate, v_1 )- , ( a_issue_warnings, v_1 )- , ( a_check_namespaces, v_0 )- , ( a_canonicalize, v_1 )- , ( a_preserve_comment, v_0 )- , ( a_remove_whitespace, v_0 )- , ( a_parse_by_mimetype, v_0 )- , ( a_ignore_encoding_errors, v_0 )- , ( a_ignore_none_xml_contents, v_0 )- , ( a_accept_mimetypes, "" )- ]+ = [ ( a_parse_html, v_0 )+ , ( a_tagsoup, v_0 )+ , ( a_strict_input, v_0 )+ , ( a_validate, v_1 )+ , ( a_issue_warnings, v_1 )+ , ( a_check_namespaces, v_0 )+ , ( a_canonicalize, v_1 )+ , ( a_preserve_comment, v_0 )+ , ( a_remove_whitespace, v_0 )+ , ( a_parse_by_mimetype, v_0 )+ , ( a_ignore_encoding_errors, v_0 )+ , ( a_ignore_none_xml_contents, v_0 )+ , ( a_accept_mimetypes, "" )+ ] - loadMineTypes "" = this- loadMineTypes f = setMimeTypeTableFromFile f+ loadMineTypes "" = this+ loadMineTypes f = setMimeTypeTableFromFile f getMimeType- = getAttrValue transferMimeType >>^ stringToLower+ = getAttrValue transferMimeType >>^ stringToLower processDoc mimeType- = traceMsg 1 (unwords [ "readDocument:", show src- , "(mime type:", show mimeType, ") will be processed"])- >>>- ( if isAcceptedMimeType (lookup1 a_accept_mimetypes options) mimeType- then ( ifA (fromLA hasEmptyBody)- ( replaceChildren none ) -- empty response, e.g. in if-modified-since request+ = traceMsg 1 (unwords [ "readDocument:", show src+ , "(mime type:", show mimeType, ") will be processed"])+ >>>+ ( if isAcceptedMimeType (lookup1 a_accept_mimetypes options) mimeType+ then ( ifA (fromLA hasEmptyBody)+ ( replaceChildren none ) -- empty response, e.g. in if-modified-since request ( parse- >>>- ( if isXmlOrHtml- then ( checknamespaces- >>>+ >>>+ ( if isXmlOrHtml+ then ( checknamespaces+ >>> rememberDTDAttrl >>>- canonicalize- >>>- whitespace- >>>- relax- )- else this- )- )+ canonicalize+ >>>+ whitespace+ >>>+ relax+ )+ else this+ )+ ) )- else ( traceMsg 1 (unwords [ "readDocument:", show src- , "mime type:", show mimeType, "not accepted"])- >>>- replaceChildren none- ) -- remove contents of not accepted mimetype- )- where- hasEmptyBody :: LA XmlTree XmlTree- hasEmptyBody = hasAttrValue transferStatus (/= "200") -- test on empty response body for not o.k. responses- `guards` -- e.g. 3xx status values+ else ( traceMsg 1 (unwords [ "readDocument:", show src+ , "mime type:", show mimeType, "not accepted"])+ >>>+ replaceChildren none+ ) -- remove contents of not accepted mimetype+ )+ where+ hasEmptyBody :: LA XmlTree XmlTree+ hasEmptyBody = hasAttrValue transferStatus (/= "200") -- test on empty response body for not o.k. responses+ `guards` -- e.g. 3xx status values ( neg getChildren <+> ( getChildren >>> isWhiteSpace ) ) - isAcceptedMimeType :: String -> String -> Bool- isAcceptedMimeType mts mt- | null mts- ||- null mt = True- | otherwise = foldr (matchMt mt') False $ mts'- where- mt' = parseMt mt- mts' = words- >>>- map parseMt- $- mts- parseMt = break (== '/')- >>>- second (drop 1)- matchMt (ma,mi) (mas,mis) r = ( (ma == mas || mas == "*")- &&- (mi == mis || mis == "*")- )- || r- parse- | isHtml- || - withTagSoup = parseHtmlDocument -- parse as HTML or with tagsoup XML- withTagSoup- withNamespaces- issueW- (not (hasOption a_canonicalize) && preserveCmt)- removeWS- isHtml- | validateWithRelax = parseXmlDocument False -- for Relax NG use XML parser without validation- | isXml = parseXmlDocument validate -- parse as XML- | removeNoneXml = replaceChildren none -- don't parse, if mime type is not XML nor HTML- | otherwise = this -- but remove contents when option is set- checknamespaces- | (withNamespaces && not withTagSoup)- ||- validateWithRelax = propagateAndValidateNamespaces- | otherwise = this- canonicalize- | withTagSoup = this -- tagsoup already removes redundant stuff- | validateWithRelax = canonicalizeAllNodes- | hasOption a_canonicalize- &&- preserveCmt = canonicalizeForXPath- | hasOption a_canonicalize = canonicalizeAllNodes- | otherwise = this- relax- | validateWithRelax = validateDocumentWithRelaxSchema options relaxSchema- | otherwise = this- whitespace- | removeWS- &&- not withTagSoup = removeDocWhiteSpace -- tagsoup already removes whitespace- | otherwise = this- validateWithRelax = hasEntry a_relax_schema options- relaxSchema = lookup1 a_relax_schema options- parseHtml = hasOption a_parse_html- isHtml = parseHtml -- force HTML- ||- ( parseByMimeType && isHtmlMimeType mimeType )- isXml = ( not parseByMimeType && not parseHtml )- ||- ( parseByMimeType- &&- ( isXmlMimeType mimeType- ||- null mimeType- ) -- mime type is XML or not known- )- isXmlOrHtml = isHtml || isXml- parseByMimeType = hasOption a_parse_by_mimetype- validate = hasOption a_validate- withNamespaces = hasOption a_check_namespaces- withTagSoup = hasOption a_tagsoup- issueW = hasOption a_issue_warnings- removeWS = hasOption a_remove_whitespace- preserveCmt = hasOption a_preserve_comment- removeNoneXml = hasOption a_ignore_none_xml_contents- hasOption n = optionIsSet n options+ isAcceptedMimeType :: String -> String -> Bool+ isAcceptedMimeType mts mt+ | null mts+ ||+ null mt = True+ | otherwise = foldr (matchMt mt') False $ mts'+ where+ mt' = parseMt mt+ mts' = words+ >>>+ map parseMt+ $+ mts+ parseMt = break (== '/')+ >>>+ second (drop 1)+ matchMt (ma,mi) (mas,mis) r = ( (ma == mas || mas == "*")+ &&+ (mi == mis || mis == "*")+ )+ || r+ parse+ | isHtml+ ||+ withTagSoup = parseHtmlDocument -- parse as HTML or with tagsoup XML+ withTagSoup+ withNamespaces+ issueW+ (not (hasOption a_canonicalize) && preserveCmt)+ removeWS+ isHtml+ | validateWithRelax = parseXmlDocument False -- for Relax NG use XML parser without validation+ | isXml = parseXmlDocument validate -- parse as XML+ | removeNoneXml = replaceChildren none -- don't parse, if mime type is not XML nor HTML+ | otherwise = this -- but remove contents when option is set+ checknamespaces+ | (withNamespaces && not withTagSoup)+ ||+ validateWithRelax = propagateAndValidateNamespaces+ | otherwise = this+ canonicalize+ | withTagSoup = this -- tagsoup already removes redundant stuff+ | validateWithRelax = canonicalizeAllNodes+ | hasOption a_canonicalize+ &&+ preserveCmt = canonicalizeForXPath+ | hasOption a_canonicalize = canonicalizeAllNodes+ | otherwise = this+ relax+ | validateWithRelax = validateDocumentWithRelaxSchema options relaxSchema+ | otherwise = this+ whitespace+ | removeWS+ &&+ not withTagSoup = removeDocWhiteSpace -- tagsoup already removes whitespace+ | otherwise = this+ validateWithRelax = hasEntry a_relax_schema options+ relaxSchema = lookup1 a_relax_schema options+ parseHtml = hasOption a_parse_html+ isHtml = parseHtml -- force HTML+ ||+ ( parseByMimeType && isHtmlMimeType mimeType )+ isXml = ( not parseByMimeType && not parseHtml )+ ||+ ( parseByMimeType+ &&+ ( isXmlMimeType mimeType+ ||+ null mimeType+ ) -- mime type is XML or not known+ )+ isXmlOrHtml = isHtml || isXml+ parseByMimeType = hasOption a_parse_by_mimetype+ validate = hasOption a_validate+ withNamespaces = hasOption a_check_namespaces+ withTagSoup = hasOption a_tagsoup+ issueW = hasOption a_issue_warnings+ removeWS = hasOption a_remove_whitespace+ preserveCmt = hasOption a_preserve_comment+ removeNoneXml = hasOption a_ignore_none_xml_contents+ hasOption n = optionIsSet n options -- ------------------------------------------------------------ -- | -- the arrow version of 'readDocument', the arrow input is the source URI -readFromDocument :: Attributes -> IOStateArrow s String XmlTree+readFromDocument :: Attributes -> IOStateArrow s String XmlTree readFromDocument userOptions = applyA ( arr $ readDocument userOptions ) @@ -373,7 +373,7 @@ -- -- Default encoding: No encoding is done, the String argument is taken as Unicode string -readString :: Attributes -> String -> IOStateArrow s b XmlTree+readString :: Attributes -> String -> IOStateArrow s b XmlTree readString userOptions content = readDocument ( (a_encoding, unicodeString) : userOptions ) (stringProtocol ++ content) @@ -382,7 +382,7 @@ -- | -- the arrow version of 'readString', the arrow input is the source URI -readFromString :: Attributes -> IOStateArrow s String XmlTree+readFromString :: Attributes -> IOStateArrow s String XmlTree readFromString userOptions = applyA ( arr $ readString userOptions ) @@ -391,11 +391,11 @@ -- | -- parse a string as HTML content, substitute all HTML entity refs and canonicalize tree -- (substitute char refs, ...). Errors are ignored.--- +-- -- A simpler version of 'readFromString' but with less functionality. -- Does not run in the IO monad -hread :: ArrowXml a => a String XmlTree+hread :: ArrowXml a => a String XmlTree hread = parseHtmlContent >>>@@ -409,7 +409,7 @@ -- parse a string as XML content, substitute all predefined XML entity refs and canonicalize tree -- (substitute char refs, ...) -xread :: ArrowXml a => a String XmlTree+xread :: ArrowXml a => a String XmlTree xread = parseXmlContent >>>
src/Text/XML/HXT/Arrow/WriteDocument.hs view
@@ -22,7 +22,7 @@ ) where -import Control.Arrow -- arrow classes+import Control.Arrow -- arrow classes import Control.Arrow.ArrowList import Control.Arrow.ArrowIf import Control.Arrow.ArrowTree@@ -31,20 +31,20 @@ import Text.XML.HXT.Arrow.XmlArrow import Text.XML.HXT.Arrow.XmlIOStateArrow -import Text.XML.HXT.Arrow.Edit ( escapeHtmlDoc- , escapeXmlDoc- , haskellRepOfXmlDoc- , indentDoc+import Text.XML.HXT.Arrow.Edit ( escapeHtmlDoc+ , escapeXmlDoc+ , haskellRepOfXmlDoc+ , indentDoc , addDefaultDTDecl- , preventEmptyElements- , removeDocWhiteSpace- , treeRepOfXmlDoc- )+ , preventEmptyElements+ , removeDocWhiteSpace+ , treeRepOfXmlDoc+ ) -import Text.XML.HXT.Arrow.DocumentOutput ( putXmlDocument- , encodeDocument- , encodeDocument'- )+import Text.XML.HXT.Arrow.DocumentOutput ( putXmlDocument+ , encodeDocument+ , encodeDocument'+ ) -- ------------------------------------------------------------ @@ -95,9 +95,9 @@ > module Main > where-> +> > import Text.XML.HXT.Arrow-> +> > main :: IO () > main > = do@@ -112,10 +112,10 @@ > module Main > where-> +> > import Text.XML.HXT.Arrow > import System.Exit-> +> > main :: IO () > main > = do@@ -133,20 +133,20 @@ > ) -} -writeDocument :: Attributes -> String -> IOStateArrow s XmlTree XmlTree+writeDocument :: Attributes -> String -> IOStateArrow s XmlTree XmlTree writeDocument userOptions dst = perform ( traceMsg 1 ("writeDocument: destination is " ++ show dst)- >>>- prepareContents userOptions encodeDocument- >>>- putXmlDocument textMode dst- >>>- traceMsg 1 "writeDocument: finished"- )+ >>>+ prepareContents userOptions encodeDocument+ >>>+ putXmlDocument textMode dst+ >>>+ traceMsg 1 "writeDocument: finished"+ ) `when` documentStatusOk where- textMode = optionIsSet a_text_mode userOptions+ textMode = optionIsSet a_text_mode userOptions -- ------------------------------------------------------------ @@ -162,7 +162,7 @@ -- The XML PI is suppressed, if not explicitly turned on with an -- option @ (a_no_xml_pi, v_0) @ -writeDocumentToString :: ArrowXml a => Attributes -> a XmlTree String+writeDocumentToString :: ArrowXml a => Attributes -> a XmlTree String writeDocumentToString userOptions = prepareContents ( addEntries userOptions@@ -178,7 +178,7 @@ -- | -- indent and format output -prepareContents :: ArrowXml a => Attributes -> (Bool -> String -> a XmlTree XmlTree) -> a XmlTree XmlTree+prepareContents :: ArrowXml a => Attributes -> (Bool -> String -> a XmlTree XmlTree) -> a XmlTree XmlTree prepareContents userOptions encodeDoc = indent >>>@@ -188,37 +188,37 @@ where formatEmptyElems | not (null noEmptyElemFor) = preventEmptyElements noEmptyElemFor- | hasOption a_no_empty_elements+ | hasOption a_no_empty_elements || hasOption a_output_xhtml = preventEmptyElements []- | otherwise = const this+ | otherwise = const this addDtd | hasOption a_add_default_dtd = addDefaultDTDecl | otherwise = this indent- | hasOption a_indent = indentDoc -- document indentation- | hasOption a_remove_whitespace = removeDocWhiteSpace -- remove all whitespace between tags- | otherwise = this+ | hasOption a_indent = indentDoc -- document indentation+ | hasOption a_remove_whitespace = removeDocWhiteSpace -- remove all whitespace between tags+ | otherwise = this format- | hasOption a_show_tree = treeRepOfXmlDoc- | hasOption a_show_haskell = haskellRepOfXmlDoc- | hasOption a_output_html = formatEmptyElems True- >>>- escapeHtmlDoc -- escape al XML and HTML chars >= 128- >>>- encodeDoc -- convert doc into text with respect to output encoding with ASCII as default- suppressXmlPi ( lookupDef usAscii a_output_encoding options )- | hasOption a_output_xml = formatEmptyElems (hasOption a_output_xhtml)- >>>- escapeXmlDoc -- escape lt, gt, amp, quot, - >>>- encodeDoc -- convert doc into text with respect to output encoding- suppressXmlPi ( lookupDef "" a_output_encoding options )- | otherwise = this+ | hasOption a_show_tree = treeRepOfXmlDoc+ | hasOption a_show_haskell = haskellRepOfXmlDoc+ | hasOption a_output_html = formatEmptyElems True+ >>>+ escapeHtmlDoc -- escape al XML and HTML chars >= 128+ >>>+ encodeDoc -- convert doc into text with respect to output encoding with ASCII as default+ suppressXmlPi ( lookupDef usAscii a_output_encoding options )+ | hasOption a_output_xml = formatEmptyElems (hasOption a_output_xhtml)+ >>>+ escapeXmlDoc -- escape lt, gt, amp, quot,+ >>>+ encodeDoc -- convert doc into text with respect to output encoding+ suppressXmlPi ( lookupDef "" a_output_encoding options )+ | otherwise = this - suppressXmlPi -- remove <?xml ... ?> when set- = hasOption a_no_xml_pi+ suppressXmlPi -- remove <?xml ... ?> when set+ = hasOption a_no_xml_pi noEmptyElemFor = words@@ -227,21 +227,21 @@ $ options hasOption n- = optionIsSet n options+ = optionIsSet n options - options = addEntries - userOptions - [ ( a_indent, v_0 )- , ( a_remove_whitespace, v_0 )- , ( a_output_xml, v_1 )- , ( a_show_tree, v_0 )- , ( a_show_haskell, v_0 )- , ( a_output_html, v_0 )- , ( a_output_xhtml, v_0 )- , ( a_no_xml_pi, v_0 )- , ( a_no_empty_elements, v_0 )+ options = addEntries+ userOptions+ [ ( a_indent, v_0 )+ , ( a_remove_whitespace, v_0 )+ , ( a_output_xml, v_1 )+ , ( a_show_tree, v_0 )+ , ( a_show_haskell, v_0 )+ , ( a_output_html, v_0 )+ , ( a_output_xhtml, v_0 )+ , ( a_no_xml_pi, v_0 )+ , ( a_no_empty_elements, v_0 ) , ( a_no_empty_elem_for, "" ) , ( a_add_default_dtd, v_0 )- ]+ ] -- ------------------------------------------------------------
src/Text/XML/HXT/Arrow/XmlArrow.hs view
@@ -21,12 +21,12 @@ ( module Text.XML.HXT.Arrow.XmlArrow ) where -import Control.Arrow -- classes+import Control.Arrow -- classes import Control.Arrow.ArrowList import Control.Arrow.ArrowIf import Control.Arrow.ArrowTree -import Control.Arrow.ListArrow -- arrow types+import Control.Arrow.ListArrow -- arrow types import Control.Arrow.StateListArrow import Control.Arrow.IOListArrow import Control.Arrow.IOStateListArrow@@ -34,8 +34,8 @@ import Data.Maybe import Text.XML.HXT.DOM.Interface-import Text.XML.HXT.DOM.Unicode ( isXmlSpaceChar- )+import Text.XML.HXT.DOM.Unicode ( isXmlSpaceChar+ ) import qualified Text.XML.HXT.DOM.XmlNode as XN import qualified Text.XML.HXT.DOM.ShowXml as XS @@ -62,165 +62,165 @@ -- discriminating predicates -- | test for text nodes- isText :: a XmlTree XmlTree- isText = isA XN.isText+ isText :: a XmlTree XmlTree+ isText = isA XN.isText -- | test for char reference, used during parsing- isCharRef :: a XmlTree XmlTree- isCharRef = isA XN.isCharRef+ isCharRef :: a XmlTree XmlTree+ isCharRef = isA XN.isCharRef -- | test for entity reference, used during parsing- isEntityRef :: a XmlTree XmlTree- isEntityRef = isA XN.isEntityRef+ isEntityRef :: a XmlTree XmlTree+ isEntityRef = isA XN.isEntityRef -- | test for comment- isCmt :: a XmlTree XmlTree- isCmt = isA XN.isCmt+ isCmt :: a XmlTree XmlTree+ isCmt = isA XN.isCmt -- | test for CDATA section, used during parsing- isCdata :: a XmlTree XmlTree- isCdata = isA XN.isCdata+ isCdata :: a XmlTree XmlTree+ isCdata = isA XN.isCdata -- | test for processing instruction- isPi :: a XmlTree XmlTree- isPi = isA XN.isPi+ isPi :: a XmlTree XmlTree+ isPi = isA XN.isPi -- | test for processing instruction \<?xml ...\>- isXmlPi :: a XmlTree XmlTree- isXmlPi = isPi >>> hasName "xml"+ isXmlPi :: a XmlTree XmlTree+ isXmlPi = isPi >>> hasName "xml" -- | test for element- isElem :: a XmlTree XmlTree- isElem = isA XN.isElem+ isElem :: a XmlTree XmlTree+ isElem = isA XN.isElem -- | test for DTD part, used during parsing- isDTD :: a XmlTree XmlTree- isDTD = isA XN.isDTD+ isDTD :: a XmlTree XmlTree+ isDTD = isA XN.isDTD -- | test for attribute tree- isAttr :: a XmlTree XmlTree- isAttr = isA XN.isAttr+ isAttr :: a XmlTree XmlTree+ isAttr = isA XN.isAttr -- | test for error message- isError :: a XmlTree XmlTree- isError = isA XN.isError+ isError :: a XmlTree XmlTree+ isError = isA XN.isError -- | test for root node (element with name \"\/\")- isRoot :: a XmlTree XmlTree- isRoot = isA XN.isRoot+ isRoot :: a XmlTree XmlTree+ isRoot = isA XN.isRoot -- | test for text nodes with text, for which a predicate holds -- -- example: @hasText (all (\`elem\` \" \\t\\n\"))@ check for text nodes with only whitespace content- - hasText :: (String -> Bool) -> a XmlTree XmlTree- hasText p = (isText >>> getText >>> isA p) `guards` this + hasText :: (String -> Bool) -> a XmlTree XmlTree+ hasText p = (isText >>> getText >>> isA p) `guards` this+ -- | test for text nodes with only white space -- -- implemented with 'hasTest' - isWhiteSpace :: a XmlTree XmlTree+ isWhiteSpace :: a XmlTree XmlTree isWhiteSpace = hasText (all isXmlSpaceChar) -- | -- test whether a node (element, attribute, pi) has a name with a special property - hasNameWith :: (QName -> Bool) -> a XmlTree XmlTree- hasNameWith p = (getQName >>> isA p) `guards` this+ hasNameWith :: (QName -> Bool) -> a XmlTree XmlTree+ hasNameWith p = (getQName >>> isA p) `guards` this -- | -- test whether a node (element, attribute, pi) has a specific qualified name -- useful only after namespace propagation- hasQName :: QName -> a XmlTree XmlTree- hasQName n = (getQName >>> isA (== n)) `guards` this+ hasQName :: QName -> a XmlTree XmlTree+ hasQName n = (getQName >>> isA (== n)) `guards` this -- | -- test whether a node has a specific name (prefix:localPart ore localPart), -- generally useful, even without namespace handling- hasName :: String -> a XmlTree XmlTree- hasName n = (getName >>> isA (== n)) `guards` this+ hasName :: String -> a XmlTree XmlTree+ hasName n = (getName >>> isA (== n)) `guards` this -- | -- test whether a node has a specific name as local part, -- useful only after namespace propagation- hasLocalPart :: String -> a XmlTree XmlTree- hasLocalPart n = (getLocalPart >>> isA (== n)) `guards` this+ hasLocalPart :: String -> a XmlTree XmlTree+ hasLocalPart n = (getLocalPart >>> isA (== n)) `guards` this -- | -- test whether a node has a specific name prefix, -- useful only after namespace propagation- hasNamePrefix :: String -> a XmlTree XmlTree- hasNamePrefix n = (getNamePrefix >>> isA (== n)) `guards` this+ hasNamePrefix :: String -> a XmlTree XmlTree+ hasNamePrefix n = (getNamePrefix >>> isA (== n)) `guards` this -- | -- test whether a node has a specific namespace URI -- useful only after namespace propagation- hasNamespaceUri :: String -> a XmlTree XmlTree- hasNamespaceUri n = (getNamespaceUri >>> isA (== n)) `guards` this+ hasNamespaceUri :: String -> a XmlTree XmlTree+ hasNamespaceUri n = (getNamespaceUri >>> isA (== n)) `guards` this -- | -- test whether an element node has an attribute node with a specific name- hasAttr :: String -> a XmlTree XmlTree- hasAttr n = (getAttrl >>> hasName n) `guards` this+ hasAttr :: String -> a XmlTree XmlTree+ hasAttr n = (getAttrl >>> hasName n) `guards` this -- | -- test whether an element node has an attribute node with a specific qualified name- hasQAttr :: QName -> a XmlTree XmlTree- hasQAttr n = (getAttrl >>> hasQName n) `guards` this+ hasQAttr :: QName -> a XmlTree XmlTree+ hasQAttr n = (getAttrl >>> hasQName n) `guards` this -- | -- test whether an element node has an attribute with a specific value- hasAttrValue :: String -> (String -> Bool) -> a XmlTree XmlTree- hasAttrValue n p = (getAttrl >>> hasName n >>> xshow getChildren >>> isA p) `guards` this+ hasAttrValue :: String -> (String -> Bool) -> a XmlTree XmlTree+ hasAttrValue n p = (getAttrl >>> hasName n >>> xshow getChildren >>> isA p) `guards` this -- | -- test whether an element node has an attribute with a qualified name and a specific value- hasQAttrValue :: QName -> (String -> Bool) -> a XmlTree XmlTree- hasQAttrValue n p = (getAttrl >>> hasQName n >>> xshow getChildren >>> isA p) `guards` this+ hasQAttrValue :: QName -> (String -> Bool) -> a XmlTree XmlTree+ hasQAttrValue n p = (getAttrl >>> hasQName n >>> xshow getChildren >>> isA p) `guards` this -- constructor arrows ------------------------------------------------------------ -- | text node construction arrow- mkText :: a String XmlTree- mkText = arr XN.mkText+ mkText :: a String XmlTree+ mkText = arr XN.mkText -- | char reference construction arrow, useful for document output- mkCharRef :: a Int XmlTree- mkCharRef = arr XN.mkCharRef+ mkCharRef :: a Int XmlTree+ mkCharRef = arr XN.mkCharRef -- | entity reference construction arrow, useful for document output- mkEntityRef :: a String XmlTree- mkEntityRef = arr XN.mkEntityRef+ mkEntityRef :: a String XmlTree+ mkEntityRef = arr XN.mkEntityRef -- | comment node construction, useful for document output- mkCmt :: a String XmlTree- mkCmt = arr XN.mkCmt+ mkCmt :: a String XmlTree+ mkCmt = arr XN.mkCmt -- | CDATA construction, useful for document output- mkCdata :: a String XmlTree- mkCdata = arr XN.mkCdata+ mkCdata :: a String XmlTree+ mkCdata = arr XN.mkCdata -- | error node construction, useful only internally- mkError :: Int -> a String XmlTree- mkError level = arr (XN.mkError level)+ mkError :: Int -> a String XmlTree+ mkError level = arr (XN.mkError level) -- | element construction: -- | the attributes and the content of the element are computed by applying arrows -- to the input- mkElement :: QName -> a n XmlTree -> a n XmlTree -> a n XmlTree- mkElement n af cf = (listA af &&& listA cf)- >>>- arr2 (\ al cl -> XN.mkElement n al cl)+ mkElement :: QName -> a n XmlTree -> a n XmlTree -> a n XmlTree+ mkElement n af cf = (listA af &&& listA cf)+ >>>+ arr2 (\ al cl -> XN.mkElement n al cl) -- | attribute node construction: -- | the attribute value is computed by applying an arrow to the input- mkAttr :: QName -> a n XmlTree -> a n XmlTree- mkAttr qn f = listA f >>> arr (XN.mkAttr qn)+ mkAttr :: QName -> a n XmlTree -> a n XmlTree+ mkAttr qn f = listA f >>> arr (XN.mkAttr qn) -- | processing instruction construction: -- | the content of the processing instruction is computed by applying an arrow to the input- mkPi :: QName -> a n XmlTree -> a n XmlTree- mkPi qn f = listA f >>> arr (XN.mkPi qn)+ mkPi :: QName -> a n XmlTree -> a n XmlTree+ mkPi qn f = listA f >>> arr (XN.mkPi qn) -- convenient arrows for constructors -------------------------------------------------- @@ -234,276 +234,276 @@ -- -- > mkqelem qn [a1,...,ai] [c1,...,cj] - mkqelem :: QName -> [a n XmlTree] -> [a n XmlTree] -> a n XmlTree- mkqelem n afs cfs = mkElement n (catA afs) (catA cfs)+ mkqelem :: QName -> [a n XmlTree] -> [a n XmlTree] -> a n XmlTree+ mkqelem n afs cfs = mkElement n (catA afs) (catA cfs) -- | convenient arrow for element construction with strings instead of qualified names as element names, see also 'mkElement' and 'mkelem'- mkelem :: String -> [a n XmlTree] -> [a n XmlTree] -> a n XmlTree- mkelem n afs cfs = mkElement (mkName n) (catA afs) (catA cfs)+ mkelem :: String -> [a n XmlTree] -> [a n XmlTree] -> a n XmlTree+ mkelem n afs cfs = mkElement (mkName n) (catA afs) (catA cfs) -- | convenient arrow for element constrution with attributes but without content, simple variant of 'mkelem' and 'mkElement'- aelem :: String -> [a n XmlTree] -> a n XmlTree- aelem n afs = catA afs >. \ al -> XN.mkElement (mkName n) al []+ aelem :: String -> [a n XmlTree] -> a n XmlTree+ aelem n afs = catA afs >. \ al -> XN.mkElement (mkName n) al [] -- | convenient arrow for simple element constrution without attributes, simple variant of 'mkelem' and 'mkElement'- selem :: String -> [a n XmlTree] -> a n XmlTree- selem n cfs = catA cfs >. XN.mkElement (mkName n) []+ selem :: String -> [a n XmlTree] -> a n XmlTree+ selem n cfs = catA cfs >. XN.mkElement (mkName n) [] -- | convenient arrow for constrution of empty elements without attributes, simple variant of 'mkelem' and 'mkElement'- eelem :: String -> a n XmlTree- eelem n = constA (XN.mkElement (mkName n) [] [])+ eelem :: String -> a n XmlTree+ eelem n = constA (XN.mkElement (mkName n) [] []) -- | construction of an element node with name \"\/\" for document roots- root :: [a n XmlTree] -> [a n XmlTree] -> a n XmlTree- root = mkelem t_root+ root :: [a n XmlTree] -> [a n XmlTree] -> a n XmlTree+ root = mkelem t_root -- | alias for 'mkAttr'- qattr :: QName -> a n XmlTree -> a n XmlTree- qattr = mkAttr+ qattr :: QName -> a n XmlTree -> a n XmlTree+ qattr = mkAttr -- | convenient arrow for attribute constrution, simple variant of 'mkAttr'- attr :: String -> a n XmlTree -> a n XmlTree- attr = mkAttr . mkName+ attr :: String -> a n XmlTree -> a n XmlTree+ attr = mkAttr . mkName -- constant arrows (ignoring the input) for tree construction ------------------------------ -- | constant arrow for text nodes- txt :: String -> a n XmlTree- txt = constA . XN.mkText+ txt :: String -> a n XmlTree+ txt = constA . XN.mkText -- | constant arrow for char reference nodes- charRef :: Int -> a n XmlTree- charRef = constA . XN.mkCharRef+ charRef :: Int -> a n XmlTree+ charRef = constA . XN.mkCharRef -- | constant arrow for entity reference nodes- entityRef :: String -> a n XmlTree- entityRef = constA . XN.mkEntityRef+ entityRef :: String -> a n XmlTree+ entityRef = constA . XN.mkEntityRef -- | constant arrow for comment- cmt :: String -> a n XmlTree- cmt = constA . XN.mkCmt+ cmt :: String -> a n XmlTree+ cmt = constA . XN.mkCmt -- | constant arrow for warning- warn :: String -> a n XmlTree- warn = constA . (XN.mkError c_warn)+ warn :: String -> a n XmlTree+ warn = constA . (XN.mkError c_warn) -- | constant arrow for errors- err :: String -> a n XmlTree- err = constA . (XN.mkError c_err)+ err :: String -> a n XmlTree+ err = constA . (XN.mkError c_err) -- | constant arrow for fatal errors- fatal :: String -> a n XmlTree- fatal = constA . (XN.mkError c_fatal)+ fatal :: String -> a n XmlTree+ fatal = constA . (XN.mkError c_fatal) -- | constant arrow for simple processing instructions, see 'mkPi'- spi :: String -> String -> a n XmlTree- spi piName piCont = constA (XN.mkPi (mkName piName) [XN.mkText piCont])+ spi :: String -> String -> a n XmlTree+ spi piName piCont = constA (XN.mkPi (mkName piName) [XN.mkText piCont]) -- | constant arrow for attribute nodes, attribute name is a qualified name and value is a text, -- | see also 'mkAttr', 'qattr', 'attr'- sqattr :: QName -> String -> a n XmlTree- sqattr an av = constA (XN.mkAttr an [XN.mkText av])+ sqattr :: QName -> String -> a n XmlTree+ sqattr an av = constA (XN.mkAttr an [XN.mkText av]) -- | constant arrow for attribute nodes, attribute name and value are -- | given by parameters, see 'mkAttr'- sattr :: String -> String -> a n XmlTree- sattr an av = constA (XN.mkAttr (mkName an) [XN.mkText av])+ sattr :: String -> String -> a n XmlTree+ sattr an av = constA (XN.mkAttr (mkName an) [XN.mkText av]) -- selector arrows -------------------------------------------------- -- | select the text of a text node- getText :: a XmlTree String- getText = arrL (maybeToList . XN.getText)+ getText :: a XmlTree String+ getText = arrL (maybeToList . XN.getText) -- | select the value of a char reference- getCharRef :: a XmlTree Int- getCharRef = arrL (maybeToList . XN.getCharRef)+ getCharRef :: a XmlTree Int+ getCharRef = arrL (maybeToList . XN.getCharRef) -- | select the name of a entity reference node- getEntityRef :: a XmlTree String- getEntityRef = arrL (maybeToList . XN.getEntityRef)+ getEntityRef :: a XmlTree String+ getEntityRef = arrL (maybeToList . XN.getEntityRef) -- | select the comment of a comment node- getCmt :: a XmlTree String- getCmt = arrL (maybeToList . XN.getCmt)+ getCmt :: a XmlTree String+ getCmt = arrL (maybeToList . XN.getCmt) -- | select the content of a CDATA node- getCdata :: a XmlTree String- getCdata = arrL (maybeToList . XN.getCdata)+ getCdata :: a XmlTree String+ getCdata = arrL (maybeToList . XN.getCdata) -- | select the name of a processing instruction- getPiName :: a XmlTree QName- getPiName = arrL (maybeToList . XN.getPiName)+ getPiName :: a XmlTree QName+ getPiName = arrL (maybeToList . XN.getPiName) -- | select the content of a processing instruction- getPiContent :: a XmlTree XmlTree- getPiContent = arrL (fromMaybe [] . XN.getPiContent)+ getPiContent :: a XmlTree XmlTree+ getPiContent = arrL (fromMaybe [] . XN.getPiContent) -- | select the name of an element node- getElemName :: a XmlTree QName- getElemName = arrL (maybeToList . XN.getElemName)+ getElemName :: a XmlTree QName+ getElemName = arrL (maybeToList . XN.getElemName) -- | select the attribute list of an element node- getAttrl :: a XmlTree XmlTree- getAttrl = arrL (fromMaybe [] . XN.getAttrl)+ getAttrl :: a XmlTree XmlTree+ getAttrl = arrL (fromMaybe [] . XN.getAttrl) -- | select the DTD type of a DTD node- getDTDPart :: a XmlTree DTDElem- getDTDPart = arrL (maybeToList . XN.getDTDPart)+ getDTDPart :: a XmlTree DTDElem+ getDTDPart = arrL (maybeToList . XN.getDTDPart) -- | select the DTD attributes of a DTD node- getDTDAttrl :: a XmlTree Attributes- getDTDAttrl = arrL (maybeToList . XN.getDTDAttrl)+ getDTDAttrl :: a XmlTree Attributes+ getDTDAttrl = arrL (maybeToList . XN.getDTDAttrl) -- | select the name of an attribute- getAttrName :: a XmlTree QName- getAttrName = arrL (maybeToList . XN.getAttrName)+ getAttrName :: a XmlTree QName+ getAttrName = arrL (maybeToList . XN.getAttrName) -- | select the error level (c_warn, c_err, c_fatal) from an error node- getErrorLevel :: a XmlTree Int- getErrorLevel = arrL (maybeToList . XN.getErrorLevel)+ getErrorLevel :: a XmlTree Int+ getErrorLevel = arrL (maybeToList . XN.getErrorLevel) -- | select the error message from an error node- getErrorMsg :: a XmlTree String- getErrorMsg = arrL (maybeToList . XN.getErrorMsg)+ getErrorMsg :: a XmlTree String+ getErrorMsg = arrL (maybeToList . XN.getErrorMsg) -- | select the qualified name from an element, attribute or pi- getQName :: a XmlTree QName- getQName = arrL (maybeToList . XN.getName)+ getQName :: a XmlTree QName+ getQName = arrL (maybeToList . XN.getName) -- | select the prefix:localPart or localPart from an element, attribute or pi- getName :: a XmlTree String- getName = arrL (maybeToList . XN.getQualifiedName)+ getName :: a XmlTree String+ getName = arrL (maybeToList . XN.getQualifiedName) -- | select the univeral name ({namespace URI} ++ localPart)- getUniversalName :: a XmlTree String- getUniversalName = arrL (maybeToList . XN.getUniversalName)+ getUniversalName :: a XmlTree String+ getUniversalName = arrL (maybeToList . XN.getUniversalName) -- | select the univeral name (namespace URI ++ localPart)- getUniversalUri :: a XmlTree String- getUniversalUri = arrL (maybeToList . XN.getUniversalUri)+ getUniversalUri :: a XmlTree String+ getUniversalUri = arrL (maybeToList . XN.getUniversalUri) -- | select the local part- getLocalPart :: a XmlTree String- getLocalPart = arrL (maybeToList . XN.getLocalPart)+ getLocalPart :: a XmlTree String+ getLocalPart = arrL (maybeToList . XN.getLocalPart) -- | select the name prefix- getNamePrefix :: a XmlTree String- getNamePrefix = arrL (maybeToList . XN.getNamePrefix)+ getNamePrefix :: a XmlTree String+ getNamePrefix = arrL (maybeToList . XN.getNamePrefix) -- | select the namespace URI- getNamespaceUri :: a XmlTree String- getNamespaceUri = arrL (maybeToList . XN.getNamespaceUri)+ getNamespaceUri :: a XmlTree String+ getNamespaceUri = arrL (maybeToList . XN.getNamespaceUri) -- | select the value of an attribute of an element node, -- always succeeds with empty string as default value \"\"- getAttrValue :: String -> a XmlTree String- getAttrValue n = xshow (getAttrl >>> hasName n >>> getChildren)+ getAttrValue :: String -> a XmlTree String+ getAttrValue n = xshow (getAttrl >>> hasName n >>> getChildren) -- | like 'getAttrValue', but fails if the attribute does not exist- getAttrValue0 :: String -> a XmlTree String- getAttrValue0 n = getAttrl >>> hasName n >>> xshow getChildren+ getAttrValue0 :: String -> a XmlTree String+ getAttrValue0 n = getAttrl >>> hasName n >>> xshow getChildren -- | like 'getAttrValue', but select the value of an attribute given by a qualified name, -- always succeeds with empty string as default value \"\"- getQAttrValue :: QName -> a XmlTree String- getQAttrValue n = xshow (getAttrl >>> hasQName n >>> getChildren)+ getQAttrValue :: QName -> a XmlTree String+ getQAttrValue n = xshow (getAttrl >>> hasQName n >>> getChildren) -- | like 'getQAttrValue', but fails if attribute does not exist- getQAttrValue0 :: QName -> a XmlTree String- getQAttrValue0 n = getAttrl >>> hasQName n >>> xshow getChildren+ getQAttrValue0 :: QName -> a XmlTree String+ getQAttrValue0 n = getAttrl >>> hasQName n >>> xshow getChildren -- edit arrows -------------------------------------------------- -- | edit the string of a text node- changeText :: (String -> String) -> a XmlTree XmlTree- changeText cf = arr (XN.changeText cf) `when` isText+ changeText :: (String -> String) -> a XmlTree XmlTree+ changeText cf = arr (XN.changeText cf) `when` isText -- | edit the comment string of a comment node- changeCmt :: (String -> String) -> a XmlTree XmlTree- changeCmt cf = arr (XN.changeCmt cf) `when` isCmt+ changeCmt :: (String -> String) -> a XmlTree XmlTree+ changeCmt cf = arr (XN.changeCmt cf) `when` isCmt -- | edit an element-, attribute- or pi- name- changeQName :: (QName -> QName) -> a XmlTree XmlTree- changeQName cf = arr (XN.changeName cf) `when` getQName+ changeQName :: (QName -> QName) -> a XmlTree XmlTree+ changeQName cf = arr (XN.changeName cf) `when` getQName -- | edit an element name- changeElemName :: (QName -> QName) -> a XmlTree XmlTree- changeElemName cf = arr (XN.changeElemName cf) `when` isElem+ changeElemName :: (QName -> QName) -> a XmlTree XmlTree+ changeElemName cf = arr (XN.changeElemName cf) `when` isElem -- | edit an attribute name- changeAttrName :: (QName -> QName) -> a XmlTree XmlTree- changeAttrName cf = arr (XN.changeAttrName cf) `when` isAttr+ changeAttrName :: (QName -> QName) -> a XmlTree XmlTree+ changeAttrName cf = arr (XN.changeAttrName cf) `when` isAttr -- | edit a pi name- changePiName :: (QName -> QName) -> a XmlTree XmlTree- changePiName cf = arr (XN.changePiName cf) `when` isPi+ changePiName :: (QName -> QName) -> a XmlTree XmlTree+ changePiName cf = arr (XN.changePiName cf) `when` isPi -- | edit an attribute value- changeAttrValue :: (String -> String) -> a XmlTree XmlTree- changeAttrValue cf = replaceChildren ( xshow getChildren- >>> arr cf- >>> mkText- )- `when` isAttr+ changeAttrValue :: (String -> String) -> a XmlTree XmlTree+ changeAttrValue cf = replaceChildren ( xshow getChildren+ >>> arr cf+ >>> mkText+ )+ `when` isAttr -- | edit an attribute list of an element node- changeAttrl :: (XmlTrees -> XmlTrees -> XmlTrees) -> a XmlTree XmlTree -> a XmlTree XmlTree- changeAttrl cf f = ( ( listA f &&& this )- >>>- arr2 changeAL- )+ changeAttrl :: (XmlTrees -> XmlTrees -> XmlTrees) -> a XmlTree XmlTree -> a XmlTree XmlTree+ changeAttrl cf f = ( ( listA f &&& this )+ >>>+ arr2 changeAL+ ) `when`- ( isElem <+> isPi )- where- changeAL as x = XN.changeAttrl (\ xs -> cf xs as) x+ ( isElem <+> isPi )+ where+ changeAL as x = XN.changeAttrl (\ xs -> cf xs as) x -- | replace an element, attribute or pi name- setQName :: QName -> a XmlTree XmlTree- setQName n = changeQName (const n)+ setQName :: QName -> a XmlTree XmlTree+ setQName n = changeQName (const n) -- | replace an element name- setElemName :: QName -> a XmlTree XmlTree- setElemName n = changeElemName (const n)+ setElemName :: QName -> a XmlTree XmlTree+ setElemName n = changeElemName (const n) -- | replace an attribute name- setAttrName :: QName -> a XmlTree XmlTree- setAttrName n = changeAttrName (const n)+ setAttrName :: QName -> a XmlTree XmlTree+ setAttrName n = changeAttrName (const n) -- | replace an element name- setPiName :: QName -> a XmlTree XmlTree- setPiName n = changePiName (const n)+ setPiName :: QName -> a XmlTree XmlTree+ setPiName n = changePiName (const n) -- | replace an atribute list of an element node- setAttrl :: a XmlTree XmlTree -> a XmlTree XmlTree- setAttrl = changeAttrl (const id) -- (\ x y -> y)+ setAttrl :: a XmlTree XmlTree -> a XmlTree XmlTree+ setAttrl = changeAttrl (const id) -- (\ x y -> y) -- | add a list of attributes to an element- addAttrl :: a XmlTree XmlTree -> a XmlTree XmlTree- addAttrl = changeAttrl (XN.mergeAttrl)+ addAttrl :: a XmlTree XmlTree -> a XmlTree XmlTree+ addAttrl = changeAttrl (XN.mergeAttrl) -- | add (or replace) an attribute- addAttr :: String -> String -> a XmlTree XmlTree- addAttr an av = addAttrl (sattr an av)+ addAttr :: String -> String -> a XmlTree XmlTree+ addAttr an av = addAttrl (sattr an av) -- | remove an attribute- removeAttr :: String -> a XmlTree XmlTree- removeAttr an = processAttrl (none `when` hasName an)+ removeAttr :: String -> a XmlTree XmlTree+ removeAttr an = processAttrl (none `when` hasName an) -- | remove an attribute with a qualified name- removeQAttr :: QName -> a XmlTree XmlTree- removeQAttr an = processAttrl (none `when` hasQName an)+ removeQAttr :: QName -> a XmlTree XmlTree+ removeQAttr an = processAttrl (none `when` hasQName an) -- | process the attributes of an element node with an arrow- processAttrl :: a XmlTree XmlTree -> a XmlTree XmlTree- processAttrl f = setAttrl (getAttrl >>> f)+ processAttrl :: a XmlTree XmlTree -> a XmlTree XmlTree+ processAttrl f = setAttrl (getAttrl >>> f) -- | process a whole tree inclusive attribute list of element nodes -- see also: 'Control.Arrow.ArrowTree.processTopDown' - processTopDownWithAttrl :: a XmlTree XmlTree -> a XmlTree XmlTree- processTopDownWithAttrl f = processTopDown ( f >>> ( processAttrl (processTopDown f) `when` isElem))+ processTopDownWithAttrl :: a XmlTree XmlTree -> a XmlTree XmlTree+ processTopDownWithAttrl f = processTopDown ( f >>> ( processAttrl (processTopDown f) `when` isElem)) -- | convenient op for adding attributes or children to a node --@@ -537,24 +537,24 @@ -- the attributes or content is added to all trees. useful for adding \"class\" or \"style\" attributes -- to table elements. - (+=) :: a b XmlTree -> a b XmlTree -> a b XmlTree- tf += cf = (tf &&& listA cf) >>> arr2 addChildren- where- addChildren :: XmlTree -> XmlTrees -> XmlTree- addChildren t cs- = foldl addChild t cs- addChild :: XmlTree -> XmlTree -> XmlTree- addChild t c- | not (XN.isElem t)- = t- | XN.isAttr c- = XN.changeAttrl (XN.addAttr c) t- | otherwise- = XN.changeChildren (++ [c]) t+ (+=) :: a b XmlTree -> a b XmlTree -> a b XmlTree+ tf += cf = (tf &&& listA cf) >>> arr2 addChildren+ where+ addChildren :: XmlTree -> XmlTrees -> XmlTree+ addChildren t cs+ = foldl addChild t cs+ addChild :: XmlTree -> XmlTree -> XmlTree+ addChild t c+ | not (XN.isElem t)+ = t+ | XN.isAttr c+ = XN.changeAttrl (XN.addAttr c) t+ | otherwise+ = XN.changeChildren (++ [c]) t -- | apply an arrow to the input and convert the resulting XML trees into a string representation- xshow :: a n XmlTree -> a n String- xshow f = f >. XS.xshow+ xshow :: a n XmlTree -> a n String+ xshow f = f >. XS.xshow {- | Document Type Definition arrows @@ -565,59 +565,59 @@ class (ArrowXml a) => ArrowDTD a where- isDTDDoctype :: a XmlTree XmlTree- isDTDDoctype = isA (maybe False (== DOCTYPE ) . XN.getDTDPart)+ isDTDDoctype :: a XmlTree XmlTree+ isDTDDoctype = isA (maybe False (== DOCTYPE ) . XN.getDTDPart) - isDTDElement :: a XmlTree XmlTree- isDTDElement = isA (maybe False (== ELEMENT ) . XN.getDTDPart)+ isDTDElement :: a XmlTree XmlTree+ isDTDElement = isA (maybe False (== ELEMENT ) . XN.getDTDPart) - isDTDContent :: a XmlTree XmlTree- isDTDContent = isA (maybe False (== CONTENT ) . XN.getDTDPart)+ isDTDContent :: a XmlTree XmlTree+ isDTDContent = isA (maybe False (== CONTENT ) . XN.getDTDPart) - isDTDAttlist :: a XmlTree XmlTree- isDTDAttlist = isA (maybe False (== ATTLIST ) . XN.getDTDPart)+ isDTDAttlist :: a XmlTree XmlTree+ isDTDAttlist = isA (maybe False (== ATTLIST ) . XN.getDTDPart) - isDTDEntity :: a XmlTree XmlTree- isDTDEntity = isA (maybe False (== ENTITY ) . XN.getDTDPart)+ isDTDEntity :: a XmlTree XmlTree+ isDTDEntity = isA (maybe False (== ENTITY ) . XN.getDTDPart) - isDTDPEntity :: a XmlTree XmlTree- isDTDPEntity = isA (maybe False (== PENTITY ) . XN.getDTDPart)+ isDTDPEntity :: a XmlTree XmlTree+ isDTDPEntity = isA (maybe False (== PENTITY ) . XN.getDTDPart) - isDTDNotation :: a XmlTree XmlTree- isDTDNotation = isA (maybe False (== NOTATION) . XN.getDTDPart)+ isDTDNotation :: a XmlTree XmlTree+ isDTDNotation = isA (maybe False (== NOTATION) . XN.getDTDPart) - isDTDCondSect :: a XmlTree XmlTree- isDTDCondSect = isA (maybe False (== CONDSECT) . XN.getDTDPart)+ isDTDCondSect :: a XmlTree XmlTree+ isDTDCondSect = isA (maybe False (== CONDSECT) . XN.getDTDPart) - isDTDName :: a XmlTree XmlTree- isDTDName = isA (maybe False (== NAME ) . XN.getDTDPart)+ isDTDName :: a XmlTree XmlTree+ isDTDName = isA (maybe False (== NAME ) . XN.getDTDPart) - isDTDPERef :: a XmlTree XmlTree- isDTDPERef = isA (maybe False (== PEREF ) . XN.getDTDPart)+ isDTDPERef :: a XmlTree XmlTree+ isDTDPERef = isA (maybe False (== PEREF ) . XN.getDTDPart) - hasDTDAttr :: String -> a XmlTree XmlTree- hasDTDAttr n = isA (isJust . lookup n . fromMaybe [] . XN.getDTDAttrl)+ hasDTDAttr :: String -> a XmlTree XmlTree+ hasDTDAttr n = isA (isJust . lookup n . fromMaybe [] . XN.getDTDAttrl) - getDTDAttrValue :: String -> a XmlTree String- getDTDAttrValue n = arrL (maybeToList . lookup n . fromMaybe [] . XN.getDTDAttrl)+ getDTDAttrValue :: String -> a XmlTree String+ getDTDAttrValue n = arrL (maybeToList . lookup n . fromMaybe [] . XN.getDTDAttrl) - setDTDAttrValue :: String -> String -> a XmlTree XmlTree- setDTDAttrValue n v = arr (XN.changeDTDAttrl (addEntry n v)) `when` isDTD+ setDTDAttrValue :: String -> String -> a XmlTree XmlTree+ setDTDAttrValue n v = arr (XN.changeDTDAttrl (addEntry n v)) `when` isDTD - mkDTDElem :: DTDElem -> Attributes -> a n XmlTree -> a n XmlTree- mkDTDElem e al cf = listA cf >>> arr (XN.mkDTDElem e al)+ mkDTDElem :: DTDElem -> Attributes -> a n XmlTree -> a n XmlTree+ mkDTDElem e al cf = listA cf >>> arr (XN.mkDTDElem e al) - mkDTDDoctype :: Attributes -> a n XmlTree -> a n XmlTree- mkDTDDoctype = mkDTDElem DOCTYPE+ mkDTDDoctype :: Attributes -> a n XmlTree -> a n XmlTree+ mkDTDDoctype = mkDTDElem DOCTYPE - mkDTDElement :: Attributes -> a n XmlTree- mkDTDElement al = mkDTDElem ELEMENT al none+ mkDTDElement :: Attributes -> a n XmlTree+ mkDTDElement al = mkDTDElem ELEMENT al none - mkDTDEntity :: Attributes -> a n XmlTree- mkDTDEntity al = mkDTDElem ENTITY al none+ mkDTDEntity :: Attributes -> a n XmlTree+ mkDTDEntity al = mkDTDElem ENTITY al none - mkDTDPEntity :: Attributes -> a n XmlTree- mkDTDPEntity al = mkDTDElem PENTITY al none+ mkDTDPEntity :: Attributes -> a n XmlTree+ mkDTDPEntity al = mkDTDElem PENTITY al none instance ArrowXml LA instance ArrowXml (SLA s)
src/Text/XML/HXT/Arrow/XmlIOStateArrow.hs view
@@ -63,7 +63,7 @@ getParamString, setParamInt, getParamInt,- + -- * Error Message Handling clearErrStatus, setErrStatus,@@ -128,48 +128,48 @@ ) where -import Control.Arrow -- arrow classes+import Control.Arrow -- arrow classes import Control.Arrow.ArrowList import Control.Arrow.ArrowIf import Control.Arrow.ArrowTree import Control.Arrow.ArrowIO import Control.Arrow.IOStateListArrow -import Control.Monad ( mzero- , mplus )+import Control.Monad ( mzero+ , mplus ) import Control.DeepSeq import Text.XML.HXT.DOM.Interface import Text.XML.HXT.Arrow.XmlArrow -import Text.XML.HXT.Arrow.Edit ( addHeadlineToXmlDoc- , treeRepOfXmlDoc- , indentDoc- )+import Text.XML.HXT.Arrow.Edit ( addHeadlineToXmlDoc+ , treeRepOfXmlDoc+ , indentDoc+ ) import Data.Maybe -import Network.URI ( URI- , escapeURIChar- , isUnescapedInURI- , nonStrictRelativeTo- , parseURIReference- , uriAuthority- , uriFragment- , uriPath- , uriPort- , uriQuery- , uriRegName- , uriScheme- , uriUserInfo- )+import Network.URI ( URI+ , escapeURIChar+ , isUnescapedInURI+ , nonStrictRelativeTo+ , parseURIReference+ , uriAuthority+ , uriFragment+ , uriPath+ , uriPort+ , uriQuery+ , uriRegName+ , uriScheme+ , uriUserInfo+ ) -import System.IO ( hPutStrLn- , hFlush- , stderr- )+import System.IO ( hPutStrLn+ , hFlush+ , stderr+ ) -import System.Directory ( getCurrentDirectory )+import System.Directory ( getCurrentDirectory ) -- ------------------------------------------------------------ {- $datatypes -}@@ -179,43 +179,43 @@ -- predefined system state data type with all components for the -- system functions, like trace, error handling, ... -data XIOSysState = XIOSys { xio_trace :: ! Int- , xio_traceCmd :: Int -> String -> IO ()- , xio_errorStatus :: ! Int- , xio_errorModule :: ! String- , xio_errorMsgHandler :: String -> IO ()- , xio_errorMsgCollect :: ! Bool- , xio_errorMsgList :: ! XmlTrees- , xio_baseURI :: ! String- , xio_defaultBaseURI :: ! String- , xio_attrList :: ! (AssocList String XmlTrees)- , xio_mimeTypes :: MimeTypeTable- }+data XIOSysState = XIOSys { xio_trace :: ! Int+ , xio_traceCmd :: Int -> String -> IO ()+ , xio_errorStatus :: ! Int+ , xio_errorModule :: ! String+ , xio_errorMsgHandler :: String -> IO ()+ , xio_errorMsgCollect :: ! Bool+ , xio_errorMsgList :: ! XmlTrees+ , xio_baseURI :: ! String+ , xio_defaultBaseURI :: ! String+ , xio_attrList :: ! (AssocList String XmlTrees)+ , xio_mimeTypes :: MimeTypeTable+ } instance NFData XIOSysState where rnf (XIOSys tr _trc es em _emh emc eml bu du al _mt)- = rnf tr `seq` rnf es `seq` rnf em `seq` rnf emc `seq` rnf eml `seq` rnf bu `seq` rnf du `seq` rnf al+ = rnf tr `seq` rnf es `seq` rnf em `seq` rnf emc `seq` rnf eml `seq` rnf bu `seq` rnf du `seq` rnf al -- | -- state datatype consists of a system state and a user state -- the user state is not fixed -data XIOState us = XIOState { xio_sysState :: ! XIOSysState- , xio_userState :: ! us- }+data XIOState us = XIOState { xio_sysState :: ! XIOSysState+ , xio_userState :: ! us+ } instance (NFData us) => NFData (XIOState us) where- rnf (XIOState sys usr) = rnf sys `seq` rnf usr+ rnf (XIOState sys usr) = rnf sys `seq` rnf usr -- | -- The arrow type for stateful arrows -type IOStateArrow s b c = IOSLA (XIOState s) b c+type IOStateArrow s b c = IOSLA (XIOState s) b c -- | -- The arrow for stateful arrows with no user defined state -type IOSArrow b c = IOStateArrow () b c+type IOSArrow b c = IOStateArrow () b c -- ------------------------------------------------------------ @@ -223,24 +223,24 @@ -- | the default global state, used as initial state when running an 'IOSArrow' with 'runIOSLA' or -- 'runX' -initialState :: us -> XIOState us-initialState s = XIOState { xio_sysState = initialSysState- , xio_userState = s- }+initialState :: us -> XIOState us+initialState s = XIOState { xio_sysState = initialSysState+ , xio_userState = s+ } -initialSysState :: XIOSysState-initialSysState = XIOSys { xio_trace = 0- , xio_traceCmd = traceOutputToStderr- , xio_errorStatus = c_ok- , xio_errorModule = ""- , xio_errorMsgHandler = hPutStrLn stderr- , xio_errorMsgCollect = False- , xio_errorMsgList = []- , xio_baseURI = ""- , xio_defaultBaseURI = ""- , xio_attrList = []- , xio_mimeTypes = defaultMimeTypeTable- }+initialSysState :: XIOSysState+initialSysState = XIOSys { xio_trace = 0+ , xio_traceCmd = traceOutputToStderr+ , xio_errorStatus = c_ok+ , xio_errorModule = ""+ , xio_errorMsgHandler = hPutStrLn stderr+ , xio_errorMsgCollect = False+ , xio_errorMsgList = []+ , xio_baseURI = ""+ , xio_defaultBaseURI = ""+ , xio_attrList = []+ , xio_mimeTypes = defaultMimeTypeTable+ } -- ------------------------------------------------------------ @@ -256,10 +256,10 @@ -- -- if input has to be feed into the arrow use 'Control.Arrow.IOStateListArrow.runIOSLA' like in @ runIOSLA f emptyX inputDoc @ -runX :: IOSArrow XmlTree c -> IO [c]-runX = runXIOState (initialState ())+runX :: IOSArrow XmlTree c -> IO [c]+runX = runXIOState (initialState ()) -runXIOState :: XIOState s -> IOStateArrow s XmlTree c -> IO [c]+runXIOState :: XIOState s -> IOStateArrow s XmlTree c -> IO [c] runXIOState s0 f = do (_finalState, res) <- runIOSLA (emptyRoot >>> f) s0 undefined@@ -273,14 +273,14 @@ -- | read the user defined part of the state -getUserState :: IOStateArrow s b s+getUserState :: IOStateArrow s b s getUserState = IOSLA $ \ s _ -> return (s, [xio_userState s]) -- | change the user defined part of the state -changeUserState :: (b -> s -> s) -> IOStateArrow s b b+changeUserState :: (b -> s -> s) -> IOStateArrow s b b changeUserState cf = IOSLA $ \ s v -> let s' = s { xio_userState = cf v (xio_userState s) }@@ -288,7 +288,7 @@ -- | set the user defined part of the state -setUserState :: IOStateArrow s s s+setUserState :: IOStateArrow s s s setUserState = changeUserState const @@ -299,66 +299,66 @@ -- extended state, and the augmented state component is removed form the state -- when the arrow has finished its execution -withExtendedUserState :: s1 -> IOStateArrow (s1, s0) b c -> IOStateArrow s0 b c+withExtendedUserState :: s1 -> IOStateArrow (s1, s0) b c -> IOStateArrow s0 b c withExtendedUserState initS1 f = IOSLA $ \ s0 x -> do ~(finalS, res) <- runIOSLA f ( XIOState { xio_sysState = xio_sysState s0- , xio_userState = (initS1, xio_userState s0)- }- ) x+ , xio_userState = (initS1, xio_userState s0)+ }+ ) x return ( XIOState { xio_sysState = xio_sysState finalS- , xio_userState = snd (xio_userState finalS)- }- , res- )+ , xio_userState = snd (xio_userState finalS)+ }+ , res+ ) -- | change the type of user state -- -- This conversion is useful, when running a state arrow with another -- structure of the user state, e.g. with () when executing some IO arrows -withOtherUserState :: s1 -> IOStateArrow s1 b c -> IOStateArrow s0 b c+withOtherUserState :: s1 -> IOStateArrow s1 b c -> IOStateArrow s0 b c withOtherUserState s1 f = IOSLA $ \ s x -> do (s', res) <- runIOSLA f ( XIOState { xio_sysState = xio_sysState s- , xio_userState = s1- }- ) x+ , xio_userState = s1+ }+ ) x return ( XIOState { xio_sysState = xio_sysState s'- , xio_userState = xio_userState s- }- , res- )+ , xio_userState = xio_userState s+ }+ , res+ ) -- ------------------------------------------------------------ {- $system state params -} -getSysParam :: (XIOSysState -> c) -> IOStateArrow s b c+getSysParam :: (XIOSysState -> c) -> IOStateArrow s b c getSysParam f = IOSLA $ \ s _x -> return (s, (:[]) . f . xio_sysState $ s) -changeSysParam :: (b -> XIOSysState -> XIOSysState) -> IOStateArrow s b b+changeSysParam :: (b -> XIOSysState -> XIOSysState) -> IOStateArrow s b b changeSysParam cf = ( IOSLA $ \ s v ->- let s' = changeSysState (cf v) s- in return (s', [v])+ let s' = changeSysState (cf v) s+ in return (s', [v]) ) where changeSysState css s = s { xio_sysState = css (xio_sysState s) } -- | store a single XML tree in global state under a given attribute name -setParam :: String -> IOStateArrow s XmlTree XmlTree+setParam :: String -> IOStateArrow s XmlTree XmlTree setParam n = (:[]) ^>> setParamList n -- | store a list of XML trees in global system state under a given attribute name -setParamList :: String -> IOStateArrow s XmlTrees XmlTree+setParamList :: String -> IOStateArrow s XmlTrees XmlTree setParamList n = changeSysParam addE >>>@@ -368,7 +368,7 @@ -- | remove an entry in global state, arrow input remains unchanged -unsetParam :: String -> IOStateArrow s b b+unsetParam :: String -> IOStateArrow s b b unsetParam n = changeSysParam delE where@@ -376,7 +376,7 @@ -- | read an attribute value from global state -getParam :: String -> IOStateArrow s b XmlTree+getParam :: String -> IOStateArrow s b XmlTree getParam n = getAllParams >>>@@ -384,47 +384,47 @@ -- | read all attributes from global state -getAllParams :: IOStateArrow s b (AssocList String XmlTrees)+getAllParams :: IOStateArrow s b (AssocList String XmlTrees) getAllParams = getSysParam xio_attrList -- | read all attributes from global state -- and convert the values to strings -getAllParamsString :: IOStateArrow s b (AssocList String String)+getAllParamsString :: IOStateArrow s b (AssocList String String) getAllParamsString = getAllParams >>> listA ( unlistA- >>>- second (xshow unlistA)- )+ >>>+ second (xshow unlistA)+ ) -setParamString :: String -> String -> IOStateArrow s b b+setParamString :: String -> String -> IOStateArrow s b b setParamString n v = perform ( txt v- >>>- setParam n- )+ >>>+ setParam n+ ) -- | read a string value from global state, -- if parameter not set \"\" is returned -getParamString :: String -> IOStateArrow s b String+getParamString :: String -> IOStateArrow s b String getParamString n = xshow (getParam n) -- | store an int value in global state -setParamInt :: String -> Int -> IOStateArrow s b b+setParamInt :: String -> Int -> IOStateArrow s b b setParamInt n v = setParamString n (show v) -- | read an int value from global state--- +-- -- > getParamInt 0 myIntAttr -getParamInt :: Int -> String -> IOStateArrow s b Int+getParamInt :: Int -> String -> IOStateArrow s b Int getParamInt def n = getParamString n >>^@@ -434,163 +434,163 @@ -- | reset global error variable -changeErrorStatus :: (Int -> Int -> Int) -> IOStateArrow s Int Int+changeErrorStatus :: (Int -> Int -> Int) -> IOStateArrow s Int Int changeErrorStatus f = changeSysParam (\ l s -> s { xio_errorStatus = f l (xio_errorStatus s) }) -clearErrStatus :: IOStateArrow s b b+clearErrStatus :: IOStateArrow s b b clearErrStatus = perform (constA 0 >>> changeErrorStatus min) -- | set global error variable -setErrStatus :: IOStateArrow s Int Int+setErrStatus :: IOStateArrow s Int Int setErrStatus = changeErrorStatus max -- | read current global error status -getErrStatus :: IOStateArrow s XmlTree Int+getErrStatus :: IOStateArrow s XmlTree Int getErrStatus = getSysParam xio_errorStatus -- | raise the global error status level to that of the input tree -setErrMsgStatus :: IOStateArrow s XmlTree XmlTree+setErrMsgStatus :: IOStateArrow s XmlTree XmlTree setErrMsgStatus = perform ( getErrorLevel- >>>- setErrStatus- )+ >>>+ setErrStatus+ ) -- | set the error message handler and the flag for collecting the errors -setErrorMsgHandler :: Bool -> (String -> IO ()) -> IOStateArrow s b b+setErrorMsgHandler :: Bool -> (String -> IO ()) -> IOStateArrow s b b setErrorMsgHandler c f = changeSysParam cf where cf _ s = s { xio_errorMsgHandler = f- , xio_errorMsgCollect = c }+ , xio_errorMsgCollect = c } -- | error message handler for output to stderr- -sysErrorMsg :: IOStateArrow s XmlTree XmlTree++sysErrorMsg :: IOStateArrow s XmlTree XmlTree sysErrorMsg = perform ( getErrorLevel &&& getErrorMsg- >>>- arr formatErrorMsg- >>>- ( IOSLA $ \ s e ->- do- (xio_errorMsgHandler . xio_sysState $ s) e- return (s, undefined)- )- )+ >>>+ arr formatErrorMsg+ >>>+ ( IOSLA $ \ s e ->+ do+ (xio_errorMsgHandler . xio_sysState $ s) e+ return (s, undefined)+ )+ ) where- formatErrorMsg (level, msg) = "\n" ++ errClass level ++ ": " ++ msg+ formatErrorMsg (level, msg) = "\n" ++ errClass level ++ ": " ++ msg errClass l- = fromMaybe "fatal error" . lookup l $ msgList- where- msgList = [ (c_ok, "no error")- , (c_warn, "warning")- , (c_err, "error")- , (c_fatal, "fatal error")- ]+ = fromMaybe "fatal error" . lookup l $ msgList+ where+ msgList = [ (c_ok, "no error")+ , (c_warn, "warning")+ , (c_err, "error")+ , (c_fatal, "fatal error")+ ] -- | the default error message handler: error output to stderr -errorMsgStderr :: IOStateArrow s b b-errorMsgStderr = setErrorMsgHandler False (hPutStrLn stderr)+errorMsgStderr :: IOStateArrow s b b+errorMsgStderr = setErrorMsgHandler False (hPutStrLn stderr) -- | error message handler for collecting errors -errorMsgCollect :: IOStateArrow s b b-errorMsgCollect = setErrorMsgHandler True (const $ return ())+errorMsgCollect :: IOStateArrow s b b+errorMsgCollect = setErrorMsgHandler True (const $ return ()) -- | error message handler for output to stderr and collecting -errorMsgStderrAndCollect :: IOStateArrow s b b-errorMsgStderrAndCollect = setErrorMsgHandler True (hPutStrLn stderr)+errorMsgStderrAndCollect :: IOStateArrow s b b+errorMsgStderrAndCollect = setErrorMsgHandler True (hPutStrLn stderr) -- | error message handler for ignoring errors -errorMsgIgnore :: IOStateArrow s b b-errorMsgIgnore = setErrorMsgHandler False (const $ return ())+errorMsgIgnore :: IOStateArrow s b b+errorMsgIgnore = setErrorMsgHandler False (const $ return ()) -- | -- if error messages are collected by the error handler for -- processing these messages by the calling application, -- this arrow reads the stored messages and clears the error message store -getErrorMessages :: IOStateArrow s b XmlTree+getErrorMessages :: IOStateArrow s b XmlTree getErrorMessages- = getSysParam (reverse . xio_errorMsgList) -- reverse the list of errors+ = getSysParam (reverse . xio_errorMsgList) -- reverse the list of errors >>>- clearErrorMsgList -- clear the error list in the system state+ clearErrorMsgList -- clear the error list in the system state >>> arrL id -clearErrorMsgList :: IOStateArrow s b b+clearErrorMsgList :: IOStateArrow s b b clearErrorMsgList = changeSysParam (\ _ s -> s { xio_errorMsgList = [] } ) -addToErrorMsgList :: IOStateArrow s XmlTree XmlTree+addToErrorMsgList :: IOStateArrow s XmlTree XmlTree addToErrorMsgList = changeSysParam cf where cf t s = if xio_errorMsgCollect s- then s { xio_errorMsgList = t : xio_errorMsgList s }- else s+ then s { xio_errorMsgList = t : xio_errorMsgList s }+ else s -- ------------------------------------------------------------ -- | -- filter error messages from input trees and issue errors -filterErrorMsg :: IOStateArrow s XmlTree XmlTree+filterErrorMsg :: IOStateArrow s XmlTree XmlTree filterErrorMsg = ( setErrMsgStatus- >>>- sysErrorMsg- >>>- addToErrorMsgList- >>>- none+ >>>+ sysErrorMsg+ >>>+ addToErrorMsgList+ >>>+ none ) `when` isError -- | generate a warnig message -issueWarn :: String -> IOStateArrow s b b-issueWarn msg = perform (warn msg >>> filterErrorMsg)+issueWarn :: String -> IOStateArrow s b b+issueWarn msg = perform (warn msg >>> filterErrorMsg) -- | generate an error message-issueErr :: String -> IOStateArrow s b b-issueErr msg = perform (err msg >>> filterErrorMsg)+issueErr :: String -> IOStateArrow s b b+issueErr msg = perform (err msg >>> filterErrorMsg) -- | generate a fatal error message, e.g. document not found -issueFatal :: String -> IOStateArrow s b b-issueFatal msg = perform (fatal msg >>> filterErrorMsg)+issueFatal :: String -> IOStateArrow s b b+issueFatal msg = perform (fatal msg >>> filterErrorMsg) -- | -- add the error level and the module where the error occured -- to the attributes of a document root node and remove the children when level is greater or equal to 'c_err'. -- called by 'setDocumentStatusFromSystemState' when the system state indicates an error -setDocumentStatus :: Int -> String -> IOStateArrow s XmlTree XmlTree+setDocumentStatus :: Int -> String -> IOStateArrow s XmlTree XmlTree setDocumentStatus level msg = ( addAttrl ( sattr a_status (show level)- <+>- sattr a_module msg- )- >>>- ( if level >= c_err- then setChildren []- else this- )+ <+>+ sattr a_module msg+ )+ >>>+ ( if level >= c_err+ then setChildren []+ else this+ ) ) `when` isRoot@@ -601,28 +601,28 @@ -- removed and the module name where the error occured and the error level are added as attributes with 'setDocumentStatus' -- else nothing is changed -setDocumentStatusFromSystemState :: String -> IOStateArrow s XmlTree XmlTree+setDocumentStatusFromSystemState :: String -> IOStateArrow s XmlTree XmlTree setDocumentStatusFromSystemState msg = setStatus $< getErrStatus where setStatus level- | level <= c_warn = this- | otherwise = setDocumentStatus level msg+ | level <= c_warn = this+ | otherwise = setDocumentStatus level msg -- | -- check whether tree is a document root and the status attribute has a value less than 'c_err' -documentStatusOk :: ArrowXml a => a XmlTree XmlTree+documentStatusOk :: ArrowXml a => a XmlTree XmlTree documentStatusOk = isRoot >>> ( (getAttrValue a_status- >>>- isA (\ v -> null v || ((read v)::Int) <= c_warn)- )- `guards`- this+ >>>+ isA (\ v -> null v || ((read v)::Int) <= c_warn)+ )+ `guards`+ this ) -- ------------------------------------------------------------@@ -630,7 +630,7 @@ -- | set the base URI of a document, used e.g. for reading includes, e.g. external entities, -- the input must be an absolute URI -setBaseURI :: IOStateArrow s String String+setBaseURI :: IOStateArrow s String String setBaseURI = changeSysParam (\ b s -> s { xio_baseURI = b } ) >>>@@ -638,18 +638,18 @@ -- | read the base URI from the globale state -getBaseURI :: IOStateArrow s b String+getBaseURI :: IOStateArrow s b String getBaseURI = getSysParam xio_baseURI >>> ( ( getDefaultBaseURI- >>>- setBaseURI - >>>- getBaseURI- )- `when`- isA null -- set and get it, if not yet done+ >>>+ setBaseURI+ >>>+ getBaseURI+ )+ `when`+ isA null -- set and get it, if not yet done ) -- | change the base URI with a possibly relative URI, can be used for@@ -658,7 +658,7 @@ -- -- see also: 'setBaseURI', 'mkAbsURI' -changeBaseURI :: IOStateArrow s String String+changeBaseURI :: IOStateArrow s String String changeBaseURI = mkAbsURI >>>@@ -667,11 +667,11 @@ -- | set the default base URI, if parameter is null, the system base (@ file:\/\/\/\<cwd\>\/ @) is used, -- else the parameter, must be called before any document is read -setDefaultBaseURI :: String -> IOStateArrow s b String+setDefaultBaseURI :: String -> IOStateArrow s b String setDefaultBaseURI base = ( if null base- then arrIO getDir- else constA base+ then arrIO getDir+ else constA base ) >>> changeSysParam (\ b s -> s { xio_defaultBaseURI = b } )@@ -679,19 +679,19 @@ traceValue 2 (("setDefaultBaseURI: new default base URI is " ++) . show) where getDir _ = do- cwd <- getCurrentDirectory- return ("file://" ++ normalize cwd ++ "/")+ cwd <- getCurrentDirectory+ return ("file://" ++ normalize cwd ++ "/") -- under Windows getCurrentDirectory returns something like: "c:\path\to\file" -- backslaches are not allowed in URIs and paths must start with a / -- so this is transformed into "/c:/path/to/file" normalize wd'@(d : ':' : _)- | d `elem` ['A'..'Z'] || d `elem` ['a'..'z']- = '/' : concatMap win32ToUriChar wd'+ | d `elem` ['A'..'Z'] || d `elem` ['a'..'z']+ = '/' : concatMap win32ToUriChar wd' normalize wd'- = concatMap escapeNonUriChar wd'- + = concatMap escapeNonUriChar wd'+ win32ToUriChar '\\' = "/" win32ToUriChar c = escapeNonUriChar c @@ -700,19 +700,19 @@ -- | get the default base URI -getDefaultBaseURI :: IOStateArrow s b String+getDefaultBaseURI :: IOStateArrow s b String getDefaultBaseURI- = getSysParam xio_defaultBaseURI -- read default uri in system state+ = getSysParam xio_defaultBaseURI -- read default uri in system state >>>- ( setDefaultBaseURI "" -- set the default uri in system state- >>>- getDefaultBaseURI ) `when` isA null -- when uri not yet set+ ( setDefaultBaseURI "" -- set the default uri in system state+ >>>+ getDefaultBaseURI ) `when` isA null -- when uri not yet set -- ------------------------------------------------------------ -- | remember base uri, run an arrow and restore the base URI, used with external entity substitution -runInLocalURIContext :: IOStateArrow s b c -> IOStateArrow s b c+runInLocalURIContext :: IOStateArrow s b c -> IOStateArrow s b c runInLocalURIContext f = ( getBaseURI &&& this ) >>>@@ -726,31 +726,31 @@ -- | set the global trace level -setTraceLevel :: Int -> IOStateArrow s b b+setTraceLevel :: Int -> IOStateArrow s b b setTraceLevel l = changeSysParam (\ _ s -> s { xio_trace = l } ) -- | read the global trace level -getTraceLevel :: IOStateArrow s b Int+getTraceLevel :: IOStateArrow s b Int getTraceLevel = getSysParam xio_trace -- | set the global trace command. This command does the trace output -setTraceCmd :: (Int -> String -> IO ()) -> IOStateArrow s b b+setTraceCmd :: (Int -> String -> IO ()) -> IOStateArrow s b b setTraceCmd c = changeSysParam (\ _ s -> s { xio_traceCmd = c } ) -- | acces the command for trace output- -getTraceCmd :: IOStateArrow a b (Int -> String -> IO ())++getTraceCmd :: IOStateArrow a b (Int -> String -> IO ()) getTraceCmd = getSysParam xio_traceCmd -- | run an arrow with a given trace level, the old trace level is restored after the arrow execution -withTraceLevel :: Int -> IOStateArrow s b c -> IOStateArrow s b c+withTraceLevel :: Int -> IOStateArrow s b c -> IOStateArrow s b c withTraceLevel level f = ( getTraceLevel &&& this ) >>>@@ -760,26 +760,26 @@ >>> arrL snd where- restoreTraceLevel :: IOStateArrow s Int Int+ restoreTraceLevel :: IOStateArrow s Int Int restoreTraceLevel- = setTraceLevel $< this+ = setTraceLevel $< this -- | apply a trace arrow and issue message to stderr -trace :: Int -> IOStateArrow s b String -> IOStateArrow s b b+trace :: Int -> IOStateArrow s b String -> IOStateArrow s b b trace level trc = perform ( trc- >>>+ >>> ( getTraceCmd &&& this ) >>>- arrIO (\ (cmd, msg) -> cmd level msg)- )+ arrIO (\ (cmd, msg) -> cmd level msg)+ ) `when` ( getTraceLevel- >>>- isA (>= level)- )+ >>>+ isA (>= level)+ ) -traceOutputToStderr :: Int -> String -> IO ()+traceOutputToStderr :: Int -> String -> IO () traceOutputToStderr _level msg = do hPutStrLn stderr msg@@ -790,18 +790,18 @@ -- The value is formated by a string conversion function. This is a substitute for -- the old and less general traceString function -traceValue :: Int -> (b -> String) -> IOStateArrow s b b+traceValue :: Int -> (b -> String) -> IOStateArrow s b b traceValue level trc = trace level (arr $ (('-' : "- (" ++ show level ++ ") ") ++) . trc) -- | an old alias for 'traceValue' -traceString :: Int -> (b -> String) -> IOStateArrow s b b-traceString = traceValue+traceString :: Int -> (b -> String) -> IOStateArrow s b b+traceString = traceValue -- | issue a string message as trace -traceMsg :: Int -> String -> IOStateArrow s b b+traceMsg :: Int -> String -> IOStateArrow s b b traceMsg level msg = traceValue level (const msg) @@ -809,38 +809,38 @@ -- -- for better readability the source is formated with indentDoc -traceSource :: IOStateArrow s XmlTree XmlTree-traceSource +traceSource :: IOStateArrow s XmlTree XmlTree+traceSource = trace 3 $ xshow ( choiceA [ isRoot :-> ( indentDoc- >>>- getChildren- )- , isElem :-> ( root [] [this]- >>> indentDoc- >>> getChildren- >>> isElem- )- , this :-> this- ]+ >>>+ getChildren+ )+ , isElem :-> ( root [] [this]+ >>> indentDoc+ >>> getChildren+ >>> isElem+ )+ , this :-> this+ ] ) -- | issue the tree representation of a document if trace level >= 4-traceTree :: IOStateArrow s XmlTree XmlTree+traceTree :: IOStateArrow s XmlTree XmlTree traceTree = trace 4 $ xshow ( treeRepOfXmlDoc- >>>- addHeadlineToXmlDoc- >>>- getChildren- )+ >>>+ addHeadlineToXmlDoc+ >>>+ getChildren+ ) -- | trace a main computation step -- issue a message when trace level >= 1, issue document source if level >= 3, issue tree when level is >= 4 -traceDoc :: String -> IOStateArrow s XmlTree XmlTree+traceDoc :: String -> IOStateArrow s XmlTree XmlTree traceDoc msg = traceMsg 1 msg >>>@@ -850,19 +850,19 @@ -- | trace the global state -traceState :: IOStateArrow s b b+traceState :: IOStateArrow s b b traceState = perform ( xshow ( (getAllParams >>. concat)- >>>- applyA (arr formatParam)- )- >>>- traceValue 2 ("global state:\n" ++)- )+ >>>+ applyA (arr formatParam)+ )+ >>>+ traceValue 2 ("global state:\n" ++)+ ) where- -- formatParam :: (String, XmlTrees) -> IOStateArrow s b1 XmlTree+ -- formatParam :: (String, XmlTrees) -> IOStateArrow s b1 XmlTree formatParam (n, v)- = mkelem "param" [sattr "name" n] [arrL (const v)] <+> txt "\n"+ = mkelem "param" [sattr "name" n] [arrL (const v)] <+> txt "\n" -- ---------------------------------------------------------- @@ -870,25 +870,25 @@ -- try to escape unescaped chars, convert backslashes to slashes for windows paths, -- and try parsing again -parseURIReference' :: String -> Maybe URI+parseURIReference' :: String -> Maybe URI parseURIReference' uri = parseURIReference uri `mplus` ( if unesc- then parseURIReference uri'- else mzero+ then parseURIReference uri'+ else mzero ) where- unesc = not . all isUnescapedInURI $ uri+ unesc = not . all isUnescapedInURI $ uri - escape '\\' = "/"- escape c = escapeURIChar isUnescapedInURI c+ escape '\\' = "/"+ escape c = escapeURIChar isUnescapedInURI c - uri' = concatMap escape uri+ uri' = concatMap escape uri -- | compute the absolut URI for a given URI and a base URI -expandURIString :: String -> String -> Maybe String+expandURIString :: String -> String -> Maybe String expandURIString uri base = do base' <- parseURIReference' base@@ -898,13 +898,13 @@ -- | arrow variant of 'expandURIString', fails if 'expandURIString' returns Nothing -expandURI :: ArrowXml a => a (String, String) String+expandURI :: ArrowXml a => a (String, String) String expandURI = arrL (maybeToList . uncurry expandURIString) -- | arrow for expanding an input URI into an absolute URI using global base URI, fails if input is not a legal URI -mkAbsURI :: IOStateArrow s String String+mkAbsURI :: IOStateArrow s String String mkAbsURI = ( this &&& getBaseURI ) >>> expandURI @@ -912,56 +912,56 @@ -- -- See Network.URI for URI components -getSchemeFromURI :: ArrowList a => a String String-getSchemeFromURI = getPartFromURI scheme+getSchemeFromURI :: ArrowList a => a String String+getSchemeFromURI = getPartFromURI scheme where scheme = init . uriScheme -- | arrow for selecting the registered name (host) of the URI, fails if input is not a legal URI -getRegNameFromURI :: ArrowList a => a String String-getRegNameFromURI = getPartFromURI host+getRegNameFromURI :: ArrowList a => a String String+getRegNameFromURI = getPartFromURI host where host = maybe "" uriRegName . uriAuthority -- | arrow for selecting the port number of the URI without leading \':\', fails if input is not a legal URI -getPortFromURI :: ArrowList a => a String String-getPortFromURI = getPartFromURI port+getPortFromURI :: ArrowList a => a String String+getPortFromURI = getPartFromURI port where port = dropWhile (==':') . maybe "" uriPort . uriAuthority -- | arrow for selecting the user info of the URI without trailing \'\@\', fails if input is not a legal URI -getUserInfoFromURI :: ArrowList a => a String String-getUserInfoFromURI = getPartFromURI ui+getUserInfoFromURI :: ArrowList a => a String String+getUserInfoFromURI = getPartFromURI ui where ui = reverse . dropWhile (=='@') . reverse . maybe "" uriUserInfo . uriAuthority -- | arrow for computing the path component of an URI, fails if input is not a legal URI -getPathFromURI :: ArrowList a => a String String-getPathFromURI = getPartFromURI uriPath+getPathFromURI :: ArrowList a => a String String+getPathFromURI = getPartFromURI uriPath -- | arrow for computing the query component of an URI, fails if input is not a legal URI -getQueryFromURI :: ArrowList a => a String String-getQueryFromURI = getPartFromURI uriQuery+getQueryFromURI :: ArrowList a => a String String+getQueryFromURI = getPartFromURI uriQuery -- | arrow for computing the fragment component of an URI, fails if input is not a legal URI -getFragmentFromURI :: ArrowList a => a String String-getFragmentFromURI = getPartFromURI uriFragment+getFragmentFromURI :: ArrowList a => a String String+getFragmentFromURI = getPartFromURI uriFragment -- | arrow for computing the path component of an URI, fails if input is not a legal URI -getPartFromURI :: ArrowList a => (URI -> String) -> a String String+getPartFromURI :: ArrowList a => (URI -> String) -> a String String getPartFromURI sel = arrL (maybeToList . getPart) where getPart s = do- uri <- parseURIReference' s- return (sel uri)+ uri <- parseURIReference' s+ return (sel uri) -- ------------------------------------------------------------ @@ -970,7 +970,7 @@ -- Default table is defined in 'Text.XML.HXT.DOM.MimeTypeDefaults'. -- This table is used when reading loacl files, (file: protocol) to determine the mime type -setMimeTypeTable :: MimeTypeTable -> IOStateArrow s b b+setMimeTypeTable :: MimeTypeTable -> IOStateArrow s b b setMimeTypeTable mtt = changeSysParam (\ _ s -> s {xio_mimeTypes = mtt}) @@ -982,7 +982,7 @@ -- The list of extenstions and mime types overwrites the default list in the system state -- of the IOStateArrow -setMimeTypeTableFromFile :: FilePath -> IOStateArrow s b b+setMimeTypeTableFromFile :: FilePath -> IOStateArrow s b b setMimeTypeTableFromFile file = setMimeTypeTable $< arrIO0 ( readMimeTypeTable file)
src/Text/XML/HXT/Arrow/XmlRegex.hs view
@@ -60,8 +60,8 @@ -- an XmlTree and of the usual cobinators for sequence ('mkSeq'), repetition -- ('mkStar', mkRep', 'mkRng') and choice ('mkAlt', 'mkOpt') -matchRegexA :: XmlRegex -> LA XmlTree XmlTree -> LA XmlTree XmlTrees-matchRegexA re ts = ts >>. (\ s -> maybe [] (const [s]) . matchXmlRegex re $ s)+matchRegexA :: XmlRegex -> LA XmlTree XmlTree -> LA XmlTree XmlTrees+matchRegexA re ts = ts >>. (\ s -> maybe [] (const [s]) . matchXmlRegex re $ s) -- | split the sequence of trees computed by the filter a into --@@ -71,189 +71,189 @@ -- if a prefix of the input sequence does not match the regex, the arrow fails -- else the pair containing the result lists is returned -splitRegexA :: XmlRegex -> LA XmlTree XmlTree -> LA XmlTree (XmlTrees, XmlTrees)-splitRegexA re ts = ts >>. (maybeToList . splitXmlRegex re)+splitRegexA :: XmlRegex -> LA XmlTree XmlTree -> LA XmlTree (XmlTrees, XmlTrees)+splitRegexA re ts = ts >>. (maybeToList . splitXmlRegex re) -- | scan the input sequence with a regex and give the result as a list of lists of trees back -- the regex must at least match one input tree, so the empty sequence should not match the regex -- -- The arrow for 'scanXmlRegex'. -scanRegexA :: XmlRegex -> LA XmlTree XmlTree -> LA XmlTree XmlTrees-scanRegexA re ts = ts >>. (fromMaybe [] . scanXmlRegex re)+scanRegexA :: XmlRegex -> LA XmlTree XmlTree -> LA XmlTree XmlTrees+scanRegexA re ts = ts >>. (fromMaybe [] . scanXmlRegex re) -- ------------------------------------------------------------ -data XmlRegex = Zero String- | Unit- | Sym (XmlTree -> Bool)- | Dot- | Star XmlRegex- | Alt XmlRegex XmlRegex- | Seq XmlRegex XmlRegex- | Rep Int XmlRegex -- 1 or more repetitions- | Rng Int Int XmlRegex -- n..m repetitions+data XmlRegex = Zero String+ | Unit+ | Sym (XmlTree -> Bool)+ | Dot+ | Star XmlRegex+ | Alt XmlRegex XmlRegex+ | Seq XmlRegex XmlRegex+ | Rep Int XmlRegex -- 1 or more repetitions+ | Rng Int Int XmlRegex -- n..m repetitions -- ------------------------------------------------------------ {- just for documentation class Inv a where- inv :: a -> Bool+ inv :: a -> Bool instance Inv XmlRegex where- inv (Zero _) = True- inv Unit = True- inv (Sym p) = p holds for some XmlTrees- inv Dot = True- inv (Star e) = inv e- inv (Alt e1 e2) = inv e1 &&- inv e2- inv (Seq e1 e2) = inv e1 &&- inv e2- inv (Rep i e) = i > 0 && inv e- inv (Rng i j e) = (i < j || (i == j && i > 1)) &&- inv e+ inv (Zero _) = True+ inv Unit = True+ inv (Sym p) = p holds for some XmlTrees+ inv Dot = True+ inv (Star e) = inv e+ inv (Alt e1 e2) = inv e1 &&+ inv e2+ inv (Seq e1 e2) = inv e1 &&+ inv e2+ inv (Rep i e) = i > 0 && inv e+ inv (Rng i j e) = (i < j || (i == j && i > 1)) &&+ inv e -} -- ------------------------------------------------------------ -- -- smart constructors -mkZero :: String -> XmlRegex-mkZero = Zero+mkZero :: String -> XmlRegex+mkZero = Zero -mkUnit :: XmlRegex-mkUnit = Unit+mkUnit :: XmlRegex+mkUnit = Unit -mkPrim :: (XmlTree -> Bool) -> XmlRegex-mkPrim = Sym+mkPrim :: (XmlTree -> Bool) -> XmlRegex+mkPrim = Sym -mkPrimA :: LA XmlTree XmlTree -> XmlRegex-mkPrimA a = mkPrim (not . null . runLA a)+mkPrimA :: LA XmlTree XmlTree -> XmlRegex+mkPrimA a = mkPrim (not . null . runLA a) -mkDot :: XmlRegex-mkDot = Dot+mkDot :: XmlRegex+mkDot = Dot -mkStar :: XmlRegex -> XmlRegex-mkStar (Zero _) = mkUnit -- {}* == ()-mkStar e@Unit = e -- ()* == ()-mkStar e@(Star _e1) = e -- (r*)* == r*-mkStar (Rep 1 e1) = mkStar e1 -- (r+)* == r*-mkStar e@(Alt _ _) = Star (rmStar e) -- (a*|b)* == (a|b)*-mkStar e = Star e+mkStar :: XmlRegex -> XmlRegex+mkStar (Zero _) = mkUnit -- {}* == ()+mkStar e@Unit = e -- ()* == ()+mkStar e@(Star _e1) = e -- (r*)* == r*+mkStar (Rep 1 e1) = mkStar e1 -- (r+)* == r*+mkStar e@(Alt _ _) = Star (rmStar e) -- (a*|b)* == (a|b)*+mkStar e = Star e -rmStar :: XmlRegex -> XmlRegex-rmStar (Alt e1 e2) = mkAlt (rmStar e1) (rmStar e2)-rmStar (Star e1) = rmStar e1-rmStar (Rep 1 e1) = rmStar e1-rmStar e1 = e1+rmStar :: XmlRegex -> XmlRegex+rmStar (Alt e1 e2) = mkAlt (rmStar e1) (rmStar e2)+rmStar (Star e1) = rmStar e1+rmStar (Rep 1 e1) = rmStar e1+rmStar e1 = e1 -mkAlt :: XmlRegex -> XmlRegex -> XmlRegex-mkAlt e1 (Zero _) = e1 -- e1 u {} = e1-mkAlt (Zero _) e2 = e2 -- {} u e2 = e2-mkAlt e1@(Star Dot) _e2 = e1 -- A* u e1 = A*-mkAlt _e1 e2@(Star Dot) = e2 -- e1 u A* = A*-mkAlt (Sym p1) (Sym p2) = mkPrim $ \ x -> p1 x || p2 x -- melting of predicates-mkAlt e1 e2@(Sym _) = mkAlt e2 e1 -- symmetry: predicates always first-mkAlt e1@(Sym _) (Alt e2@(Sym _) e3) = mkAlt (mkAlt e1 e2) e3 -- prepare melting of predicates-mkAlt (Alt e1 e2) e3 = mkAlt e1 (mkAlt e2 e3) -- associativity-mkAlt e1 e2 = Alt e1 e2+mkAlt :: XmlRegex -> XmlRegex -> XmlRegex+mkAlt e1 (Zero _) = e1 -- e1 u {} = e1+mkAlt (Zero _) e2 = e2 -- {} u e2 = e2+mkAlt e1@(Star Dot) _e2 = e1 -- A* u e1 = A*+mkAlt _e1 e2@(Star Dot) = e2 -- e1 u A* = A*+mkAlt (Sym p1) (Sym p2) = mkPrim $ \ x -> p1 x || p2 x -- melting of predicates+mkAlt e1 e2@(Sym _) = mkAlt e2 e1 -- symmetry: predicates always first+mkAlt e1@(Sym _) (Alt e2@(Sym _) e3) = mkAlt (mkAlt e1 e2) e3 -- prepare melting of predicates+mkAlt (Alt e1 e2) e3 = mkAlt e1 (mkAlt e2 e3) -- associativity+mkAlt e1 e2 = Alt e1 e2 -mkSeq :: XmlRegex -> XmlRegex -> XmlRegex-mkSeq e1@(Zero _) _e2 = e1-mkSeq _e1 e2@(Zero _) = e2-mkSeq Unit e2 = e2-mkSeq e1 Unit = e1-mkSeq (Seq e1 e2) e3 = mkSeq e1 (mkSeq e2 e3)-mkSeq e1 e2 = Seq e1 e2+mkSeq :: XmlRegex -> XmlRegex -> XmlRegex+mkSeq e1@(Zero _) _e2 = e1+mkSeq _e1 e2@(Zero _) = e2+mkSeq Unit e2 = e2+mkSeq e1 Unit = e1+mkSeq (Seq e1 e2) e3 = mkSeq e1 (mkSeq e2 e3)+mkSeq e1 e2 = Seq e1 e2 -mkRep :: Int -> XmlRegex -> XmlRegex-mkRep 0 e = mkStar e-mkRep _ e@(Zero _) = e-mkRep _ e@Unit = e-mkRep i e = Rep i e+mkRep :: Int -> XmlRegex -> XmlRegex+mkRep 0 e = mkStar e+mkRep _ e@(Zero _) = e+mkRep _ e@Unit = e+mkRep i e = Rep i e -mkRng :: Int -> Int -> XmlRegex -> XmlRegex-mkRng 0 0 _e = mkUnit-mkRng 1 1 e = e+mkRng :: Int -> Int -> XmlRegex -> XmlRegex+mkRng 0 0 _e = mkUnit+mkRng 1 1 e = e mkRng lb ub _e- | lb > ub = Zero $- "illegal range " ++- show lb ++ ".." ++ show ub-mkRng _l _u e@(Zero _) = e-mkRng _l _u e@Unit = e-mkRng lb ub e = Rng lb ub e+ | lb > ub = Zero $+ "illegal range " +++ show lb ++ ".." ++ show ub+mkRng _l _u e@(Zero _) = e+mkRng _l _u e@Unit = e+mkRng lb ub e = Rng lb ub e -mkOpt :: XmlRegex -> XmlRegex-mkOpt = mkRng 0 1+mkOpt :: XmlRegex -> XmlRegex+mkOpt = mkRng 0 1 -- ------------------------------------------------------------ instance Show XmlRegex where- show (Zero s) = "{err:" ++ s ++ "}"- show Unit = "()"- show (Sym _p) = "{single tree pred}"- show Dot = "."- show (Star e) = "(" ++ show e ++ ")*"- show (Alt e1 e2) = "(" ++ show e1 ++ "|" ++ show e2 ++ ")"- show (Seq e1 e2) = show e1 ++ show e2- show (Rep 1 e) = "(" ++ show e ++ ")+"- show (Rep i e) = "(" ++ show e ++ "){" ++ show i ++ ",}"- show (Rng 0 1 e) = "(" ++ show e ++ ")?"- show (Rng i j e) = "(" ++ show e ++ "){" ++ show i ++ "," ++ show j ++ "}"+ show (Zero s) = "{err:" ++ s ++ "}"+ show Unit = "()"+ show (Sym _p) = "{single tree pred}"+ show Dot = "."+ show (Star e) = "(" ++ show e ++ ")*"+ show (Alt e1 e2) = "(" ++ show e1 ++ "|" ++ show e2 ++ ")"+ show (Seq e1 e2) = show e1 ++ show e2+ show (Rep 1 e) = "(" ++ show e ++ ")+"+ show (Rep i e) = "(" ++ show e ++ "){" ++ show i ++ ",}"+ show (Rng 0 1 e) = "(" ++ show e ++ ")?"+ show (Rng i j e) = "(" ++ show e ++ "){" ++ show i ++ "," ++ show j ++ "}" -- ------------------------------------------------------------ -nullable :: XmlRegex -> Bool-nullable (Zero _) = False-nullable Unit = True-nullable (Sym _p) = False -- assumption: p holds for at least one tree-nullable Dot = False-nullable (Star _) = True-nullable (Alt e1 e2) = nullable e1 ||- nullable e2-nullable (Seq e1 e2) = nullable e1 &&- nullable e2-nullable (Rep _i e) = nullable e-nullable (Rng i _ e) = i == 0 ||- nullable e+nullable :: XmlRegex -> Bool+nullable (Zero _) = False+nullable Unit = True+nullable (Sym _p) = False -- assumption: p holds for at least one tree+nullable Dot = False+nullable (Star _) = True+nullable (Alt e1 e2) = nullable e1 ||+ nullable e2+nullable (Seq e1 e2) = nullable e1 &&+ nullable e2+nullable (Rep _i e) = nullable e+nullable (Rng i _ e) = i == 0 ||+ nullable e -- ------------------------------------------------------------ -delta :: XmlRegex -> XmlTree -> XmlRegex-delta e@(Zero _) _ = e-delta Unit c = mkZero $- "unexpected char " ++ show c+delta :: XmlRegex -> XmlTree -> XmlRegex+delta e@(Zero _) _ = e+delta Unit c = mkZero $+ "unexpected char " ++ show c delta (Sym p) c- | p c = mkUnit- | otherwise = mkZero $- "unexpected tree " ++ show c-delta Dot _ = mkUnit-delta e@(Star e1) c = mkSeq (delta e1 c) e-delta (Alt e1 e2) c = mkAlt (delta e1 c) (delta e2 c)+ | p c = mkUnit+ | otherwise = mkZero $+ "unexpected tree " ++ show c+delta Dot _ = mkUnit+delta e@(Star e1) c = mkSeq (delta e1 c) e+delta (Alt e1 e2) c = mkAlt (delta e1 c) (delta e2 c) delta (Seq e1 e2) c- | nullable e1 = mkAlt (mkSeq (delta e1 c) e2) (delta e2 c)- | otherwise = mkSeq (delta e1 c) e2-delta (Rep i e) c = mkSeq (delta e c) (mkRep (i-1) e)-delta (Rng i j e) c = mkSeq (delta e c) (mkRng ((i-1) `max` 0) (j-1) e)+ | nullable e1 = mkAlt (mkSeq (delta e1 c) e2) (delta e2 c)+ | otherwise = mkSeq (delta e1 c) e2+delta (Rep i e) c = mkSeq (delta e c) (mkRep (i-1) e)+delta (Rng i j e) c = mkSeq (delta e c) (mkRng ((i-1) `max` 0) (j-1) e) -- ------------------------------------------------------------ -delta' :: XmlRegex -> XmlTrees -> XmlRegex-delta' = foldl delta+delta' :: XmlRegex -> XmlTrees -> XmlRegex+delta' = foldl delta -- | match a sequence of XML trees with a regular expression over trees -- -- If the input matches, the result is Nothing, else Just an error message is returned -matchXmlRegex :: XmlRegex -> XmlTrees -> Maybe String+matchXmlRegex :: XmlRegex -> XmlTrees -> Maybe String matchXmlRegex e = res . delta' e where- res (Zero er) = Just er+ res (Zero er) = Just er res re- | nullable re = Nothing -- o.k.- | otherwise = Just $ "input does not match " ++ show e+ | nullable re = Nothing -- o.k.+ | otherwise = Just $ "input does not match " ++ show e -- ------------------------------------------------------------ @@ -261,21 +261,21 @@ -- -- If there is no matching prefix, Nothing is returned -splitXmlRegex :: XmlRegex -> XmlTrees -> Maybe (XmlTrees, XmlTrees)-splitXmlRegex re = splitXmlRegex' re []+splitXmlRegex :: XmlRegex -> XmlTrees -> Maybe (XmlTrees, XmlTrees)+splitXmlRegex re = splitXmlRegex' re [] -splitXmlRegex' :: XmlRegex -> XmlTrees -> XmlTrees -> Maybe (XmlTrees, XmlTrees)+splitXmlRegex' :: XmlRegex -> XmlTrees -> XmlTrees -> Maybe (XmlTrees, XmlTrees) splitXmlRegex' re res []- | nullable re = Just (reverse res, [])- | otherwise = Nothing+ | nullable re = Just (reverse res, [])+ | otherwise = Nothing splitXmlRegex' (Zero _) _ _- = Nothing+ = Nothing splitXmlRegex' re res xs@(x:xs')- | isJust res' = res'- | nullable re = Just (reverse res, xs)- | otherwise = Nothing+ | isJust res' = res'+ | nullable re = Just (reverse res, xs)+ | otherwise = Nothing where re' = delta re x res' = splitXmlRegex' re' (x:res) xs'@@ -287,17 +287,17 @@ -- If the parts cannot be split because of a missing match, or because of the -- empty sequence as match, Nothing is returned -scanXmlRegex :: XmlRegex -> XmlTrees -> Maybe [XmlTrees]-scanXmlRegex re ts = scanXmlRegex' re (splitXmlRegex re ts)+scanXmlRegex :: XmlRegex -> XmlTrees -> Maybe [XmlTrees]+scanXmlRegex re ts = scanXmlRegex' re (splitXmlRegex re ts) -scanXmlRegex' :: XmlRegex -> Maybe (XmlTrees, XmlTrees) -> Maybe [XmlTrees]-scanXmlRegex' _ Nothing = Nothing-scanXmlRegex' _ (Just (rs, [])) = Just [rs]-scanXmlRegex' _ (Just ([], _)) = Nothing -- re is nullable (the empty word matches), nothing split off- -- would give infinite list of empty lists+scanXmlRegex' :: XmlRegex -> Maybe (XmlTrees, XmlTrees) -> Maybe [XmlTrees]+scanXmlRegex' _ Nothing = Nothing+scanXmlRegex' _ (Just (rs, [])) = Just [rs]+scanXmlRegex' _ (Just ([], _)) = Nothing -- re is nullable (the empty word matches), nothing split off+ -- would give infinite list of empty lists scanXmlRegex' re (Just (rs, rest))- | isNothing res = Nothing- | otherwise = Just (rs : fromJust res)+ | isNothing res = Nothing+ | otherwise = Just (rs : fromJust res) where res = scanXmlRegex' re (splitXmlRegex re rest)
src/Text/XML/HXT/DOM/FormatXmlTree.hs view
@@ -30,43 +30,43 @@ -- ------------------------------------------------------------ -formatXmlContents :: XmlTree -> XmlTrees+formatXmlContents :: XmlTree -> XmlTrees formatXmlContents t = [mkText (formatXmlTree t)] -formatXmlTree :: XmlTree -> String+formatXmlTree :: XmlTree -> String formatXmlTree = formatTree xnode2String -xnode2String :: XNode -> String+xnode2String :: XNode -> String xnode2String n | isElem n- = "XTag " ++ showName n ++ showAtts n+ = "XTag " ++ showName n ++ showAtts n | isPi n- = "XPi " ++ showName n ++ showAtts n+ = "XPi " ++ showName n ++ showAtts n | otherwise- = show n+ = show n where -showName :: XNode -> String-showName = maybe "" showQn . getName+showName :: XNode -> String+showName = maybe "" showQn . getName -showAtts :: XNode -> String-showAtts = concatMap showAl . fromMaybe [] . getAttrl+showAtts :: XNode -> String+showAtts = concatMap showAl . fromMaybe [] . getAttrl -showAl :: XmlTree -> String-showAl t -- (NTree (XAttr an) av)+showAl :: XmlTree -> String+showAl t -- (NTree (XAttr an) av) | isAttr t- = "\n| " ++ (maybe "" showQn . getName $ t) ++ "=" ++ show (xshow . getChildren $ t)+ = "\n| " ++ (maybe "" showQn . getName $ t) ++ "=" ++ show (xshow . getChildren $ t) | otherwise- = show t+ = show t -showQn :: QName -> String+showQn :: QName -> String showQn n | null ns- = show $ qualifiedName n+ = show $ qualifiedName n | otherwise- = show $ "{" ++ ns ++ "}" ++ qualifiedName n+ = show $ "{" ++ ns ++ "}" ++ qualifiedName n where ns = namespaceUri n
src/Text/XML/HXT/DOM/Interface.hs view
@@ -26,11 +26,11 @@ ) where -import Text.XML.HXT.DOM.XmlKeywords -- constants-import Text.XML.HXT.DOM.TypeDefs -- XML Tree types+import Text.XML.HXT.DOM.XmlKeywords -- constants+import Text.XML.HXT.DOM.TypeDefs -- XML Tree types import Text.XML.HXT.DOM.Util-import Text.XML.HXT.DOM.XmlOptions -- predefined options-import Text.XML.HXT.DOM.MimeTypes -- mime types related stuff+import Text.XML.HXT.DOM.XmlOptions -- predefined options+import Text.XML.HXT.DOM.MimeTypes -- mime types related stuff -- ------------------------------------------------------------
src/Text/XML/HXT/DOM/IsoLatinTables.hs view
@@ -1,7 +1,7 @@ module Text.XML.HXT.DOM.IsoLatinTables where -iso_8859_2 :: [(Char, Char)]+iso_8859_2 :: [(Char, Char)] iso_8859_2 = [ ('\161', '\260' ) , ('\162', '\728' )@@ -62,7 +62,7 @@ , ('\255', '\729' ) ] -iso_8859_3 :: [(Char, Char)]+iso_8859_3 :: [(Char, Char)] iso_8859_3 = [ ('\161', '\294' ) , ('\162', '\728' )@@ -94,7 +94,7 @@ , ('\255', '\729' ) ] -iso_8859_4 :: [(Char, Char)]+iso_8859_4 :: [(Char, Char)] iso_8859_4 = [ ('\161', '\260' ) , ('\162', '\312' )@@ -148,7 +148,7 @@ , ('\255', '\729' ) ] -iso_8859_5 :: [(Char, Char)]+iso_8859_5 :: [(Char, Char)] iso_8859_5 = [ ('\161', '\1025' ) , ('\162', '\1026' )@@ -246,7 +246,7 @@ , ('\255', '\1119' ) ] -iso_8859_6 :: [(Char, Char)]+iso_8859_6 :: [(Char, Char)] iso_8859_6 = [ ('\172', '\1548' ) , ('\187', '\1563' )@@ -298,7 +298,7 @@ , ('\242', '\1618' ) ] -iso_8859_7 :: [(Char, Char)]+iso_8859_7 :: [(Char, Char)] iso_8859_7 = [ ('\161', '\8216' ) , ('\162', '\8217' )@@ -379,7 +379,7 @@ , ('\254', '\974' ) ] -iso_8859_8 :: [(Char, Char)]+iso_8859_8 :: [(Char, Char)] iso_8859_8 = [ ('\170', '\215' ) , ('\186', '\247' )@@ -415,7 +415,7 @@ , ('\254', '\8207' ) ] -iso_8859_9 :: [(Char, Char)]+iso_8859_9 :: [(Char, Char)] iso_8859_9 = [ ('\208', '\286' ) , ('\221', '\304' )@@ -425,7 +425,7 @@ , ('\254', '\351' ) ] -iso_8859_10 :: [(Char, Char)]+iso_8859_10 :: [(Char, Char)] iso_8859_10 = [ ('\161', '\260' ) , ('\162', '\274' )@@ -475,7 +475,7 @@ , ('\255', '\312' ) ] -iso_8859_11 :: [(Char, Char)]+iso_8859_11 :: [(Char, Char)] iso_8859_11 = [ ('\161', '\3585' ) , ('\162', '\3586' )@@ -566,7 +566,7 @@ , ('\251', '\3675' ) ] -iso_8859_13 :: [(Char, Char)]+iso_8859_13 :: [(Char, Char)] iso_8859_13 = [ ('\161', '\8221' ) , ('\165', '\8222' )@@ -626,7 +626,7 @@ , ('\255', '\8217' ) ] -iso_8859_14 :: [(Char, Char)]+iso_8859_14 :: [(Char, Char)] iso_8859_14 = [ ('\161', '\7682' ) , ('\162', '\7683' )@@ -661,7 +661,7 @@ , ('\254', '\375' ) ] -iso_8859_15 :: [(Char, Char)]+iso_8859_15 :: [(Char, Char)] iso_8859_15 = [ ('\164', '\8364' ) , ('\166', '\352' )@@ -673,7 +673,7 @@ , ('\190', '\376' ) ] -iso_8859_16 :: [(Char, Char)]+iso_8859_16 :: [(Char, Char)] iso_8859_16 = [ ('\161', '\260' ) , ('\162', '\261' )
src/Text/XML/HXT/DOM/MimeTypeDefaults.hs view
@@ -1,584 +1,584 @@ -- | default mime type table--- --- this file is generated from file /etc/mime.types--module Text.XML.HXT.DOM.MimeTypeDefaults-where---- | the table with the mapping from file name extensions to mime types--mimeTypeDefaults :: [(String, String)]-mimeTypeDefaults- = [ ("123", "application/vnd.lotus-1-2-3")- , ("3ds", "image/x-3ds")- , ("3g2", "video/x-3gpp2")- , ("3gp", "video/3gpp")- , ("669", "audio/x-mod")- , ("BAY", "image/x-dcraw")- , ("BLEND", "application/x-blender")- , ("BMQ", "image/x-dcraw")- , ("C", "text/x-c++src")- , ("CR2", "image/x-dcraw")- , ("CRW", "image/x-dcraw")- , ("CS1", "image/x-dcraw")- , ("CSSL", "text/css")- , ("DC2", "image/x-dcraw")- , ("DCR", "image/x-dcraw")- , ("FFF", "image/x-dcraw")- , ("K25", "image/x-dcraw")- , ("KDC", "image/x-dcraw")- , ("MOS", "image/x-dcraw")- , ("MRW", "image/x-dcraw")- , ("NEF", "image/x-dcraw")- , ("NSV", "video/x-nsv")- , ("ORF", "image/x-dcraw")- , ("PAR2", "application/x-par2")- , ("PEF", "image/x-dcraw")- , ("RAF", "image/x-dcraw")- , ("RDC", "image/x-dcraw")- , ("SRF", "image/x-dcraw")- , ("TTC", "application/x-font-ttf")- , ("X3F", "image/x-dcraw")- , ("XM", "audio/x-mod")- , ("Z", "application/x-compress")- , ("a", "application/x-archive")- , ("aac", "audio/x-aac")- , ("abw", "application/x-abiword")- , ("abw.CRASHED", "application/x-abiword")- , ("abw.gz", "application/x-abiword")- , ("ac3", "audio/ac3")- , ("adb", "text/x-adasrc")- , ("ads", "text/x-adasrc")- , ("afm", "application/x-font-afm")- , ("ag", "image/x-applix-graphics")- , ("ai", "application/illustrator")- , ("aif", "audio/x-aiff")- , ("aif", "audio/x-aiff")- , ("aifc", "audio/x-aiff")- , ("aiff", "audio/x-aiff")- , ("aiff", "audio/x-aiff")- , ("al", "application/x-perl")- , ("anim[1-9j]", "video/x-anim")- , ("aop", "application/x-frontline")- , ("arj", "application/x-arj")- , ("as", "application/x-applix-spreadsheet")- , ("asax", "application/x-asax")- , ("asc", "text/plain")- , ("ascx", "application/x-ascx")- , ("asf", "video/x-ms-asf")- , ("ashx", "application/x-ashx")- , ("asix", "application/x-asix")- , ("asmx", "application/x-asmx")- , ("asp", "application/x-asp")- , ("aspx", "application/x-aspx")- , ("asx", "video/x-ms-asf")- , ("au", "audio/basic")- , ("avi", "video/x-msvideo")- , ("aw", "application/x-applix-word")- , ("axd", "application/x-axd")- , ("bak", "application/x-trash")- , ("bay", "image/x-dcraw")- , ("bcpio", "application/x-bcpio")- , ("bdf", "application/x-font-bdf")- , ("bib", "text/x-bibtex")- , ("bin", "application/octet-stream")- , ("bin", "application/x-stuffit")- , ("blend", "application/x-blender")- , ("blender", "application/x-blender")- , ("bmp", "image/bmp")- , ("bmq", "image/x-dcraw")- , ("boo", "text/x-boo")- , ("bz", "application/x-bzip")- , ("bz", "application/x-bzip")- , ("bz2", "application/x-bzip")- , ("bz2", "application/x-bzip")- , ("c", "text/x-csrc")- , ("c++", "text/x-c++src")- , ("caves", "application/x-gnome-stones")- , ("cc", "text/x-c++src")- , ("cdf", "application/x-netcdf")- , ("cdr", "application/vnd.corel-draw")- , ("cer", "application/x-x509-ca-cert")- , ("cert", "application/x-x509-ca-cert")- , ("cgi", "application/x-cgi")- , ("cgm", "image/cgm")- , ("chm", "application/x-chm")- , ("chrt", "application/x-kchart")- , ("cht", "application/chemtool")- , ("class", "application/x-java")- , ("cls", "text/x-tex")- , ("cmbx", "application/x-cmbx")- , ("config", "application/x-config")- , ("connection", "application/x-gnome-db-connection")- , ("cpio", "application/x-cpio")- , ("cpio.gz", "application/x-cpio-compressed")- , ("cpp", "text/x-c++src")- , ("cr2", "image/x-dcraw")- , ("crt", "application/x-x509-ca-cert")- , ("crw", "image/x-dcraw")- , ("cs", "text/x-csharp")- , ("cs1", "image/x-dcraw")- , ("csh", "application/x-csh")- , ("css", "text/css")- , ("csv", "text/x-comma-separated-values")- , ("cue", "application/x-cue")- , ("cur", "image/x-win-bitmap")- , ("cxx", "text/x-c++src")- , ("d", "text/x-dsrc")- , ("dat", "video/mpeg")- , ("database", "application/x-gnome-db-database")- , ("dbf", "application/x-dbase")- , ("dc", "application/x-dc-rom")- , ("dc2", "image/x-dcraw")- , ("dcl", "text/x-dcl")- , ("dcm", "application/dicom")- , ("dcr", "image/x-dcraw")- , ("deb", "application/x-deb")- , ("der", "application/x-x509-ca-cert")- , ("desktop", "application/x-desktop")- , ("devhelp", "application/x-devhelp")- , ("dia", "application/x-dia-diagram")- , ("dif", "video/dv")- , ("diff", "text/x-patch")- , ("disco", "application/x-disco")- , ("display", "application/x-gdesklets-display")- , ("djv", "image/vnd.djvu")- , ("djvu", "image/vnd.djvu")- , ("doc", "application/msword")- , ("docbook", "application/docbook+xml")- , ("dsl", "text/x-dsl")- , ("dtd", "text/x-dtd")- , ("dv", "video/dv")- , ("dvi", "application/x-dvi")- , ("dwg", "image/vnd.dwg")- , ("dxf", "image/vnd.dxf")- , ("ear", "application/x-java-archive")- , ("egon", "application/x-egon")- , ("el", "text/x-emacs-lisp")- , ("eps", "image/x-eps")- , ("epsf", "image/x-eps")- , ("epsi", "image/x-eps")- , ("etheme", "application/x-e-theme")- , ("etx", "text/x-setext")- , ("exe", "application/x-executable")- , ("exe", "application/x-ms-dos-executable")- , ("ez", "application/andrew-inset")- , ("f", "text/x-fortran")- , ("fff", "image/x-dcraw")- , ("fig", "image/x-xfig")- , ("fits", "image/x-fits")- , ("flac", "audio/x-flac")- , ("flc", "video/x-flic")- , ("fli", "video/x-flic")- , ("flw", "application/x-kivio")- , ("fo", "text/x-xslfo")- , ("g3", "image/fax-g3")- , ("gb", "application/x-gameboy-rom")- , ("gcrd", "text/directory")- , ("gen", "application/x-genesis-rom")- , ("gf", "application/x-tex-gf")- , ("gg", "application/x-sms-rom")- , ("gif", "image/gif")- , ("glabels", "application/x-glabels")- , ("glade", "application/x-glade")- , ("gmo", "application/x-gettext-translation")- , ("gnc", "application/x-gnucash")- , ("gnucash", "application/x-gnucash")- , ("gnumeric", "application/x-gnumeric")- , ("gpg", "application/pgp-encrypted")- , ("gra", "application/x-graphite")- , ("gsf", "application/x-font-type1")- , ("gtar", "application/x-gtar")- , ("gz", "application/x-gzip")- , ("h", "text/x-chdr")- , ("h++", "text/x-chdr")- , ("hdf", "application/x-hdf")- , ("hh", "text/x-c++hdr")- , ("hp", "text/x-chdr")- , ("hpgl", "application/vnd.hp-hpgl")- , ("hs", "text/x-haskell")- , ("htm", "text/html")- , ("html", "text/html")- , ("ica", "application/x-ica")- , ("icb", "image/x-icb")- , ("ico", "image/x-ico")- , ("ics", "text/calendar")- , ("idl", "text/x-idl")- , ("ief", "image/ief")- , ("iff", "image/x-iff")- , ("il", "text/x-msil")- , ("ilbm", "image/x-ilbm")- , ("iso", "application/x-cd-image")- , ("it", "audio/x-it")- , ("jam", "application/x-jamin")- , ("jar", "application/x-jar")- , ("jar", "application/x-java-archive")- , ("java", "text/x-java")- , ("jng", "image/x-jng")- , ("jnlp", "application/x-java-jnlp-file")- , ("jp2", "image/jpeg2000")- , ("jpe", "image/jpeg")- , ("jpeg", "image/jpeg")- , ("jpg", "image/jpeg")- , ("jpr", "application/x-jbuilder-project")- , ("jpx", "application/x-jbuilder-project")- , ("js", "application/x-javascript")- , ("js", "text/x-js")- , ("k", "application/x-tex-pk")- , ("k25", "image/x-dcraw")- , ("karbon", "application/x-karbon")- , ("kdc", "image/x-dcraw")- , ("kdelnk", "application/x-desktop")- , ("kfo", "application/x-kformula")- , ("kil", "application/x-killustrator")- , ("kino", "application/x-smil")- , ("kon", "application/x-kontour")- , ("kpm", "application/x-kpovmodeler")- , ("kpr", "application/x-kpresenter")- , ("kpt", "application/x-kpresenter")- , ("kra", "application/x-krita")- , ("ksp", "application/x-kspread")- , ("kud", "application/x-kugar")- , ("kwd", "application/x-kword")- , ("kwt", "application/x-kword")- , ("la", "application/x-shared-library-la")- , ("lha", "application/x-lha")- , ("lhs", "text/x-literate-haskell")- , ("lhz", "application/x-lhz")- , ("log", "text/x-log")- , ("ltx", "text/x-tex")- , ("lwo", "image/x-lwo")- , ("lwob", "image/x-lwo")- , ("lws", "image/x-lws")- , ("lyx", "application/x-lyx")- , ("lzh", "application/x-lha")- , ("lzh", "application/x-lha")- , ("lzo", "application/x-lzop")- , ("m", "text/x-objcsrc")- , ("m15", "audio/x-mod")- , ("m3u", "audio/x-mpegurl")- , ("m4a", "audio/x-m4a")- , ("man", "application/x-troff-man")- , ("master", "application/x-master-page")- , ("md", "application/x-genesis-rom")- , ("mdp", "application/x-mdp")- , ("mds", "application/x-mds")- , ("mdsx", "application/x-mdsx")- , ("me", "text/x-troff-me")- , ("mergeant", "application/x-mergeant")- , ("mgp", "application/x-magicpoint")- , ("mid", "audio/midi")- , ("midi", "audio/midi")- , ("mif", "application/x-mif")- , ("mkv", "application/x-matroska")- , ("mm", "text/x-troff-mm")- , ("mml", "text/mathml")- , ("mng", "video/x-mng")- , ("moc", "text/x-moc")- , ("mod", "audio/x-mod")- , ("moov", "video/quicktime")- , ("mos", "image/x-dcraw")- , ("mov", "video/quicktime")- , ("movie", "video/x-sgi-movie")- , ("mp2", "video/mpeg")- , ("mp3", "audio/mpeg")- , ("mpe", "video/mpeg")- , ("mpeg", "video/mpeg")- , ("mpg", "video/mpeg")- , ("mps", "application/x-mps")- , ("mrproject", "application/x-planner")- , ("mrw", "image/x-dcraw")- , ("ms", "text/x-troff-ms")- , ("msod", "image/x-msod")- , ("msx", "application/x-msx-rom")- , ("mtm", "audio/x-mod")- , ("n", "text/x-nemerle")- , ("n64", "application/x-n64-rom")- , ("nb", "application/mathematica")- , ("nc", "application/x-netcdf")- , ("nef", "image/x-dcraw")- , ("nes", "application/x-nes-rom")- , ("nsv", "video/x-nsv")- , ("o", "application/x-object")- , ("obj", "application/x-tgif")- , ("oda", "application/oda")- , ("odb", "application/vnd.oasis.opendocument.database")- , ("odc", "application/vnd.oasis.opendocument.chart")- , ("odf", "application/vnd.oasis.opendocument.formula")- , ("odg", "application/vnd.oasis.opendocument.graphics")- , ("odi", "application/vnd.oasis.opendocument.image")- , ("odm", "application/vnd.oasis.opendocument.text-master")- , ("odp", "application/vnd.oasis.opendocument.presentation")- , ("ods", "application/vnd.oasis.opendocument.spreadsheet")- , ("odt", "application/vnd.oasis.opendocument.text")- , ("ogg", "application/ogg")- , ("old", "application/x-trash")- , ("oleo", "application/x-oleo")- , ("orf", "image/x-dcraw")- , ("otg", "application/vnd.oasis.opendocument.graphics-template")- , ("oth", "application/vnd.oasis.opendocument.text-web")- , ("otp", "application/vnd.oasis.opendocument.presentation-template")- , ("ots", "application/vnd.oasis.opendocument.spreadsheet-template")- , ("ott", "application/vnd.oasis.opendocument.text-template")- , ("p", "text/x-pascal")- , ("p12", "application/x-pkcs12")- , ("p7s", "application/pkcs7-signature")- , ("par2", "application/x-par2")- , ("pas", "text/x-pascal")- , ("patch", "text/x-patch")- , ("pbm", "image/x-portable-bitmap")- , ("pcd", "image/x-photo-cd")- , ("pcf", "application/x-font-pcf")- , ("pcf.Z", "application/x-font-type1")- , ("pcf.gz", "application/x-font-pcf")- , ("pcl", "application/vnd.hp-pcl")- , ("pdb", "application/vnd.palm")- , ("pdb", "application/x-palm-database")- , ("pdf", "application/pdf")- , ("pef", "image/x-dcraw")- , ("pem", "application/x-x509-ca-cert")- , ("perl", "application/x-perl")- , ("pfa", "application/x-font-type1")- , ("pfb", "application/x-font-type1")- , ("pfx", "application/x-pkcs12")- , ("pgm", "image/x-portable-graymap")- , ("pgn", "application/x-chess-pgn")- , ("pgp", "application/pgp")- , ("pgp", "application/pgp-encrypted")- , ("php", "application/x-php")- , ("php3", "application/x-php")- , ("php4", "application/x-php")- , ("pict", "image/x-pict")- , ("pict1", "image/x-pict")- , ("pict2", "image/x-pict")- , ("pkr", "application/pgp-keys")- , ("pl", "application/x-perl")- , ("planner", "application/x-planner")- , ("pln", "application/x-planperfect")- , ("pls", "audio/x-scpls")- , ("pls", "audio/x-scpls")- , ("pm", "application/x-perl")- , ("png", "image/png")- , ("pnm", "image/x-portable-anymap")- , ("po", "text/x-gettext-translation")- , ("pot", "application/vnd.ms-powerpoint")- , ("pot", "text/x-gettext-translation-template")- , ("ppm", "image/x-portable-pixmap")- , ("pps", "application/vnd.ms-powerpoint")- , ("ppt", "application/vnd.ms-powerpoint")- , ("ppz", "application/vnd.ms-powerpoint")- , ("prc", "application/x-palm-database")- , ("prj", "application/x-anjuta-project")- , ("prjx", "application/x-prjx")- , ("ps", "application/postscript")- , ("ps.gz", "application/x-gzpostscript")- , ("psd", "image/x-psd")- , ("psf", "application/x-font-linux-psf")- , ("psid", "audio/prs.sid")- , ("pto", "application/x-ptoptimizer-script")- , ("pw", "application/x-pw")- , ("py", "text/x-python")- , ("pyc", "application/x-python-bytecode")- , ("pyo", "application/x-python-bytecode")- , ("qif", "application/x-qw")- , ("qt", "video/quicktime")- , ("qtvr", "video/quicktime")- , ("ra", "audio/vnd.rn-realaudio")- , ("ra", "audio/x-pn-realaudio")- , ("raf", "image/x-dcraw")- , ("ram", "audio/x-pn-realaudio")- , ("ram", "audio/x-pn-realaudio")- , ("rar", "application/x-rar")- , ("rar", "application/x-rar-compressed")- , ("ras", "image/x-cmu-raster")- , ("rdc", "image/x-dcraw")- , ("rdf", "text/rdf")- , ("rdp", "application/x-rdp")- , ("rej", "application/x-reject")- , ("rem", "application/x-remoting")- , ("resources", "application/x-resources")- , ("resx", "application/x-resourcesx")- , ("rgb", "image/x-rgb")- , ("rle", "image/rle")- , ("rm", "application/vnd.rn-realmedia")- , ("rm", "audio/x-pn-realaudio")- , ("rmm", "audio/x-pn-realaudio")- , ("rms", "application/vnd.rn-realmedia-secure")- , ("rmvb", "application/vnd.rn-realmedia-vbr")- , ("rng", "text/x-rng")- , ("roff", "application/x-troff")- , ("rpm", "application/x-rpm")- , ("rss", "text/rss")- , ("rt", "text/vnd.rn-realtext")- , ("rtf", "application/rtf")- , ("rtx", "text/richtext")- , ("rv", "video/vnd.rn-realvideo")- , ("s3m", "audio/x-s3m")- , ("sam", "application/x-amipro")- , ("sc", "application/x-sc")- , ("scd", "application/x-scribus")- , ("scd.gz", "application/x-scribus")- , ("scm", "text/x-scheme")- , ("sda", "application/vnd.stardivision.draw")- , ("sdc", "application/vnd.stardivision.calc")- , ("sdd", "application/vnd.stardivision.impress")- , ("sdp", "application/sdp")- , ("sdp", "application/vnd.stardivision.impress")- , ("sds", "application/vnd.stardivision.chart")- , ("sdw", "application/vnd.stardivision.writer")- , ("sgi", "image/x-sgi")- , ("sgl", "application/vnd.stardivision.writer")- , ("sgm", "text/sgml")- , ("sgml", "text/sgml")- , ("sh", "application/x-shellscript")- , ("shar", "application/x-shar")- , ("siag", "application/x-siag")- , ("sid", "audio/prs.sid")- , ("sig", "application/pgp-signature")- , ("sik", "application/x-trash")- , ("sit", "application/stuffit")- , ("sit", "application/x-stuffit")- , ("skr", "application/pgp-keys")- , ("sla", "application/x-scribus")- , ("sla.gz", "application/x-scribus")- , ("slk", "text/spreadsheet")- , ("smd", "application/vnd.stardivision.mail")- , ("smf", "application/vnd.stardivision.math")- , ("smi", "application/smil")- , ("smi", "application/x-smil")- , ("smil", "application/smil")- , ("smil", "application/x-smil")- , ("sml", "application/smil")- , ("sms", "application/x-sms-rom")- , ("snd", "audio/basic")- , ("so", "application/x-sharedlib")- , ("soap", "application/x-soap-remoting")- , ("spd", "application/x-font-speedo")- , ("sql", "text/x-sql")- , ("src", "application/x-wais-source")- , ("srf", "image/x-dcraw")- , ("ssm", "application/x-streamingmedia")- , ("stc", "application/vnd.sun.xml.calc.template")- , ("std", "application/vnd.sun.xml.draw.template")- , ("sti", "application/vnd.sun.xml.impress.template")- , ("stm", "audio/x-stm")- , ("stw", "application/vnd.sun.xml.writer.template")- , ("sty", "text/x-tex")- , ("sun", "image/x-sun-raster")- , ("sv4cpio", "application/x-sv4cpio")- , ("sv4crc", "application/x-sv4crc")- , ("svg", "image/svg+xml")- , ("swf", "application/x-shockwave-flash")- , ("sxc", "application/vnd.sun.xml.calc")- , ("sxd", "application/vnd.sun.xml.draw")- , ("sxg", "application/vnd.sun.xml.writer.global")- , ("sxi", "application/vnd.sun.xml.impress")- , ("sxm", "application/vnd.sun.xml.math")- , ("sxw", "application/vnd.sun.xml.writer")- , ("sylk", "text/spreadsheet")- , ("t", "application/x-troff")- , ("tar", "application/x-tar")- , ("tar.Z", "application/x-compressed-tar")- , ("tar.Z", "application/x-tarz")- , ("tar.bz", "application/x-bzip-compressed-tar")- , ("tar.bz", "application/x-bzip-compressed-tar")- , ("tar.bz2", "application/x-bzip-compressed-tar")- , ("tar.bz2", "application/x-bzip-compressed-tar")- , ("tar.gz", "application/x-compressed-tar")- , ("tar.gz", "application/x-compressed-tar")- , ("tar.lzo", "application/x-lzop-compressed-tar")- , ("tar.lzo", "application/x-tzo")- , ("taz", "application/x-compressed-tar")- , ("tbz", "application/x-bzip-compressed-tar")- , ("tbz2", "application/x-bzip-compressed-tar")- , ("tcl", "text/x-tcl")- , ("tex", "text/x-tex")- , ("texi", "text/x-texinfo")- , ("texinfo", "text/x-texinfo")- , ("tga", "image/x-tga")- , ("tgz", "application/x-compressed-tar")- , ("tgz", "application/x-compressed-tar")- , ("theme", "application/x-theme")- , ("tif", "image/tiff")- , ("tiff", "image/tiff")- , ("tk", "text/x-tcl")- , ("tm", "text/x-texmacs")- , ("toc", "application/x-toc")- , ("torrent", "application/x-bittorrent")- , ("tr", "application/x-troff")- , ("ts", "application/x-linguist")- , ("ts", "text/x-texmacs")- , ("tsv", "text/tab-separated-values")- , ("ttc", "application/x-font-ttf")- , ("ttf", "application/x-font-ttf")- , ("txt", "text/plain")- , ("tzo", "application/x-lzop-compressed-tar")- , ("tzo", "application/x-tzo")- , ("ui", "application/x-designer")- , ("uil", "text/x-uil")- , ("ult", "audio/x-mod")- , ("uni", "audio/x-mod")- , ("uri", "text/x-uri")- , ("url", "text/x-uri")- , ("ustar", "application/x-ustar")- , ("vb", "text/x-vb")- , ("vcf", "text/directory")- , ("vcs", "text/calendar")- , ("vct", "text/directory")- , ("vob", "video/mpeg")- , ("voc", "audio/x-voc")- , ("vor", "application/vnd.stardivision.writer")- , ("war", "application/x-java-archive")- , ("wav", "audio/x-wav")- , ("wb1", "application/x-quattro-pro")- , ("wb1", "application/x-quattropro")- , ("wb2", "application/x-quattro-pro")- , ("wb2", "application/x-quattropro")- , ("wb3", "application/x-quattro-pro")- , ("wb3", "application/x-quattropro")- , ("wk1", "application/vnd.lotus-1-2-3")- , ("wk3", "application/vnd.lotus-1-2-3")- , ("wk4", "application/vnd.lotus-1-2-3")- , ("wks", "application/vnd.lotus-1-2-3")- , ("wmf", "image/x-wmf")- , ("wml", "text/vnd.wap.wml")- , ("wmv", "video/x-ms-wmv")- , ("wpd", "application/vnd.wordperfect")- , ("wpg", "application/x-wpg")- , ("wri", "application/x-mswrite")- , ("wrl", "model/vrml")- , ("wsdl", "application/x-wsdl")- , ("x3f", "image/x-dcraw")- , ("xac", "application/x-gnucash")- , ("xbel", "application/x-xbel")- , ("xbm", "image/x-xbitmap")- , ("xcf", "image/x-xcf")- , ("xcf.bz2", "image/x-compressed-xcf")- , ("xcf.gz", "image/x-compressed-xcf")- , ("xds", "text/x-xds")- , ("xhtml", "application/xhtml+xml")- , ("xi", "audio/x-xi")- , ("xla", "application/vnd.ms-excel")- , ("xlc", "application/vnd.ms-excel")- , ("xld", "application/vnd.ms-excel")- , ("xll", "application/vnd.ms-excel")- , ("xlm", "application/vnd.ms-excel")- , ("xls", "application/vnd.ms-excel")- , ("xlt", "application/vnd.ms-excel")- , ("xlw", "application/vnd.ms-excel")- , ("xm", "audio/x-xm")- , ("xmi", "text/x-xmi")- , ("xml", "text/xml")- , ("xpl", "audio/x-scpls")- , ("xpm", "image/x-xpixmap")- , ("xsl", "text/x-xsl")- , ("xsl", "text/x-xslt")- , ("xslfo", "text/x-xslfo")- , ("xslt", "text/x-xslt")- , ("xul", "application/vnd.mozilla.xul+xml")- , ("xwd", "image/x-xwindowdump")- , ("zabw", "application/x-abiword")- , ("zip", "application/zip")- , ("zoo", "application/x-zoo")+--+-- this file is generated from file /etc/mime.types++module Text.XML.HXT.DOM.MimeTypeDefaults+where++-- | the table with the mapping from file name extensions to mime types++mimeTypeDefaults :: [(String, String)]+mimeTypeDefaults+ = [ ("123", "application/vnd.lotus-1-2-3")+ , ("3ds", "image/x-3ds")+ , ("3g2", "video/x-3gpp2")+ , ("3gp", "video/3gpp")+ , ("669", "audio/x-mod")+ , ("BAY", "image/x-dcraw")+ , ("BLEND", "application/x-blender")+ , ("BMQ", "image/x-dcraw")+ , ("C", "text/x-c++src")+ , ("CR2", "image/x-dcraw")+ , ("CRW", "image/x-dcraw")+ , ("CS1", "image/x-dcraw")+ , ("CSSL", "text/css")+ , ("DC2", "image/x-dcraw")+ , ("DCR", "image/x-dcraw")+ , ("FFF", "image/x-dcraw")+ , ("K25", "image/x-dcraw")+ , ("KDC", "image/x-dcraw")+ , ("MOS", "image/x-dcraw")+ , ("MRW", "image/x-dcraw")+ , ("NEF", "image/x-dcraw")+ , ("NSV", "video/x-nsv")+ , ("ORF", "image/x-dcraw")+ , ("PAR2", "application/x-par2")+ , ("PEF", "image/x-dcraw")+ , ("RAF", "image/x-dcraw")+ , ("RDC", "image/x-dcraw")+ , ("SRF", "image/x-dcraw")+ , ("TTC", "application/x-font-ttf")+ , ("X3F", "image/x-dcraw")+ , ("XM", "audio/x-mod")+ , ("Z", "application/x-compress")+ , ("a", "application/x-archive")+ , ("aac", "audio/x-aac")+ , ("abw", "application/x-abiword")+ , ("abw.CRASHED", "application/x-abiword")+ , ("abw.gz", "application/x-abiword")+ , ("ac3", "audio/ac3")+ , ("adb", "text/x-adasrc")+ , ("ads", "text/x-adasrc")+ , ("afm", "application/x-font-afm")+ , ("ag", "image/x-applix-graphics")+ , ("ai", "application/illustrator")+ , ("aif", "audio/x-aiff")+ , ("aif", "audio/x-aiff")+ , ("aifc", "audio/x-aiff")+ , ("aiff", "audio/x-aiff")+ , ("aiff", "audio/x-aiff")+ , ("al", "application/x-perl")+ , ("anim[1-9j]", "video/x-anim")+ , ("aop", "application/x-frontline")+ , ("arj", "application/x-arj")+ , ("as", "application/x-applix-spreadsheet")+ , ("asax", "application/x-asax")+ , ("asc", "text/plain")+ , ("ascx", "application/x-ascx")+ , ("asf", "video/x-ms-asf")+ , ("ashx", "application/x-ashx")+ , ("asix", "application/x-asix")+ , ("asmx", "application/x-asmx")+ , ("asp", "application/x-asp")+ , ("aspx", "application/x-aspx")+ , ("asx", "video/x-ms-asf")+ , ("au", "audio/basic")+ , ("avi", "video/x-msvideo")+ , ("aw", "application/x-applix-word")+ , ("axd", "application/x-axd")+ , ("bak", "application/x-trash")+ , ("bay", "image/x-dcraw")+ , ("bcpio", "application/x-bcpio")+ , ("bdf", "application/x-font-bdf")+ , ("bib", "text/x-bibtex")+ , ("bin", "application/octet-stream")+ , ("bin", "application/x-stuffit")+ , ("blend", "application/x-blender")+ , ("blender", "application/x-blender")+ , ("bmp", "image/bmp")+ , ("bmq", "image/x-dcraw")+ , ("boo", "text/x-boo")+ , ("bz", "application/x-bzip")+ , ("bz", "application/x-bzip")+ , ("bz2", "application/x-bzip")+ , ("bz2", "application/x-bzip")+ , ("c", "text/x-csrc")+ , ("c++", "text/x-c++src")+ , ("caves", "application/x-gnome-stones")+ , ("cc", "text/x-c++src")+ , ("cdf", "application/x-netcdf")+ , ("cdr", "application/vnd.corel-draw")+ , ("cer", "application/x-x509-ca-cert")+ , ("cert", "application/x-x509-ca-cert")+ , ("cgi", "application/x-cgi")+ , ("cgm", "image/cgm")+ , ("chm", "application/x-chm")+ , ("chrt", "application/x-kchart")+ , ("cht", "application/chemtool")+ , ("class", "application/x-java")+ , ("cls", "text/x-tex")+ , ("cmbx", "application/x-cmbx")+ , ("config", "application/x-config")+ , ("connection", "application/x-gnome-db-connection")+ , ("cpio", "application/x-cpio")+ , ("cpio.gz", "application/x-cpio-compressed")+ , ("cpp", "text/x-c++src")+ , ("cr2", "image/x-dcraw")+ , ("crt", "application/x-x509-ca-cert")+ , ("crw", "image/x-dcraw")+ , ("cs", "text/x-csharp")+ , ("cs1", "image/x-dcraw")+ , ("csh", "application/x-csh")+ , ("css", "text/css")+ , ("csv", "text/x-comma-separated-values")+ , ("cue", "application/x-cue")+ , ("cur", "image/x-win-bitmap")+ , ("cxx", "text/x-c++src")+ , ("d", "text/x-dsrc")+ , ("dat", "video/mpeg")+ , ("database", "application/x-gnome-db-database")+ , ("dbf", "application/x-dbase")+ , ("dc", "application/x-dc-rom")+ , ("dc2", "image/x-dcraw")+ , ("dcl", "text/x-dcl")+ , ("dcm", "application/dicom")+ , ("dcr", "image/x-dcraw")+ , ("deb", "application/x-deb")+ , ("der", "application/x-x509-ca-cert")+ , ("desktop", "application/x-desktop")+ , ("devhelp", "application/x-devhelp")+ , ("dia", "application/x-dia-diagram")+ , ("dif", "video/dv")+ , ("diff", "text/x-patch")+ , ("disco", "application/x-disco")+ , ("display", "application/x-gdesklets-display")+ , ("djv", "image/vnd.djvu")+ , ("djvu", "image/vnd.djvu")+ , ("doc", "application/msword")+ , ("docbook", "application/docbook+xml")+ , ("dsl", "text/x-dsl")+ , ("dtd", "text/x-dtd")+ , ("dv", "video/dv")+ , ("dvi", "application/x-dvi")+ , ("dwg", "image/vnd.dwg")+ , ("dxf", "image/vnd.dxf")+ , ("ear", "application/x-java-archive")+ , ("egon", "application/x-egon")+ , ("el", "text/x-emacs-lisp")+ , ("eps", "image/x-eps")+ , ("epsf", "image/x-eps")+ , ("epsi", "image/x-eps")+ , ("etheme", "application/x-e-theme")+ , ("etx", "text/x-setext")+ , ("exe", "application/x-executable")+ , ("exe", "application/x-ms-dos-executable")+ , ("ez", "application/andrew-inset")+ , ("f", "text/x-fortran")+ , ("fff", "image/x-dcraw")+ , ("fig", "image/x-xfig")+ , ("fits", "image/x-fits")+ , ("flac", "audio/x-flac")+ , ("flc", "video/x-flic")+ , ("fli", "video/x-flic")+ , ("flw", "application/x-kivio")+ , ("fo", "text/x-xslfo")+ , ("g3", "image/fax-g3")+ , ("gb", "application/x-gameboy-rom")+ , ("gcrd", "text/directory")+ , ("gen", "application/x-genesis-rom")+ , ("gf", "application/x-tex-gf")+ , ("gg", "application/x-sms-rom")+ , ("gif", "image/gif")+ , ("glabels", "application/x-glabels")+ , ("glade", "application/x-glade")+ , ("gmo", "application/x-gettext-translation")+ , ("gnc", "application/x-gnucash")+ , ("gnucash", "application/x-gnucash")+ , ("gnumeric", "application/x-gnumeric")+ , ("gpg", "application/pgp-encrypted")+ , ("gra", "application/x-graphite")+ , ("gsf", "application/x-font-type1")+ , ("gtar", "application/x-gtar")+ , ("gz", "application/x-gzip")+ , ("h", "text/x-chdr")+ , ("h++", "text/x-chdr")+ , ("hdf", "application/x-hdf")+ , ("hh", "text/x-c++hdr")+ , ("hp", "text/x-chdr")+ , ("hpgl", "application/vnd.hp-hpgl")+ , ("hs", "text/x-haskell")+ , ("htm", "text/html")+ , ("html", "text/html")+ , ("ica", "application/x-ica")+ , ("icb", "image/x-icb")+ , ("ico", "image/x-ico")+ , ("ics", "text/calendar")+ , ("idl", "text/x-idl")+ , ("ief", "image/ief")+ , ("iff", "image/x-iff")+ , ("il", "text/x-msil")+ , ("ilbm", "image/x-ilbm")+ , ("iso", "application/x-cd-image")+ , ("it", "audio/x-it")+ , ("jam", "application/x-jamin")+ , ("jar", "application/x-jar")+ , ("jar", "application/x-java-archive")+ , ("java", "text/x-java")+ , ("jng", "image/x-jng")+ , ("jnlp", "application/x-java-jnlp-file")+ , ("jp2", "image/jpeg2000")+ , ("jpe", "image/jpeg")+ , ("jpeg", "image/jpeg")+ , ("jpg", "image/jpeg")+ , ("jpr", "application/x-jbuilder-project")+ , ("jpx", "application/x-jbuilder-project")+ , ("js", "application/x-javascript")+ , ("js", "text/x-js")+ , ("k", "application/x-tex-pk")+ , ("k25", "image/x-dcraw")+ , ("karbon", "application/x-karbon")+ , ("kdc", "image/x-dcraw")+ , ("kdelnk", "application/x-desktop")+ , ("kfo", "application/x-kformula")+ , ("kil", "application/x-killustrator")+ , ("kino", "application/x-smil")+ , ("kon", "application/x-kontour")+ , ("kpm", "application/x-kpovmodeler")+ , ("kpr", "application/x-kpresenter")+ , ("kpt", "application/x-kpresenter")+ , ("kra", "application/x-krita")+ , ("ksp", "application/x-kspread")+ , ("kud", "application/x-kugar")+ , ("kwd", "application/x-kword")+ , ("kwt", "application/x-kword")+ , ("la", "application/x-shared-library-la")+ , ("lha", "application/x-lha")+ , ("lhs", "text/x-literate-haskell")+ , ("lhz", "application/x-lhz")+ , ("log", "text/x-log")+ , ("ltx", "text/x-tex")+ , ("lwo", "image/x-lwo")+ , ("lwob", "image/x-lwo")+ , ("lws", "image/x-lws")+ , ("lyx", "application/x-lyx")+ , ("lzh", "application/x-lha")+ , ("lzh", "application/x-lha")+ , ("lzo", "application/x-lzop")+ , ("m", "text/x-objcsrc")+ , ("m15", "audio/x-mod")+ , ("m3u", "audio/x-mpegurl")+ , ("m4a", "audio/x-m4a")+ , ("man", "application/x-troff-man")+ , ("master", "application/x-master-page")+ , ("md", "application/x-genesis-rom")+ , ("mdp", "application/x-mdp")+ , ("mds", "application/x-mds")+ , ("mdsx", "application/x-mdsx")+ , ("me", "text/x-troff-me")+ , ("mergeant", "application/x-mergeant")+ , ("mgp", "application/x-magicpoint")+ , ("mid", "audio/midi")+ , ("midi", "audio/midi")+ , ("mif", "application/x-mif")+ , ("mkv", "application/x-matroska")+ , ("mm", "text/x-troff-mm")+ , ("mml", "text/mathml")+ , ("mng", "video/x-mng")+ , ("moc", "text/x-moc")+ , ("mod", "audio/x-mod")+ , ("moov", "video/quicktime")+ , ("mos", "image/x-dcraw")+ , ("mov", "video/quicktime")+ , ("movie", "video/x-sgi-movie")+ , ("mp2", "video/mpeg")+ , ("mp3", "audio/mpeg")+ , ("mpe", "video/mpeg")+ , ("mpeg", "video/mpeg")+ , ("mpg", "video/mpeg")+ , ("mps", "application/x-mps")+ , ("mrproject", "application/x-planner")+ , ("mrw", "image/x-dcraw")+ , ("ms", "text/x-troff-ms")+ , ("msod", "image/x-msod")+ , ("msx", "application/x-msx-rom")+ , ("mtm", "audio/x-mod")+ , ("n", "text/x-nemerle")+ , ("n64", "application/x-n64-rom")+ , ("nb", "application/mathematica")+ , ("nc", "application/x-netcdf")+ , ("nef", "image/x-dcraw")+ , ("nes", "application/x-nes-rom")+ , ("nsv", "video/x-nsv")+ , ("o", "application/x-object")+ , ("obj", "application/x-tgif")+ , ("oda", "application/oda")+ , ("odb", "application/vnd.oasis.opendocument.database")+ , ("odc", "application/vnd.oasis.opendocument.chart")+ , ("odf", "application/vnd.oasis.opendocument.formula")+ , ("odg", "application/vnd.oasis.opendocument.graphics")+ , ("odi", "application/vnd.oasis.opendocument.image")+ , ("odm", "application/vnd.oasis.opendocument.text-master")+ , ("odp", "application/vnd.oasis.opendocument.presentation")+ , ("ods", "application/vnd.oasis.opendocument.spreadsheet")+ , ("odt", "application/vnd.oasis.opendocument.text")+ , ("ogg", "application/ogg")+ , ("old", "application/x-trash")+ , ("oleo", "application/x-oleo")+ , ("orf", "image/x-dcraw")+ , ("otg", "application/vnd.oasis.opendocument.graphics-template")+ , ("oth", "application/vnd.oasis.opendocument.text-web")+ , ("otp", "application/vnd.oasis.opendocument.presentation-template")+ , ("ots", "application/vnd.oasis.opendocument.spreadsheet-template")+ , ("ott", "application/vnd.oasis.opendocument.text-template")+ , ("p", "text/x-pascal")+ , ("p12", "application/x-pkcs12")+ , ("p7s", "application/pkcs7-signature")+ , ("par2", "application/x-par2")+ , ("pas", "text/x-pascal")+ , ("patch", "text/x-patch")+ , ("pbm", "image/x-portable-bitmap")+ , ("pcd", "image/x-photo-cd")+ , ("pcf", "application/x-font-pcf")+ , ("pcf.Z", "application/x-font-type1")+ , ("pcf.gz", "application/x-font-pcf")+ , ("pcl", "application/vnd.hp-pcl")+ , ("pdb", "application/vnd.palm")+ , ("pdb", "application/x-palm-database")+ , ("pdf", "application/pdf")+ , ("pef", "image/x-dcraw")+ , ("pem", "application/x-x509-ca-cert")+ , ("perl", "application/x-perl")+ , ("pfa", "application/x-font-type1")+ , ("pfb", "application/x-font-type1")+ , ("pfx", "application/x-pkcs12")+ , ("pgm", "image/x-portable-graymap")+ , ("pgn", "application/x-chess-pgn")+ , ("pgp", "application/pgp")+ , ("pgp", "application/pgp-encrypted")+ , ("php", "application/x-php")+ , ("php3", "application/x-php")+ , ("php4", "application/x-php")+ , ("pict", "image/x-pict")+ , ("pict1", "image/x-pict")+ , ("pict2", "image/x-pict")+ , ("pkr", "application/pgp-keys")+ , ("pl", "application/x-perl")+ , ("planner", "application/x-planner")+ , ("pln", "application/x-planperfect")+ , ("pls", "audio/x-scpls")+ , ("pls", "audio/x-scpls")+ , ("pm", "application/x-perl")+ , ("png", "image/png")+ , ("pnm", "image/x-portable-anymap")+ , ("po", "text/x-gettext-translation")+ , ("pot", "application/vnd.ms-powerpoint")+ , ("pot", "text/x-gettext-translation-template")+ , ("ppm", "image/x-portable-pixmap")+ , ("pps", "application/vnd.ms-powerpoint")+ , ("ppt", "application/vnd.ms-powerpoint")+ , ("ppz", "application/vnd.ms-powerpoint")+ , ("prc", "application/x-palm-database")+ , ("prj", "application/x-anjuta-project")+ , ("prjx", "application/x-prjx")+ , ("ps", "application/postscript")+ , ("ps.gz", "application/x-gzpostscript")+ , ("psd", "image/x-psd")+ , ("psf", "application/x-font-linux-psf")+ , ("psid", "audio/prs.sid")+ , ("pto", "application/x-ptoptimizer-script")+ , ("pw", "application/x-pw")+ , ("py", "text/x-python")+ , ("pyc", "application/x-python-bytecode")+ , ("pyo", "application/x-python-bytecode")+ , ("qif", "application/x-qw")+ , ("qt", "video/quicktime")+ , ("qtvr", "video/quicktime")+ , ("ra", "audio/vnd.rn-realaudio")+ , ("ra", "audio/x-pn-realaudio")+ , ("raf", "image/x-dcraw")+ , ("ram", "audio/x-pn-realaudio")+ , ("ram", "audio/x-pn-realaudio")+ , ("rar", "application/x-rar")+ , ("rar", "application/x-rar-compressed")+ , ("ras", "image/x-cmu-raster")+ , ("rdc", "image/x-dcraw")+ , ("rdf", "text/rdf")+ , ("rdp", "application/x-rdp")+ , ("rej", "application/x-reject")+ , ("rem", "application/x-remoting")+ , ("resources", "application/x-resources")+ , ("resx", "application/x-resourcesx")+ , ("rgb", "image/x-rgb")+ , ("rle", "image/rle")+ , ("rm", "application/vnd.rn-realmedia")+ , ("rm", "audio/x-pn-realaudio")+ , ("rmm", "audio/x-pn-realaudio")+ , ("rms", "application/vnd.rn-realmedia-secure")+ , ("rmvb", "application/vnd.rn-realmedia-vbr")+ , ("rng", "text/x-rng")+ , ("roff", "application/x-troff")+ , ("rpm", "application/x-rpm")+ , ("rss", "text/rss")+ , ("rt", "text/vnd.rn-realtext")+ , ("rtf", "application/rtf")+ , ("rtx", "text/richtext")+ , ("rv", "video/vnd.rn-realvideo")+ , ("s3m", "audio/x-s3m")+ , ("sam", "application/x-amipro")+ , ("sc", "application/x-sc")+ , ("scd", "application/x-scribus")+ , ("scd.gz", "application/x-scribus")+ , ("scm", "text/x-scheme")+ , ("sda", "application/vnd.stardivision.draw")+ , ("sdc", "application/vnd.stardivision.calc")+ , ("sdd", "application/vnd.stardivision.impress")+ , ("sdp", "application/sdp")+ , ("sdp", "application/vnd.stardivision.impress")+ , ("sds", "application/vnd.stardivision.chart")+ , ("sdw", "application/vnd.stardivision.writer")+ , ("sgi", "image/x-sgi")+ , ("sgl", "application/vnd.stardivision.writer")+ , ("sgm", "text/sgml")+ , ("sgml", "text/sgml")+ , ("sh", "application/x-shellscript")+ , ("shar", "application/x-shar")+ , ("siag", "application/x-siag")+ , ("sid", "audio/prs.sid")+ , ("sig", "application/pgp-signature")+ , ("sik", "application/x-trash")+ , ("sit", "application/stuffit")+ , ("sit", "application/x-stuffit")+ , ("skr", "application/pgp-keys")+ , ("sla", "application/x-scribus")+ , ("sla.gz", "application/x-scribus")+ , ("slk", "text/spreadsheet")+ , ("smd", "application/vnd.stardivision.mail")+ , ("smf", "application/vnd.stardivision.math")+ , ("smi", "application/smil")+ , ("smi", "application/x-smil")+ , ("smil", "application/smil")+ , ("smil", "application/x-smil")+ , ("sml", "application/smil")+ , ("sms", "application/x-sms-rom")+ , ("snd", "audio/basic")+ , ("so", "application/x-sharedlib")+ , ("soap", "application/x-soap-remoting")+ , ("spd", "application/x-font-speedo")+ , ("sql", "text/x-sql")+ , ("src", "application/x-wais-source")+ , ("srf", "image/x-dcraw")+ , ("ssm", "application/x-streamingmedia")+ , ("stc", "application/vnd.sun.xml.calc.template")+ , ("std", "application/vnd.sun.xml.draw.template")+ , ("sti", "application/vnd.sun.xml.impress.template")+ , ("stm", "audio/x-stm")+ , ("stw", "application/vnd.sun.xml.writer.template")+ , ("sty", "text/x-tex")+ , ("sun", "image/x-sun-raster")+ , ("sv4cpio", "application/x-sv4cpio")+ , ("sv4crc", "application/x-sv4crc")+ , ("svg", "image/svg+xml")+ , ("swf", "application/x-shockwave-flash")+ , ("sxc", "application/vnd.sun.xml.calc")+ , ("sxd", "application/vnd.sun.xml.draw")+ , ("sxg", "application/vnd.sun.xml.writer.global")+ , ("sxi", "application/vnd.sun.xml.impress")+ , ("sxm", "application/vnd.sun.xml.math")+ , ("sxw", "application/vnd.sun.xml.writer")+ , ("sylk", "text/spreadsheet")+ , ("t", "application/x-troff")+ , ("tar", "application/x-tar")+ , ("tar.Z", "application/x-compressed-tar")+ , ("tar.Z", "application/x-tarz")+ , ("tar.bz", "application/x-bzip-compressed-tar")+ , ("tar.bz", "application/x-bzip-compressed-tar")+ , ("tar.bz2", "application/x-bzip-compressed-tar")+ , ("tar.bz2", "application/x-bzip-compressed-tar")+ , ("tar.gz", "application/x-compressed-tar")+ , ("tar.gz", "application/x-compressed-tar")+ , ("tar.lzo", "application/x-lzop-compressed-tar")+ , ("tar.lzo", "application/x-tzo")+ , ("taz", "application/x-compressed-tar")+ , ("tbz", "application/x-bzip-compressed-tar")+ , ("tbz2", "application/x-bzip-compressed-tar")+ , ("tcl", "text/x-tcl")+ , ("tex", "text/x-tex")+ , ("texi", "text/x-texinfo")+ , ("texinfo", "text/x-texinfo")+ , ("tga", "image/x-tga")+ , ("tgz", "application/x-compressed-tar")+ , ("tgz", "application/x-compressed-tar")+ , ("theme", "application/x-theme")+ , ("tif", "image/tiff")+ , ("tiff", "image/tiff")+ , ("tk", "text/x-tcl")+ , ("tm", "text/x-texmacs")+ , ("toc", "application/x-toc")+ , ("torrent", "application/x-bittorrent")+ , ("tr", "application/x-troff")+ , ("ts", "application/x-linguist")+ , ("ts", "text/x-texmacs")+ , ("tsv", "text/tab-separated-values")+ , ("ttc", "application/x-font-ttf")+ , ("ttf", "application/x-font-ttf")+ , ("txt", "text/plain")+ , ("tzo", "application/x-lzop-compressed-tar")+ , ("tzo", "application/x-tzo")+ , ("ui", "application/x-designer")+ , ("uil", "text/x-uil")+ , ("ult", "audio/x-mod")+ , ("uni", "audio/x-mod")+ , ("uri", "text/x-uri")+ , ("url", "text/x-uri")+ , ("ustar", "application/x-ustar")+ , ("vb", "text/x-vb")+ , ("vcf", "text/directory")+ , ("vcs", "text/calendar")+ , ("vct", "text/directory")+ , ("vob", "video/mpeg")+ , ("voc", "audio/x-voc")+ , ("vor", "application/vnd.stardivision.writer")+ , ("war", "application/x-java-archive")+ , ("wav", "audio/x-wav")+ , ("wb1", "application/x-quattro-pro")+ , ("wb1", "application/x-quattropro")+ , ("wb2", "application/x-quattro-pro")+ , ("wb2", "application/x-quattropro")+ , ("wb3", "application/x-quattro-pro")+ , ("wb3", "application/x-quattropro")+ , ("wk1", "application/vnd.lotus-1-2-3")+ , ("wk3", "application/vnd.lotus-1-2-3")+ , ("wk4", "application/vnd.lotus-1-2-3")+ , ("wks", "application/vnd.lotus-1-2-3")+ , ("wmf", "image/x-wmf")+ , ("wml", "text/vnd.wap.wml")+ , ("wmv", "video/x-ms-wmv")+ , ("wpd", "application/vnd.wordperfect")+ , ("wpg", "application/x-wpg")+ , ("wri", "application/x-mswrite")+ , ("wrl", "model/vrml")+ , ("wsdl", "application/x-wsdl")+ , ("x3f", "image/x-dcraw")+ , ("xac", "application/x-gnucash")+ , ("xbel", "application/x-xbel")+ , ("xbm", "image/x-xbitmap")+ , ("xcf", "image/x-xcf")+ , ("xcf.bz2", "image/x-compressed-xcf")+ , ("xcf.gz", "image/x-compressed-xcf")+ , ("xds", "text/x-xds")+ , ("xhtml", "application/xhtml+xml")+ , ("xi", "audio/x-xi")+ , ("xla", "application/vnd.ms-excel")+ , ("xlc", "application/vnd.ms-excel")+ , ("xld", "application/vnd.ms-excel")+ , ("xll", "application/vnd.ms-excel")+ , ("xlm", "application/vnd.ms-excel")+ , ("xls", "application/vnd.ms-excel")+ , ("xlt", "application/vnd.ms-excel")+ , ("xlw", "application/vnd.ms-excel")+ , ("xm", "audio/x-xm")+ , ("xmi", "text/x-xmi")+ , ("xml", "text/xml")+ , ("xpl", "audio/x-scpls")+ , ("xpm", "image/x-xpixmap")+ , ("xsl", "text/x-xsl")+ , ("xsl", "text/x-xslt")+ , ("xslfo", "text/x-xslfo")+ , ("xslt", "text/x-xslt")+ , ("xul", "application/vnd.mozilla.xul+xml")+ , ("xwd", "image/x-xwindowdump")+ , ("zabw", "application/x-abiword")+ , ("zip", "application/zip")+ , ("zoo", "application/x-zoo") ]
src/Text/XML/HXT/DOM/MimeTypes.hs view
@@ -18,21 +18,21 @@ module Text.XML.HXT.DOM.MimeTypes where -import Control.Monad ( mplus )+import Control.Monad ( mplus ) -import qualified Data.ByteString as B+import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as C import Data.Char import Data.List-import qualified Data.Map as M+import qualified Data.Map as M import Data.Maybe import Text.XML.HXT.DOM.MimeTypeDefaults -- ------------------------------------------------------------ -type MimeTypeTable = M.Map String String+type MimeTypeTable = M.Map String String -- ------------------------------------------------------------ @@ -48,66 +48,66 @@ text_pdf, text_plain, text_xml,- text_xml_external_parsed_entity :: String+ text_xml_external_parsed_entity :: String -application_xhtml = "application/xhtml+xml"-application_xml = "application/xml"-application_xml_external_parsed_entity = "application/xml-external-parsed-entity"-application_xml_dtd = "application/xml-dtd"+application_xhtml = "application/xhtml+xml"+application_xml = "application/xml"+application_xml_external_parsed_entity = "application/xml-external-parsed-entity"+application_xml_dtd = "application/xml-dtd" -text_html = "text/html"-text_pdf = "text/pdf"-text_plain = "text/plain"-text_xml = "text/xml"-text_xml_external_parsed_entity = "text/xml-external-parsed-entity"+text_html = "text/html"+text_pdf = "text/pdf"+text_plain = "text/plain"+text_xml = "text/xml"+text_xml_external_parsed_entity = "text/xml-external-parsed-entity" -isTextMimeType :: String -> Bool-isTextMimeType = ("text/" `isPrefixOf`)+isTextMimeType :: String -> Bool+isTextMimeType = ("text/" `isPrefixOf`) -isHtmlMimeType :: String -> Bool-isHtmlMimeType t = t == text_html+isHtmlMimeType :: String -> Bool+isHtmlMimeType t = t == text_html -isXmlMimeType :: String -> Bool-isXmlMimeType t = ( t `elem` [ application_xhtml- , application_xml- , application_xml_external_parsed_entity- , application_xml_dtd- , text_xml- , text_xml_external_parsed_entity- ]- ||- "+xml" `isSuffixOf` t -- application/mathml+xml- ) -- or image/svg+xml+isXmlMimeType :: String -> Bool+isXmlMimeType t = ( t `elem` [ application_xhtml+ , application_xml+ , application_xml_external_parsed_entity+ , application_xml_dtd+ , text_xml+ , text_xml_external_parsed_entity+ ]+ ||+ "+xml" `isSuffixOf` t -- application/mathml+xml+ ) -- or image/svg+xml -defaultMimeTypeTable :: MimeTypeTable-defaultMimeTypeTable = M.fromList mimeTypeDefaults+defaultMimeTypeTable :: MimeTypeTable+defaultMimeTypeTable = M.fromList mimeTypeDefaults -extensionToMimeType :: String -> MimeTypeTable -> String-extensionToMimeType e = fromMaybe "" . lookupMime +extensionToMimeType :: String -> MimeTypeTable -> String+extensionToMimeType e = fromMaybe "" . lookupMime where- lookupMime t = M.lookup e t -- try exact match- `mplus`- M.lookup (map toLower e) t -- else try lowercase match- `mplus`- M.lookup (map toUpper e) t -- else try uppercase match+ lookupMime t = M.lookup e t -- try exact match+ `mplus`+ M.lookup (map toLower e) t -- else try lowercase match+ `mplus`+ M.lookup (map toUpper e) t -- else try uppercase match -- ------------------------------------------------------------ -readMimeTypeTable :: FilePath -> IO MimeTypeTable-readMimeTypeTable inp = do- cb <- B.readFile inp- return . M.fromList . parseMimeTypeTable . C.unpack $ cb+readMimeTypeTable :: FilePath -> IO MimeTypeTable+readMimeTypeTable inp = do+ cb <- B.readFile inp+ return . M.fromList . parseMimeTypeTable . C.unpack $ cb -parseMimeTypeTable :: String -> [(String, String)]-parseMimeTypeTable = concat- . map buildPairs- . map words- . filter (not . ("#" `isPrefixOf`))- . filter (not . all (isSpace))- . lines+parseMimeTypeTable :: String -> [(String, String)]+parseMimeTypeTable = concat+ . map buildPairs+ . map words+ . filter (not . ("#" `isPrefixOf`))+ . filter (not . all (isSpace))+ . lines where- buildPairs :: [String] -> [(String, String)]- buildPairs [] = []- buildPairs (mt:exts) = map (\ x -> (x, mt)) $ exts+ buildPairs :: [String] -> [(String, String)]+ buildPairs [] = []+ buildPairs (mt:exts) = map (\ x -> (x, mt)) $ exts -- ------------------------------------------------------------
src/Text/XML/HXT/DOM/QualifiedName.hs view
@@ -136,7 +136,7 @@ -- | Two QNames are equal if (1. case) namespaces are both empty and the qualified names -- (prefix:localpart) are the same or (2. case) namespaces are set and namespaces and -- local parts both are equal- + instance Eq QName where (LP lp1) == (LP lp2) = lp1 == lp2 (PX px1 qn1) == (PX px2 qn2) = px1 == px2 && qn1== qn2@@ -289,10 +289,10 @@ -- a prefix and a local part. mkName :: String -> QName-mkName n +mkName n | (':' `elem` n) &&- not (null px) -- more restrictive: isWellformedQualifiedName n+ not (null px) -- more restrictive: isWellformedQualifiedName n = mkPrefixLocalPart px lp | otherwise = mkPrefixLocalPart "" n where@@ -467,7 +467,7 @@ isNameSpaceName (NS _ n) = isNameSpaceName n -- |--- +-- -- predicate is used in filter 'valdateNamespaces'. isDeclaredNamespace :: QName -> Bool
src/Text/XML/HXT/DOM/ShowXml.hs view
@@ -24,11 +24,11 @@ import Data.Maybe import Data.Tree.NTree.TypeDefs -import Text.XML.HXT.DOM.TypeDefs -- XML Tree types+import Text.XML.HXT.DOM.TypeDefs -- XML Tree types import Text.XML.HXT.DOM.XmlKeywords-import Text.XML.HXT.DOM.XmlNode ( mkDTDElem- , getDTDAttrl- )+import Text.XML.HXT.DOM.XmlNode ( mkDTDElem+ , getDTDAttrl+ ) -- ----------------------------------------------------------------------------- --@@ -37,15 +37,15 @@ -- | -- convert the result of a filter into a string ----- see also : 'xmlTreesToText' for filter version, 'Text.XML.HXT.Parser.XmlParsec.xread' for the inverse operation +-- see also : 'xmlTreesToText' for filter version, 'Text.XML.HXT.Parser.XmlParsec.xread' for the inverse operation -xshow :: XmlTrees -> String-xshow [(NTree (XText s) _)] = s -- special case optimisation-xshow ts = showXmlTrees ts ""+xshow :: XmlTrees -> String+xshow [(NTree (XText s) _)] = s -- special case optimisation+xshow ts = showXmlTrees ts "" -- ------------------------------------------------------------ -showXmlTree :: XmlTree -> String -> String+showXmlTree :: XmlTree -> String -> String showXmlTree (NTree (XText s) _) = showString s@@ -71,14 +71,14 @@ . showString "?>" where- showPiAttr :: XmlTree -> String -> String+ showPiAttr :: XmlTree -> String -> String showPiAttr a@(NTree (XAttr an) cs)- | qualifiedName an == a_value- = showBlank . showXmlTrees cs- | otherwise- = showXmlTree a+ | qualifiedName an == a_value+ = showBlank . showXmlTrees cs+ | otherwise+ = showXmlTree a showPiAttr _- = id+ = id showXmlTree (NTree (XTag t al) []) = showLt . showQName t . showXmlTrees al . showSlash . showGt@@ -99,37 +99,37 @@ -- ------------------------------------------------------------ -showXmlTrees :: XmlTrees -> String -> String-showXmlTrees = foldr (.) id . map showXmlTree+showXmlTrees :: XmlTrees -> String -> String+showXmlTrees = foldr (.) id . map showXmlTree -showXmlTrees' :: XmlTrees -> String -> String-showXmlTrees' = foldr (\ x y -> x . showNL . y) id . map showXmlTree+showXmlTrees' :: XmlTrees -> String -> String+showXmlTrees' = foldr (\ x y -> x . showNL . y) id . map showXmlTree -- ------------------------------------------------------------ -showQName :: QName -> String -> String+showQName :: QName -> String -> String showQName = showString . qualifiedName -- ------------------------------------------------------------ -showQuoteString :: String -> String -> String+showQuoteString :: String -> String -> String showQuoteString s | '\"' `elem` s- = showApos . showString s . showApos+ = showApos . showString s . showApos | otherwise- = showQuot . showString s . showQuot+ = showQuot . showString s . showQuot -- ------------------------------------------------------------ -showAttr :: String -> Attributes -> String -> String+showAttr :: String -> Attributes -> String -> String showAttr k al = showString (fromMaybe "" . lookup k $ al) -- ------------------------------------------------------------ -showPEAttr :: Attributes -> String -> String+showPEAttr :: Attributes -> String -> String showPEAttr al = showPE (lookup a_peref al) where@@ -138,7 +138,7 @@ -- ------------------------------------------------------------ -showExternalId :: Attributes -> String -> String+showExternalId :: Attributes -> String -> String showExternalId al = id2Str (lookup k_system al) (lookup k_public al) where@@ -149,16 +149,16 @@ -- ------------------------------------------------------------ -showNData :: Attributes -> String -> String+showNData :: Attributes -> String -> String showNData al = nd2Str (lookup k_ndata al) where- nd2Str Nothing = id- nd2Str (Just v) = showBlank . showString k_ndata . showBlank . showString v+ nd2Str Nothing = id+ nd2Str (Just v) = showBlank . showString k_ndata . showBlank . showString v -- ------------------------------------------------------------ -showXmlDTD :: DTDElem -> Attributes -> XmlTrees -> String -> String+showXmlDTD :: DTDElem -> Attributes -> XmlTrees -> String -> String showXmlDTD DOCTYPE al cs = showString "<!DOCTYPE "@@ -189,60 +189,60 @@ = showString "<!ATTLIST " . ( if isNothing . lookup a_name $ al- then- showXmlTrees cs- else- showAttr a_name al- .- showBlank- .- ( case lookup a_value al of- Nothing -> ( showPEAttr- . fromMaybe [] . getDTDAttrl- . head- ) cs- Just a -> ( showString a- .+ then+ showXmlTrees cs+ else+ showAttr a_name al+ .+ showBlank+ .+ ( case lookup a_value al of+ Nothing -> ( showPEAttr+ . fromMaybe [] . getDTDAttrl+ . head+ ) cs+ Just a -> ( showString a+ . showAttrType (lookup1 a_type al) . showAttrKind (lookup1 a_kind al)- )- )+ )+ ) ) . showString " >" where showAttrType t- | t == k_peref- = showBlank . showPEAttr al- | t == k_enumeration- = showAttrEnum- | t == k_notation- = showBlank . showString k_notation . showAttrEnum- | otherwise- = showBlank . showString t+ | t == k_peref+ = showBlank . showPEAttr al+ | t == k_enumeration+ = showAttrEnum+ | t == k_notation+ = showBlank . showString k_notation . showAttrEnum+ | otherwise+ = showBlank . showString t showAttrEnum- = showString " ("- .- foldr1 (\ s1 s2 -> s1 . showString " | " . s2) (map (getEnum . fromMaybe [] . getDTDAttrl) cs)- .- showString ")"- where- getEnum :: Attributes -> String -> String- getEnum l = showAttr a_name l . showPEAttr l+ = showString " ("+ .+ foldr1 (\ s1 s2 -> s1 . showString " | " . s2) (map (getEnum . fromMaybe [] . getDTDAttrl) cs)+ .+ showString ")"+ where+ getEnum :: Attributes -> String -> String+ getEnum l = showAttr a_name l . showPEAttr l showAttrKind k- | k == k_default- = showBlank . showQuoteString (lookup1 a_default al)- | k == k_fixed- = showBlank . showString k_fixed- .- showBlank . showQuoteString (lookup1 a_default al)- | k == ""- = id- | otherwise- = showBlank . showString k+ | k == k_default+ = showBlank . showQuoteString (lookup1 a_default al)+ | k == k_fixed+ = showBlank . showString k_fixed+ .+ showBlank . showQuoteString (lookup1 a_default al)+ | k == ""+ = id+ | otherwise+ = showBlank . showString k showXmlDTD NOTATION al _cs = showString "<!NOTATION "@@ -284,40 +284,40 @@ -- ------------------------------------------------------------ -showElemType :: String -> XmlTrees -> String -> String+showElemType :: String -> XmlTrees -> String -> String showElemType t cs | t == v_pcdata- = showLpar . showString v_pcdata . showRpar+ = showLpar . showString v_pcdata . showRpar | t == v_mixed && (not . null) cs- = showLpar- .- showString v_pcdata- .- ( foldr (.) id . map (mixedContent . selAttrl . getNode) ) cs1- .+ = showLpar+ .+ showString v_pcdata+ .+ ( foldr (.) id . map (mixedContent . selAttrl . getNode) ) cs1+ . showRpar- .- showAttr a_modifier al1- | t == v_mixed -- incorrect tree, e.g. after erronius pe substitution- = showLpar- .- showRpar+ .+ showAttr a_modifier al1+ | t == v_mixed -- incorrect tree, e.g. after erronius pe substitution+ = showLpar+ .+ showRpar | t == v_children && (not . null) cs- = showContent (head cs)+ = showContent (head cs) | t == v_children- = showLpar- . showRpar+ = showLpar+ . showRpar | t == k_peref- = foldr (.) id . map showContent $ cs+ = foldr (.) id . map showContent $ cs | otherwise- = showString t+ = showString t where [(NTree (XDTD CONTENT al1) cs1)] = cs mixedContent :: Attributes -> String -> String mixedContent l- = showString " | " . showAttr a_name l . showPEAttr l+ = showString " | " . showAttr a_name l . showPEAttr l selAttrl (XDTD _ as) = as selAttrl (XText tex) = [(a_name, tex)]@@ -325,33 +325,33 @@ -- ------------------------------------------------------------ -showContent :: XmlTree -> String -> String+showContent :: XmlTree -> String -> String showContent (NTree (XDTD de al) cs) = cont2String de where- cont2String :: DTDElem -> String -> String+ cont2String :: DTDElem -> String -> String cont2String NAME- = showAttr a_name al+ = showAttr a_name al cont2String PEREF- = showPEAttr al+ = showPEAttr al cont2String CONTENT- = showLpar- .- foldr1 (combine (lookup1 a_kind al)) (map showContent cs)+ = showLpar .+ foldr1 (combine (lookup1 a_kind al)) (map showContent cs)+ . showRpar . showAttr a_modifier al cont2String n- = error ("cont2string " ++ show n ++ " is undefined")+ = error ("cont2string " ++ show n ++ " is undefined") combine k s1 s2- = s1- .- showString ( if k == v_seq- then ", "- else " | "- )+ = s1 .+ showString ( if k == v_seq+ then ", "+ else " | "+ )+ . s2 showContent n@@ -359,7 +359,7 @@ -- ------------------------------------------------------------ -showEntity :: String -> Attributes -> XmlTrees -> String -> String+showEntity :: String -> Attributes -> XmlTrees -> String -> String showEntity kind al cs = showString "<!ENTITY "@@ -378,7 +378,7 @@ -- ------------------------------------------------------------ -showEntityValue :: XmlTrees -> String -> String+showEntityValue :: XmlTrees -> String -> String showEntityValue [] = id@@ -391,15 +391,15 @@ showBlank, showEq, showLt, showGt, showSlash, showApos, showQuot, showLpar, showRpar, showNL :: String -> String -showBlank = showChar ' '-showEq = showChar '='-showLt = showChar '<'-showGt = showChar '>'-showSlash = showChar '/'-showApos = showChar '\''-showQuot = showChar '\"'-showLpar = showChar '('-showRpar = showChar ')'-showNL = showChar '\n'+showBlank = showChar ' '+showEq = showChar '='+showLt = showChar '<'+showGt = showChar '>'+showSlash = showChar '/'+showApos = showChar '\''+showQuot = showChar '\"'+showLpar = showChar '('+showRpar = showChar ')'+showNL = showChar '\n' -- -----------------------------------------------------------------------------
src/Text/XML/HXT/DOM/TypeDefs.hs view
@@ -39,11 +39,11 @@ -- | Node of xml tree representation -type XmlTree = NTree XNode+type XmlTree = NTree XNode -- | List of nodes of xml tree representation -type XmlTrees = NTrees XNode+type XmlTrees = NTrees XNode -- ----------------------------------------------------------------------------- --@@ -51,32 +51,32 @@ -- | Represents elements -data XNode = XText String -- ^ ordinary text (leaf)- | XCharRef Int -- ^ character reference (leaf)- | XEntityRef String -- ^ entity reference (leaf)- | XCmt String -- ^ comment (leaf)- | XCdata String -- ^ CDATA section (leaf)- | XPi QName XmlTrees -- ^ Processing Instr with qualified name (leaf)- -- with list of attributes.- -- If tag name is xml, attributs are \"version\", \"encoding\", \"standalone\",- -- else attribute list is empty, content is a text child node- | XTag QName XmlTrees -- ^ tag with qualified name and list of attributes (inner node or leaf)- | XDTD DTDElem Attributes -- ^ DTD element with assoc list for dtd element features- | XAttr QName -- ^ attribute with qualified name, the attribute value is stored in children- | XError Int String -- ^ error message with level and text- deriving (Eq, Ord, Show, Read, Typeable)+data XNode = XText String -- ^ ordinary text (leaf)+ | XCharRef Int -- ^ character reference (leaf)+ | XEntityRef String -- ^ entity reference (leaf)+ | XCmt String -- ^ comment (leaf)+ | XCdata String -- ^ CDATA section (leaf)+ | XPi QName XmlTrees -- ^ Processing Instr with qualified name (leaf)+ -- with list of attributes.+ -- If tag name is xml, attributs are \"version\", \"encoding\", \"standalone\",+ -- else attribute list is empty, content is a text child node+ | XTag QName XmlTrees -- ^ tag with qualified name and list of attributes (inner node or leaf)+ | XDTD DTDElem Attributes -- ^ DTD element with assoc list for dtd element features+ | XAttr QName -- ^ attribute with qualified name, the attribute value is stored in children+ | XError Int String -- ^ error message with level and text+ deriving (Eq, Ord, Show, Read, Typeable) instance NFData XNode where- rnf (XText s) = rnf s- rnf (XCharRef i) = rnf i- rnf (XEntityRef n) = rnf n- rnf (XCmt c) = rnf c- rnf (XCdata s) = rnf s- rnf (XPi qn ts) = rnf qn `seq` rnf ts- rnf (XTag qn cs) = rnf qn `seq` rnf cs- rnf (XDTD de al) = rnf de `seq` rnf al- rnf (XAttr qn) = rnf qn- rnf (XError n e) = rnf n `seq` rnf e+ rnf (XText s) = rnf s+ rnf (XCharRef i) = rnf i+ rnf (XEntityRef n) = rnf n+ rnf (XCmt c) = rnf c+ rnf (XCdata s) = rnf s+ rnf (XPi qn ts) = rnf qn `seq` rnf ts+ rnf (XTag qn cs) = rnf qn `seq` rnf cs+ rnf (XDTD de al) = rnf de `seq` rnf al+ rnf (XAttr qn) = rnf qn+ rnf (XError n e) = rnf n `seq` rnf e -- ----------------------------------------------------------------------------- --@@ -84,40 +84,40 @@ -- | Represents a DTD element -data DTDElem = DOCTYPE -- ^ attr: name, system, public, XDTD elems as children- | ELEMENT -- ^ attr: name, kind- --- -- name: element name- --- -- kind: \"EMPTY\" | \"ANY\" | \"\#PCDATA\" | children | mixed- | CONTENT -- ^ element content- --- -- attr: kind, modifier- --- -- modifier: \"\" | \"?\" | \"*\" | \"+\"- --- -- kind: seq | choice- | ATTLIST -- ^ attributes:- -- name - name of element- --- -- value - name of attribute- --- -- type: \"CDATA\" | \"ID\" | \"IDREF\" | \"IDREFS\" | \"ENTITY\" | \"ENTITIES\" |- --- -- \"NMTOKEN\" | \"NMTOKENS\" |\"NOTATION\" | \"ENUMTYPE\"- --- -- kind: \"#REQUIRED\" | \"#IMPLIED\" | \"DEFAULT\"- | ENTITY -- ^ for entity declarations- | PENTITY -- ^ for parameter entity declarations- | NOTATION -- ^ for notations- | CONDSECT -- ^ for INCLUDEs, IGNOREs and peRefs: attr: type- --- -- type = INCLUDE, IGNORE or %...;- | NAME -- ^ attr: name- --- -- for lists of names in notation types or nmtokens in enumeration types- | PEREF -- ^ for Parameter Entity References in DTDs- deriving (Eq, Ord, Enum, Show, Read, Typeable)+data DTDElem = DOCTYPE -- ^ attr: name, system, public, XDTD elems as children+ | ELEMENT -- ^ attr: name, kind+ --+ -- name: element name+ --+ -- kind: \"EMPTY\" | \"ANY\" | \"\#PCDATA\" | children | mixed+ | CONTENT -- ^ element content+ --+ -- attr: kind, modifier+ --+ -- modifier: \"\" | \"?\" | \"*\" | \"+\"+ --+ -- kind: seq | choice+ | ATTLIST -- ^ attributes:+ -- name - name of element+ --+ -- value - name of attribute+ --+ -- type: \"CDATA\" | \"ID\" | \"IDREF\" | \"IDREFS\" | \"ENTITY\" | \"ENTITIES\" |+ --+ -- \"NMTOKEN\" | \"NMTOKENS\" |\"NOTATION\" | \"ENUMTYPE\"+ --+ -- kind: \"#REQUIRED\" | \"#IMPLIED\" | \"DEFAULT\"+ | ENTITY -- ^ for entity declarations+ | PENTITY -- ^ for parameter entity declarations+ | NOTATION -- ^ for notations+ | CONDSECT -- ^ for INCLUDEs, IGNOREs and peRefs: attr: type+ --+ -- type = INCLUDE, IGNORE or %...;+ | NAME -- ^ attr: name+ --+ -- for lists of names in notation types or nmtokens in enumeration types+ | PEREF -- ^ for Parameter Entity References in DTDs+ deriving (Eq, Ord, Enum, Show, Read, Typeable) instance NFData DTDElem @@ -127,15 +127,15 @@ -- -- used for storing option lists and features of DTD parts -type Attributes = AssocList String String+type Attributes = AssocList String String -- ----------------------------------------------------------------------------- -- -- Constants for error levels -- | no error, everything is ok-c_ok :: Int-c_ok = 0+c_ok :: Int+c_ok = 0 -- | Error level for XError, type warning c_warn :: Int@@ -157,12 +157,12 @@ -- such that the selected nodes can be processed or selected later in -- processing a document tree -data XmlNodeSet = XNS { thisNode :: Bool -- ^ is this node part of the set ?- , attrNodes :: [QName] -- ^ the set of attribute nodes- , childNodes :: ChildNodes -- ^ the set of child nodes, a list of pairs of index and node set - }- deriving (Eq, Show, Typeable)+data XmlNodeSet = XNS { thisNode :: Bool -- ^ is this node part of the set ?+ , attrNodes :: [QName] -- ^ the set of attribute nodes+ , childNodes :: ChildNodes -- ^ the set of child nodes, a list of pairs of index and node set+ }+ deriving (Eq, Show, Typeable) -type ChildNodes = [(Int, XmlNodeSet)]+type ChildNodes = [(Int, XmlNodeSet)] -- -----------------------------------------------------------------------------
src/Text/XML/HXT/DOM/UTF8Decoding.hs view
@@ -27,17 +27,17 @@ -- | calls 'Data.Char.UTF8.decode' for parsing and decoding UTF-8 -decodeUtf8 :: String -> (String, [String])+decodeUtf8 :: String -> (String, [String]) decodeUtf8 str = (res, map (uncurry toErrStr) errs) where (res, errs) = UTF8.decode . stringToByteString $ str -decodeUtf8IgnoreErrors :: String -> String+decodeUtf8IgnoreErrors :: String -> String decodeUtf8IgnoreErrors = fst . decodeUtf8 -decodeUtf8EmbedErrors :: String -> [Either String Char]+decodeUtf8EmbedErrors :: String -> [Either String Char] decodeUtf8EmbedErrors str = map (either (Left . uncurry toErrStr) Right) $ UTF8.decodeEmbedErrors $ stringToByteString $ str@@ -47,6 +47,6 @@ toErrStr :: UTF8.Error -> Int -> String toErrStr err pos- = " at input position " ++ show pos ++ ": " ++ show err+ = " at input position " ++ show pos ++ ": " ++ show err -- ------------------------------------------------------------
src/Text/XML/HXT/DOM/Unicode.hs view
@@ -80,8 +80,8 @@ import Text.XML.HXT.DOM.Util ( swap, partitionEither ) import Text.XML.HXT.DOM.IsoLatinTables-import Text.XML.HXT.DOM.UTF8Decoding ( decodeUtf8, decodeUtf8EmbedErrors )-import Text.XML.HXT.DOM.Util ( intToHexString )+import Text.XML.HXT.DOM.UTF8Decoding ( decodeUtf8, decodeUtf8EmbedErrors )+import Text.XML.HXT.DOM.Util ( intToHexString ) import Text.XML.HXT.DOM.XmlKeywords -- ------------------------------------------------------------@@ -90,19 +90,19 @@ -- Precondition for this is the support of Unicode character range -- in the compiler (e.g. ghc but not hugs) -type Unicode = Char+type Unicode = Char -- | the type for Unicode strings -type UString = [Unicode]+type UString = [Unicode] -- | UTF-8 charachters are represented by the Char type -type UTF8Char = Char+type UTF8Char = Char -- | UTF-8 strings are implemented as Haskell strings -type UTF8String = String+type UTF8String = String -- | Decoding function with a pair containing the result string and a list of decoding errors as result @@ -121,22 +121,22 @@ -- | -- test for a legal 1 byte XML char -is1ByteXmlChar :: Unicode -> Bool+is1ByteXmlChar :: Unicode -> Bool is1ByteXmlChar c = c < '\x80' && ( c >= ' '- ||- c == '\n'- ||- c == '\t'- ||- c == '\r'- )+ ||+ c == '\n'+ ||+ c == '\t'+ ||+ c == '\r'+ ) -- | -- test for a legal latin1 XML char -isXmlLatin1Char :: Unicode -> Bool+isXmlLatin1Char :: Unicode -> Bool isXmlLatin1Char i = is1ByteXmlChar i ||@@ -147,48 +147,48 @@ -- | -- conversion from Unicode strings (UString) to UTF8 encoded strings. -unicodeToUtf8 :: UString -> UTF8String-unicodeToUtf8 = concatMap unicodeCharToUtf8+unicodeToUtf8 :: UString -> UTF8String+unicodeToUtf8 = concatMap unicodeCharToUtf8 -- | -- conversion from Unicode (Char) to a UTF8 encoded string. -unicodeCharToUtf8 :: Unicode -> UTF8String+unicodeCharToUtf8 :: Unicode -> UTF8String unicodeCharToUtf8 c- | i >= 0 && i <= 0x0000007F -- 1 byte UTF8 (7 bits)- = [ toEnum i ]- | i >= 0x00000080 && i <= 0x000007FF -- 2 byte UTF8 (5 + 6 bits)- = [ toEnum (0xC0 + i `div` 0x40)- , toEnum (0x80 + i `mod` 0x40)- ]- | i >= 0x00000800 && i <= 0x0000FFFF -- 3 byte UTF8 (4 + 6 + 6 bits)- = [ toEnum (0xE0 + i `div` 0x1000)- , toEnum (0x80 + (i `div` 0x40) `mod` 0x40)- , toEnum (0x80 + i `mod` 0x40)- ]- | i >= 0x00010000 && i <= 0x001FFFFF -- 4 byte UTF8 (3 + 6 + 6 + 6 bits)- = [ toEnum (0xF0 + i `div` 0x40000)- , toEnum (0x80 + (i `div` 0x1000) `mod` 0x40)- , toEnum (0x80 + (i `div` 0x40) `mod` 0x40)- , toEnum (0x80 + i `mod` 0x40)- ]- | i >= 0x00200000 && i <= 0x03FFFFFF -- 5 byte UTF8 (2 + 6 + 6 + 6 + 6 bits)- = [ toEnum (0xF8 + i `div` 0x1000000)- , toEnum (0x80 + (i `div` 0x40000) `mod` 0x40)- , toEnum (0x80 + (i `div` 0x1000) `mod` 0x40)- , toEnum (0x80 + (i `div` 0x40) `mod` 0x40)- , toEnum (0x80 + i `mod` 0x40)- ]- | i >= 0x04000000 && i <= 0x7FFFFFFF -- 6 byte UTF8 (1 + 6 + 6 + 6 + 6 + 6 bits)- = [ toEnum (0xFC + i `div` 0x40000000)- , toEnum (0x80 + (i `div` 0x1000000) `mod` 0x40)- , toEnum (0x80 + (i `div` 0x40000) `mod` 0x40)- , toEnum (0x80 + (i `div` 0x1000) `mod` 0x40)- , toEnum (0x80 + (i `div` 0x40) `mod` 0x40)- , toEnum (0x80 + i `mod` 0x40)- ]- | otherwise -- other values not supported- = error ("unicodeCharToUtf8: illegal integer argument " ++ show i)+ | i >= 0 && i <= 0x0000007F -- 1 byte UTF8 (7 bits)+ = [ toEnum i ]+ | i >= 0x00000080 && i <= 0x000007FF -- 2 byte UTF8 (5 + 6 bits)+ = [ toEnum (0xC0 + i `div` 0x40)+ , toEnum (0x80 + i `mod` 0x40)+ ]+ | i >= 0x00000800 && i <= 0x0000FFFF -- 3 byte UTF8 (4 + 6 + 6 bits)+ = [ toEnum (0xE0 + i `div` 0x1000)+ , toEnum (0x80 + (i `div` 0x40) `mod` 0x40)+ , toEnum (0x80 + i `mod` 0x40)+ ]+ | i >= 0x00010000 && i <= 0x001FFFFF -- 4 byte UTF8 (3 + 6 + 6 + 6 bits)+ = [ toEnum (0xF0 + i `div` 0x40000)+ , toEnum (0x80 + (i `div` 0x1000) `mod` 0x40)+ , toEnum (0x80 + (i `div` 0x40) `mod` 0x40)+ , toEnum (0x80 + i `mod` 0x40)+ ]+ | i >= 0x00200000 && i <= 0x03FFFFFF -- 5 byte UTF8 (2 + 6 + 6 + 6 + 6 bits)+ = [ toEnum (0xF8 + i `div` 0x1000000)+ , toEnum (0x80 + (i `div` 0x40000) `mod` 0x40)+ , toEnum (0x80 + (i `div` 0x1000) `mod` 0x40)+ , toEnum (0x80 + (i `div` 0x40) `mod` 0x40)+ , toEnum (0x80 + i `mod` 0x40)+ ]+ | i >= 0x04000000 && i <= 0x7FFFFFFF -- 6 byte UTF8 (1 + 6 + 6 + 6 + 6 + 6 bits)+ = [ toEnum (0xFC + i `div` 0x40000000)+ , toEnum (0x80 + (i `div` 0x1000000) `mod` 0x40)+ , toEnum (0x80 + (i `div` 0x40000) `mod` 0x40)+ , toEnum (0x80 + (i `div` 0x1000) `mod` 0x40)+ , toEnum (0x80 + (i `div` 0x40) `mod` 0x40)+ , toEnum (0x80 + i `mod` 0x40)+ ]+ | otherwise -- other values not supported+ = error ("unicodeCharToUtf8: illegal integer argument " ++ show i) where i = fromEnum c @@ -197,7 +197,7 @@ -- | -- checking for valid XML characters -isXmlChar :: Unicode -> Bool+isXmlChar :: Unicode -> Bool isXmlChar c = isInList c [ ('\x0009', '\x000A')@@ -210,7 +210,7 @@ -- | -- checking for XML space character: \\\n, \\\r, \\\t and \" \" -isXmlSpaceChar :: Unicode -> Bool+isXmlSpaceChar :: Unicode -> Bool isXmlSpaceChar c = c `elem` ['\x20', '\x09', '\x0D', '\x0A'] @@ -219,22 +219,22 @@ -- -- see also : 'isXmlSpaceChar' -isXml11SpaceChar :: Unicode -> Bool+isXml11SpaceChar :: Unicode -> Bool isXml11SpaceChar c = c `elem` ['\x20', '\x09', '\x0D', '\x0A', '\x85', '\x2028'] -- | -- checking for XML name character -isXmlNameChar :: Unicode -> Bool+isXmlNameChar :: Unicode -> Bool isXmlNameChar c = isXmlLetter c || isXmlDigit c ||- (c == '\x2D' || c == '\x2E') -- '-' | '.'+ (c == '\x2D' || c == '\x2E') -- '-' | '.' ||- (c == '\x3A' || c == '\x5F') -- Letter | ':' | '_'+ (c == '\x3A' || c == '\x5F') -- Letter | ':' | '_' || isXmlCombiningChar c ||@@ -245,18 +245,18 @@ -- -- see also : 'isXmlNameChar' -isXmlNameStartChar :: Unicode -> Bool+isXmlNameStartChar :: Unicode -> Bool isXmlNameStartChar c = isXmlLetter c ||- (c == '\x3A' || c == '\x5F') -- Letter | ':' | '_'+ (c == '\x3A' || c == '\x5F') -- Letter | ':' | '_' -- | -- checking for XML NCName character: no \":\" allowed -- -- see also : 'isXmlNameChar' -isXmlNCNameChar :: Unicode -> Bool+isXmlNCNameChar :: Unicode -> Bool isXmlNCNameChar c = c /= '\x3A' &&@@ -267,7 +267,7 @@ -- -- see also : 'isXmlNameChar', 'isXmlNCNameChar' -isXmlNCNameStartChar :: Unicode -> Bool+isXmlNCNameStartChar :: Unicode -> Bool isXmlNCNameStartChar c = c /= '\x3A' &&@@ -276,19 +276,19 @@ -- | -- checking for XML public id character -isXmlPubidChar :: Unicode -> Bool+isXmlPubidChar :: Unicode -> Bool isXmlPubidChar c = isInList c [ ('0', '9')- , ('A', 'Z')- , ('a', 'z')- ]+ , ('A', 'Z')+ , ('a', 'z')+ ] || ( c `elem` " \r\n-'()+,./:=?;!*#@$_%" ) -- | -- checking for XML letter -isXmlLetter :: Unicode -> Bool+isXmlLetter :: Unicode -> Bool isXmlLetter c = isXmlBaseChar c ||@@ -297,7 +297,7 @@ -- | -- checking for XML base charater -isXmlBaseChar :: Unicode -> Bool+isXmlBaseChar :: Unicode -> Bool isXmlBaseChar c = isInList c [ ('\x0041', '\x005A')@@ -506,7 +506,7 @@ -- | -- checking for XML ideographic charater -isXmlIdeographicChar :: Unicode -> Bool+isXmlIdeographicChar :: Unicode -> Bool isXmlIdeographicChar c = isInList c [ ('\x3007', '\x3007')@@ -517,7 +517,7 @@ -- | -- checking for XML combining charater -isXmlCombiningChar :: Unicode -> Bool+isXmlCombiningChar :: Unicode -> Bool isXmlCombiningChar c = isInList c [ ('\x0300', '\x0345')@@ -620,7 +620,7 @@ -- | -- checking for XML digit -isXmlDigit :: Unicode -> Bool+isXmlDigit :: Unicode -> Bool isXmlDigit c = isInList c [ ('\x0030', '\x0039')@@ -643,7 +643,7 @@ -- | -- checking for XML extender -isXmlExtender :: Unicode -> Bool+isXmlExtender :: Unicode -> Bool isXmlExtender c = isInList c [ ('\x00B7', '\x00B7')@@ -670,7 +670,7 @@ -- They are either control characters or permanently undefined Unicode characters: -isXmlControlOrPermanentlyUndefined :: Unicode -> Bool+isXmlControlOrPermanentlyUndefined :: Unicode -> Bool isXmlControlOrPermanentlyUndefined c = isInList c [ ('\x7F', '\x84')@@ -696,28 +696,28 @@ -- ------------------------------------------------------------ -isInList :: Unicode -> [(Unicode, Unicode)] -> Bool+isInList :: Unicode -> [(Unicode, Unicode)] -> Bool isInList i = foldr (\(lb, ub) b -> i >= lb && (i <= ub || b)) False {- The expression (i>=lb && i<=ub) || b would work more generally, but in a sorted list, the above one aborts the computation as early as possible. -} {--isInList' :: Unicode -> [(Unicode, Unicode)] -> Bool+isInList' :: Unicode -> [(Unicode, Unicode)] -> Bool isInList' i ((lb, ub) : l)- | i < lb = False- | i <= ub = True+ | i < lb = False+ | i <= ub = True | otherwise = isInList' i l isInList' _ [] = False {- works, but is not so fast -}-isInList'' :: Unicode -> [(Unicode, Unicode)] -> Bool+isInList'' :: Unicode -> [(Unicode, Unicode)] -> Bool isInList'' i = any (flip isInRange i) -- move to an Utility module?-isInRange :: Ord a => (a,a) -> a -> Bool+isInRange :: Ord a => (a,a) -> a -> Bool isInRange (l,r) x = l<=x && x<=r propIsInList :: Bool@@ -736,10 +736,10 @@ -- | -- code conversion from latin1 to Unicode -latin1ToUnicode :: String -> UString-latin1ToUnicode = id+latin1ToUnicode :: String -> UString+latin1ToUnicode = id -latinToUnicode :: [(Char, Char)] -> String -> UString+latinToUnicode :: [(Char, Char)] -> String -> UString latinToUnicode tt = map charToUni where@@ -754,11 +754,11 @@ -- -- Structure of decoding function copied from 'Data.Char.UTF8.decode'. -decodeAscii :: DecodingFct+decodeAscii :: DecodingFct decodeAscii = swap . partitionEither . decodeAsciiEmbedErrors -decodeAsciiEmbedErrors :: String -> UStringWithErrors+decodeAsciiEmbedErrors :: String -> UStringWithErrors decodeAsciiEmbedErrors str = map (\(c,pos) -> if isValid c then Right c@@ -766,13 +766,13 @@ where posStr = zip str [(0::Int)..] toErrStr errChr pos- = " at input position " ++ show pos ++ ": none ASCII char " ++ show errChr+ = " at input position " ++ show pos ++ ": none ASCII char " ++ show errChr isValid x = x < '\x80' -- | -- UCS-2 big endian to Unicode conversion -ucs2BigEndianToUnicode :: String -> UString+ucs2BigEndianToUnicode :: String -> UString ucs2BigEndianToUnicode (b : l : r) = toEnum (fromEnum b * 256 + fromEnum l) : ucs2BigEndianToUnicode r@@ -781,15 +781,15 @@ = [] ucs2BigEndianToUnicode _- = [] -- error "illegal UCS-2 byte input sequence with odd length"- -- is ignored (garbage in, garbage out)+ = [] -- error "illegal UCS-2 byte input sequence with odd length"+ -- is ignored (garbage in, garbage out) -- ------------------------------------------------------------ -- | -- UCS-2 little endian to Unicode conversion -ucs2LittleEndianToUnicode :: String -> UString+ucs2LittleEndianToUnicode :: String -> UString ucs2LittleEndianToUnicode (l : b : r) = toEnum (fromEnum b * 256 + fromEnum l) : ucs2LittleEndianToUnicode r@@ -798,41 +798,41 @@ = [] ucs2LittleEndianToUnicode [_]- = [] -- error "illegal UCS-2 byte input sequence with odd length"- -- is ignored+ = [] -- error "illegal UCS-2 byte input sequence with odd length"+ -- is ignored -- ------------------------------------------------------------ -- | -- UCS-2 to UTF-8 conversion with byte order mark analysis -ucs2ToUnicode :: String -> UString+ucs2ToUnicode :: String -> UString -ucs2ToUnicode ('\xFE':'\xFF':s) -- 2 byte mark for big endian encoding+ucs2ToUnicode ('\xFE':'\xFF':s) -- 2 byte mark for big endian encoding = ucs2BigEndianToUnicode s -ucs2ToUnicode ('\xFF':'\xFE':s) -- 2 byte mark for little endian encoding+ucs2ToUnicode ('\xFF':'\xFE':s) -- 2 byte mark for little endian encoding = ucs2LittleEndianToUnicode s ucs2ToUnicode s- = ucs2BigEndianToUnicode s -- default: big endian+ = ucs2BigEndianToUnicode s -- default: big endian -- ------------------------------------------------------------ -- | -- UTF-8 to Unicode conversion with deletion of leading byte order mark, as described in XML standard F.1 -utf8ToUnicode :: DecodingFct+utf8ToUnicode :: DecodingFct -utf8ToUnicode ('\xEF':'\xBB':'\xBF':s) -- remove byte order mark ( XML standard F.1 )+utf8ToUnicode ('\xEF':'\xBB':'\xBF':s) -- remove byte order mark ( XML standard F.1 ) = decodeUtf8 s utf8ToUnicode s = decodeUtf8 s -utf8ToUnicodeEmbedErrors :: DecodingFctEmbedErrors+utf8ToUnicodeEmbedErrors :: DecodingFctEmbedErrors -utf8ToUnicodeEmbedErrors ('\xEF':'\xBB':'\xBF':s) -- remove byte order mark ( XML standard F.1 )+utf8ToUnicodeEmbedErrors ('\xEF':'\xBB':'\xBF':s) -- remove byte order mark ( XML standard F.1 ) = decodeUtf8EmbedErrors s utf8ToUnicodeEmbedErrors s@@ -843,9 +843,9 @@ -- | -- UTF-16 big endian to UTF-8 conversion with removal of byte order mark -utf16beToUnicode :: String -> UString+utf16beToUnicode :: String -> UString -utf16beToUnicode ('\xFE':'\xFF':s) -- remove byte order mark+utf16beToUnicode ('\xFE':'\xFF':s) -- remove byte order mark = ucs2BigEndianToUnicode s utf16beToUnicode s@@ -856,9 +856,9 @@ -- | -- UTF-16 little endian to UTF-8 conversion with removal of byte order mark -utf16leToUnicode :: String -> UString+utf16leToUnicode :: String -> UString -utf16leToUnicode ('\xFF':'\xFE':s) -- remove byte order mark+utf16leToUnicode ('\xFF':'\xFE':s) -- remove byte order mark = ucs2LittleEndianToUnicode s utf16leToUnicode s@@ -876,7 +876,7 @@ -- -- see also : 'unicodeToLatin1' -unicodeToXmlEntity :: UString -> String+unicodeToXmlEntity :: UString -> String unicodeToXmlEntity = escape is1ByteXmlChar (intToCharRef . fromEnum) @@ -889,7 +889,7 @@ -- -- see also : 'unicodeToXmlEntity' -unicodeToLatin1 :: UString -> String+unicodeToLatin1 :: UString -> String unicodeToLatin1 = escape isXmlLatin1Char (intToCharRef . fromEnum) @@ -909,7 +909,7 @@ -- -- see also : 'unicodeRemoveNoneLatin1', 'unicodeToXmlEntity' -unicodeRemoveNoneAscii :: UString -> String+unicodeRemoveNoneAscii :: UString -> String unicodeRemoveNoneAscii = filter is1ByteXmlChar @@ -920,7 +920,7 @@ -- -- see also : 'unicodeRemoveNoneAscii', 'unicodeToLatin1' -unicodeRemoveNoneLatin1 :: UString -> String+unicodeRemoveNoneLatin1 :: UString -> String unicodeRemoveNoneLatin1 = filter isXmlLatin1Char @@ -931,7 +931,7 @@ -- -- see also : 'intToCharRefHex' -intToCharRef :: Int -> String+intToCharRef :: Int -> String intToCharRef i = "&#" ++ show i ++ ";" @@ -940,14 +940,14 @@ -- -- see also: 'intToCharRef' -intToCharRefHex :: Int -> String+intToCharRefHex :: Int -> String intToCharRefHex i = "&#x" ++ h2 ++ ";" where h1 = intToHexString i h2 = if length h1 `mod` 2 == 1- then '0': h1- else h1+ then '0': h1+ else h1 -- ------------------------------------------------------------ --@@ -956,11 +956,11 @@ -- -- \#x0D and \#x0D\#x0A are mapped to \#x0A -normalizeNL :: String -> String-normalizeNL ('\r' : '\n' : rest) = '\n' : normalizeNL rest-normalizeNL ('\r' : rest) = '\n' : normalizeNL rest-normalizeNL (c : rest) = c : normalizeNL rest-normalizeNL [] = []+normalizeNL :: String -> String+normalizeNL ('\r' : '\n' : rest) = '\n' : normalizeNL rest+normalizeNL ('\r' : rest) = '\n' : normalizeNL rest+normalizeNL (c : rest) = c : normalizeNL rest+normalizeNL [] = [] -- ------------------------------------------------------------@@ -974,31 +974,31 @@ but this way it is certainly more efficient. -} -decodingTable :: [(String, DecodingFct)]+decodingTable :: [(String, DecodingFct)] decodingTable- = [ (utf8, utf8ToUnicode )- , (isoLatin1, liftDecFct latin1ToUnicode )- , (usAscii, decodeAscii )- , (ucs2, liftDecFct ucs2ToUnicode )- , (utf16, liftDecFct ucs2ToUnicode )- , (utf16be, liftDecFct utf16beToUnicode )- , (utf16le, liftDecFct utf16leToUnicode )- , (iso8859_2, liftDecFct (latinToUnicode iso_8859_2) )- , (iso8859_3, liftDecFct (latinToUnicode iso_8859_3) )- , (iso8859_4, liftDecFct (latinToUnicode iso_8859_4) )- , (iso8859_5, liftDecFct (latinToUnicode iso_8859_5) )- , (iso8859_6, liftDecFct (latinToUnicode iso_8859_6) )- , (iso8859_7, liftDecFct (latinToUnicode iso_8859_7) )- , (iso8859_8, liftDecFct (latinToUnicode iso_8859_8) )- , (iso8859_9, liftDecFct (latinToUnicode iso_8859_9) )- , (iso8859_10, liftDecFct (latinToUnicode iso_8859_10) )- , (iso8859_11, liftDecFct (latinToUnicode iso_8859_11) )- , (iso8859_13, liftDecFct (latinToUnicode iso_8859_13) )- , (iso8859_14, liftDecFct (latinToUnicode iso_8859_14) )- , (iso8859_15, liftDecFct (latinToUnicode iso_8859_15) )- , (iso8859_16, liftDecFct (latinToUnicode iso_8859_16) )- , (unicodeString, liftDecFct id )- , ("", liftDecFct id ) -- default+ = [ (utf8, utf8ToUnicode )+ , (isoLatin1, liftDecFct latin1ToUnicode )+ , (usAscii, decodeAscii )+ , (ucs2, liftDecFct ucs2ToUnicode )+ , (utf16, liftDecFct ucs2ToUnicode )+ , (utf16be, liftDecFct utf16beToUnicode )+ , (utf16le, liftDecFct utf16leToUnicode )+ , (iso8859_2, liftDecFct (latinToUnicode iso_8859_2) )+ , (iso8859_3, liftDecFct (latinToUnicode iso_8859_3) )+ , (iso8859_4, liftDecFct (latinToUnicode iso_8859_4) )+ , (iso8859_5, liftDecFct (latinToUnicode iso_8859_5) )+ , (iso8859_6, liftDecFct (latinToUnicode iso_8859_6) )+ , (iso8859_7, liftDecFct (latinToUnicode iso_8859_7) )+ , (iso8859_8, liftDecFct (latinToUnicode iso_8859_8) )+ , (iso8859_9, liftDecFct (latinToUnicode iso_8859_9) )+ , (iso8859_10, liftDecFct (latinToUnicode iso_8859_10) )+ , (iso8859_11, liftDecFct (latinToUnicode iso_8859_11) )+ , (iso8859_13, liftDecFct (latinToUnicode iso_8859_13) )+ , (iso8859_14, liftDecFct (latinToUnicode iso_8859_14) )+ , (iso8859_15, liftDecFct (latinToUnicode iso_8859_15) )+ , (iso8859_16, liftDecFct (latinToUnicode iso_8859_16) )+ , (unicodeString, liftDecFct id )+ , ("", liftDecFct id ) -- default ] where liftDecFct df = \ s -> (df s, [])@@ -1006,7 +1006,7 @@ -- | -- the lookup function for selecting the decoding function -getDecodingFct :: String -> Maybe DecodingFct+getDecodingFct :: String -> Maybe DecodingFct getDecodingFct enc = lookup (map toUpper enc) decodingTable @@ -1015,31 +1015,31 @@ -- Similar to 'decodingTable' but it embeds errors -- in the string of decoded characters. -decodingTableEmbedErrors :: [(String, DecodingFctEmbedErrors)]+decodingTableEmbedErrors :: [(String, DecodingFctEmbedErrors)] decodingTableEmbedErrors- = [ (utf8, utf8ToUnicodeEmbedErrors )- , (isoLatin1, liftDecFct latin1ToUnicode )- , (usAscii, decodeAsciiEmbedErrors )- , (ucs2, liftDecFct ucs2ToUnicode )- , (utf16, liftDecFct ucs2ToUnicode )- , (utf16be, liftDecFct utf16beToUnicode )- , (utf16le, liftDecFct utf16leToUnicode )- , (iso8859_2, liftDecFct (latinToUnicode iso_8859_2) )- , (iso8859_3, liftDecFct (latinToUnicode iso_8859_3) )- , (iso8859_4, liftDecFct (latinToUnicode iso_8859_4) )- , (iso8859_5, liftDecFct (latinToUnicode iso_8859_5) )- , (iso8859_6, liftDecFct (latinToUnicode iso_8859_6) )- , (iso8859_7, liftDecFct (latinToUnicode iso_8859_7) )- , (iso8859_8, liftDecFct (latinToUnicode iso_8859_8) )- , (iso8859_9, liftDecFct (latinToUnicode iso_8859_9) )- , (iso8859_10, liftDecFct (latinToUnicode iso_8859_10) )- , (iso8859_11, liftDecFct (latinToUnicode iso_8859_11) )- , (iso8859_13, liftDecFct (latinToUnicode iso_8859_13) )- , (iso8859_14, liftDecFct (latinToUnicode iso_8859_14) )- , (iso8859_15, liftDecFct (latinToUnicode iso_8859_15) )- , (iso8859_16, liftDecFct (latinToUnicode iso_8859_16) )- , (unicodeString, liftDecFct id )- , ("", liftDecFct id ) -- default+ = [ (utf8, utf8ToUnicodeEmbedErrors )+ , (isoLatin1, liftDecFct latin1ToUnicode )+ , (usAscii, decodeAsciiEmbedErrors )+ , (ucs2, liftDecFct ucs2ToUnicode )+ , (utf16, liftDecFct ucs2ToUnicode )+ , (utf16be, liftDecFct utf16beToUnicode )+ , (utf16le, liftDecFct utf16leToUnicode )+ , (iso8859_2, liftDecFct (latinToUnicode iso_8859_2) )+ , (iso8859_3, liftDecFct (latinToUnicode iso_8859_3) )+ , (iso8859_4, liftDecFct (latinToUnicode iso_8859_4) )+ , (iso8859_5, liftDecFct (latinToUnicode iso_8859_5) )+ , (iso8859_6, liftDecFct (latinToUnicode iso_8859_6) )+ , (iso8859_7, liftDecFct (latinToUnicode iso_8859_7) )+ , (iso8859_8, liftDecFct (latinToUnicode iso_8859_8) )+ , (iso8859_9, liftDecFct (latinToUnicode iso_8859_9) )+ , (iso8859_10, liftDecFct (latinToUnicode iso_8859_10) )+ , (iso8859_11, liftDecFct (latinToUnicode iso_8859_11) )+ , (iso8859_13, liftDecFct (latinToUnicode iso_8859_13) )+ , (iso8859_14, liftDecFct (latinToUnicode iso_8859_14) )+ , (iso8859_15, liftDecFct (latinToUnicode iso_8859_15) )+ , (iso8859_16, liftDecFct (latinToUnicode iso_8859_16) )+ , (unicodeString, liftDecFct id )+ , ("", liftDecFct id ) -- default ] where liftDecFct df = map Right . df@@ -1047,7 +1047,7 @@ -- | -- the lookup function for selecting the decoding function -getDecodingFctEmbedErrors :: String -> Maybe DecodingFctEmbedErrors+getDecodingFctEmbedErrors :: String -> Maybe DecodingFctEmbedErrors getDecodingFctEmbedErrors enc = lookup (map toUpper enc) decodingTableEmbedErrors @@ -1057,49 +1057,49 @@ -- the table of supported output encoding schemes and the associated -- conversion functions from Unicode -outputEncodingTable :: [(String, (UString -> String))]+outputEncodingTable :: [(String, (UString -> String))] outputEncodingTable- = [ (utf8, unicodeToUtf8 )- , (isoLatin1, unicodeToLatin1 )- , (usAscii, unicodeToXmlEntity )- , (ucs2, ucs2ToUnicode )- , (unicodeString, id )- , ("", unicodeToUtf8 ) -- default+ = [ (utf8, unicodeToUtf8 )+ , (isoLatin1, unicodeToLatin1 )+ , (usAscii, unicodeToXmlEntity )+ , (ucs2, ucs2ToUnicode )+ , (unicodeString, id )+ , ("", unicodeToUtf8 ) -- default ] -- | -- the lookup function for selecting the encoding function -getOutputEncodingFct :: String -> Maybe (String -> UString)+getOutputEncodingFct :: String -> Maybe (String -> UString) getOutputEncodingFct enc = lookup (map toUpper enc) outputEncodingTable -- ------------------------------------------------------------ -- -guessEncoding :: String -> String+guessEncoding :: String -> String -guessEncoding ('\xFF':'\xFE':'\x00':'\x00':_) = "UCS-4LE" -- with byte order mark-guessEncoding ('\xFF':'\xFE':_) = "UTF-16LE" -- with byte order mark+guessEncoding ('\xFF':'\xFE':'\x00':'\x00':_) = "UCS-4LE" -- with byte order mark+guessEncoding ('\xFF':'\xFE':_) = "UTF-16LE" -- with byte order mark -guessEncoding ('\xFE':'\xFF':'\x00':'\x00':_) = "UCS-4-3421" -- with byte order mark-guessEncoding ('\xFE':'\xFF':_) = "UTF-16BE" -- with byte order mark+guessEncoding ('\xFE':'\xFF':'\x00':'\x00':_) = "UCS-4-3421" -- with byte order mark+guessEncoding ('\xFE':'\xFF':_) = "UTF-16BE" -- with byte order mark -guessEncoding ('\xEF':'\xBB':'\xBF':_) = utf8 -- with byte order mark+guessEncoding ('\xEF':'\xBB':'\xBF':_) = utf8 -- with byte order mark -guessEncoding ('\x00':'\x00':'\xFE':'\xFF':_) = "UCS-4BE" -- with byte order mark-guessEncoding ('\x00':'\x00':'\xFF':'\xFE':_) = "UCS-4-2143" -- with byte order mark+guessEncoding ('\x00':'\x00':'\xFE':'\xFF':_) = "UCS-4BE" -- with byte order mark+guessEncoding ('\x00':'\x00':'\xFF':'\xFE':_) = "UCS-4-2143" -- with byte order mark -guessEncoding ('\x00':'\x00':'\x00':'\x3C':_) = "UCS-4BE" -- "<" of "<?xml"-guessEncoding ('\x3C':'\x00':'\x00':'\x00':_) = "UCS-4LE" -- "<" of "<?xml"-guessEncoding ('\x00':'\x00':'\x3C':'\x00':_) = "UCS-4-2143" -- "<" of "<?xml"-guessEncoding ('\x00':'\x3C':'\x00':'\x00':_) = "UCS-4-3412" -- "<" of "<?xml"+guessEncoding ('\x00':'\x00':'\x00':'\x3C':_) = "UCS-4BE" -- "<" of "<?xml"+guessEncoding ('\x3C':'\x00':'\x00':'\x00':_) = "UCS-4LE" -- "<" of "<?xml"+guessEncoding ('\x00':'\x00':'\x3C':'\x00':_) = "UCS-4-2143" -- "<" of "<?xml"+guessEncoding ('\x00':'\x3C':'\x00':'\x00':_) = "UCS-4-3412" -- "<" of "<?xml" -guessEncoding ('\x00':'\x3C':'\x00':'\x3F':_) = "UTF-16BE" -- "<?" of "<?xml"-guessEncoding ('\x3C':'\x00':'\x3F':'\x00':_) = "UTF-16LE" -- "<?" of "<?xml"+guessEncoding ('\x00':'\x3C':'\x00':'\x3F':_) = "UTF-16BE" -- "<?" of "<?xml"+guessEncoding ('\x3C':'\x00':'\x3F':'\x00':_) = "UTF-16LE" -- "<?" of "<?xml" -guessEncoding ('\x4C':'\x6F':'\xA7':'\x94':_) = "EBCDIC" -- "<?xm" of "<?xml"+guessEncoding ('\x4C':'\x6F':'\xA7':'\x94':_) = "EBCDIC" -- "<?xm" of "<?xml" -guessEncoding _ = "" -- no guess+guessEncoding _ = "" -- no guess -- ------------------------------------------------------------
src/Text/XML/HXT/DOM/Util.hs view
@@ -52,113 +52,113 @@ ) where -import Data.Char-import Data.List-import Data.Maybe+import Data.Char+import Data.List+import Data.Maybe -- ------------------------------------------------------------ -- | -- remove leading and trailing whitespace with standard Haskell predicate isSpace -stringTrim :: String -> String-stringTrim = reverse . dropWhile isSpace . reverse . dropWhile isSpace+stringTrim :: String -> String+stringTrim = reverse . dropWhile isSpace . reverse . dropWhile isSpace -- | -- convert string to uppercase with standard Haskell toUpper function -stringToUpper :: String -> String-stringToUpper = map toUpper+stringToUpper :: String -> String+stringToUpper = map toUpper -- | -- convert string to lowercase with standard Haskell toLower function -stringToLower :: String -> String-stringToLower = map toLower+stringToLower :: String -> String+stringToLower = map toLower -- | find all positions where a string occurs within another string -stringAll :: (Eq a) => [a] -> [a] -> [Int]-stringAll x = map fst . filter ((x `isPrefixOf`) . snd) . zip [0..] . tails+stringAll :: (Eq a) => [a] -> [a] -> [Int]+stringAll x = map fst . filter ((x `isPrefixOf`) . snd) . zip [0..] . tails -- | find the position of the first occurence of a string -stringFirst :: (Eq a) => [a] -> [a] -> Maybe Int-stringFirst x = listToMaybe . stringAll x+stringFirst :: (Eq a) => [a] -> [a] -> Maybe Int+stringFirst x = listToMaybe . stringAll x -- | find the position of the last occurence of a string -stringLast :: (Eq a) => [a] -> [a] -> Maybe Int-stringLast x = listToMaybe . reverse . stringAll x+stringLast :: (Eq a) => [a] -> [a] -> Maybe Int+stringLast x = listToMaybe . reverse . stringAll x -- ------------------------------------------------------------ -- | Removes leading \/ trailing whitespaces and leading zeros -normalizeNumber :: String -> String+normalizeNumber :: String -> String normalizeNumber- = reverse . dropWhile (== ' ') . reverse . + = reverse . dropWhile (== ' ') . reverse . dropWhile (\x -> x == '0' || x == ' ') -- | Reduce whitespace sequences to a single whitespace -normalizeWhitespace :: String -> String-normalizeWhitespace = unwords . words+normalizeWhitespace :: String -> String+normalizeWhitespace = unwords . words -- | replace all whitespace chars by blanks -normalizeBlanks :: String -> String-normalizeBlanks = map (\ x -> if isSpace x then ' ' else x)+normalizeBlanks :: String -> String+normalizeBlanks = map (\ x -> if isSpace x then ' ' else x) -- ------------------------------------------------------------ --- | Escape all disallowed characters in URI +-- | Escape all disallowed characters in URI -- references (see <http://www.w3.org/TR/xlink/#link-locators>) escapeURI :: String -> String escapeURI ref = concatMap replace ref where- notAllowed :: Char -> Bool+ notAllowed :: Char -> Bool notAllowed c- = c < '\31'- ||- c `elem` ['\DEL', ' ', '<', '>', '\"', '{', '}', '|', '\\', '^', '`' ]+ = c < '\31'+ ||+ c `elem` ['\DEL', ' ', '<', '>', '\"', '{', '}', '|', '\\', '^', '`' ] replace :: Char -> String replace c- | notAllowed c- = '%' : charToHexString c- | otherwise- = [c]+ | notAllowed c+ = '%' : charToHexString c+ | otherwise+ = [c] -- ------------------------------------------------------------ -escapeXml :: String -> String -> String+escapeXml :: String -> String -> String escapeXml escSet = concatMap esc where esc c- | c `elem` escSet- = "&#" ++ show (fromEnum c) ++ ";"- | otherwise- = [c]+ | c `elem` escSet+ = "&#" ++ show (fromEnum c) ++ ";"+ | otherwise+ = [c] -- | -- escape XML chars <, >, ", and ampercent by transforming them into character references -- -- see also : 'attrEscapeXml' -stringEscapeXml :: String -> String-stringEscapeXml = escapeXml "<>\"\'&"+stringEscapeXml :: String -> String+stringEscapeXml = escapeXml "<>\"\'&" -- | -- escape XML chars < and ampercent by transforming them into character references, used for escaping text nodes -- -- see also : 'attrEscapeXml' -textEscapeXml :: String -> String-textEscapeXml = escapeXml "<&"+textEscapeXml :: String -> String+textEscapeXml = escapeXml "<&" -- | -- escape XML chars in attribute values, same as stringEscapeXml, but none blank whitespace@@ -166,10 +166,10 @@ -- -- see also : 'stringEscapeXml' -attrEscapeXml :: String -> String-attrEscapeXml = escapeXml "<>\"\'&\n\r\t"+attrEscapeXml :: String -> String+attrEscapeXml = escapeXml "<>\"\'&\n\r\t" -stringToInt :: Int -> String -> Int+stringToInt :: Int -> String -> Int stringToInt base digits = sign * (foldl acc 0 $ concatMap digToInt digits1) where@@ -178,44 +178,44 @@ splitSign ds = ( 1 , ds) (sign, digits1) = splitSign digits digToInt c- | c >= '0' && c <= '9'- = [ord c - ord '0']- | c >= 'A' && c <= 'Z'- = [ord c - ord 'A' + 10]- | c >= 'a' && c <= 'z'- = [ord c - ord 'a' + 10]- | otherwise- = []+ | c >= '0' && c <= '9'+ = [ord c - ord '0']+ | c >= 'A' && c <= 'Z'+ = [ord c - ord 'A' + 10]+ | c >= 'a' && c <= 'z'+ = [ord c - ord 'a' + 10]+ | otherwise+ = [] acc i1 i0- = i1 * base + i0+ = i1 * base + i0 -- | -- convert a string of hexadecimal digits into an Int -hexStringToInt :: String -> Int-hexStringToInt = stringToInt 16+hexStringToInt :: String -> Int+hexStringToInt = stringToInt 16 -- | -- convert a string of digits into an Int -decimalStringToInt :: String -> Int-decimalStringToInt = stringToInt 10+decimalStringToInt :: String -> Int+decimalStringToInt = stringToInt 10 -- | -- convert a string into a hexadecimal string applying charToHexString -- -- see also : 'charToHexString' -stringToHexString :: String -> String-stringToHexString = concatMap charToHexString+stringToHexString :: String -> String+stringToHexString = concatMap charToHexString -- | -- convert a char (byte) into a 2-digit hexadecimal string -- -- see also : 'stringToHexString', 'intToHexString' -charToHexString :: Char -> String+charToHexString :: Char -> String charToHexString c = [ fourBitsToChar (c' `div` 16) , fourBitsToChar (c' `mod` 16)@@ -228,20 +228,20 @@ -- -- see also : 'charToHexString' -intToHexString :: Int -> String+intToHexString :: Int -> String intToHexString i | i == 0- = "0"+ = "0" | i > 0- = intToStr i+ = intToStr i | otherwise- = error ("intToHexString: negative argument " ++ show i)+ = error ("intToHexString: negative argument " ++ show i) where- intToStr 0 = ""- intToStr i' = intToStr (i' `div` 16) ++ [fourBitsToChar (i' `mod` 16)]+ intToStr 0 = ""+ intToStr i' = intToStr (i' `div` 16) ++ [fourBitsToChar (i' `mod` 16)] -fourBitsToChar :: Int -> Char-fourBitsToChar i = "0123456789ABCDEF" !! i+fourBitsToChar :: Int -> Char+fourBitsToChar i = "0123456789ABCDEF" !! i -- ------------------------------------------------------------ @@ -249,36 +249,36 @@ -- take all elements of a list which occur more than once. The result does not contain doubles. -- (doubles . doubles == doubles) -doubles :: Eq a => [a] -> [a]+doubles :: Eq a => [a] -> [a] doubles = doubles' [] where doubles' acc []- = acc+ = acc doubles' acc (e : s)- | e `elem` s- &&- e `notElem` acc- = doubles' (e:acc) s- | otherwise- = doubles' acc s+ | e `elem` s+ &&+ e `notElem` acc+ = doubles' (e:acc) s+ | otherwise+ = doubles' acc s -- | -- drop all elements from a list which occur more than once. -singles :: Eq a => [a] -> [a]+singles :: Eq a => [a] -> [a] singles = singles' [] where singles' acc []- = acc+ = acc singles' acc (e : s)- | e `elem` s- ||- e `elem` acc- = singles' acc s- | otherwise- = singles' (e : acc) s+ | e `elem` s+ ||+ e `elem` acc+ = singles' acc s+ | otherwise+ = singles' (e : acc) s -- | -- remove duplicates from list@@ -307,10 +307,10 @@ -- | mothers little helpers for to much curry -uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d-uncurry3 f ~(a, b, c) = f a b c+uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d+uncurry3 f ~(a, b, c) = f a b c -uncurry4 :: (a -> b -> c -> d -> e) -> (a, b, c, d) -> e-uncurry4 f ~(a, b, c, d) = f a b c d+uncurry4 :: (a -> b -> c -> d -> e) -> (a, b, c, d) -> e+uncurry4 f ~(a, b, c, d) = f a b c d -- ------------------------------------------------------------
src/Text/XML/HXT/DOM/XmlKeywords.hs view
@@ -23,13 +23,13 @@ -- -- string constants for representing DTD keywords and attributes -t_xml, -- tag names- t_root :: String+t_xml, -- tag names+ t_root :: String a_accept_mimetypes, a_add_default_dtd, a_canonicalize,- a_default, -- attribute names+ a_default, -- attribute names a_check_namespaces, a_contentLength, a_collect_errors,@@ -95,9 +95,9 @@ a_verbose, a_version, a_xml,- a_xmlns :: String+ a_xmlns :: String -v_0, -- attribute values+v_0, -- attribute values v_1, v_2, v_yes,@@ -112,9 +112,9 @@ v_option, v_pcdata, v_star,- v_plus :: String+ v_plus :: String -k_any, -- DTD keywords+k_any, -- DTD keywords k_cdata, k_empty, k_entity,@@ -136,131 +136,131 @@ k_notation, k_pcdata, k_required,- k_default :: String+ k_default :: String -- ------------------------------------------------------------ -t_xml = "xml"-t_root = "/" -- name of root node tag+t_xml = "xml"+t_root = "/" -- name of root node tag -a_accept_mimetypes = "accept-mimetypes"+a_accept_mimetypes = "accept-mimetypes" a_add_default_dtd = "add-default-dtd"-a_canonicalize = "canonicalize"-a_check_namespaces = "check-namespaces"-a_collect_errors = "collect-errors"-a_column = "column"-a_contentLength = "Content-Length"-a_default = "default"-a_default_baseuri = "default-base-URI"-a_do_not_canonicalize = "do-not-canonicalize"-a_do_not_check_namespaces = "do-not-check-namespaces"-a_do_not_issue_errors = "do-not-issue-errors"-a_do_not_issue_warnings = "do-not-issue-warnings"-a_do_not_preserve_comment = "do-not-preserve-comment"-a_do_not_remove_whitespace = "do-not-remove-whitespace"-a_do_not_use_curl = "do-not-use-curl"-a_do_not_validate = "do-not-validate"-a_encoding = "encoding"-a_error = "error"-a_error_log = "errorLog"-a_help = "help"-a_if_modified_since = "if-modified-since"-a_ignore_encoding_errors = "ignore-encoding-errors"-a_ignore_none_xml_contents = "ignore-none-xml-contents"-a_indent = "indent"-a_issue_warnings = "issue-warnings"-a_issue_errors = "issue-errors"-a_kind = "kind"-a_line = "line"-a_mime_types = "mimetypes"-a_module = "module"-a_modifier = "modifier"-a_name = "name"-a_no_empty_elements = "no-empty-elements"+a_canonicalize = "canonicalize"+a_check_namespaces = "check-namespaces"+a_collect_errors = "collect-errors"+a_column = "column"+a_contentLength = "Content-Length"+a_default = "default"+a_default_baseuri = "default-base-URI"+a_do_not_canonicalize = "do-not-canonicalize"+a_do_not_check_namespaces = "do-not-check-namespaces"+a_do_not_issue_errors = "do-not-issue-errors"+a_do_not_issue_warnings = "do-not-issue-warnings"+a_do_not_preserve_comment = "do-not-preserve-comment"+a_do_not_remove_whitespace = "do-not-remove-whitespace"+a_do_not_use_curl = "do-not-use-curl"+a_do_not_validate = "do-not-validate"+a_encoding = "encoding"+a_error = "error"+a_error_log = "errorLog"+a_help = "help"+a_if_modified_since = "if-modified-since"+a_ignore_encoding_errors = "ignore-encoding-errors"+a_ignore_none_xml_contents = "ignore-none-xml-contents"+a_indent = "indent"+a_issue_warnings = "issue-warnings"+a_issue_errors = "issue-errors"+a_kind = "kind"+a_line = "line"+a_mime_types = "mimetypes"+a_module = "module"+a_modifier = "modifier"+a_name = "name"+a_no_empty_elements = "no-empty-elements" a_no_empty_elem_for = "no-empty-elem-for"-a_no_redirect = "no-redirect"+a_no_redirect = "no-redirect" a_no_xml_pi = "no-xml-pi"-a_options_curl = "options-curl"-a_output_file = "output-file"-a_output_encoding = "output-encoding"-a_output_html = "output-html"-a_output_xhtml = "output-xhtml"-a_output_xml = "output-xml"-a_parse_by_mimetype = "parse-by-mimetype"-a_parse_html = "parse-html"-a_parse_xml = "parse-xml"-a_peref = k_peref-a_preserve_comment = "preserve-comment"-a_propagate_errors = "propagate-errors"-a_proxy = "proxy"-a_redirect = "redirect"-a_remove_whitespace = "remove-whitespace"-a_show_haskell = "show-haskell"-a_show_tree = "show-tree"-a_source = "source"-a_standalone = "standalone"-a_status = "status"-a_strict_input = "strict-input"-a_tagsoup = "tagsoup"-a_text_mode = "text-mode"-a_trace = "trace"-a_type = "type"-a_url = "url"-a_use_curl = "use-curl"-a_validate = "validate"-a_value = "value"-a_verbose = "verbose"-a_version = "version"-a_xml = "xml"-a_xmlns = "xmlns"+a_options_curl = "options-curl"+a_output_file = "output-file"+a_output_encoding = "output-encoding"+a_output_html = "output-html"+a_output_xhtml = "output-xhtml"+a_output_xml = "output-xml"+a_parse_by_mimetype = "parse-by-mimetype"+a_parse_html = "parse-html"+a_parse_xml = "parse-xml"+a_peref = k_peref+a_preserve_comment = "preserve-comment"+a_propagate_errors = "propagate-errors"+a_proxy = "proxy"+a_redirect = "redirect"+a_remove_whitespace = "remove-whitespace"+a_show_haskell = "show-haskell"+a_show_tree = "show-tree"+a_source = "source"+a_standalone = "standalone"+a_status = "status"+a_strict_input = "strict-input"+a_tagsoup = "tagsoup"+a_text_mode = "text-mode"+a_trace = "trace"+a_type = "type"+a_url = "url"+a_use_curl = "use-curl"+a_validate = "validate"+a_value = "value"+a_verbose = "verbose"+a_version = "version"+a_xml = "xml"+a_xmlns = "xmlns" -v_yes = "yes"-v_no = "no"-v_0 = "0"-v_1 = "1"-v_2 = "2"+v_yes = "yes"+v_no = "no"+v_0 = "0"+v_1 = "1"+v_2 = "2" -v_any = k_any-v_children = "children"-v_choice = "choice"-v_empty = k_empty-v_pcdata = k_pcdata-v_mixed = "mixed"-v_seq = "seq"+v_any = k_any+v_children = "children"+v_choice = "choice"+v_empty = k_empty+v_pcdata = k_pcdata+v_mixed = "mixed"+v_seq = "seq" -v_null = ""-v_option = "?"-v_star = "*"-v_plus = "+"+v_null = ""+v_option = "?"+v_star = "*"+v_plus = "+" -k_any = "ANY"-k_cdata = "CDATA"-k_empty = "EMPTY"-k_entity = "ENTITY"-k_entities = "ENTITIES"-k_id = "ID"-k_idref = "IDREF"-k_idrefs = "IDREFS"-k_include = "INCLUDE"-k_ignore = "IGNORE"-k_nmtoken = "NMTOKEN"-k_nmtokens = "NMTOKENS"-k_peref = "PERef"-k_public = "PUBLIC"-k_system = "SYSTEM"+k_any = "ANY"+k_cdata = "CDATA"+k_empty = "EMPTY"+k_entity = "ENTITY"+k_entities = "ENTITIES"+k_id = "ID"+k_idref = "IDREF"+k_idrefs = "IDREFS"+k_include = "INCLUDE"+k_ignore = "IGNORE"+k_nmtoken = "NMTOKEN"+k_nmtokens = "NMTOKENS"+k_peref = "PERef"+k_public = "PUBLIC"+k_system = "SYSTEM" -k_enumeration = "#ENUMERATION"-k_fixed = "#FIXED"-k_implied = "#IMPLIED"-k_ndata = "NDATA"-k_notation = "NOTATION"-k_pcdata = "#PCDATA"-k_required = "#REQUIRED"-k_default = "#DEFAULT"+k_enumeration = "#ENUMERATION"+k_fixed = "#FIXED"+k_implied = "#IMPLIED"+k_ndata = "NDATA"+k_notation = "NOTATION"+k_pcdata = "#PCDATA"+k_required = "#REQUIRED"+k_default = "#DEFAULT" -dtdPrefix :: String-dtdPrefix = "doctype-"+dtdPrefix :: String+dtdPrefix = "doctype-" -- ------------------------------------------------------------ --@@ -279,25 +279,25 @@ , transferMessage , transferVersion :: String -transferPrefix = "transfer-"+transferPrefix = "transfer-" -transferProtocol = transferPrefix ++ "Protocol"-transferVersion = transferPrefix ++ "Version"-transferMimeType = transferPrefix ++ "MimeType"-transferEncoding = transferPrefix ++ "Encoding"-transferDefaultURI = transferPrefix ++ "DefaultURI"-transferStatus = transferPrefix ++ "Status"-transferMessage = transferPrefix ++ "Message"-transferURI = transferPrefix ++ "URI"+transferProtocol = transferPrefix ++ "Protocol"+transferVersion = transferPrefix ++ "Version"+transferMimeType = transferPrefix ++ "MimeType"+transferEncoding = transferPrefix ++ "Encoding"+transferDefaultURI = transferPrefix ++ "DefaultURI"+transferStatus = transferPrefix ++ "Status"+transferMessage = transferPrefix ++ "Message"+transferURI = transferPrefix ++ "URI" -- ------------------------------------------------------------ -- -httpPrefix :: String-httpPrefix = "http-"+httpPrefix :: String+httpPrefix = "http-" -stringProtocol :: String-stringProtocol = "string:"+stringProtocol :: String+stringProtocol = "string:" -- ------------------------------------------------------------ --@@ -307,31 +307,31 @@ , iso8859_1, iso8859_2, iso8859_3, iso8859_4, iso8859_5 , iso8859_6, iso8859_7, iso8859_8, iso8859_9, iso8859_10 , iso8859_11, iso8859_13, iso8859_14, iso8859_15, iso8859_16- , usAscii, ucs2, utf8, utf16, utf16be, utf16le, unicodeString :: String+ , usAscii, ucs2, utf8, utf16, utf16be, utf16le, unicodeString :: String -isoLatin1 = iso8859_1-iso8859_1 = "ISO-8859-1"-iso8859_2 = "ISO-8859-2"-iso8859_3 = "ISO-8859-3"-iso8859_4 = "ISO-8859-4"-iso8859_5 = "ISO-8859-5"-iso8859_6 = "ISO-8859-6"-iso8859_7 = "ISO-8859-7"-iso8859_8 = "ISO-8859-8"-iso8859_9 = "ISO-8859-9"-iso8859_10 = "ISO-8859-10"-iso8859_11 = "ISO-8859-11"-iso8859_13 = "ISO-8859-13"-iso8859_14 = "ISO-8859-14"-iso8859_15 = "ISO-8859-15"-iso8859_16 = "ISO-8859-16"-usAscii = "US-ASCII"-ucs2 = "ISO-10646-UCS-2"-utf8 = "UTF-8"-utf16 = "UTF-16"-utf16be = "UTF-16BE"-utf16le = "UTF-16LE"-unicodeString = "UNICODE"+isoLatin1 = iso8859_1+iso8859_1 = "ISO-8859-1"+iso8859_2 = "ISO-8859-2"+iso8859_3 = "ISO-8859-3"+iso8859_4 = "ISO-8859-4"+iso8859_5 = "ISO-8859-5"+iso8859_6 = "ISO-8859-6"+iso8859_7 = "ISO-8859-7"+iso8859_8 = "ISO-8859-8"+iso8859_9 = "ISO-8859-9"+iso8859_10 = "ISO-8859-10"+iso8859_11 = "ISO-8859-11"+iso8859_13 = "ISO-8859-13"+iso8859_14 = "ISO-8859-14"+iso8859_15 = "ISO-8859-15"+iso8859_16 = "ISO-8859-16"+usAscii = "US-ASCII"+ucs2 = "ISO-10646-UCS-2"+utf8 = "UTF-8"+utf16 = "UTF-16"+utf16be = "UTF-16BE"+utf16le = "UTF-16LE"+unicodeString = "UNICODE" -- ------------------------------------------------------------ --@@ -340,37 +340,37 @@ -- | -- the predefined namespace uri for xml: \"http:\/\/www.w3.org\/XML\/1998\/namespace\" -xmlNamespace :: String-xmlNamespace = "http://www.w3.org/XML/1998/namespace"+xmlNamespace :: String+xmlNamespace = "http://www.w3.org/XML/1998/namespace" -- | -- the predefined namespace uri for xmlns: \"http:\/\/www.w3.org\/2000\/xmlns\/\" -xmlnsNamespace :: String-xmlnsNamespace = "http://www.w3.org/2000/xmlns/"+xmlnsNamespace :: String+xmlnsNamespace = "http://www.w3.org/2000/xmlns/" -- | Relax NG namespace-relaxNamespace :: String-relaxNamespace = "http://relaxng.org/ns/structure/1.0"+relaxNamespace :: String+relaxNamespace = "http://relaxng.org/ns/structure/1.0" -- ------------------------------------------------------------ -- option for Relax NG a_relax_schema,- a_do_not_check_restrictions, + a_do_not_check_restrictions, a_check_restrictions, a_do_not_validate_externalRef, a_validate_externalRef, a_do_not_validate_include, a_validate_include,- a_output_changes, - a_do_not_collect_errors :: String + a_output_changes,+ a_do_not_collect_errors :: String -a_relax_schema = "relax-schema"+a_relax_schema = "relax-schema" a_do_not_check_restrictions = "do-not-check-restrictions" a_check_restrictions = "check-restrictions" a_do_not_validate_externalRef = "do-not-validate-externalRef"-a_validate_externalRef = "validate-externalRef" +a_validate_externalRef = "validate-externalRef" a_do_not_validate_include = "do-not-validate-include" a_validate_include = "validate-include" a_output_changes = "output-pattern-transformations"
src/Text/XML/HXT/DOM/XmlNode.hs view
@@ -40,294 +40,294 @@ class XmlNode a where -- discriminating predicates - isText :: a -> Bool- isCharRef :: a -> Bool- isEntityRef :: a -> Bool- isCmt :: a -> Bool- isCdata :: a -> Bool- isPi :: a -> Bool- isElem :: a -> Bool- isRoot :: a -> Bool- isDTD :: a -> Bool- isAttr :: a -> Bool- isError :: a -> Bool+ isText :: a -> Bool+ isCharRef :: a -> Bool+ isEntityRef :: a -> Bool+ isCmt :: a -> Bool+ isCdata :: a -> Bool+ isPi :: a -> Bool+ isElem :: a -> Bool+ isRoot :: a -> Bool+ isDTD :: a -> Bool+ isAttr :: a -> Bool+ isError :: a -> Bool -- constructor functions for leave nodes - mkText :: String -> a- mkCharRef :: Int -> a- mkEntityRef :: String -> a- mkCmt :: String -> a- mkCdata :: String -> a- mkPi :: QName -> XmlTrees -> a- mkError :: Int -> String -> a+ mkText :: String -> a+ mkCharRef :: Int -> a+ mkEntityRef :: String -> a+ mkCmt :: String -> a+ mkCdata :: String -> a+ mkPi :: QName -> XmlTrees -> a+ mkError :: Int -> String -> a -- selectors - getText :: a -> Maybe String- getCharRef :: a -> Maybe Int- getEntityRef :: a -> Maybe String- getCmt :: a -> Maybe String- getCdata :: a -> Maybe String- getPiName :: a -> Maybe QName- getPiContent :: a -> Maybe XmlTrees- getElemName :: a -> Maybe QName- getAttrl :: a -> Maybe XmlTrees- getDTDPart :: a -> Maybe DTDElem- getDTDAttrl :: a -> Maybe Attributes- getAttrName :: a -> Maybe QName- getErrorLevel :: a -> Maybe Int- getErrorMsg :: a -> Maybe String+ getText :: a -> Maybe String+ getCharRef :: a -> Maybe Int+ getEntityRef :: a -> Maybe String+ getCmt :: a -> Maybe String+ getCdata :: a -> Maybe String+ getPiName :: a -> Maybe QName+ getPiContent :: a -> Maybe XmlTrees+ getElemName :: a -> Maybe QName+ getAttrl :: a -> Maybe XmlTrees+ getDTDPart :: a -> Maybe DTDElem+ getDTDAttrl :: a -> Maybe Attributes+ getAttrName :: a -> Maybe QName+ getErrorLevel :: a -> Maybe Int+ getErrorMsg :: a -> Maybe String -- derived selectors - getName :: a -> Maybe QName- getQualifiedName :: a -> Maybe String- getUniversalName :: a -> Maybe String- getUniversalUri :: a -> Maybe String- getLocalPart :: a -> Maybe String- getNamePrefix :: a -> Maybe String- getNamespaceUri :: a -> Maybe String+ getName :: a -> Maybe QName+ getQualifiedName :: a -> Maybe String+ getUniversalName :: a -> Maybe String+ getUniversalUri :: a -> Maybe String+ getLocalPart :: a -> Maybe String+ getNamePrefix :: a -> Maybe String+ getNamespaceUri :: a -> Maybe String -- "modifier" functions - changeText :: (String -> String) -> a -> a- changeCmt :: (String -> String) -> a -> a- changeName :: (QName -> QName) -> a -> a- changeElemName :: (QName -> QName) -> a -> a- changeAttrl :: (XmlTrees -> XmlTrees) -> a -> a- changeAttrName :: (QName -> QName) -> a -> a- changePiName :: (QName -> QName) -> a -> a- changeDTDAttrl :: (Attributes -> Attributes) -> a -> a+ changeText :: (String -> String) -> a -> a+ changeCmt :: (String -> String) -> a -> a+ changeName :: (QName -> QName) -> a -> a+ changeElemName :: (QName -> QName) -> a -> a+ changeAttrl :: (XmlTrees -> XmlTrees) -> a -> a+ changeAttrName :: (QName -> QName) -> a -> a+ changePiName :: (QName -> QName) -> a -> a+ changeDTDAttrl :: (Attributes -> Attributes) -> a -> a - setText :: String -> a -> a- setCmt :: String -> a -> a- setName :: QName -> a -> a- setElemName :: QName -> a -> a- setElemAttrl :: XmlTrees -> a -> a- setAttrName :: QName -> a -> a- setPiName :: QName -> a -> a- setDTDAttrl :: Attributes -> a -> a+ setText :: String -> a -> a+ setCmt :: String -> a -> a+ setName :: QName -> a -> a+ setElemName :: QName -> a -> a+ setElemAttrl :: XmlTrees -> a -> a+ setAttrName :: QName -> a -> a+ setPiName :: QName -> a -> a+ setDTDAttrl :: Attributes -> a -> a -- default implementations - getName n = getElemName n `mplus` getAttrName n `mplus` getPiName n- getQualifiedName n = getName n >>= \ n' -> return (qualifiedName n')- getUniversalName n = getName n >>= \ n' -> return (universalName n')- getUniversalUri n = getName n >>= \ n' -> return (universalUri n')- getLocalPart n = getName n >>= \ n' -> return (localPart n')- getNamePrefix n = getName n >>= \ n' -> return (namePrefix n')- getNamespaceUri n = getName n >>= \ n' -> return (namespaceUri n')+ getName n = getElemName n `mplus` getAttrName n `mplus` getPiName n+ getQualifiedName n = getName n >>= \ n' -> return (qualifiedName n')+ getUniversalName n = getName n >>= \ n' -> return (universalName n')+ getUniversalUri n = getName n >>= \ n' -> return (universalUri n')+ getLocalPart n = getName n >>= \ n' -> return (localPart n')+ getNamePrefix n = getName n >>= \ n' -> return (namePrefix n')+ getNamespaceUri n = getName n >>= \ n' -> return (namespaceUri n') - setText t = changeText (const t)- setCmt c = changeCmt (const c)- setName n = changeName (const n)- setElemName n = changeElemName (const n)- setElemAttrl al = changeAttrl (const al)- setAttrName n = changeAttrName (const n)- setPiName n = changePiName (const n)- setDTDAttrl al = changeDTDAttrl (const al)+ setText t = changeText (const t)+ setCmt c = changeCmt (const c)+ setName n = changeName (const n)+ setElemName n = changeElemName (const n)+ setElemAttrl al = changeAttrl (const al)+ setAttrName n = changeAttrName (const n)+ setPiName n = changePiName (const n)+ setDTDAttrl al = changeDTDAttrl (const al) -- XNode and XmlTree are instances of XmlNode instance XmlNode XNode where- isText (XText _) = True- isText _ = False+ isText (XText _) = True+ isText _ = False - isCharRef (XCharRef _) = True- isCharRef _ = False+ isCharRef (XCharRef _) = True+ isCharRef _ = False - isEntityRef (XEntityRef _) = True- isEntityRef _ = False+ isEntityRef (XEntityRef _) = True+ isEntityRef _ = False - isCmt (XCmt _) = True- isCmt _ = False+ isCmt (XCmt _) = True+ isCmt _ = False - isCdata (XCdata _) = True- isCdata _ = False+ isCdata (XCdata _) = True+ isCdata _ = False - isPi (XPi _ _) = True- isPi _ = False+ isPi (XPi _ _) = True+ isPi _ = False - isElem (XTag _ _) = True- isElem _ = False+ isElem (XTag _ _) = True+ isElem _ = False isRoot t = isElem t- &&- fromMaybe "" (getQualifiedName t) == t_root+ &&+ fromMaybe "" (getQualifiedName t) == t_root - isDTD (XDTD _ _) = True- isDTD _ = False+ isDTD (XDTD _ _) = True+ isDTD _ = False - isAttr (XAttr _) = True- isAttr _ = False+ isAttr (XAttr _) = True+ isAttr _ = False - isError (XError _ _) = True- isError _ = False+ isError (XError _ _) = True+ isError _ = False - mkText t = XText t- mkCharRef c = XCharRef c- mkEntityRef e = XEntityRef e- mkCmt c = XCmt c- mkCdata d = XCdata d- mkPi n c = XPi n (if null c then [] else [mkAttr (mkName a_value) c])- mkError l msg = XError l msg+ mkText t = XText t+ mkCharRef c = XCharRef c+ mkEntityRef e = XEntityRef e+ mkCmt c = XCmt c+ mkCdata d = XCdata d+ mkPi n c = XPi n (if null c then [] else [mkAttr (mkName a_value) c])+ mkError l msg = XError l msg - getText (XText t) = Just t- getText _ = Nothing+ getText (XText t) = Just t+ getText _ = Nothing - getCharRef (XCharRef c) = Just c- getCharRef _ = Nothing+ getCharRef (XCharRef c) = Just c+ getCharRef _ = Nothing - getEntityRef (XEntityRef e) = Just e- getEntityRef _ = Nothing+ getEntityRef (XEntityRef e) = Just e+ getEntityRef _ = Nothing - getCmt (XCmt c) = Just c- getCmt _ = Nothing+ getCmt (XCmt c) = Just c+ getCmt _ = Nothing - getCdata (XCdata d) = Just d- getCdata _ = Nothing+ getCdata (XCdata d) = Just d+ getCdata _ = Nothing - getPiName (XPi n _) = Just n- getPiName _ = Nothing+ getPiName (XPi n _) = Just n+ getPiName _ = Nothing - getPiContent (XPi _ c) = Just c- getPiContent _ = Nothing+ getPiContent (XPi _ c) = Just c+ getPiContent _ = Nothing - getElemName (XTag n _) = Just n- getElemName _ = Nothing+ getElemName (XTag n _) = Just n+ getElemName _ = Nothing - getAttrl (XTag _ al) = Just al- getAttrl (XPi _ al) = Just al- getAttrl _ = Nothing+ getAttrl (XTag _ al) = Just al+ getAttrl (XPi _ al) = Just al+ getAttrl _ = Nothing - getDTDPart (XDTD p _) = Just p- getDTDPart _ = Nothing+ getDTDPart (XDTD p _) = Just p+ getDTDPart _ = Nothing - getDTDAttrl (XDTD _ al) = Just al- getDTDAttrl _ = Nothing+ getDTDAttrl (XDTD _ al) = Just al+ getDTDAttrl _ = Nothing - getAttrName (XAttr n) = Just n- getAttrName _ = Nothing+ getAttrName (XAttr n) = Just n+ getAttrName _ = Nothing - getErrorLevel (XError l _) = Just l- getErrorLevel _ = Nothing+ getErrorLevel (XError l _) = Just l+ getErrorLevel _ = Nothing - getErrorMsg (XError _ m) = Just m- getErrorMsg _ = Nothing+ getErrorMsg (XError _ m) = Just m+ getErrorMsg _ = Nothing - changeText cf (XText t) = XText (cf t)- changeText _ _ = error "changeText undefined"+ changeText cf (XText t) = XText (cf t)+ changeText _ _ = error "changeText undefined" - changeCmt cf (XCmt c) = XCmt (cf c)- changeCmt _ _ = error "changeCmt undefined"+ changeCmt cf (XCmt c) = XCmt (cf c)+ changeCmt _ _ = error "changeCmt undefined" - changeName cf (XTag n al) = XTag (cf n) al- changeName cf (XAttr n) = XAttr (cf n)- changeName cf (XPi n al) = XPi (cf n) al- changeName _ _ = error "changeName undefined"+ changeName cf (XTag n al) = XTag (cf n) al+ changeName cf (XAttr n) = XAttr (cf n)+ changeName cf (XPi n al) = XPi (cf n) al+ changeName _ _ = error "changeName undefined" - changeElemName cf (XTag n al) = XTag (cf n) al- changeElemName _ _ = error "changeElemName undefined"+ changeElemName cf (XTag n al) = XTag (cf n) al+ changeElemName _ _ = error "changeElemName undefined" - changeAttrl cf (XTag n al) = XTag n (cf al)- changeAttrl cf (XPi n al) = XPi n (cf al)- changeAttrl _ _ = error "changeAttrl undefined"+ changeAttrl cf (XTag n al) = XTag n (cf al)+ changeAttrl cf (XPi n al) = XPi n (cf al)+ changeAttrl _ _ = error "changeAttrl undefined" - changeAttrName cf (XAttr n) = XAttr (cf n)- changeAttrName _ _ = error "changeAttrName undefined"+ changeAttrName cf (XAttr n) = XAttr (cf n)+ changeAttrName _ _ = error "changeAttrName undefined" - changePiName cf (XPi n al) = XPi (cf n) al- changePiName _ _ = error "changeAttrName undefined"+ changePiName cf (XPi n al) = XPi (cf n) al+ changePiName _ _ = error "changeAttrName undefined" - changeDTDAttrl cf (XDTD p al) = XDTD p (cf al)- changeDTDAttrl _ _ = error "changeDTDAttrl undefined"+ changeDTDAttrl cf (XDTD p al) = XDTD p (cf al)+ changeDTDAttrl _ _ = error "changeDTDAttrl undefined" -mkElementNode :: QName -> XmlTrees -> XNode-mkElementNode = XTag+mkElementNode :: QName -> XmlTrees -> XNode+mkElementNode = XTag -mkAttrNode :: QName -> XNode-mkAttrNode = XAttr+mkAttrNode :: QName -> XNode+mkAttrNode = XAttr -mkDTDNode :: DTDElem -> Attributes -> XNode-mkDTDNode = XDTD+mkDTDNode :: DTDElem -> Attributes -> XNode+mkDTDNode = XDTD instance XmlNode a => XmlNode (NTree a) where- isText = isText . getNode- isCharRef = isCharRef . getNode- isEntityRef = isEntityRef . getNode- isCmt = isCmt . getNode- isCdata = isCdata . getNode- isPi = isPi . getNode- isElem = isElem . getNode- isRoot = isRoot . getNode- isDTD = isDTD . getNode- isAttr = isAttr . getNode- isError = isError . getNode+ isText = isText . getNode+ isCharRef = isCharRef . getNode+ isEntityRef = isEntityRef . getNode+ isCmt = isCmt . getNode+ isCdata = isCdata . getNode+ isPi = isPi . getNode+ isElem = isElem . getNode+ isRoot = isRoot . getNode+ isDTD = isDTD . getNode+ isAttr = isAttr . getNode+ isError = isError . getNode - mkText = mkLeaf . mkText- mkCharRef = mkLeaf . mkCharRef- mkEntityRef = mkLeaf . mkEntityRef- mkCmt = mkLeaf . mkCmt- mkCdata = mkLeaf . mkCdata- mkPi n = mkLeaf . mkPi n- mkError l = mkLeaf . mkError l+ mkText = mkLeaf . mkText+ mkCharRef = mkLeaf . mkCharRef+ mkEntityRef = mkLeaf . mkEntityRef+ mkCmt = mkLeaf . mkCmt+ mkCdata = mkLeaf . mkCdata+ mkPi n = mkLeaf . mkPi n+ mkError l = mkLeaf . mkError l - getText = getText . getNode- getCharRef = getCharRef . getNode- getEntityRef = getEntityRef . getNode- getCmt = getCmt . getNode- getCdata = getCdata . getNode- getPiName = getPiName . getNode- getPiContent = getPiContent . getNode- getElemName = getElemName . getNode- getAttrl = getAttrl . getNode- getDTDPart = getDTDPart . getNode- getDTDAttrl = getDTDAttrl . getNode- getAttrName = getAttrName . getNode- getErrorLevel = getErrorLevel . getNode- getErrorMsg = getErrorMsg . getNode+ getText = getText . getNode+ getCharRef = getCharRef . getNode+ getEntityRef = getEntityRef . getNode+ getCmt = getCmt . getNode+ getCdata = getCdata . getNode+ getPiName = getPiName . getNode+ getPiContent = getPiContent . getNode+ getElemName = getElemName . getNode+ getAttrl = getAttrl . getNode+ getDTDPart = getDTDPart . getNode+ getDTDAttrl = getDTDAttrl . getNode+ getAttrName = getAttrName . getNode+ getErrorLevel = getErrorLevel . getNode+ getErrorMsg = getErrorMsg . getNode - changeText cf = changeNode (changeText cf)- changeCmt cf = changeNode (changeCmt cf)- changeName cf = changeNode (changeName cf)- changeElemName cf = changeNode (changeElemName cf)- changeAttrl cf = changeNode (changeAttrl cf)- changeAttrName cf = changeNode (changeAttrName cf)- changePiName cf = changeNode (changePiName cf)- changeDTDAttrl cf = changeNode (changeDTDAttrl cf)+ changeText cf = changeNode (changeText cf)+ changeCmt cf = changeNode (changeCmt cf)+ changeName cf = changeNode (changeName cf)+ changeElemName cf = changeNode (changeElemName cf)+ changeAttrl cf = changeNode (changeAttrl cf)+ changeAttrName cf = changeNode (changeAttrName cf)+ changePiName cf = changeNode (changePiName cf)+ changeDTDAttrl cf = changeNode (changeDTDAttrl cf) -mkElement :: QName -> XmlTrees -> XmlTrees -> XmlTree-mkElement n al = mkTree (mkElementNode n al)+mkElement :: QName -> XmlTrees -> XmlTrees -> XmlTree+mkElement n al = mkTree (mkElementNode n al) -mkRoot :: XmlTrees -> XmlTrees -> XmlTree-mkRoot al = mkTree (mkElementNode (mkName t_root) al)+mkRoot :: XmlTrees -> XmlTrees -> XmlTree+mkRoot al = mkTree (mkElementNode (mkName t_root) al) -mkAttr :: QName -> XmlTrees -> XmlTree-mkAttr n = mkTree (mkAttrNode n)+mkAttr :: QName -> XmlTrees -> XmlTree+mkAttr n = mkTree (mkAttrNode n) -mkDTDElem :: DTDElem -> Attributes -> XmlTrees -> XmlTree-mkDTDElem e al = mkTree (mkDTDNode e al)+mkDTDElem :: DTDElem -> Attributes -> XmlTrees -> XmlTree+mkDTDElem e al = mkTree (mkDTDNode e al) -addAttr :: XmlTree -> XmlTrees -> XmlTrees+addAttr :: XmlTree -> XmlTrees -> XmlTrees addAttr a al- | isAttr a = add al- | otherwise = al+ | isAttr a = add al+ | otherwise = al where an = (qualifiedName . fromJust . getAttrName) a add []- = [a]+ = [a] add (a1:al1)- | isAttr a1- &&- (qualifiedName . fromJust . getAttrName) a1 == an- = a : al1- | otherwise- = a1 : add al1+ | isAttr a1+ &&+ (qualifiedName . fromJust . getAttrName) a1 == an+ = a : al1+ | otherwise+ = a1 : add al1 -mergeAttrl :: XmlTrees -> XmlTrees -> XmlTrees-mergeAttrl = foldr addAttr+mergeAttrl :: XmlTrees -> XmlTrees -> XmlTrees+mergeAttrl = foldr addAttr -- ------------------------------------------------------------
src/Text/XML/HXT/DOM/XmlOptions.hs view
@@ -41,116 +41,116 @@ --- 'a_preserve_comment', 'a_do_not_preserve_comment', 'a_check_namespaces', 'a_do_not_check_namespaces', -- 'a_remove_whitespace', 'a_do_not_remove_whitespace' -inputOptions :: [OptDescr (String, String)]+inputOptions :: [OptDescr (String, String)] inputOptions- = [ Option "t" [a_trace] (OptArg trc "LEVEL") "trace level (0-4), default 1"- , Option "p" [a_proxy] (ReqArg (att a_proxy) "PROXY") "proxy for http access (e.g. \"www-cache:3128\")"- , Option "" [a_redirect] (NoArg (att a_redirect v_1)) "automatically follow redirected URIs"- , Option "" [a_no_redirect] (NoArg (att a_redirect v_0)) "switch off following redirected URIs"- , Option "" [a_use_curl] (NoArg (att a_use_curl v_1)) "obsolete, since hxt-8.1 HTTP access is always done with curl bindings"- , Option "" [a_do_not_use_curl] (NoArg (att a_use_curl v_0)) "obsolete, since hxt-8.1 HTTP access is always done with curl bindings"- , Option "" [a_options_curl] (ReqArg (att a_options_curl) "STR") "additional curl options, e.g. for timeout, ..."- , Option "" [a_default_baseuri] (ReqArg (att transferURI) "URI") "default base URI, default: \"file:///<cwd>/\""- , Option "e" [a_encoding] (ReqArg (att a_encoding) "CHARSET") ( "default document encoding (" ++ utf8 ++ ", " ++ isoLatin1 ++ ", " ++ usAscii ++ ", ...)" )+ = [ Option "t" [a_trace] (OptArg trc "LEVEL") "trace level (0-4), default 1"+ , Option "p" [a_proxy] (ReqArg (att a_proxy) "PROXY") "proxy for http access (e.g. \"www-cache:3128\")"+ , Option "" [a_redirect] (NoArg (att a_redirect v_1)) "automatically follow redirected URIs"+ , Option "" [a_no_redirect] (NoArg (att a_redirect v_0)) "switch off following redirected URIs"+ , Option "" [a_use_curl] (NoArg (att a_use_curl v_1)) "obsolete, since hxt-8.1 HTTP access is always done with curl bindings"+ , Option "" [a_do_not_use_curl] (NoArg (att a_use_curl v_0)) "obsolete, since hxt-8.1 HTTP access is always done with curl bindings"+ , Option "" [a_options_curl] (ReqArg (att a_options_curl) "STR") "additional curl options, e.g. for timeout, ..."+ , Option "" [a_default_baseuri] (ReqArg (att transferURI) "URI") "default base URI, default: \"file:///<cwd>/\""+ , Option "e" [a_encoding] (ReqArg (att a_encoding) "CHARSET") ( "default document encoding (" ++ utf8 ++ ", " ++ isoLatin1 ++ ", " ++ usAscii ++ ", ...)" ) , Option "" [a_mime_types] (ReqArg (att a_mime_types) "FILE") "set mime type configuration file, e.g. \"/etc/mime.types\""- , Option "" [a_issue_errors] (NoArg (att a_issue_errors v_1)) "issue all errorr messages on stderr (default)"- , Option "" [a_do_not_issue_errors] (NoArg (att a_issue_errors v_0)) "ignore all error messages"- , Option "" [a_ignore_encoding_errors] (NoArg (att a_ignore_encoding_errors v_1)) "ignore encoding errors"- , Option "" [a_ignore_none_xml_contents] (NoArg (att a_ignore_none_xml_contents v_1)) "discards all contents of none XML/HTML documents, only the meta info remains in the doc tree"- , Option "" [a_accept_mimetypes] (ReqArg (att a_accept_mimetypes) "MIMETYPES") "only accept documents matching the given list of mimetype specs"- , Option "H" [a_parse_html] (NoArg (att a_parse_html v_1)) "parse input as HTML, try to interprete everything as HTML, no validation"- , Option "M" [a_parse_by_mimetype] (NoArg (att a_parse_by_mimetype v_1)) "parse dependent on mime type: text/html as HTML, text/xml and text/xhtml and others as XML, else no parse"- , Option "" [a_parse_xml] (NoArg (att a_parse_html v_0)) "parse input as XML, (default)"- , Option "" [a_strict_input] (NoArg (att a_strict_input v_1)) "read input files strictly, this ensures closing the files correctly even if not read completely"- , Option "T" [a_tagsoup] (NoArg (att a_tagsoup v_1)) "lazy tagsoup parser, for HTML and XML, no DTD, no validation, no PIs, only XHTML entityrefs"- , Option "" [a_issue_warnings] (NoArg (att a_issue_warnings v_1)) "issue warnings, when parsing HTML (default)"- , Option "Q" [a_do_not_issue_warnings] (NoArg (att a_issue_warnings v_0)) "ignore warnings, when parsing HTML"- , Option "" [a_validate] (NoArg (att a_validate v_1)) "document validation when parsing XML (default)"- , Option "w" [a_do_not_validate] (NoArg (att a_validate v_0)) "only wellformed check, no validation"- , Option "" [a_canonicalize] (NoArg (att a_canonicalize v_1)) "canonicalize document, remove DTD, comment, transform CDATA, CharRef's, ... (default)"- , Option "c" [a_do_not_canonicalize] (NoArg (att a_canonicalize v_0)) "do not canonicalize document, don't remove DTD, comment, don't transform CDATA, CharRef's, ..."- , Option "C" [a_preserve_comment] (NoArg (att a_preserve_comment v_1)) "don't remove comments during canonicalisation"- , Option "" [a_do_not_preserve_comment] (NoArg (att a_preserve_comment v_0)) "remove comments during canonicalisation (default)"- , Option "n" [a_check_namespaces] (NoArg (att a_check_namespaces v_1)) "tag tree with namespace information and check namespaces"- , Option "" [a_do_not_check_namespaces] (NoArg (att a_check_namespaces v_0)) "ignore namespaces (default)"- , Option "r" [a_remove_whitespace] (NoArg (att a_remove_whitespace v_1)) "remove redundant whitespace, simplifies tree and processing"- , Option "" [a_do_not_remove_whitespace] (NoArg (att a_remove_whitespace v_0)) "don't remove redundant whitespace (default)"+ , Option "" [a_issue_errors] (NoArg (att a_issue_errors v_1)) "issue all errorr messages on stderr (default)"+ , Option "" [a_do_not_issue_errors] (NoArg (att a_issue_errors v_0)) "ignore all error messages"+ , Option "" [a_ignore_encoding_errors] (NoArg (att a_ignore_encoding_errors v_1)) "ignore encoding errors"+ , Option "" [a_ignore_none_xml_contents] (NoArg (att a_ignore_none_xml_contents v_1)) "discards all contents of none XML/HTML documents, only the meta info remains in the doc tree"+ , Option "" [a_accept_mimetypes] (ReqArg (att a_accept_mimetypes) "MIMETYPES") "only accept documents matching the given list of mimetype specs"+ , Option "H" [a_parse_html] (NoArg (att a_parse_html v_1)) "parse input as HTML, try to interprete everything as HTML, no validation"+ , Option "M" [a_parse_by_mimetype] (NoArg (att a_parse_by_mimetype v_1)) "parse dependent on mime type: text/html as HTML, text/xml and text/xhtml and others as XML, else no parse"+ , Option "" [a_parse_xml] (NoArg (att a_parse_html v_0)) "parse input as XML, (default)"+ , Option "" [a_strict_input] (NoArg (att a_strict_input v_1)) "read input files strictly, this ensures closing the files correctly even if not read completely"+ , Option "T" [a_tagsoup] (NoArg (att a_tagsoup v_1)) "lazy tagsoup parser, for HTML and XML, no DTD, no validation, no PIs, only XHTML entityrefs"+ , Option "" [a_issue_warnings] (NoArg (att a_issue_warnings v_1)) "issue warnings, when parsing HTML (default)"+ , Option "Q" [a_do_not_issue_warnings] (NoArg (att a_issue_warnings v_0)) "ignore warnings, when parsing HTML"+ , Option "" [a_validate] (NoArg (att a_validate v_1)) "document validation when parsing XML (default)"+ , Option "w" [a_do_not_validate] (NoArg (att a_validate v_0)) "only wellformed check, no validation"+ , Option "" [a_canonicalize] (NoArg (att a_canonicalize v_1)) "canonicalize document, remove DTD, comment, transform CDATA, CharRef's, ... (default)"+ , Option "c" [a_do_not_canonicalize] (NoArg (att a_canonicalize v_0)) "do not canonicalize document, don't remove DTD, comment, don't transform CDATA, CharRef's, ..."+ , Option "C" [a_preserve_comment] (NoArg (att a_preserve_comment v_1)) "don't remove comments during canonicalisation"+ , Option "" [a_do_not_preserve_comment] (NoArg (att a_preserve_comment v_0)) "remove comments during canonicalisation (default)"+ , Option "n" [a_check_namespaces] (NoArg (att a_check_namespaces v_1)) "tag tree with namespace information and check namespaces"+ , Option "" [a_do_not_check_namespaces] (NoArg (att a_check_namespaces v_0)) "ignore namespaces (default)"+ , Option "r" [a_remove_whitespace] (NoArg (att a_remove_whitespace v_1)) "remove redundant whitespace, simplifies tree and processing"+ , Option "" [a_do_not_remove_whitespace] (NoArg (att a_remove_whitespace v_0)) "don't remove redundant whitespace (default)" ] where- att n v = (n, v)+ att n v = (n, v) trc = att a_trace . show . max 0 . min 9 . (read :: String -> Int) . ('0':) . filter (`elem` "0123456789") . fromMaybe v_1 -- | available Relax NG validation options -- -- defines options--- 'a_check_restrictions', 'a_validate_externalRef', 'a_validate_include', 'a_do_not_check_restrictions', +-- 'a_check_restrictions', 'a_validate_externalRef', 'a_validate_include', 'a_do_not_check_restrictions', -- 'a_do_not_validate_externalRef', 'a_do_not_validate_include' relaxOptions :: [OptDescr (String, String)]-relaxOptions - = [ Option "X" [a_relax_schema] (ReqArg (att a_relax_schema) "SCHEMA") "validation with Relax NG, SCHEMA is the URI for the Relax NG schema"- , Option "" [a_check_restrictions] (NoArg (a_check_restrictions, v_1)) "check Relax NG schema restrictions during schema simplification (default)"- , Option "" [a_do_not_check_restrictions] (NoArg (a_check_restrictions, v_0)) "do not check Relax NG schema restrictions"- , Option "" [a_validate_externalRef] (NoArg (a_validate_externalRef, v_1)) "validate a Relax NG schema referenced by a externalRef-Pattern (default)"- , Option "" [a_do_not_validate_externalRef] (NoArg (a_validate_externalRef, v_0)) "do not validate a Relax NG schema referenced by an externalRef-Pattern"- , Option "" [a_validate_include] (NoArg (a_validate_include, v_1)) "validate a Relax NG schema referenced by an include-Pattern (default)"- , Option "" [a_do_not_validate_include] (NoArg (a_validate_include, v_0)) "do not validate a Relax NG schema referenced by an include-Pattern"- {-- , Option "" [a_output_changes] (NoArg (a_output_changes, v_1)) "output Pattern transformations in case of an error" - , Option "" [a_do_not_collect_errors] (NoArg (a_do_not_collect_errors, v_1)) "stop Relax NG simplification after the first error has occurred"- -}+relaxOptions+ = [ Option "X" [a_relax_schema] (ReqArg (att a_relax_schema) "SCHEMA") "validation with Relax NG, SCHEMA is the URI for the Relax NG schema"+ , Option "" [a_check_restrictions] (NoArg (a_check_restrictions, v_1)) "check Relax NG schema restrictions during schema simplification (default)"+ , Option "" [a_do_not_check_restrictions] (NoArg (a_check_restrictions, v_0)) "do not check Relax NG schema restrictions"+ , Option "" [a_validate_externalRef] (NoArg (a_validate_externalRef, v_1)) "validate a Relax NG schema referenced by a externalRef-Pattern (default)"+ , Option "" [a_do_not_validate_externalRef] (NoArg (a_validate_externalRef, v_0)) "do not validate a Relax NG schema referenced by an externalRef-Pattern"+ , Option "" [a_validate_include] (NoArg (a_validate_include, v_1)) "validate a Relax NG schema referenced by an include-Pattern (default)"+ , Option "" [a_do_not_validate_include] (NoArg (a_validate_include, v_0)) "do not validate a Relax NG schema referenced by an include-Pattern"+ {-+ , Option "" [a_output_changes] (NoArg (a_output_changes, v_1)) "output Pattern transformations in case of an error"+ , Option "" [a_do_not_collect_errors] (NoArg (a_do_not_collect_errors, v_1)) "stop Relax NG simplification after the first error has occurred"+ -} ] where- att n v = (n, v)+ att n v = (n, v) -- | -- commonly useful options for XML output -- -- defines options: 'a_indent', 'a_output_encoding', 'a_output_file', 'a_output_html' -outputOptions :: [OptDescr (String, String)]+outputOptions :: [OptDescr (String, String)] outputOptions- = [ Option "i" [a_indent] (NoArg (att a_indent v_1)) "indent XML output for readability"- , Option "o" [a_output_encoding] (ReqArg (att a_output_encoding) "CHARSET") ( "encoding of output (" ++ utf8 ++ ", " ++ isoLatin1 ++ ", " ++ usAscii ++ ")" )- , Option "f" [a_output_file] (ReqArg (att a_output_file) "FILE") "output file for resulting document (default: stdout)"- , Option "" [a_output_html] (NoArg (att a_output_html v_1)) "output of none ASCII chars as HTMl entity references"- , Option "" [a_no_xml_pi] (NoArg (att a_no_xml_pi v_1)) ("output without <?xml ...?> processing instruction, useful in combination with --" ++ show a_output_html)- , Option "" [a_output_xhtml] (NoArg (att a_output_xhtml v_1)) "output of HTML elements with empty content (script, ...) done in format <elem...></elem> instead of <elem/>"+ = [ Option "i" [a_indent] (NoArg (att a_indent v_1)) "indent XML output for readability"+ , Option "o" [a_output_encoding] (ReqArg (att a_output_encoding) "CHARSET") ( "encoding of output (" ++ utf8 ++ ", " ++ isoLatin1 ++ ", " ++ usAscii ++ ")" )+ , Option "f" [a_output_file] (ReqArg (att a_output_file) "FILE") "output file for resulting document (default: stdout)"+ , Option "" [a_output_html] (NoArg (att a_output_html v_1)) "output of none ASCII chars as HTMl entity references"+ , Option "" [a_no_xml_pi] (NoArg (att a_no_xml_pi v_1)) ("output without <?xml ...?> processing instruction, useful in combination with --" ++ show a_output_html)+ , Option "" [a_output_xhtml] (NoArg (att a_output_xhtml v_1)) "output of HTML elements with empty content (script, ...) done in format <elem...></elem> instead of <elem/>" , Option "" [a_no_empty_elem_for] (ReqArg (att a_no_empty_elem_for) "NAMES") "output of empty elements done in format <elem...></elem> only for given list of element names" , Option "" [a_no_empty_elements] (NoArg (att a_no_empty_elements v_1)) "output of empty elements done in format <elem...></elem> instead of <elem/>" , Option "" [a_add_default_dtd] (NoArg (att a_add_default_dtd v_1)) "add the document type declaration given in the input document"- , Option "" [a_text_mode] (NoArg (att a_text_mode v_1)) "output in text mode"+ , Option "" [a_text_mode] (NoArg (att a_text_mode v_1)) "output in text mode" ] where- att n v = (n, v)+ att n v = (n, v) -- | -- commonly useful options -- -- defines options: 'a_verbose', 'a_help' -generalOptions :: [OptDescr (String, String)]+generalOptions :: [OptDescr (String, String)] generalOptions- = [ Option "v" [a_verbose] (NoArg (a_verbose, v_1)) "verbose output"- , Option "h?" [a_help] (NoArg (a_help, v_1)) "this message"+ = [ Option "v" [a_verbose] (NoArg (a_verbose, v_1)) "verbose output"+ , Option "h?" [a_help] (NoArg (a_help, v_1)) "this message" ] -- | -- defines 'a_version' option -versionOptions :: [OptDescr (String, String)]+versionOptions :: [OptDescr (String, String)] versionOptions- = [ Option "V" [a_version] (NoArg (a_version, v_1)) "show program version"+ = [ Option "V" [a_version] (NoArg (a_version, v_1)) "show program version" ] -- | -- debug output options -showOptions :: [OptDescr (String, String)]+showOptions :: [OptDescr (String, String)] showOptions- = [ Option "" [a_show_tree] (NoArg (a_show_tree, v_1)) "output tree representation instead of document source"- , Option "" [a_show_haskell] (NoArg (a_show_haskell, v_1)) "output internal Haskell representation instead of document source"+ = [ Option "" [a_show_tree] (NoArg (a_show_tree, v_1)) "output tree representation instead of document source"+ , Option "" [a_show_haskell] (NoArg (a_show_haskell, v_1)) "output internal Haskell representation instead of document source" ] -- ------------------------------------------------------------@@ -158,11 +158,11 @@ -- | -- select options from a predefined list of option desciptions -selectOptions :: [String] -> [OptDescr (String, String)] -> [OptDescr (String, String)]+selectOptions :: [String] -> [OptDescr (String, String)] -> [OptDescr (String, String)] selectOptions ol os = concat . map (\ on -> filter (\ (Option _ ons _ _) -> on `elem` ons) os) $ ol -removeOptions :: [String] -> [OptDescr (String, String)] -> [OptDescr (String, String)]+removeOptions :: [String] -> [OptDescr (String, String)] -> [OptDescr (String, String)] removeOptions ol os = filter (\ (Option _ ons _ _) -> not . any (`elem` ol) $ ons ) os @@ -173,16 +173,16 @@ -- and checks if the value represents True. The following strings are interpreted -- as true: \"1\", \"True\", \"true\", \"yes\", \"Yes\". -optionIsSet :: String -> Attributes -> Bool-optionIsSet n = isTrueValue . lookupDef "" n+optionIsSet :: String -> Attributes -> Bool+optionIsSet n = isTrueValue . lookupDef "" n -- | check whether a string represents True -- -- definition: ----- > isTrueValue = (`elem` ["1", "True", "true", "Yes", "yes"])+-- > isTrueValue = (`elem` ["1", "True", "true", "Yes", "yes"]) -isTrueValue :: String -> Bool-isTrueValue = (`elem` ["1", "True", "true", "Yes", "yes"])+isTrueValue :: String -> Bool+isTrueValue = (`elem` ["1", "True", "true", "Yes", "yes"]) -- ------------------------------------------------------------
src/Text/XML/HXT/DTDValidation/AttributeValueValidation.hs view
@@ -56,21 +56,21 @@ checkAttributeValue :: XmlTrees -> XmlTree -> XmlArrow checkAttributeValue dtdPart attrDecl | isDTDAttlistNode attrDecl- = choiceA- [ isElem :-> ( checkAttrVal $< getAttrValue attrName )- , isDTDAttlist :-> ( checkAttrVal $< (getDTDAttrl >>^ dtd_default) )- , this :-> none- ]+ = choiceA+ [ isElem :-> ( checkAttrVal $< getAttrValue attrName )+ , isDTDAttlist :-> ( checkAttrVal $< (getDTDAttrl >>^ dtd_default) )+ , this :-> none+ ] | otherwise- = none+ = none where- al = getDTDAttributes attrDecl- attrName = dtd_value al+ al = getDTDAttributes attrDecl+ attrName = dtd_value al attrType = dtd_type al checkAttrVal attrValue- = checkValue attrType dtdPart normalizedVal attrDecl- where- normalizedVal = normalizeAttributeValue (Just attrDecl) attrValue+ = checkValue attrType dtdPart normalizedVal attrDecl+ where+ normalizedVal = normalizeAttributeValue (Just attrDecl) attrValue -- | -- Dispatches the attibute check by the attribute type.@@ -89,17 +89,17 @@ checkValue :: String -> XmlTrees -> String -> XmlTree -> XmlArrow checkValue typ dtdPart attrValue attrDecl- | typ == k_cdata = none- | typ == k_enumeration = checkValueEnumeration attrDecl attrValue- | typ == k_entity = checkValueEntity dtdPart attrDecl attrValue- | typ == k_entities = checkValueEntities dtdPart attrDecl attrValue- | typ == k_id = checkValueId attrDecl attrValue- | typ == k_idref = checkValueIdref attrDecl attrValue- | typ == k_idrefs = checkValueIdrefs attrDecl attrValue- | typ == k_nmtoken = checkValueNmtoken attrDecl attrValue- | typ == k_nmtokens = checkValueNmtokens attrDecl attrValue- | typ == k_notation = checkValueEnumeration attrDecl attrValue- | otherwise = error ("Attribute type " ++ show typ ++ " unknown.")+ | typ == k_cdata = none+ | typ == k_enumeration = checkValueEnumeration attrDecl attrValue+ | typ == k_entity = checkValueEntity dtdPart attrDecl attrValue+ | typ == k_entities = checkValueEntities dtdPart attrDecl attrValue+ | typ == k_id = checkValueId attrDecl attrValue+ | typ == k_idref = checkValueIdref attrDecl attrValue+ | typ == k_idrefs = checkValueIdrefs attrDecl attrValue+ | typ == k_nmtoken = checkValueNmtoken attrDecl attrValue+ | typ == k_nmtokens = checkValueNmtokens attrDecl attrValue+ | typ == k_notation = checkValueEnumeration attrDecl attrValue+ | otherwise = error ("Attribute type " ++ show typ ++ " unknown.") -- | -- Checks the value of Enumeration attribute types. (3.3.1 \/ p.27 in Spec)@@ -113,12 +113,12 @@ | isDTDAttlistNode attrDecl && attrValue `notElem` enumVals- = err ( "Attribute " ++ show (dtd_value al) ++ " for element " ++ show (dtd_name al) +++ = err ( "Attribute " ++ show (dtd_value al) ++ " for element " ++ show (dtd_name al) ++ " must have a value from list "++ show enumVals {- ++ " but has value " ++ show attrValue-} ++ ".") | otherwise- = none+ = none where- al = getDTDAttributes attrDecl+ al = getDTDAttributes attrDecl enumVals :: [String] enumVals = map (dtd_name . getDTDAttributes) $ (runLA getChildren attrDecl)@@ -138,13 +138,13 @@ | isDTDAttlistNode attrDecl && attrValue `notElem` upEntities- = err ( "Entity " ++ show attrValue ++ " of attribute " ++ show (dtd_value al) +++ = err ( "Entity " ++ show attrValue ++ " of attribute " ++ show (dtd_value al) ++ " for element " ++ show (dtd_name al) ++ " is not unparsed. " ++ "The following unparsed entities exist: " ++ show upEntities ++ ".") | otherwise- = none+ = none where- al = getDTDAttributes attrDecl+ al = getDTDAttributes attrDecl upEntities :: [String] upEntities = map (dtd_name . getDTDAttributes) (isUnparsedEntity $$ dtdPart)@@ -162,14 +162,14 @@ checkValueEntities ::XmlTrees -> XmlTree -> String -> XmlArrow checkValueEntities dtdPart attrDecl attrValue | isDTDAttlistNode attrDecl- = if null valueList- then err ("Attribute " ++ show (dtd_value al) ++ " of element " +++ = if null valueList+ then err ("Attribute " ++ show (dtd_value al) ++ " of element " ++ show (dtd_name al) ++ " must be one or more names.") else catA . map (checkValueEntity dtdPart attrDecl) $ valueList | otherwise- = none+ = none where- al = getDTDAttributes attrDecl+ al = getDTDAttributes attrDecl valueList = words attrValue -- |@@ -182,22 +182,22 @@ checkValueNmtoken :: XmlTree -> String -> XmlArrow checkValueNmtoken attrDecl attrValue | isDTDAttlistNode attrDecl- = constA attrValue >>> checkNmtoken+ = constA attrValue >>> checkNmtoken | otherwise- = none+ = none where- al = getDTDAttributes attrDecl+ al = getDTDAttributes attrDecl checkNmtoken- = mkText >>> arrL (parseNMToken "")- >>>- isError- >>>- getErrorMsg- >>>- arr (\ s -> ( "Attribute value " ++ show attrValue ++ " of attribute " ++ show (dtd_value al) ++- " for element " ++ show (dtd_name al) ++ " must be a name token, "++ (lines s) !! 1 ++".") )+ = mkText >>> arrL (parseNMToken "") >>>- mkError c_err+ isError+ >>>+ getErrorMsg+ >>>+ arr (\ s -> ( "Attribute value " ++ show attrValue ++ " of attribute " ++ show (dtd_value al) +++ " for element " ++ show (dtd_name al) ++ " must be a name token, "++ (lines s) !! 1 ++".") )+ >>>+ mkError c_err -- | -- Checks the value of NMTOKENS attribute types. (3.3.1 \/ p.26 in Spec)@@ -209,14 +209,14 @@ checkValueNmtokens :: XmlTree -> String -> XmlArrow checkValueNmtokens attrDecl attrValue | isDTDAttlistNode attrDecl- = if null valueList- then err ( "Attribute "++ show (dtd_value al) ++" of element " +++ = if null valueList+ then err ( "Attribute "++ show (dtd_value al) ++" of element " ++ show (dtd_name al) ++ " must be one or more name tokens.") else catA . map (checkValueNmtoken attrDecl) $ valueList | otherwise- = none+ = none where- al = getDTDAttributes attrDecl+ al = getDTDAttributes attrDecl valueList = words attrValue -- |@@ -272,22 +272,22 @@ checkForName :: String -> XmlTree -> String -> XmlArrow checkForName msg attrDecl attrValue | isDTDAttlistNode attrDecl- = constA attrValue >>> checkName+ = constA attrValue >>> checkName | otherwise- = none+ = none where- al = getDTDAttributes attrDecl+ al = getDTDAttributes attrDecl checkName- = mkText >>> arrL (parseName "")- >>>- isError- >>>- getErrorMsg- >>>- arr (\s -> ( msg ++ " " ++ show attrValue ++" of attribute " ++ show (dtd_value al) ++- " for element "++ show (dtd_name al) ++" must be a name, " ++ (lines s) !! 1 ++ ".") )+ = mkText >>> arrL (parseName "") >>>- mkError c_err+ isError+ >>>+ getErrorMsg+ >>>+ arr (\s -> ( msg ++ " " ++ show attrValue ++" of attribute " ++ show (dtd_value al) +++ " for element "++ show (dtd_name al) ++" must be a name, " ++ (lines s) !! 1 ++ ".") )+ >>>+ mkError c_err -- ----------------------------------------------------------------------------- @@ -305,13 +305,13 @@ normalizeAttributeValue (Just attrDecl) value = normalizeAttribute attrType where- al = getDTDAttributes attrDecl+ al = getDTDAttributes attrDecl attrType = dtd_type al normalizeAttribute :: String -> String normalizeAttribute typ- | typ == k_cdata = cdataNormalization value- | otherwise = otherNormalization value+ | typ == k_cdata = cdataNormalization value+ | otherwise = otherNormalization value -- Attribute not declared in DTD, normalization as CDATA normalizeAttributeValue Nothing value
src/Text/XML/HXT/DTDValidation/DTDValidation.hs view
@@ -50,33 +50,33 @@ = isDTDDoctype `guards` ( listA getChildren- >>>- ( validateParts $<< (getNotationNames &&& getElemNames) )+ >>>+ ( validateParts $<< (getNotationNames &&& getElemNames) ) ) where validateParts notationNames elemNames- = validateNotations- <+>- validateEntities notationNames+ = validateNotations <+>- validateElements elemNames- <+>- validateAttributes elemNames notationNames+ validateEntities notationNames+ <+>+ validateElements elemNames+ <+>+ validateAttributes elemNames notationNames - getNotationNames :: LA [XmlTree] [String]- getNotationNames = listA $ unlistA >>> isDTDNotation >>> getDTDAttrValue a_name+ getNotationNames :: LA [XmlTree] [String]+ getNotationNames = listA $ unlistA >>> isDTDNotation >>> getDTDAttrValue a_name - getElemNames :: LA [XmlTree] [String]- getElemNames = listA $ unlistA >>> isDTDElement >>> getDTDAttrValue a_name+ getElemNames :: LA [XmlTree] [String]+ getElemNames = listA $ unlistA >>> isDTDElement >>> getDTDAttrValue a_name -- ------------------------------------------------------------ -checkName :: String -> SLA [String] XmlTree XmlTree -> SLA [String] XmlTree XmlTree+checkName :: String -> SLA [String] XmlTree XmlTree -> SLA [String] XmlTree XmlTree checkName name msg = ifA ( getState- >>>- isA (name `elem`)- )+ >>>+ isA (name `elem`)+ ) msg (nextState (name:) >>> none) @@ -93,25 +93,25 @@ validateNotations :: LA XmlTrees XmlTree validateNotations = fromSLA [] ( unlistA- >>>- isDTDNotation- >>>- (checkForUniqueNotation $< getDTDAttrl)- )+ >>>+ isDTDNotation+ >>>+ (checkForUniqueNotation $< getDTDAttrl)+ ) where checkForUniqueNotation :: Attributes -> SLA [String] XmlTree XmlTree checkForUniqueNotation al- = checkName name $- err ( "Notation "++ show name ++ " was already specified." )- where- name = dtd_name al+ = checkName name $+ err ( "Notation "++ show name ++ " was already specified." )+ where+ name = dtd_name al -- | -- Validation of Entities. -- -- 1. Issues a warning if entities are declared multiple times. ----- Optional warning: (4.2 \/ p.35 in Spec) +-- Optional warning: (4.2 \/ p.35 in Spec) -- -- -- 2. Validates that a notation is declared for an unparsed entity.@@ -124,60 +124,60 @@ -- -- - returns : a list of errors -validateEntities :: [String] -> LA XmlTrees XmlTree+validateEntities :: [String] -> LA XmlTrees XmlTree validateEntities notationNames = ( fromSLA [] ( unlistA- >>>- isDTDEntity- >>>- (checkForUniqueEntity $< getDTDAttrl)- )+ >>>+ isDTDEntity+ >>>+ (checkForUniqueEntity $< getDTDAttrl)+ ) ) <+> ( unlistA- >>>- isUnparsedEntity- >>>- (checkNotationDecl $< getDTDAttrl)+ >>>+ isUnparsedEntity+ >>>+ (checkNotationDecl $< getDTDAttrl) ) where -- Check if entities are declared multiple times - checkForUniqueEntity :: Attributes -> SLA [String] XmlTree XmlTree+ checkForUniqueEntity :: Attributes -> SLA [String] XmlTree XmlTree checkForUniqueEntity al- = checkName name $- warn ( "Entity "++ show name ++ " was already specified. " ++- "First declaration will be used." )- where- name = dtd_name al+ = checkName name $+ warn ( "Entity "++ show name ++ " was already specified. " +++ "First declaration will be used." )+ where+ name = dtd_name al -- Find unparsed entities for which no notation is specified - checkNotationDecl :: Attributes -> XmlArrow+ checkNotationDecl :: Attributes -> XmlArrow checkNotationDecl al- | notationName `elem` notationNames- = none- | otherwise- = err ( "The notation " ++ show notationName ++ " must be declared " ++- "when referenced in the unparsed entity declaration for " ++- show upEntityName ++ "."- )- where- notationName = lookup1 k_ndata al- upEntityName = dtd_name al+ | notationName `elem` notationNames+ = none+ | otherwise+ = err ( "The notation " ++ show notationName ++ " must be declared " +++ "when referenced in the unparsed entity declaration for " +++ show upEntityName ++ "."+ )+ where+ notationName = lookup1 k_ndata al+ upEntityName = dtd_name al -- | -- Validation of Element declarations. -- -- 1. Validates that an element is not declared multiple times. ----- Validity constraint: Unique Element Type Declaration (3.2 \/ p.21 in Spec) +-- Validity constraint: Unique Element Type Declaration (3.2 \/ p.21 in Spec) -- -- -- 2. Validates that an element name only appears once in a mixed-content declaration. ----- Validity constraint: No Duplicate Types (3.2 \/ p.21 in Spec) +-- Validity constraint: No Duplicate Types (3.2 \/ p.21 in Spec) -- -- -- 3. Issues a warning if an element mentioned in a content model is not declared in the@@ -192,28 +192,28 @@ -- - returns : a list of errors -validateElements :: [String] -> LA XmlTrees XmlTree+validateElements :: [String] -> LA XmlTrees XmlTree validateElements elemNames -- dtdPart = ( fromSLA [] ( unlistA- >>>- isDTDElement- >>>- (checkForUniqueElement $< getDTDAttrl)- )+ >>>+ isDTDElement+ >>>+ (checkForUniqueElement $< getDTDAttrl)+ ) ) <+> ( unlistA- >>>- isMixedContentElement- >>>- (checkMixedContent $< getDTDAttrl)+ >>>+ isMixedContentElement+ >>>+ (checkMixedContent $< getDTDAttrl) ) <+> ( unlistA- >>>- isDTDElement- >>>- (checkContentModel elemNames $< getDTDAttrl)+ >>>+ isDTDElement+ >>>+ (checkContentModel elemNames $< getDTDAttrl) ) where @@ -221,64 +221,64 @@ checkForUniqueElement :: Attributes -> SLA [String] XmlTree XmlTree checkForUniqueElement al- = checkName name $- err ( "Element type " ++ show name ++- " must not be declared more than once." )- where- name = dtd_name al+ = checkName name $+ err ( "Element type " ++ show name +++ " must not be declared more than once." )+ where+ name = dtd_name al -- Validates that an element name only appears once in a mixed-content declaration - checkMixedContent :: Attributes -> XmlArrow+ checkMixedContent :: Attributes -> XmlArrow checkMixedContent al- = fromSLA [] ( getChildren- >>>- getChildren- >>>- isDTDName- >>>- (check $< getDTDAttrl)- )- where- elemName = dtd_name al- check al'- = checkName name $- err ( "The element type " ++ show name ++- " was already specified in the mixed-content model of the element declaration " ++- show elemName ++ "." )- where- name = dtd_name al'+ = fromSLA [] ( getChildren+ >>>+ getChildren+ >>>+ isDTDName+ >>>+ (check $< getDTDAttrl)+ )+ where+ elemName = dtd_name al+ check al'+ = checkName name $+ err ( "The element type " ++ show name +++ " was already specified in the mixed-content model of the element declaration " +++ show elemName ++ "." )+ where+ name = dtd_name al' -- Issues a warning if an element mentioned in a content model is not -- declared in the DTD. checkContentModel :: [String] -> Attributes -> XmlArrow checkContentModel names al- | cm `elem` [v_children, v_mixed]- = getChildren >>> checkContent- | otherwise- = none- where- elemName = dtd_name al- cm = dtd_type al+ | cm `elem` [v_children, v_mixed]+ = getChildren >>> checkContent+ | otherwise+ = none+ where+ elemName = dtd_name al+ cm = dtd_type al - checkContent :: XmlArrow- checkContent- = choiceA- [ isDTDName :-> ( checkName' $< getDTDAttrl )- , isDTDContent :-> ( getChildren >>> checkContent )- , this :-> none- ]- where- checkName' al'- | childElemName `elem` names- = none- | otherwise- = warn ( "The element type "++ show childElemName ++- ", used in content model of element "++ show elemName ++- ", is not declared."- )- where- childElemName = dtd_name al'+ checkContent :: XmlArrow+ checkContent+ = choiceA+ [ isDTDName :-> ( checkName' $< getDTDAttrl )+ , isDTDContent :-> ( getChildren >>> checkContent )+ , this :-> none+ ]+ where+ checkName' al'+ | childElemName `elem` names+ = none+ | otherwise+ = warn ( "The element type "++ show childElemName +++ ", used in content model of element "++ show elemName +++ ", is not declared."+ )+ where+ childElemName = dtd_name al' -- | -- Validation of Attribute declarations.@@ -299,32 +299,32 @@ -- 3. Issues a warning if the same Nmtoken occures more than once in enumerated -- attribute types of a single element type. ----- Optional warning: (3.3.1 \/ p.27 in Spec) +-- Optional warning: (3.3.1 \/ p.27 in Spec) -- -- -- 4. Validates that an element type has not more than one ID attribute defined. ----- Validity constraint: One ID per Element Type (3.3.1 \/ p.26 in Spec) +-- Validity constraint: One ID per Element Type (3.3.1 \/ p.26 in Spec) -- -- -- 5. Validates that an element type has not more than one NOTATION attribute defined. ----- Validity constraint: One Notation per Element Type (3.3.1 \/ p.27 in Spec) +-- Validity constraint: One Notation per Element Type (3.3.1 \/ p.27 in Spec) -- -- -- 6. Validates that an ID attributes has the type #IMPLIED or #REQUIRED. ----- Validity constraint: ID Attribute Default (3.3.1 \/ p.26 in Spec) +-- Validity constraint: ID Attribute Default (3.3.1 \/ p.26 in Spec) -- -- -- 7. Validates that all referenced notations are declared. ----- Validity constraint: Notation Attributes (3.3.1 \/ p.27 in Spec) +-- Validity constraint: Notation Attributes (3.3.1 \/ p.27 in Spec) -- -- -- 8. Validates that notations are not declared for EMPTY elements. ----- Validity constraint: No Notation on Empty Element (3.3.1 \/p.27 in Spec) +-- Validity constraint: No Notation on Empty Element (3.3.1 \/p.27 in Spec) -- -- -- 9. Validates that the default value matches the lexical constraints of it's type.@@ -365,11 +365,11 @@ <+> -- 8. Validate that notations are not declared for EMPTY elements ( checkNoNotationForEmptyElements $< listA ( unlistA- >>>- isEmptyElement- >>>- getDTDAttrValue a_name- )+ >>>+ isEmptyElement+ >>>+ getDTDAttrValue a_name+ ) ) <+> -- 9. Validate that the default value matches the lexical constraints of it's type@@ -380,14 +380,14 @@ -- control structures runCheck select check- = unlistA >>> isDTDAttlist- >>>- select- >>>- (check $< getDTDAttrl)- + = unlistA >>> isDTDAttlist+ >>>+ select+ >>>+ (check $< getDTDAttrl)+ runNameCheck select check- = fromSLA [] $ runCheck select check+ = fromSLA [] $ runCheck select check -------------------------------------------------------------------------- @@ -395,15 +395,15 @@ checkDeclaredElements :: [String] -> Attributes -> XmlArrow checkDeclaredElements elemNames' al- | en `elem` elemNames'- = none- | otherwise- = warn ( "The element type \""++ en ++ "\" used in dclaration "++- "of attribute \""++ an ++"\" is not declared."- )- where- en = dtd_name al- an = dtd_value al+ | en `elem` elemNames'+ = none+ | otherwise+ = warn ( "The element type \""++ en ++ "\" used in dclaration "+++ "of attribute \""++ an ++"\" is not declared."+ )+ where+ en = dtd_name al+ an = dtd_value al -------------------------------------------------------------------------- @@ -411,14 +411,14 @@ checkForUniqueAttributeDeclaration :: Attributes -> SLA [String] XmlTree XmlTree checkForUniqueAttributeDeclaration al- = checkName name $- warn ( "Attribute \""++ aname ++"\" for element type \""++- ename ++"\" is already declared. First "++- "declaration will be used." )- where- ename = dtd_name al- aname = dtd_value al- name = ename ++ "|" ++ aname+ = checkName name $+ warn ( "Attribute \""++ aname ++"\" for element type \""+++ ename ++"\" is already declared. First "+++ "declaration will be used." )+ where+ ename = dtd_name al+ aname = dtd_value al+ name = ename ++ "|" ++ aname -------------------------------------------------------------------------- @@ -427,20 +427,20 @@ checkEnumeratedTypes :: Attributes -> XmlArrow checkEnumeratedTypes al = fromSLA [] ( getChildren- >>>- isDTDName- >>>- (checkForUniqueType $< getDTDAttrl)- )- where- checkForUniqueType :: Attributes -> SLA [String] XmlTree XmlTree+ >>>+ isDTDName+ >>>+ (checkForUniqueType $< getDTDAttrl)+ )+ where+ checkForUniqueType :: Attributes -> SLA [String] XmlTree XmlTree checkForUniqueType al'- = checkName nmtoken $- warn ( "Nmtoken \""++ nmtoken ++"\" should not "++- "occur more than once in attribute \""++ dtd_value al ++- "\" for element \""++ dtd_name al ++ "\"." )- where- nmtoken = dtd_name al'+ = checkName nmtoken $+ warn ( "Nmtoken \""++ nmtoken ++"\" should not "+++ "occur more than once in attribute \""++ dtd_value al +++ "\" for element \""++ dtd_name al ++ "\"." )+ where+ nmtoken = dtd_name al' -------------------------------------------------------------------------- @@ -448,12 +448,12 @@ checkForUniqueId :: Attributes -> SLA [String] XmlTree XmlTree checkForUniqueId al- = checkName ename $- err ( "Element \""++ ename ++ "\" already has attribute of type "++- "ID, another attribute \""++ dtd_value al ++ "\" of type ID is "++- "not permitted." )- where- ename = dtd_name al+ = checkName ename $+ err ( "Element \""++ ename ++ "\" already has attribute of type "+++ "ID, another attribute \""++ dtd_value al ++ "\" of type ID is "+++ "not permitted." )+ where+ ename = dtd_name al -------------------------------------------------------------------------- @@ -461,12 +461,12 @@ checkForUniqueNotation :: Attributes -> SLA [String] XmlTree XmlTree checkForUniqueNotation al- = checkName ename $- err ( "Element \""++ ename ++ "\" already has attribute of type "++- "NOTATION, another attribute \""++ dtd_value al ++ "\" of type NOTATION "++- "is not permitted." )- where- ename = dtd_name al+ = checkName ename $+ err ( "Element \""++ ename ++ "\" already has attribute of type "+++ "NOTATION, another attribute \""++ dtd_value al ++ "\" of type NOTATION "+++ "is not permitted." )+ where+ ename = dtd_name al -------------------------------------------------------------------------- @@ -474,13 +474,13 @@ checkIdKindConstraint :: Attributes -> XmlArrow checkIdKindConstraint al- | attKind `elem` [k_implied, k_required]- = none- | otherwise- = err ( "ID attribute \""++ dtd_value al ++"\" must have a declared default "++- "of \"#IMPLIED\" or \"REQUIRED\"")- where- attKind = dtd_kind al+ | attKind `elem` [k_implied, k_required]+ = none+ | otherwise+ = err ( "ID attribute \""++ dtd_value al ++"\" must have a declared default "+++ "of \"#IMPLIED\" or \"REQUIRED\"")+ where+ attKind = dtd_kind al --------------------------------------------------------------------------@@ -490,22 +490,22 @@ checkNotationDeclaration :: [String] -> Attributes -> XmlArrow checkNotationDeclaration notations al = getChildren- >>>- isDTDName- >>>- (checkNotations $< getDTDAttrl)- where- checkNotations :: Attributes -> XmlArrow- checkNotations al'- | notation `elem` notations- = none- | otherwise- = err ( "The notation \""++ notation ++"\" must be declared when "++- "referenced in the notation type list for attribute \""++ dtd_value al ++- "\" of element \""++ dtd_name al ++"\"."- )+ >>>+ isDTDName+ >>>+ (checkNotations $< getDTDAttrl)+ where+ checkNotations :: Attributes -> XmlArrow+ checkNotations al'+ | notation `elem` notations+ = none+ | otherwise+ = err ( "The notation \""++ notation ++"\" must be declared when "+++ "referenced in the notation type list for attribute \""++ dtd_value al +++ "\" of element \""++ dtd_name al ++"\"."+ ) where- notation = dtd_name al'+ notation = dtd_name al' -------------------------------------------------------------------------- @@ -513,24 +513,24 @@ checkNoNotationForEmptyElements :: [String] -> LA XmlTrees XmlTree checkNoNotationForEmptyElements emptyElems- = unlistA- >>>- isDTDAttlist- >>>- isNotationAttrType- >>>- (checkNoNotationForEmptyElement $< getDTDAttrl)- where- checkNoNotationForEmptyElement :: Attributes -> XmlArrow- checkNoNotationForEmptyElement al- | ename `elem` emptyElems- = err ( "Attribute \""++ dtd_value al ++"\" of type NOTATION must not be "++- "declared on the element \""++ ename ++"\" declared EMPTY."- )+ = unlistA+ >>>+ isDTDAttlist+ >>>+ isNotationAttrType+ >>>+ (checkNoNotationForEmptyElement $< getDTDAttrl)+ where+ checkNoNotationForEmptyElement :: Attributes -> XmlArrow+ checkNoNotationForEmptyElement al+ | ename `elem` emptyElems+ = err ( "Attribute \""++ dtd_value al ++"\" of type NOTATION must not be "+++ "declared on the element \""++ ename ++"\" declared EMPTY."+ ) | otherwise- = none- where- ename = dtd_name al+ = none+ where+ ename = dtd_name al -------------------------------------------------------------------------- @@ -538,10 +538,10 @@ checkDefaultValueTypes :: XmlTrees -> LA XmlTrees XmlTree checkDefaultValueTypes dtdPart'- = unlistA >>> isDTDAttlist- >>>- isDefaultAttrKind- >>>+ = unlistA >>> isDTDAttlist+ >>>+ isDefaultAttrKind+ >>> (checkAttributeValue dtdPart' $< this) -- ------------------------------------------------------------@@ -557,33 +557,33 @@ removeDoublicateDefs = replaceChildren ( fromSLA [] ( getChildren- >>>- choiceA [ isDTDAttlist :-> (removeDoubleAttlist $< getDTDAttrl)- , isDTDEntity :-> (removeDoubleEntity $< getDTDAttrl)- , this :-> this- ]- )+ >>>+ choiceA [ isDTDAttlist :-> (removeDoubleAttlist $< getDTDAttrl)+ , isDTDEntity :-> (removeDoubleEntity $< getDTDAttrl)+ , this :-> this+ ]+ ) ) `when` isDTDDoctype where checkName' n'- = ifA ( getState- >>>- isA (n' `elem`)- )- none- (this >>> perform (nextState (n':)))+ = ifA ( getState+ >>>+ isA (n' `elem`)+ )+ none+ (this >>> perform (nextState (n':))) removeDoubleAttlist :: Attributes -> SLA [String] XmlTree XmlTree removeDoubleAttlist al- = checkName' elemAttr- where- elemAttr = elemName ++ "|" ++ attrName- attrName = dtd_value al- elemName = dtd_name al+ = checkName' elemAttr+ where+ elemAttr = elemName ++ "|" ++ attrName+ attrName = dtd_value al+ elemName = dtd_name al - removeDoubleEntity :: Attributes -> SLA [String] XmlTree XmlTree+ removeDoubleEntity :: Attributes -> SLA [String] XmlTree XmlTree removeDoubleEntity al = checkName' (dtd_name al)
src/Text/XML/HXT/DTDValidation/DocTransformation.hs view
@@ -49,10 +49,10 @@ -- Lookup-table which maps element names to their transformation functions. The -- transformation functions are XmlArrows. -type TransEnvTable = [TransEnv]-type TransEnv = (ElemName, TransFct)-type ElemName = String-type TransFct = XmlArrow+type TransEnvTable = [TransEnv]+type TransEnv = (ElemName, TransFct)+type ElemName = String+type TransFct = XmlArrow -- ------------------------------------------------------------@@ -83,15 +83,15 @@ traverseTree transEnv = processTopDown ( ( (transFct $< getName)- >>>- processChildren (traverseTree transEnv)- )+ >>>+ processChildren (traverseTree transEnv)+ ) `when` isElem ) where- transFct :: String -> XmlArrow- transFct name = fromMaybe this . lookup name $ transEnv+ transFct :: String -> XmlArrow+ transFct name = fromMaybe this . lookup name $ transEnv -- | -- Build all transformation functions.@@ -119,16 +119,16 @@ buildTransformationFunctions :: XmlTrees -> XmlTree -> [TransEnv] buildTransformationFunctions dtdPart dn- | isDTDElementNode dn = [(name, transFct)]- | otherwise = []+ | isDTDElementNode dn = [(name, transFct)]+ | otherwise = [] where- al = getDTDAttributes dn- name = dtd_name al- transFct = setDefaultAttributeValues dtdPart dn- >>>- normalizeAttributeValues dtdPart dn- >>>- lexicographicAttributeOrder+ al = getDTDAttributes dn+ name = dtd_name al+ transFct = setDefaultAttributeValues dtdPart dn+ >>>+ normalizeAttributeValues dtdPart dn+ >>>+ lexicographicAttributeOrder -- ------------------------------------------------------------ @@ -142,8 +142,8 @@ lexicographicAttributeOrder = setAttrl (getAttrl >>. sortAttrl) where- sortAttrl :: XmlTrees -> XmlTrees- sortAttrl = sortBy (comparing nameOfAttr)+ sortAttrl :: XmlTrees -> XmlTrees+ sortAttrl = sortBy (comparing nameOfAttr) -- | -- Normalize attribute values.@@ -153,25 +153,25 @@ normalizeAttributeValues :: XmlTrees -> XmlTree -> XmlArrow normalizeAttributeValues dtdPart dn- | isDTDElementNode dn = processAttrl (normalizeAttr $< getName)- | otherwise = this+ | isDTDElementNode dn = processAttrl (normalizeAttr $< getName)+ | otherwise = this where- al = getDTDAttributes dn- elemName = dtd_name al+ al = getDTDAttributes dn+ elemName = dtd_name al declaredAtts = isAttlistOfElement elemName $$ dtdPart normalizeAttr :: String -> XmlArrow normalizeAttr nameOfAtt- = normalizeAttrValue ( if null attDescr- then Nothing- else Just (head attDescr)- )- where- attDescr = filter ((== nameOfAtt) . valueOfDTD a_value) declaredAtts+ = normalizeAttrValue ( if null attDescr+ then Nothing+ else Just (head attDescr)+ )+ where+ attDescr = filter ((== nameOfAtt) . valueOfDTD a_value) declaredAtts normalizeAttrValue :: Maybe XmlTree -> XmlArrow normalizeAttrValue descr- = replaceChildren ((xshow getChildren >>^ normalizeAttributeValue descr) >>> mkText)+ = replaceChildren ((xshow getChildren >>^ normalizeAttributeValue descr) >>> mkText) -- | -- Set default attribute values if they are not set.@@ -181,30 +181,30 @@ setDefaultAttributeValues :: XmlTrees -> XmlTree -> XmlArrow setDefaultAttributeValues dtdPart dn- | isDTDElementNode dn = seqA (map setDefault defaultAtts)- | otherwise = this+ | isDTDElementNode dn = seqA (map setDefault defaultAtts)+ | otherwise = this where- elemName = dtd_name . getDTDAttributes $ dn- defaultAtts = ( isAttlistOfElement elemName- >>>- ( isFixedAttrKind -- select attributes with default values- `orElse`- isDefaultAttrKind- )- ) $$ dtdPart+ elemName = dtd_name . getDTDAttributes $ dn+ defaultAtts = ( isAttlistOfElement elemName+ >>>+ ( isFixedAttrKind -- select attributes with default values+ `orElse`+ isDefaultAttrKind+ )+ ) $$ dtdPart - setDefault :: XmlTree -> XmlArrow- setDefault attrDescr -- add the default attributes- = ( addAttr attName defaultValue -- to tag nodes with missing attributes- `whenNot`- hasAttr attName- )- `when`- isElem- where- al = getDTDAttributes attrDescr- attName = dtd_value al- defaultValue = dtd_default al+ setDefault :: XmlTree -> XmlArrow+ setDefault attrDescr -- add the default attributes+ = ( addAttr attName defaultValue -- to tag nodes with missing attributes+ `whenNot`+ hasAttr attName+ )+ `when`+ isElem+ where+ al = getDTDAttributes attrDescr+ attName = dtd_value al+ defaultValue = dtd_default al -- ------------------------------------------------------------
src/Text/XML/HXT/DTDValidation/DocValidation.hs view
@@ -40,10 +40,10 @@ -- Lookup-table which maps element names to their validation functions. The -- validation functions are XmlArrows. -type ValiEnvTable = [ValiEnv]-type ValiEnv = (ElemName, ValFct)-type ElemName = String-type ValFct = XmlArrow+type ValiEnvTable = [ValiEnv]+type ValiEnv = (ElemName, ValFct)+type ElemName = String+type ValFct = XmlArrow -- ------------------------------------------------------------@@ -57,7 +57,7 @@ -- -- - returns : a list of errors -validateDoc :: XmlTree -> XmlArrow+validateDoc :: XmlTree -> XmlArrow validateDoc dtdPart = traverseTree valTable where@@ -71,18 +71,18 @@ -- -- - returns : list of errors -traverseTree :: ValiEnvTable -> XmlArrow+traverseTree :: ValiEnvTable -> XmlArrow traverseTree valiEnv- = choiceA [ isElem :-> (valFct $< getQName)- , this :-> none- ]+ = choiceA [ isElem :-> (valFct $< getQName)+ , this :-> none+ ] <+> ( getChildren >>> traverseTree valiEnv ) where- valFct :: QName -> XmlArrow- valFct name = case (lookup (qualifiedName name) valiEnv) of- Nothing -> err ("Element " ++ show (qualifiedName name) ++ " not declared in DTD.")- Just f -> f+ valFct :: QName -> XmlArrow+ valFct name = case (lookup (qualifiedName name) valiEnv) of+ Nothing -> err ("Element " ++ show (qualifiedName name) ++ " not declared in DTD.")+ Just f -> f -- ------------------------------------------------------------ @@ -96,7 +96,7 @@ buildAllValidationFunctions :: XmlTree -> ValiEnvTable buildAllValidationFunctions dtdPart = concat $- buildValidateRoot dtdPart : -- construct a list of validation filters for all element declarations+ buildValidateRoot dtdPart : -- construct a list of validation filters for all element declarations map (buildValidateFunctions dtdNodes) dtdNodes where dtdNodes = runLA getChildren dtdPart@@ -111,22 +111,22 @@ buildValidateRoot :: XmlTree -> [ValiEnv] buildValidateRoot dn- | isDTDDoctypeNode dn = [(t_root, valFct)]- | otherwise = []+ | isDTDDoctypeNode dn = [(t_root, valFct)]+ | otherwise = [] where- name = dtd_name . getDTDAttributes $ dn+ name = dtd_name . getDTDAttributes $ dn - valFct :: XmlArrow- valFct = isElem- `guards`- ( checkRegex (re_sym name)- >>>- msgToErr (("Root Element must be " ++ show name ++ ". ") ++)- )+ valFct :: XmlArrow+ valFct = isElem+ `guards`+ ( checkRegex (re_sym name)+ >>>+ msgToErr (("Root Element must be " ++ show name ++ ". ") ++)+ ) -checkRegex :: RE String -> LA XmlTree String-checkRegex re = listA getChildren- >>> arr (\ cs -> checkRE (matches re cs))+checkRegex :: RE String -> LA XmlTree String+checkRegex re = listA getChildren+ >>> arr (\ cs -> checkRE (matches re cs)) -- | -- Build validation functions for an element.@@ -141,15 +141,15 @@ buildValidateFunctions :: XmlTrees -> XmlTree -> [ValiEnv] buildValidateFunctions dtdPart dn- | isDTDElementNode dn = [(elemName, valFct)]- | otherwise = []+ | isDTDElementNode dn = [(elemName, valFct)]+ | otherwise = [] where elemName = dtd_name . getDTDAttributes $ dn valFct :: XmlArrow valFct = buildContentValidation dn <+>- buildAttributeValidation dtdPart dn+ buildAttributeValidation dtdPart dn -- ------------------------------------------------------------ @@ -181,80 +181,80 @@ | typ == v_children = contentValidationChildren cs | typ == v_mixed = contentValidationMixed cs | otherwise = none- where- cs = runLA getChildren dn+ where+ cs = runLA getChildren dn -- Checks #PCDATA content models contentValidationPcdata :: XmlArrow contentValidationPcdata- = isElem `guards` (contentVal $< getQName)- where- contentVal name- = checkRegex (re_rep (re_sym k_pcdata))- >>>- msgToErr ( ( "The content of element " ++- show (qualifiedName name) ++- " must match (#PCDATA). "- ) ++- )+ = isElem `guards` (contentVal $< getQName)+ where+ contentVal name+ = checkRegex (re_rep (re_sym k_pcdata))+ >>>+ msgToErr ( ( "The content of element " +++ show (qualifiedName name) +++ " must match (#PCDATA). "+ ) +++ ) -- Checks EMPTY content models contentValidationEmpty :: XmlArrow contentValidationEmpty- = isElem `guards` (contentVal $< getQName)- where- contentVal name- = checkRegex re_unit- >>>- msgToErr ( ( "The content of element " ++- show (qualifiedName name) ++- " must match EMPTY. "- ) ++- )+ = isElem `guards` (contentVal $< getQName)+ where+ contentVal name+ = checkRegex re_unit+ >>>+ msgToErr ( ( "The content of element " +++ show (qualifiedName name) +++ " must match EMPTY. "+ ) +++ ) -- Checks ANY content models contentValidationAny :: XmlArrow contentValidationAny- = isElem `guards` (contentVal $< getName)- where- contentVal name- = checkRegex (re_rep (re_dot))- >>>- msgToErr ( ( "The content of element " ++- show name ++- " must match ANY. "- ) ++- )+ = isElem `guards` (contentVal $< getName)+ where+ contentVal name+ = checkRegex (re_rep (re_dot))+ >>>+ msgToErr ( ( "The content of element " +++ show name +++ " must match ANY. "+ ) +++ ) -- Checks "children" content models contentValidationChildren :: XmlTrees -> XmlArrow contentValidationChildren cm- = isElem `guards` (contentVal $< getName)- where- contentVal name- = checkRegex re- >>>- msgToErr ( ( "The content of element " ++- show name ++- " must match " ++ printRE re ++ ". "- ) ++- )- re = createRE (head cm)+ = isElem `guards` (contentVal $< getName)+ where+ contentVal name+ = checkRegex re+ >>>+ msgToErr ( ( "The content of element " +++ show name +++ " must match " ++ printRE re ++ ". "+ ) +++ )+ re = createRE (head cm) -- Checks "mixed content" content models contentValidationMixed :: XmlTrees -> XmlArrow contentValidationMixed cm- = isElem `guards` (contentVal $< getName)- where- contentVal name- = checkRegex re- >>>- msgToErr ( ( "The content of element " ++- show name ++- " must match " ++ printRE re ++ ". "- ) ++- )- re = re_rep (re_alt (re_sym k_pcdata) (createRE (head cm)))+ = isElem `guards` (contentVal $< getName)+ where+ contentVal name+ = checkRegex re+ >>>+ msgToErr ( ( "The content of element " +++ show name +++ " must match " ++ printRE re ++ ". "+ ) +++ )+ re = re_rep (re_alt (re_sym k_pcdata) (createRE (head cm))) -- | -- Build a regular expression from the content model. The regular expression@@ -265,34 +265,34 @@ -- -- - returns : regular expression of the content model -createRE :: XmlTree -> RE String+createRE :: XmlTree -> RE String createRE dn | isDTDContentNode dn- = processModifier modifier+ = processModifier modifier | isDTDNameNode dn- = re_sym name+ = re_sym name | otherwise- = error ("createRE: illegeal parameter:\n" ++ show dn)+ = error ("createRE: illegeal parameter:\n" ++ show dn) where- al = getDTDAttributes dn- name = dtd_name al- modifier = dtd_modifier al- kind = dtd_kind al- cs = runLA getChildren dn+ al = getDTDAttributes dn+ name = dtd_name al+ modifier = dtd_modifier al+ kind = dtd_kind al+ cs = runLA getChildren dn processModifier :: String -> RE String processModifier m- | m == v_plus = re_plus (processKind kind)- | m == v_star = re_rep (processKind kind)- | m == v_option = re_opt (processKind kind)- | m == v_null = processKind kind- | otherwise = error ("Unknown modifier: " ++ show m)+ | m == v_plus = re_plus (processKind kind)+ | m == v_star = re_rep (processKind kind)+ | m == v_option = re_opt (processKind kind)+ | m == v_null = processKind kind+ | otherwise = error ("Unknown modifier: " ++ show m) processKind :: String -> RE String processKind k- | k == v_seq = makeSequence cs- | k == v_choice = makeChoice cs- | otherwise = error ("Unknown kind: " ++ show k)+ | k == v_seq = makeSequence cs+ | k == v_choice = makeChoice cs+ | otherwise = error ("Unknown kind: " ++ show k) makeSequence :: XmlTrees -> RE String makeSequence [] = re_unit@@ -337,20 +337,20 @@ -- - returns : a function which takes an element (XTag), checks if its -- attributes are unique and returns a list of errors -noDoublicateAttributes :: XmlArrow+noDoublicateAttributes :: XmlArrow noDoublicateAttributes = isElem `guards` ( noDoubles' $< getName ) where noDoubles' elemName- = listA (getAttrl >>> getName)- >>> applyA (arr (catA . map toErr . doubles . reverse))- where- toErr n1 = err ( "Attribute " ++ show n1 ++- " was already specified for element " ++- show elemName ++ "."- )+ = listA (getAttrl >>> getName)+ >>> applyA (arr (catA . map toErr . doubles . reverse))+ where+ toErr n1 = err ( "Attribute " ++ show n1 +++ " was already specified for element " +++ show elemName ++ "."+ ) -- | -- Validate that all \#REQUIRED attributes are provided.@@ -363,30 +363,30 @@ -- - returns : a function which takes an element (XTag), checks if all -- required attributes are provided and returns a list of errors -checkRequiredAttributes :: XmlTrees -> XmlTree -> XmlArrow+checkRequiredAttributes :: XmlTrees -> XmlTree -> XmlArrow checkRequiredAttributes attrDecls dn | isDTDElementNode dn- = isElem- `guards`- ( checkRequired $< getName )+ = isElem+ `guards`+ ( checkRequired $< getName ) | otherwise- = none+ = none where elemName = dtd_name . getDTDAttributes $ dn requiredAtts = (isAttlistOfElement elemName >>> isRequiredAttrKind) $$ attrDecls checkRequired :: String -> XmlArrow checkRequired name- = catA . map checkReq $ requiredAtts- where- checkReq :: XmlTree -> XmlArrow- checkReq attrDecl- = neg (hasAttr attName)- `guards`- err ( "Attribute " ++ show attName ++ " must be declared for element type " ++- show name ++ "." )- where- attName = dtd_value . getDTDAttributes $ attrDecl+ = catA . map checkReq $ requiredAtts+ where+ checkReq :: XmlTree -> XmlArrow+ checkReq attrDecl+ = neg (hasAttr attName)+ `guards`+ err ( "Attribute " ++ show attName ++ " must be declared for element type " +++ show name ++ "." )+ where+ attName = dtd_value . getDTDAttributes $ attrDecl -- | -- Validate that \#FIXED attributes match the default value.@@ -402,44 +402,44 @@ checkFixedAttributes :: XmlTrees -> XmlTree -> XmlArrow checkFixedAttributes attrDecls dn | isDTDElementNode dn- = isElem- `guards`- ( checkFixed $< getName )+ = isElem+ `guards`+ ( checkFixed $< getName ) | otherwise- = none+ = none where elemName = dtd_name . getDTDAttributes $ dn fixedAtts = (isAttlistOfElement elemName >>> isFixedAttrKind) $$ attrDecls checkFixed :: String -> XmlArrow checkFixed name- = catA . map checkFix $ fixedAtts- where- checkFix :: XmlTree -> XmlArrow- checkFix an- | isDTDAttlistNode an- = checkFixedVal $< getAttrValue attName- | otherwise- = none- where- al' = getDTDAttributes an- attName = dtd_value al'- defa = dtd_default al'- fixedValue = normalizeAttributeValue (Just an) defa+ = catA . map checkFix $ fixedAtts+ where+ checkFix :: XmlTree -> XmlArrow+ checkFix an+ | isDTDAttlistNode an+ = checkFixedVal $< getAttrValue attName+ | otherwise+ = none+ where+ al' = getDTDAttributes an+ attName = dtd_value al'+ defa = dtd_default al'+ fixedValue = normalizeAttributeValue (Just an) defa - checkFixedVal :: String -> XmlArrow- checkFixedVal val- = ( ( hasAttr attName- >>>- isA (const (attValue /= fixedValue))- )- `guards`- err ( "Attribute " ++ show attName ++ " of element " ++ show name ++- " with value " ++ show attValue ++ " must have a value of " ++- show fixedValue ++ "." )- )- where- attValue = normalizeAttributeValue (Just an) val+ checkFixedVal :: String -> XmlArrow+ checkFixedVal val+ = ( ( hasAttr attName+ >>>+ isA (const (attValue /= fixedValue))+ )+ `guards`+ err ( "Attribute " ++ show attName ++ " of element " ++ show name +++ " with value " ++ show attValue ++ " must have a value of " +++ show fixedValue ++ "." )+ )+ where+ attValue = normalizeAttributeValue (Just an) val -- | -- Validate that an element has no attributes which are not declared.@@ -461,24 +461,24 @@ checkNotDeclared :: XmlArrow checkNotDeclared- = isElem- `guards`- ( getAttrl >>> searchForDeclaredAtt elemName decls )+ = isElem+ `guards`+ ( getAttrl >>> searchForDeclaredAtt elemName decls ) searchForDeclaredAtt :: String -> XmlTrees -> XmlArrow searchForDeclaredAtt name (dn : xs)- | isDTDAttlistNode dn- = ( getName >>> isA ( (dtd_value . getDTDAttributes $ dn) /= ) )- `guards`- searchForDeclaredAtt name xs- | otherwise- = searchForDeclaredAtt name xs+ | isDTDAttlistNode dn+ = ( getName >>> isA ( (dtd_value . getDTDAttributes $ dn) /= ) )+ `guards`+ searchForDeclaredAtt name xs+ | otherwise+ = searchForDeclaredAtt name xs searchForDeclaredAtt name []- = mkErr $< getName- where- mkErr n = err ( "Attribute " ++ show n ++ " of element " ++- show name ++ " is not declared in DTD." )+ = mkErr $< getName+ where+ mkErr n = err ( "Attribute " ++ show n ++ " of element " +++ show name ++ " is not declared in DTD." ) -- | -- Validate that the attribute value meets the lexical constraints of its type.@@ -495,27 +495,27 @@ checkValuesOfAttributes attrDecls dtdPart elemDescr = checkValues where- elemName = dtd_name . getDTDAttributes $ elemDescr+ elemName = dtd_name . getDTDAttributes $ elemDescr decls = isAttlistOfElement elemName $$ attrDecls checkValues :: XmlArrow checkValues- = isElem- `guards`- ( checkValue $< getAttrl )+ = isElem+ `guards`+ ( checkValue $< getAttrl ) checkValue att- = catA . map checkVal $ decls- where- checkVal :: XmlTree -> XmlArrow- checkVal attrDecl- | isDTDAttlistNode attrDecl- &&- nameOfAttr att == dtd_value al'- = checkAttributeValue dtdPart attrDecl- | otherwise- = none- where- al' = getDTDAttributes attrDecl+ = catA . map checkVal $ decls+ where+ checkVal :: XmlTree -> XmlArrow+ checkVal attrDecl+ | isDTDAttlistNode attrDecl+ &&+ nameOfAttr att == dtd_value al'+ = checkAttributeValue dtdPart attrDecl+ | otherwise+ = none+ where+ al' = getDTDAttributes attrDecl -- ------------------------------------------------------------
src/Text/XML/HXT/DTDValidation/IdValidation.hs view
@@ -44,10 +44,10 @@ -- Lookup-table which maps element names to their validation functions. The -- validation functions are XmlFilters. -type IdEnvTable = [IdEnv]-type IdEnv = (ElemName, IdFct)-type ElemName = String-type IdFct = XmlArrow+type IdEnvTable = [IdEnv]+type IdEnv = (ElemName, IdFct)+type ElemName = String+type IdFct = XmlArrow -- ------------------------------------------------------------ @@ -65,17 +65,17 @@ = validateIds' $< listA (traverseTree idEnv) where idAttrTypes = runLA (getChildren >>> isIdAttrType) dtdPart- elements = runLA (getChildren >>> isDTDElement) dtdPart+ elements = runLA (getChildren >>> isDTDElement) dtdPart atts = runLA (getChildren >>> isDTDAttlist) dtdPart- idEnv = buildIdCollectorFcts idAttrTypes+ idEnv = buildIdCollectorFcts idAttrTypes - validateIds' :: XmlTrees -> XmlArrow+ validateIds' :: XmlTrees -> XmlArrow validateIds' idNodeList- = ( constA idNodeList >>> checkForUniqueIds idAttrTypes )- <+>- checkIdReferences idRefEnv- where- idRefEnv = buildIdrefValidationFcts idAttrTypes elements atts idNodeList+ = ( constA idNodeList >>> checkForUniqueIds idAttrTypes )+ <+>+ checkIdReferences idRefEnv+ where+ idRefEnv = buildIdrefValidationFcts idAttrTypes elements atts idNodeList @@ -90,8 +90,8 @@ traverseTree idEnv = multi (isElem `guards` (idFct $< getName)) where- idFct :: String -> XmlArrow- idFct name = fromMaybe none . lookup name $ idEnv+ idFct :: String -> XmlArrow+ idFct name = fromMaybe none . lookup name $ idEnv -- | -- Returns the value of an element's ID attribute. The attribute name has to be@@ -103,26 +103,26 @@ -- -- - returns : normalized value of the ID attribute -getIdValue :: XmlTrees -> XmlTree -> String+getIdValue :: XmlTrees -> XmlTree -> String getIdValue dns = concat . runLA (single getIdValue') where- getIdValue' :: LA XmlTree String+ getIdValue' :: LA XmlTree String getIdValue'- = isElem `guards` catA (map getIdVal dns)- where- getIdVal dn- | isDTDAttlistNode dn = hasName elemName- `guards`- ( getAttrValue0 attrName- >>>- arr (normalizeAttributeValue (Just dn))- )- | otherwise = none- where- al = getDTDAttributes dn- elemName = dtd_name al- attrName = dtd_value al+ = isElem `guards` catA (map getIdVal dns)+ where+ getIdVal dn+ | isDTDAttlistNode dn = hasName elemName+ `guards`+ ( getAttrValue0 attrName+ >>>+ arr (normalizeAttributeValue (Just dn))+ )+ | otherwise = none+ where+ al = getDTDAttributes dn+ elemName = dtd_name al+ attrName = dtd_value al -- ------------------------------------------------------------ @@ -141,12 +141,12 @@ where buildIdCollectorFct :: XmlTree -> [IdEnv] buildIdCollectorFct dn- | isDTDAttlistNode dn = [(elemName, hasAttr attrName)]- | otherwise = []- where- al = getDTDAttributes dn+ | isDTDAttlistNode dn = [(elemName, hasAttr attrName)]+ | otherwise = []+ where+ al = getDTDAttributes dn elemName = dtd_name al- attrName = dtd_value al+ attrName = dtd_value al -- | -- Build validation functions for checking if IDREF\/IDREFS values match a value@@ -166,54 +166,54 @@ buildElemValidationFct :: XmlTree -> [IdEnv] buildElemValidationFct dn- | isDTDElementNode dn = [(elemName, buildIdrefValidationFct idRefAttrTypes)]- | otherwise = []- where- al = getDTDAttributes dn- elemName = dtd_name al- idRefAttrTypes = (isAttlistOfElement elemName >>> isIdRefAttrType) $$ atts+ | isDTDElementNode dn = [(elemName, buildIdrefValidationFct idRefAttrTypes)]+ | otherwise = []+ where+ al = getDTDAttributes dn+ elemName = dtd_name al+ idRefAttrTypes = (isAttlistOfElement elemName >>> isIdRefAttrType) $$ atts buildIdrefValidationFct :: XmlTrees -> XmlArrow buildIdrefValidationFct- = catA . map buildIdref+ = catA . map buildIdref - buildIdref :: XmlTree -> XmlArrow+ buildIdref :: XmlTree -> XmlArrow buildIdref dn- | isDTDAttlistNode dn = isElem >>> (checkIdref $< getName)- | otherwise = none- where- al = getDTDAttributes dn- attrName = dtd_value al- attrType = dtd_type al+ | isDTDAttlistNode dn = isElem >>> (checkIdref $< getName)+ | otherwise = none+ where+ al = getDTDAttributes dn+ attrName = dtd_value al+ attrType = dtd_type al - checkIdref :: String -> XmlArrow- checkIdref name- = hasAttr attrName- `guards`- ( checkIdVal $< getAttrValue attrName )- where- checkIdVal :: String -> XmlArrow- checkIdVal av- | attrType == k_idref- = checkValueDeclared attrValue- | null valueList- = err ( "Attribute " ++ show attrName ++- " of Element " ++ show name ++- " must have at least one name."- )- | otherwise- = catA . map checkValueDeclared $ valueList- where- valueList = words attrValue- attrValue = normalizeAttributeValue (Just dn) av+ checkIdref :: String -> XmlArrow+ checkIdref name+ = hasAttr attrName+ `guards`+ ( checkIdVal $< getAttrValue attrName )+ where+ checkIdVal :: String -> XmlArrow+ checkIdVal av+ | attrType == k_idref+ = checkValueDeclared attrValue+ | null valueList+ = err ( "Attribute " ++ show attrName +++ " of Element " ++ show name +++ " must have at least one name."+ )+ | otherwise+ = catA . map checkValueDeclared $ valueList+ where+ valueList = words attrValue+ attrValue = normalizeAttributeValue (Just dn) av - checkValueDeclared :: String -> XmlArrow- checkValueDeclared attrValue- = if attrValue `elem` idValueList- then none- else err ( "An Element with identifier " ++ show attrValue ++- " must appear in the document."- )+ checkValueDeclared :: String -> XmlArrow+ checkValueDeclared attrValue+ = if attrValue `elem` idValueList+ then none+ else err ( "An Element with identifier " ++ show attrValue +++ " must appear in the document."+ ) -- ------------------------------------------------------------ @@ -229,25 +229,25 @@ -- - returns : a list of errors checkForUniqueIds :: XmlTrees -> LA XmlTrees XmlTree-checkForUniqueIds idAttrTypes -- idNodeList+checkForUniqueIds idAttrTypes -- idNodeList = fromSLA [] ( unlistA- >>>- isElem- >>>- (checkForUniqueId $<< getName &&& this)- )+ >>>+ isElem+ >>>+ (checkForUniqueId $<< getName &&& this)+ ) where checkForUniqueId :: String -> XmlTree -> SLA [String] XmlTree XmlTree checkForUniqueId name x- = ifA ( getState- >>>- isA (attrValue `elem`)- )- (err ( "Attribute value " ++ show attrValue ++ " of type ID for element " ++- show name ++ " must be unique within the document." ))+ = ifA ( getState+ >>>+ isA (attrValue `elem`)+ )+ (err ( "Attribute value " ++ show attrValue ++ " of type ID for element " +++ show name ++ " must be unique within the document." )) (nextState (attrValue:) >>> none)- where- attrValue = getIdValue (isAttlistOfElement name $$ idAttrTypes) x+ where+ attrValue = getIdValue (isAttlistOfElement name $$ idAttrTypes) x -- | -- Validate that all IDREF\/IDREFS values match the value of some ID attribute.
src/Text/XML/HXT/DTDValidation/RE.hs view
@@ -18,11 +18,11 @@ Janusz A. Brzozowski. - Derivatives of Regular Expressions. Journal of the ACM, Volume 11, Issue 4, 1964. + Derivatives of Regular Expressions. Journal of the ACM, Volume 11, Issue 4, 1964. Mark Hopkins. - Regular Expression Package. Posted to comp.compilers, 1994.+ Regular Expression Package. Posted to comp.compilers, 1994. Available per FTP at <ftp://iecc.com/pub/file/regex.tar.gz>. -} @@ -52,16 +52,16 @@ -- Data type for regular expressions. data RE a =- RE_ZERO String --' L(0) = {} (empty set)- | RE_UNIT --' L(1) = { [] } (empty sequence)- | RE_SYM a --' L(x) = { [x] }- | RE_DOT --' accept any single symbol- | RE_REP (RE a) --' L(e*) = { [] } `union` L(e+)- | RE_PLUS (RE a) --' L(e+) = { x ++ y | x <- L(e), y <- L(e*) }- | RE_OPT (RE a) --' L(e?) = L(e) `union` { [] }- | RE_SEQ (RE a) (RE a) --' L(e,f) = { x ++ y | x <- L(e), y <- L(f) }- | RE_ALT (RE a) (RE a) --' L(e|f) = L(e) `union` L(f)- deriving (Show, Eq)+ RE_ZERO String --' L(0) = {} (empty set)+ | RE_UNIT --' L(1) = { [] } (empty sequence)+ | RE_SYM a --' L(x) = { [x] }+ | RE_DOT --' accept any single symbol+ | RE_REP (RE a) --' L(e*) = { [] } `union` L(e+)+ | RE_PLUS (RE a) --' L(e+) = { x ++ y | x <- L(e), y <- L(e*) }+ | RE_OPT (RE a) --' L(e?) = L(e) `union` { [] }+ | RE_SEQ (RE a) (RE a) --' L(e,f) = { x ++ y | x <- L(e), y <- L(f) }+ | RE_ALT (RE a) (RE a) --' L(e|f) = L(e) `union` L(f)+ deriving (Show, Eq) @@ -75,8 +75,8 @@ -- -- - returns : regular expression for an empty set -re_zero :: String -> RE a-re_zero m = RE_ZERO m+re_zero :: String -> RE a+re_zero m = RE_ZERO m -- |@@ -84,8 +84,8 @@ -- -- - returns : regular expression for an empty sequence -re_unit :: RE a-re_unit = RE_UNIT+re_unit :: RE a+re_unit = RE_UNIT -- |@@ -95,8 +95,8 @@ -- -- - returns : regular expression for accepting a symbol -re_sym :: a -> RE a-re_sym x = RE_SYM x+re_sym :: a -> RE a+re_sym x = RE_SYM x -- |@@ -104,8 +104,8 @@ -- -- - returns : regular expression for accepting any singel symbol -re_dot :: RE a-re_dot = RE_DOT+re_dot :: RE a+re_dot = RE_DOT -- |@@ -115,12 +115,12 @@ -- -- - returns : new regular expression -re_rep :: RE a -> RE a-re_rep RE_UNIT = RE_UNIT-re_rep (RE_ZERO _) = RE_UNIT-re_rep e@(RE_REP _) = RE_REP (rem_rep e) -- remove nested reps-re_rep e@(RE_ALT _ _) = RE_REP (rem_rep e) -- remove nested reps in alternatives-re_rep e = RE_REP e+re_rep :: RE a -> RE a+re_rep RE_UNIT = RE_UNIT+re_rep (RE_ZERO _) = RE_UNIT+re_rep e@(RE_REP _) = RE_REP (rem_rep e) -- remove nested reps+re_rep e@(RE_ALT _ _) = RE_REP (rem_rep e) -- remove nested reps in alternatives+re_rep e = RE_REP e -- | -- remove redundant nested *'s in RE@@ -128,10 +128,10 @@ -- but without this simplification the runtime can increase exponentally -- when computing deltas, e.g. for a** or (a|b*)* which is the same as (a|b)* -rem_rep :: RE a -> RE a-rem_rep (RE_ALT e1 e2) = RE_ALT (rem_rep e1) (rem_rep e2)-rem_rep (RE_REP e1) = rem_rep e1-rem_rep e1 = e1+rem_rep :: RE a -> RE a+rem_rep (RE_ALT e1 e2) = RE_ALT (rem_rep e1) (rem_rep e2)+rem_rep (RE_REP e1) = rem_rep e1+rem_rep e1 = e1 -- |@@ -141,10 +141,10 @@ -- -- - returns : new regular expression -re_plus :: RE a -> RE a-re_plus RE_UNIT = RE_UNIT-re_plus (RE_ZERO m) = RE_ZERO m-re_plus e = RE_PLUS e+re_plus :: RE a -> RE a+re_plus RE_UNIT = RE_UNIT+re_plus (RE_ZERO m) = RE_ZERO m+re_plus e = RE_PLUS e -- |@@ -154,10 +154,10 @@ -- -- - returns : new regular expression -re_opt :: RE a -> RE a-re_opt RE_UNIT = RE_UNIT-re_opt (RE_ZERO _) = RE_UNIT-re_opt e = RE_OPT e+re_opt :: RE a -> RE a+re_opt RE_UNIT = RE_UNIT+re_opt (RE_ZERO _) = RE_UNIT+re_opt e = RE_OPT e -- |@@ -169,12 +169,12 @@ -- -- - returns : new regular expression -re_seq :: RE a -> RE a -> RE a-re_seq (RE_ZERO m) _ = RE_ZERO m-re_seq RE_UNIT f = f-re_seq _ (RE_ZERO m) = RE_ZERO m-re_seq e RE_UNIT = e-re_seq e f = RE_SEQ e f+re_seq :: RE a -> RE a -> RE a+re_seq (RE_ZERO m) _ = RE_ZERO m+re_seq RE_UNIT f = f+re_seq _ (RE_ZERO m) = RE_ZERO m+re_seq e RE_UNIT = e+re_seq e f = RE_SEQ e f -- |@@ -186,10 +186,10 @@ -- -- - returns : new regular expression -re_alt :: RE a -> RE a -> RE a-re_alt (RE_ZERO _) f = f-re_alt e (RE_ZERO _) = e-re_alt e f = RE_ALT e f+re_alt :: RE a -> RE a -> RE a+re_alt (RE_ZERO _) f = f+re_alt e (RE_ZERO _) = e+re_alt e f = RE_ALT e f @@ -208,16 +208,16 @@ -- - returns : true if regular expression matches the empty sequence, -- otherwise false -nullable :: (Show a) => RE a -> Bool-nullable (RE_ZERO _) = False-nullable RE_UNIT = True-nullable (RE_SYM _) = False-nullable (RE_REP _) = True-nullable (RE_PLUS e) = nullable e-nullable (RE_OPT _) = True-nullable (RE_SEQ e f) = nullable e && nullable f-nullable (RE_ALT e f) = nullable e || nullable f-nullable RE_DOT = False+nullable :: (Show a) => RE a -> Bool+nullable (RE_ZERO _) = False+nullable RE_UNIT = True+nullable (RE_SYM _) = False+nullable (RE_REP _) = True+nullable (RE_PLUS e) = nullable e+nullable (RE_OPT _) = True+nullable (RE_SEQ e f) = nullable e && nullable f+nullable (RE_ALT e f) = nullable e || nullable f+nullable RE_DOT = False -- |@@ -233,19 +233,19 @@ delta :: (Eq a, Show a) => RE a -> a -> RE a delta re x = case re of- RE_ZERO _ -> re -- re_zero m- RE_UNIT -> re_zero ("Symbol " ++ show x ++ " unexpected.")- RE_SYM sym- | x == sym -> re_unit- | otherwise -> re_zero ("Symbol " ++ show sym ++ " expected, but symbol " ++ show x ++ " found.")- RE_REP e -> re_seq (delta e x) re -- (re_rep e)- RE_PLUS e -> re_seq (delta e x) (re_rep e)- RE_OPT e -> delta e x- RE_SEQ e f- | nullable e -> re_alt (re_seq (delta e x) f) (delta f x)- | otherwise -> re_seq (delta e x) f- RE_ALT e f -> re_alt (delta e x) (delta f x)- RE_DOT -> re_unit+ RE_ZERO _ -> re -- re_zero m+ RE_UNIT -> re_zero ("Symbol " ++ show x ++ " unexpected.")+ RE_SYM sym+ | x == sym -> re_unit+ | otherwise -> re_zero ("Symbol " ++ show sym ++ " expected, but symbol " ++ show x ++ " found.")+ RE_REP e -> re_seq (delta e x) re -- (re_rep e)+ RE_PLUS e -> re_seq (delta e x) (re_rep e)+ RE_OPT e -> delta e x+ RE_SEQ e f+ | nullable e -> re_alt (re_seq (delta e x) f) (delta f x)+ | otherwise -> re_seq (delta e x) f+ RE_ALT e f -> re_alt (delta e x) (delta f x)+ RE_DOT -> re_unit -- |@@ -274,11 +274,11 @@ -- an error message is returned checkRE :: (Show a) => RE a -> String-checkRE (RE_UNIT) = ""-checkRE (RE_ZERO m) = m+checkRE (RE_UNIT) = ""+checkRE (RE_ZERO m) = m checkRE re- | nullable re = ""- | otherwise = "Input must match " ++ printRE re+ | nullable re = ""+ | otherwise = "Input must match " ++ printRE re @@ -299,29 +299,29 @@ where printRE1 :: (Show a) => RE a -> String printRE1 re = case re of- RE_ZERO m -> "ERROR: " ++ m- RE_UNIT -> ""- RE_SYM sym -> show sym- RE_DOT -> "."- RE_REP e- | isSingle e -> printRE1 e ++ "*"- | otherwise -> "(" ++ printRE1 e ++ ")*"- RE_PLUS e- | isSingle e -> printRE1 e ++ "+"- | otherwise -> "(" ++ printRE1 e ++ ")+"- RE_OPT e- | isSingle e -> printRE1 e ++ "?"- | otherwise -> "(" ++ printRE1 e ++ ")?"- RE_SEQ e f- | isAlt e && not (isAlt f) -> "(" ++ printRE1 e ++ ") , " ++ printRE1 f- | not (isAlt e) && isAlt f -> printRE1 e ++ " , (" ++ printRE1 f ++ ")"- | isAlt e && isAlt f -> "(" ++ printRE1 e ++ ") , (" ++ printRE1 f ++ ")"- | otherwise -> printRE1 e ++ " , " ++ printRE1 f- RE_ALT e f- | isSeq e && not (isSeq f) -> "(" ++ printRE1 e ++ ") | " ++ printRE1 f- | not (isSeq e) && isSeq f -> printRE1 e ++ " | (" ++ printRE1 f ++ ")"- | isSeq e && isSeq f -> "(" ++ printRE1 e ++ ") | (" ++ printRE1 f ++ ")"- | otherwise -> printRE1 e ++ " | " ++ printRE1 f+ RE_ZERO m -> "ERROR: " ++ m+ RE_UNIT -> ""+ RE_SYM sym -> show sym+ RE_DOT -> "."+ RE_REP e+ | isSingle e -> printRE1 e ++ "*"+ | otherwise -> "(" ++ printRE1 e ++ ")*"+ RE_PLUS e+ | isSingle e -> printRE1 e ++ "+"+ | otherwise -> "(" ++ printRE1 e ++ ")+"+ RE_OPT e+ | isSingle e -> printRE1 e ++ "?"+ | otherwise -> "(" ++ printRE1 e ++ ")?"+ RE_SEQ e f+ | isAlt e && not (isAlt f) -> "(" ++ printRE1 e ++ ") , " ++ printRE1 f+ | not (isAlt e) && isAlt f -> printRE1 e ++ " , (" ++ printRE1 f ++ ")"+ | isAlt e && isAlt f -> "(" ++ printRE1 e ++ ") , (" ++ printRE1 f ++ ")"+ | otherwise -> printRE1 e ++ " , " ++ printRE1 f+ RE_ALT e f+ | isSeq e && not (isSeq f) -> "(" ++ printRE1 e ++ ") | " ++ printRE1 f+ | not (isSeq e) && isSeq f -> printRE1 e ++ " | (" ++ printRE1 f ++ ")"+ | isSeq e && isSeq f -> "(" ++ printRE1 e ++ ") | (" ++ printRE1 f ++ ")"+ | otherwise -> printRE1 e ++ " | " ++ printRE1 f isSingle :: RE a -> Bool
src/Text/XML/HXT/DTDValidation/TypeDefs.hs view
@@ -29,13 +29,13 @@ ) where -import Control.Arrow -- classes+import Control.Arrow -- classes import Control.Arrow.ArrowList import Control.Arrow.ArrowIf import Control.Arrow.ArrowState import Control.Arrow.ArrowTree -import Control.Arrow.ListArrow -- arrow types+import Control.Arrow.ListArrow -- arrow types import Control.Arrow.StateListArrow import Text.XML.HXT.Arrow.XmlArrow@@ -46,8 +46,8 @@ infixr 0 $$ -type XmlArrow = LA XmlTree XmlTree-type XmlArrowS = LA XmlTree XmlTrees+type XmlArrow = LA XmlTree XmlTree+type XmlArrowS = LA XmlTree XmlTrees -- ------------------------------------------------------------ @@ -56,89 +56,89 @@ , dtd_type , dtd_kind , dtd_modifier- , dtd_default :: Attributes -> String+ , dtd_default :: Attributes -> String -dtd_name = lookup1 a_name-dtd_value = lookup1 a_value-dtd_type = lookup1 a_type-dtd_kind = lookup1 a_kind-dtd_modifier = lookup1 a_modifier-dtd_default = lookup1 a_default+dtd_name = lookup1 a_name+dtd_value = lookup1 a_value+dtd_type = lookup1 a_type+dtd_kind = lookup1 a_kind+dtd_modifier = lookup1 a_modifier+dtd_default = lookup1 a_default -- ------------------------------------------------------------ -isUnparsedEntity :: ArrowDTD a => a XmlTree XmlTree-isUnparsedEntity = filterA $- getDTDAttrl >>> isA (hasEntry k_ndata)+isUnparsedEntity :: ArrowDTD a => a XmlTree XmlTree+isUnparsedEntity = filterA $+ getDTDAttrl >>> isA (hasEntry k_ndata) -hasDTDAttrValue :: ArrowDTD a => String -> (String -> Bool) -> a XmlTree XmlTree-hasDTDAttrValue an p = filterA $- getDTDAttrl >>> isA (p . lookup1 an)+hasDTDAttrValue :: ArrowDTD a => String -> (String -> Bool) -> a XmlTree XmlTree+hasDTDAttrValue an p = filterA $+ getDTDAttrl >>> isA (p . lookup1 an) -isRequiredAttrKind :: ArrowDTD a => a XmlTree XmlTree-isRequiredAttrKind = hasDTDAttrValue a_kind (== k_required)+isRequiredAttrKind :: ArrowDTD a => a XmlTree XmlTree+isRequiredAttrKind = hasDTDAttrValue a_kind (== k_required) -isDefaultAttrKind :: ArrowDTD a => a XmlTree XmlTree-isDefaultAttrKind = hasDTDAttrValue a_kind (== k_default)+isDefaultAttrKind :: ArrowDTD a => a XmlTree XmlTree+isDefaultAttrKind = hasDTDAttrValue a_kind (== k_default) -isFixedAttrKind :: ArrowDTD a => a XmlTree XmlTree-isFixedAttrKind = hasDTDAttrValue a_kind (== k_fixed)+isFixedAttrKind :: ArrowDTD a => a XmlTree XmlTree+isFixedAttrKind = hasDTDAttrValue a_kind (== k_fixed) -isMixedContentElement :: ArrowDTD a => a XmlTree XmlTree-isMixedContentElement = hasDTDAttrValue a_type (== v_mixed)+isMixedContentElement :: ArrowDTD a => a XmlTree XmlTree+isMixedContentElement = hasDTDAttrValue a_type (== v_mixed) -isEmptyElement :: ArrowDTD a => a XmlTree XmlTree-isEmptyElement = hasDTDAttrValue a_type (== k_empty)+isEmptyElement :: ArrowDTD a => a XmlTree XmlTree+isEmptyElement = hasDTDAttrValue a_type (== k_empty) -isEnumAttrType :: ArrowDTD a => a XmlTree XmlTree-isEnumAttrType = hasDTDAttrValue a_type (== k_enumeration)+isEnumAttrType :: ArrowDTD a => a XmlTree XmlTree+isEnumAttrType = hasDTDAttrValue a_type (== k_enumeration) -isIdAttrType :: ArrowDTD a => a XmlTree XmlTree-isIdAttrType = hasDTDAttrValue a_type (== k_id)+isIdAttrType :: ArrowDTD a => a XmlTree XmlTree+isIdAttrType = hasDTDAttrValue a_type (== k_id) -isIdRefAttrType :: ArrowDTD a => a XmlTree XmlTree-isIdRefAttrType = hasDTDAttrValue a_type (`elem` [k_idref, k_idrefs])+isIdRefAttrType :: ArrowDTD a => a XmlTree XmlTree+isIdRefAttrType = hasDTDAttrValue a_type (`elem` [k_idref, k_idrefs]) -isNotationAttrType :: ArrowDTD a => a XmlTree XmlTree-isNotationAttrType = hasDTDAttrValue a_type (== k_notation)+isNotationAttrType :: ArrowDTD a => a XmlTree XmlTree+isNotationAttrType = hasDTDAttrValue a_type (== k_notation) -isAttlistOfElement :: ArrowDTD a => String -> a XmlTree XmlTree-isAttlistOfElement el = isDTDAttlist- >>>- hasDTDAttrValue a_name (== el)+isAttlistOfElement :: ArrowDTD a => String -> a XmlTree XmlTree+isAttlistOfElement el = isDTDAttlist+ >>>+ hasDTDAttrValue a_name (== el) -valueOfDTD :: String -> XmlTree -> String-valueOfDTD n = concat . runLA ( getDTDAttrl >>^ lookup1 n )+valueOfDTD :: String -> XmlTree -> String+valueOfDTD n = concat . runLA ( getDTDAttrl >>^ lookup1 n ) -valueOf :: String -> XmlTree -> String-valueOf n = concat . runLA ( getAttrValue n )+valueOf :: String -> XmlTree -> String+valueOf n = concat . runLA ( getAttrValue n ) -getDTDAttributes :: XmlTree -> Attributes-getDTDAttributes = concat . runLA getDTDAttrl+getDTDAttributes :: XmlTree -> Attributes+getDTDAttributes = concat . runLA getDTDAttrl -isDTDDoctypeNode :: XmlTree -> Bool-isDTDDoctypeNode = not . null . runLA isDTDDoctype+isDTDDoctypeNode :: XmlTree -> Bool+isDTDDoctypeNode = not . null . runLA isDTDDoctype -isDTDElementNode :: XmlTree -> Bool-isDTDElementNode = not . null . runLA isDTDElement+isDTDElementNode :: XmlTree -> Bool+isDTDElementNode = not . null . runLA isDTDElement -isDTDAttlistNode :: XmlTree -> Bool-isDTDAttlistNode = not . null . runLA isDTDAttlist+isDTDAttlistNode :: XmlTree -> Bool+isDTDAttlistNode = not . null . runLA isDTDAttlist -isDTDContentNode :: XmlTree -> Bool-isDTDContentNode = not . null . runLA isDTDContent+isDTDContentNode :: XmlTree -> Bool+isDTDContentNode = not . null . runLA isDTDContent -isDTDNameNode :: XmlTree -> Bool-isDTDNameNode = not . null . runLA isDTDName+isDTDNameNode :: XmlTree -> Bool+isDTDNameNode = not . null . runLA isDTDName -isElemNode :: XmlTree -> Bool-isElemNode = not . null . runLA isElem+isElemNode :: XmlTree -> Bool+isElemNode = not . null . runLA isElem -nameOfAttr :: XmlTree -> String-nameOfAttr = concat . runLA (getAttrName >>^ qualifiedName)+nameOfAttr :: XmlTree -> String+nameOfAttr = concat . runLA (getAttrName >>^ qualifiedName) -nameOfElem :: XmlTree -> String-nameOfElem = concat . runLA (getElemName >>^ qualifiedName)+nameOfElem :: XmlTree -> String+nameOfElem = concat . runLA (getElemName >>^ qualifiedName) -- | -- infix operator for applying an arrow to a list of trees@@ -149,16 +149,16 @@ -- -- - returns : list of results -($$) :: XmlArrow -> XmlTrees -> XmlTrees-f $$ l = runLA (unlistA >>> f) l+($$) :: XmlArrow -> XmlTrees -> XmlTrees+f $$ l = runLA (unlistA >>> f) l -- | create an error message -msgToErr :: (String -> String) -> LA String XmlTree-msgToErr f = mkErr $< this- where- mkErr "" = none- mkErr s = err (f s)+msgToErr :: (String -> String) -> LA String XmlTree+msgToErr f = mkErr $< this+ where+ mkErr "" = none+ mkErr s = err (f s) -- ------------------------------------------------------------
src/Text/XML/HXT/DTDValidation/Validation.hs view
@@ -49,8 +49,8 @@ -- - returns : a function which expects a complete document as XmlTree input -- and returns a list of all errors found. -validate :: XmlArrow-validate = validateDTD <+> validateDoc+validate :: XmlArrow+validate = validateDTD <+> validateDoc -- | -- Check if the DTD is valid.@@ -59,11 +59,11 @@ -- - returns : a function which expects an XmlTree from the parser as input -- and returns a list of all errors found in the DTD. -validateDTD :: XmlArrow-validateDTD = choiceA- [ getDTDSubset :-> DTDValidation.validateDTD- , this :-> err "Can't validate DTD: There is no DOCTYPE declaration in the document."- ]+validateDTD :: XmlArrow+validateDTD = choiceA+ [ getDTDSubset :-> DTDValidation.validateDTD+ , this :-> err "Can't validate DTD: There is no DOCTYPE declaration in the document."+ ] -- | -- Check if the document corresponds to the given DTD. --@@ -71,20 +71,20 @@ -- - returns : a function which expects a complete document as XmlTree input -- and returns a list of all errors found in the content part. -validateDoc :: XmlArrow+validateDoc :: XmlArrow validateDoc = validateDoc' $< getDTD where- validateDoc' [] = err "Can't validate document: There is no DOCTYPE declaration in the document."- validateDoc' (dtdPart:_) = DocValidation.validateDoc dtdPart- <+>- IdValidation.validateIds dtdPart+ validateDoc' [] = err "Can't validate document: There is no DOCTYPE declaration in the document."+ validateDoc' (dtdPart:_) = DocValidation.validateDoc dtdPart+ <+>+ IdValidation.validateIds dtdPart -getDTD :: XmlArrowS-getDTD = listA ( getDTDSubset- >>>- removeDoublicateDefs- )+getDTD :: XmlArrowS+getDTD = listA ( getDTDSubset+ >>>+ removeDoublicateDefs+ ) -- | -- filter for transforming a document with respect to the given DTD.@@ -97,14 +97,14 @@ -- - returns : a function which expects a complete XML document tree -- and returns the transformed XmlTree -transform :: XmlArrow-transform = choiceA- [ isRoot :-> (transformDoc $< getDTD)- , this :-> fatal "Can't transform document: No document root given"- ]+transform :: XmlArrow+transform = choiceA+ [ isRoot :-> (transformDoc $< getDTD)+ , this :-> fatal "Can't transform document: No document root given"+ ] where- transformDoc [] = this- transformDoc dtd = DocTransformation.transform (head dtd)+ transformDoc [] = this+ transformDoc dtd = DocTransformation.transform (head dtd) -- | -- Removes doublicate declarations from the DTD which first declaration is@@ -114,17 +114,17 @@ -- - returns : A function that replaces the children of DOCTYPE nodes by a list -- where all multiple declarations are removed. -removeDoublicateDefs :: XmlArrow-removeDoublicateDefs = DTDValidation.removeDoublicateDefs+removeDoublicateDefs :: XmlArrow+removeDoublicateDefs = DTDValidation.removeDoublicateDefs -- -- selects the DTD part of a document -- but only, if there is more than the internal part for the 4 predefined XML entities -getDTDSubset :: XmlArrow-getDTDSubset = getChildren- >>>- ( filterA $ isDTDDoctype >>> getDTDAttrl >>> isA (hasEntry a_name) )+getDTDSubset :: XmlArrow+getDTDSubset = getChildren+ >>>+ ( filterA $ isDTDDoctype >>> getDTDAttrl >>> isA (hasEntry a_name) ) -- ------------------------------------------------------------
src/Text/XML/HXT/DTDValidation/XmlRE.hs view
@@ -82,35 +82,35 @@ delta re el | not (allowed el) = re | otherwise = case re of- RE_ZERO m -> re_zero m- RE_UNIT -> re_zero (elemName el ++" unexpected.")+ RE_ZERO m -> re_zero m+ RE_UNIT -> re_zero (elemName el ++" unexpected.") RE_SYM sym- | sym == k_pcdata -> if ((XN.isText el) || (XN.isCdata el))- then re_unit- else re_zero ("Character data expected, but "++ elemName el ++" found.")- | expectedNode el sym -> re_unit- | otherwise -> re_zero ("Element "++ show sym ++" expected, but "++ elemName el ++" found.")+ | sym == k_pcdata -> if ((XN.isText el) || (XN.isCdata el))+ then re_unit+ else re_zero ("Character data expected, but "++ elemName el ++" found.")+ | expectedNode el sym -> re_unit+ | otherwise -> re_zero ("Element "++ show sym ++" expected, but "++ elemName el ++" found.") RE_REP e -> re_seq (delta e el) (re_rep e) RE_PLUS e -> re_seq (delta e el) (re_rep e) RE_OPT e -> delta e el RE_SEQ e f- | nullable e -> re_alt (re_seq (delta e el) f) (delta f el)- | otherwise -> re_seq (delta e el) f+ | nullable e -> re_alt (re_seq (delta e el) f) (delta f el)+ | otherwise -> re_seq (delta e el) f RE_ALT e f -> re_alt (delta e el) (delta f el) RE_DOT -> re_unit where- expectedNode :: XmlTree -> String -> Bool+ expectedNode :: XmlTree -> String -> Bool expectedNode n sym- | XN.isElem n = nameOfElem n == sym- | otherwise = False+ | XN.isElem n = nameOfElem n == sym+ | otherwise = False - elemName :: XmlTree -> String+ elemName :: XmlTree -> String elemName n- | XN.isElem n = "element "++ show (nameOfElem n)- | otherwise = "character data"+ | XN.isElem n = "element "++ show (nameOfElem n)+ | otherwise = "character data" - allowed :: XmlTree -> Bool- allowed n = XN.isElem n || XN.isText n || XN.isCdata n+ allowed :: XmlTree -> Bool+ allowed n = XN.isElem n || XN.isText n || XN.isCdata n -- ------------------------------------------------------------
src/Text/XML/HXT/IO/GetFILE.hs view
@@ -25,106 +25,106 @@ import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as C -import Network.URI ( unEscapeString- )+import Network.URI ( unEscapeString+ ) -import System.IO ( IOMode(..)- , openBinaryFile- -- , getContents is defined in the prelude- , hGetContents- )+import System.IO ( IOMode(..)+ , openBinaryFile+ -- , getContents is defined in the prelude+ , hGetContents+ ) -import System.IO.Error ( ioeGetErrorString- , try- )+import System.IO.Error ( ioeGetErrorString+ , try+ ) -import System.Directory ( doesFileExist- , getPermissions- , readable- )-import Text.XML.HXT.DOM.XmlKeywords+import System.Directory ( doesFileExist+ , getPermissions+ , readable+ )+import Text.XML.HXT.DOM.XmlKeywords -- ------------------------------------------------------------ -getStdinCont :: Bool -> IO (Either ([(String, String)], String)- String)+getStdinCont :: Bool -> IO (Either ([(String, String)], String)+ String) getStdinCont strictInput = do c <- try ( if strictInput- then do- cb <- B.getContents- return (C.unpack cb)- else getContents- )+ then do+ cb <- B.getContents+ return (C.unpack cb)+ else getContents+ ) return (either readErr Right c) where readErr e- = Left ( [ (transferStatus, "999")- , (transferMessage, msg)- ]- , msg- )- where- msg = "stdin read error: " ++ es- es = ioeGetErrorString e+ = Left ( [ (transferStatus, "999")+ , (transferMessage, msg)+ ]+ , msg+ )+ where+ msg = "stdin read error: " ++ es+ es = ioeGetErrorString e -getCont :: Bool -> String -> IO (Either ([(String, String)], String)- String)+getCont :: Bool -> String -> IO (Either ([(String, String)], String)+ String) getCont strictInput source- = do -- preliminary+ = do -- preliminary source'' <- checkFile source' case source'' of Nothing -> return $ fileErr "file not found"- Just fn -> do- perm <- getPermissions fn- if not (readable perm)- then return $ fileErr "file not readable"- else do- c <- try $- if strictInput- then do- cb <- B.readFile fn- return (C.unpack cb)- else do- h <- openBinaryFile fn ReadMode- hGetContents h- return (either readErr Right c)+ Just fn -> do+ perm <- getPermissions fn+ if not (readable perm)+ then return $ fileErr "file not readable"+ else do+ c <- try $+ if strictInput+ then do+ cb <- B.readFile fn+ return (C.unpack cb)+ else do+ h <- openBinaryFile fn ReadMode+ hGetContents h+ return (either readErr Right c) where source' = drivePath $ source readErr e- = fileErr (ioeGetErrorString e)+ = fileErr (ioeGetErrorString e) fileErr msg0- = Left ( [ (transferStatus, "999")- , (transferMessage, msg)- ]- , msg- )- where- msg = "file read error: " ++ show msg0 ++ " when accessing " ++ show source'+ = Left ( [ (transferStatus, "999")+ , (transferMessage, msg)+ ]+ , msg+ )+ where+ msg = "file read error: " ++ show msg0 ++ " when accessing " ++ show source' -- remove leading / if file starts with windows drive letter, e.g. /c:/windows -> c:/windows drivePath ('/' : file@(d : ':' : _more))- | d `elem` ['A'..'Z'] || d `elem` ['a'..'z']- = file+ | d `elem` ['A'..'Z'] || d `elem` ['a'..'z']+ = file drivePath file- = file+ = file -- | check whether file exists, if not -- try to unescape filename and check again -- return the existing filename -checkFile :: String -> IO (Maybe String)+checkFile :: String -> IO (Maybe String) checkFile fn = do exists <- doesFileExist fn if exists- then return (Just fn)- else do- exists' <- doesFileExist fn'- return ( if exists'- then Just fn'- else Nothing- )+ then return (Just fn)+ else do+ exists' <- doesFileExist fn'+ return ( if exists'+ then Just fn'+ else Nothing+ ) where fn' = unEscapeString fn
src/Text/XML/HXT/IO/GetHTTPLibCurl.hs view
@@ -21,68 +21,68 @@ where -import Control.Arrow ( first- , (>>>)- )+import Control.Arrow ( first+ , (>>>)+ ) import Control.Concurrent.MVar-import Control.Monad ( when )+import Control.Monad ( when ) import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as C -import Data.Char ( isDigit- , isSpace- )-import Data.List ( isPrefixOf )+import Data.Char ( isDigit+ , isSpace+ )+import Data.List ( isPrefixOf ) import Network.Curl import System.IO-import System.IO.Unsafe ( unsafePerformIO )+import System.IO.Unsafe ( unsafePerformIO ) -import Text.ParserCombinators.Parsec ( parse )+import Text.ParserCombinators.Parsec ( parse ) -import Text.XML.HXT.DOM.Util ( stringToLower )+import Text.XML.HXT.DOM.Util ( stringToLower ) import Text.XML.HXT.DOM.XmlKeywords-import Text.XML.HXT.DOM.XmlOptions ( isTrueValue )+import Text.XML.HXT.DOM.XmlOptions ( isTrueValue ) import Text.XML.HXT.Parser.ProtocolHandlerUtil- ( parseContentType )+ ( parseContentType ) import Text.XML.HXT.Version -- ------------------------------------------------------------ -- -- the global flag for initializing curl in the 1. call -isInitCurl :: MVar Bool-isInitCurl = unsafePerformIO $ newMVar False+isInitCurl :: MVar Bool+isInitCurl = unsafePerformIO $ newMVar False {-# NOINLINE isInitCurl #-} -initCurl :: IO ()+initCurl :: IO () initCurl = do i <- takeMVar isInitCurl when (not i) ( do- _ <- curl_global_init 3- return ()- )+ _ <- curl_global_init 3+ return ()+ ) putMVar isInitCurl True -- ------------------------------------------------------------ -- The curl lib is not thread save -curlResource :: MVar ()-curlResource = unsafePerformIO $ newMVar ()+curlResource :: MVar ()+curlResource = unsafePerformIO $ newMVar () {-# NOINLINE curlResource #-} -requestCurl :: IO ()-requestCurl = takeMVar curlResource+requestCurl :: IO ()+requestCurl = takeMVar curlResource -releaseCurl :: IO ()-releaseCurl = putMVar curlResource ()+releaseCurl :: IO ()+releaseCurl = putMVar curlResource () -- ------------------------------------------------------------ @@ -102,8 +102,8 @@ -- -- will set the user agent and the referer URL for this request. -getCont :: [(String, String)] -> String -> IO (Either ([(String, String)], String)- ([(String, String)], String))+getCont :: [(String, String)] -> String -> IO (Either ([(String, String)], String)+ ([(String, String)], String)) getCont options uri = do initCurl@@ -116,195 +116,195 @@ return resp' where _dumpResponse r- = do- hPutStrLn stderr $ show $ respCurlCode r- hPutStrLn stderr $ show $ respStatus r- hPutStrLn stderr $ respStatusLine r- hPutStrLn stderr $ show $ respHeaders r- hPutStrLn stderr $ respBody r+ = do+ hPutStrLn stderr $ show $ respCurlCode r+ hPutStrLn stderr $ show $ respStatus r+ hPutStrLn stderr $ respStatusLine r+ hPutStrLn stderr $ show $ respHeaders r+ hPutStrLn stderr $ respBody r curlOptions- = defaultOptions ++ concatMap (uncurry copt) options ++ standardOptions+ = defaultOptions ++ concatMap (uncurry copt) options ++ standardOptions - defaultOptions -- these options may be overwritten- = [ CurlUserAgent ("hxt/" ++ hxt_version ++ " via libcurl")- , CurlFollowLocation True- ]+ defaultOptions -- these options may be overwritten+ = [ CurlUserAgent ("hxt/" ++ hxt_version ++ " via libcurl")+ , CurlFollowLocation True+ ] - standardOptions -- these options can't be overwritten- = [ CurlFailOnError False- , CurlHeader False- , CurlNoProgress True- ]+ standardOptions -- these options can't be overwritten+ = [ CurlFailOnError False+ , CurlHeader False+ , CurlNoProgress True+ ] evalResponse r- | rc /= CurlOK- = Left ( [ mkH transferStatus "999"- , mkH transferMessage $ "curl library rc: " ++ show rc- ]- , "curl library error when requesting URI "- ++ show uri- ++ ": (curl return code=" ++ show rc ++ ") "- )- | rs < 200 && rs >= 300- = Left ( contentT rsh ++ headers- , "http error when accessing URI "- ++ show uri- ++ ": "- ++ show rsl- )- | otherwise- = B.length body+ | rc /= CurlOK+ = Left ( [ mkH transferStatus "999"+ , mkH transferMessage $ "curl library rc: " ++ show rc+ ]+ , "curl library error when requesting URI "+ ++ show uri+ ++ ": (curl return code=" ++ show rc ++ ") "+ )+ | rs < 200 && rs >= 300+ = Left ( contentT rsh ++ headers+ , "http error when accessing URI "+ ++ show uri+ ++ ": "+ ++ show rsl+ )+ | otherwise+ = B.length body `seq` Right ( contentT rsh ++ headers , C.unpack body- )- where+ )+ where body :: B.ByteString body = respBody r - mkH x y = (x, dropWhile isSpace y)+ mkH x y = (x, dropWhile isSpace y) - headers- = map (\ (k, v) -> mkH (httpPrefix ++ stringToLower k) v) rsh- +++ headers+ = map (\ (k, v) -> mkH (httpPrefix ++ stringToLower k) v) rsh+ ++ statusLine (words rsl) - contentT- = map (first stringToLower) -- all header names to lowercase- >>>- filter ((== "content-type") . fst) -- select content-type header- >>>- reverse -- when libcurl is called with automatic redirects, there are more than one content-type headers- >>>- take 1 -- take the last one, (if at leat one is found)- >>>- map snd -- select content-type value- >>>- map ( either (const []) id- . parse parseContentType "" -- parse the content-type for mimetype and charset- )- >>>- concat+ contentT+ = map (first stringToLower) -- all header names to lowercase+ >>>+ filter ((== "content-type") . fst) -- select content-type header+ >>>+ reverse -- when libcurl is called with automatic redirects, there are more than one content-type headers+ >>>+ take 1 -- take the last one, (if at leat one is found)+ >>>+ map snd -- select content-type value+ >>>+ map ( either (const []) id+ . parse parseContentType "" -- parse the content-type for mimetype and charset+ )+ >>>+ concat - statusLine (vers : _code : msg) -- the status line of the curl response can be an old one, e.g. in the case of a redirect,- = [ mkH transferVersion vers -- so the return code is taken from the status field, which is contains the last status- , mkH transferMessage $ unwords msg- , mkH transferStatus $ show rs- ]+ statusLine (vers : _code : msg) -- the status line of the curl response can be an old one, e.g. in the case of a redirect,+ = [ mkH transferVersion vers -- so the return code is taken from the status field, which is contains the last status+ , mkH transferMessage $ unwords msg+ , mkH transferStatus $ show rs+ ] statusLine _- = []+ = [] - rc = respCurlCode r- rs = respStatus r- rsl = respStatusLine r- rsh = respHeaders r+ rc = respCurlCode r+ rs = respStatus r+ rsl = respStatusLine r+ rsh = respHeaders r -- ------------------------------------------------------------ -copt :: String -> String -> [CurlOption]+copt :: String -> String -> [CurlOption] copt k v | "curl" `isPrefixOf` k- = opt2copt (drop 4 k) v+ = opt2copt (drop 4 k) v | k `elem` [a_proxy, a_redirect]- = opt2copt k v+ = opt2copt k v | k == a_options_curl- = curlOptionString v+ = curlOptionString v | otherwise- = []+ = [] -opt2copt :: String -> String -> [CurlOption]+opt2copt :: String -> String -> [CurlOption] opt2copt k v- | k `elem` ["-A", "--user-agent"] = [CurlUserAgent v]- | k `elem` ["-b", "--cookie"] = [CurlCookie v]+ | k `elem` ["-A", "--user-agent"] = [CurlUserAgent v]+ | k `elem` ["-b", "--cookie"] = [CurlCookie v] | k == "--connect-timeout" &&- isIntArg v = [CurlConnectTimeout $ read v]- | k == "--crlf" = [CurlCRLF $ isTrue v]- | k `elem` ["-d", "--data"] = [CurlPostFields $ lines v]- | k `elem` ["-e", "--referer"] = [CurlReferer v]- | k `elem` ["-H", "--header"] = [CurlHttpHeaders $ lines v]- | k == "--ignore-content-length" = [CurlIgnoreContentLength $ isTrue v]- | k `elem` ["-I", "--head"] = [CurlNoBody $ isTrue v]+ isIntArg v = [CurlConnectTimeout $ read v]+ | k == "--crlf" = [CurlCRLF $ isTrue v]+ | k `elem` ["-d", "--data"] = [CurlPostFields $ lines v]+ | k `elem` ["-e", "--referer"] = [CurlReferer v]+ | k `elem` ["-H", "--header"] = [CurlHttpHeaders $ lines v]+ | k == "--ignore-content-length" = [CurlIgnoreContentLength $ isTrue v]+ | k `elem` ["-I", "--head"] = [CurlNoBody $ isTrue v] | k `elem` ["-L", "--location", a_redirect]- = [CurlFollowLocation $ isTrue v]+ = [CurlFollowLocation $ isTrue v] | k == "--max-filesize" &&- isIntArg v = [CurlMaxFileSizeLarge $ read v]+ isIntArg v = [CurlMaxFileSizeLarge $ read v] | k `elem` ["-m", "--max-time"] &&- isIntArg v = [CurlTimeoutMS $ read v]- | k `elem` ["-n", "--netrc"] = [CurlNetrcFile v]- | k `elem` ["--ssl-verify-peer"] = [CurlSSLVerifyPeer $ read v]+ isIntArg v = [CurlTimeoutMS $ read v]+ | k `elem` ["-n", "--netrc"] = [CurlNetrcFile v]+ | k `elem` ["--ssl-verify-peer"] = [CurlSSLVerifyPeer $ read v] | k `elem` ["-R", "--remote-time"] = [CurlFiletime $ isTrue v]- | k `elem` ["-u", "--user"] = [CurlUserPwd v]- | k `elem` ["-U", "--proxy-user"] = [CurlProxyUserPwd v]+ | k `elem` ["-u", "--user"] = [CurlUserPwd v]+ | k `elem` ["-U", "--proxy-user"] = [CurlProxyUserPwd v] | k `elem` ["-x", "--proxy", a_proxy]- = proxyOptions+ = proxyOptions | k `elem` ["-X", "--request"] = [CurlCustomRequest v] | k `elem` ["-y", "--speed-time"] && isIntArg v = [CurlLowSpeedTime $ read v] | k `elem` ["-Y", "--speed-limit"] &&- isIntArg v = [CurlLowSpeed $ read v]+ isIntArg v = [CurlLowSpeed $ read v] | k `elem` ["-z", "--time-cond", a_if_modified_since]- = ifModifiedOptions+ = ifModifiedOptions - | k == a_if_modified_since = [CurlHttpHeaders $ ["If-Modified-Since: " ++ v] ]- -- CurlTimeValue seems to be buggy, therefore this workaround+ | k == a_if_modified_since = [CurlHttpHeaders $ ["If-Modified-Since: " ++ v] ]+ -- CurlTimeValue seems to be buggy, therefore this workaround | k == "--max-redirs" &&- isIntArg v = [CurlMaxRedirs $ read v]- | k `elem` ["-0", "--http1.0"] = [CurlHttpVersion HttpVersion10]- | otherwise = []+ isIntArg v = [CurlMaxRedirs $ read v]+ | k `elem` ["-0", "--http1.0"] = [CurlHttpVersion HttpVersion10]+ | otherwise = [] where ifModifiedOptions- | "-" `isPrefixOf` v- &&- isIntArg v' = [CurlTimeCondition TimeCondIfUnmodSince- ,CurlTimeValue $ read v'- ]- | isIntArg v = [CurlTimeCondition TimeCondIfModSince- ,CurlTimeValue $ read v'- ]- | otherwise = []- where- v' = tail v+ | "-" `isPrefixOf` v+ &&+ isIntArg v' = [CurlTimeCondition TimeCondIfUnmodSince+ ,CurlTimeValue $ read v'+ ]+ | isIntArg v = [CurlTimeCondition TimeCondIfModSince+ ,CurlTimeValue $ read v'+ ]+ | otherwise = []+ where+ v' = tail v proxyOptions- = [ CurlProxyPort pport- , CurlProxy phost- ]- where- pport- | isIntArg ppp = read v- | otherwise = 1080- (phost, pp) = span (/=':') v- ppp = drop 1 pp+ = [ CurlProxyPort pport+ , CurlProxy phost+ ]+ where+ pport+ | isIntArg ppp = read v+ | otherwise = 1080+ (phost, pp) = span (/=':') v+ ppp = drop 1 pp -isTrue :: String -> Bool-isTrue s = null s || isTrueValue s+isTrue :: String -> Bool+isTrue s = null s || isTrueValue s -isIntArg :: String -> Bool-isIntArg s = not (null s) && all isDigit s+isIntArg :: String -> Bool+isIntArg s = not (null s) && all isDigit s -curlOptionString :: String -> [CurlOption]+curlOptionString :: String -> [CurlOption] curlOptionString = concatMap (uncurry copt) . opts . words where opts l- | null l = []- | not ("-" `isPrefixOf` k) = opts l1 -- k not an option: ignore- | null l1 = opts (k:"":l1) -- last option- | "-" `isPrefixOf` v = (k, "") : opts (v:l) -- k option without arg- | otherwise = (k, v) : opts l2 -- k with value- where- (k:l1) = l- (v:l2) = l1+ | null l = []+ | not ("-" `isPrefixOf` k) = opts l1 -- k not an option: ignore+ | null l1 = opts (k:"":l1) -- last option+ | "-" `isPrefixOf` v = (k, "") : opts (v:l) -- k option without arg+ | otherwise = (k, v) : opts l2 -- k with value+ where+ (k:l1) = l+ (v:l2) = l1 -- ------------------------------------------------------------
src/Text/XML/HXT/Parser/HtmlParsec.hs view
@@ -12,7 +12,7 @@ This parser tries to interprete everything as HTML no errors are emitted during parsing. If something looks weired, warning messages are inserted in the document tree.- + All filter are pure XmlFilter, errror handling and IO is done in 'Text.XML.HXT.Parser.HtmlParser' or other modules@@ -102,25 +102,25 @@ -- ------------------------------------------------------------ -parseHtmlText :: String -> XmlTree -> XmlTrees+parseHtmlText :: String -> XmlTree -> XmlTrees parseHtmlText loc t = parseXmlText htmlDocument loc $ t -- ------------------------------------------------------------ -parseHtmlFromString :: Parser XmlTrees -> String -> String -> XmlTrees+parseHtmlFromString :: Parser XmlTrees -> String -> String -> XmlTrees parseHtmlFromString parser loc = either ((:[]) . mkError c_err . (++ "\n") . show) id . parse parser loc -parseHtmlDocument :: String -> String -> XmlTrees-parseHtmlDocument = parseHtmlFromString htmlDocument+parseHtmlDocument :: String -> String -> XmlTrees+parseHtmlDocument = parseHtmlFromString htmlDocument -parseHtmlContent :: String -> XmlTrees-parseHtmlContent = parseHtmlFromString htmlContent "text"+parseHtmlContent :: String -> XmlTrees+parseHtmlContent = parseHtmlFromString htmlContent "text" -- ------------------------------------------------------------ -htmlDocument :: Parser XmlTrees+htmlDocument :: Parser XmlTrees htmlDocument = do pl <- htmlProlog@@ -128,114 +128,114 @@ eof return (pl ++ el) -htmlProlog :: Parser XmlTrees+htmlProlog :: Parser XmlTrees htmlProlog = do xml <- option []- ( try xMLDecl'- <|>- ( do- pos <- getPosition- _ <- try (string "<?")- return $ [mkError c_warn (show pos ++ " wrong XML declaration")]- )- )+ ( try xMLDecl'+ <|>+ ( do+ pos <- getPosition+ _ <- try (string "<?")+ return $ [mkError c_warn (show pos ++ " wrong XML declaration")]+ )+ ) misc1 <- many misc dtdPart <- option []- ( try doctypedecl- <|>- ( do- pos <- getPosition- _ <- try (upperCaseString "<!DOCTYPE")- return $ [mkError c_warn (show pos ++ " HTML DOCTYPE declaration ignored")]- )- )+ ( try doctypedecl+ <|>+ ( do+ pos <- getPosition+ _ <- try (upperCaseString "<!DOCTYPE")+ return $ [mkError c_warn (show pos ++ " HTML DOCTYPE declaration ignored")]+ )+ ) return (xml ++ misc1 ++ dtdPart) -doctypedecl :: Parser XmlTrees+doctypedecl :: Parser XmlTrees doctypedecl = between (try $ upperCaseString "<!DOCTYPE") (char '>') ( do- skipS- n <- name- exId <- ( do- skipS- option [] externalID- )- skipS0- return [mkDTDElem DOCTYPE ((a_name, n) : exId) []]+ skipS+ n <- name+ exId <- ( do+ skipS+ option [] externalID+ )+ skipS0+ return [mkDTDElem DOCTYPE ((a_name, n) : exId) []] ) -externalID :: Parser Attributes+externalID :: Parser Attributes externalID = do _ <- try (upperCaseString k_public) skipS pl <- pubidLiteral sl <- option "" $ try ( do- skipS- systemLiteral- )+ skipS+ systemLiteral+ ) return $ (k_public, pl) : if null sl then [] else [(k_system, sl)] -htmlContent :: Parser XmlTrees+htmlContent :: Parser XmlTrees htmlContent = option [] ( do- context <- hContent ([], [])- pos <- getPosition- return $ closeTags pos context+ context <- hContent ([], [])+ pos <- getPosition+ return $ closeTags pos context ) where closeTags _ (body, [])- = reverse body+ = reverse body closeTags pos' (body, ((tn, al, body1) : restOpen))- = closeTags pos' (addHtmlWarn (show pos' ++ ": no closing tag found for \"<" ++ tn ++ " ...>\"")- .- addHtmlTag tn al body- $- (body1, restOpen)- )+ = closeTags pos' (addHtmlWarn (show pos' ++ ": no closing tag found for \"<" ++ tn ++ " ...>\"")+ .+ addHtmlTag tn al body+ $+ (body1, restOpen)+ ) -type OpenTags = [(String, XmlTrees, XmlTrees)]-type Context = (XmlTrees, OpenTags)+type OpenTags = [(String, XmlTrees, XmlTrees)]+type Context = (XmlTrees, OpenTags) -hElement :: Context -> Parser Context+hElement :: Context -> Parser Context hElement context = ( do- t <- hSimpleData- return (addHtmlElems [t] context)+ t <- hSimpleData+ return (addHtmlElems [t] context) ) <|> hOpenTag context <|> hCloseTag context <|>- ( do -- wrong tag, take it as text- pos <- getPosition- c <- xmlChar- return ( addHtmlWarn (show pos ++ " markup char " ++ show c ++ " not allowed in this context")- .- addHtmlElems [mkText [c]]- $- context- )+ ( do -- wrong tag, take it as text+ pos <- getPosition+ c <- xmlChar+ return ( addHtmlWarn (show pos ++ " markup char " ++ show c ++ " not allowed in this context")+ .+ addHtmlElems [mkText [c]]+ $+ context+ ) ) <|> ( do- pos <- getPosition- c <- anyChar- return ( addHtmlWarn ( show pos- ++ " illegal data in input or illegal XML char "- ++ show c- ++ " found and ignored, possibly wrong encoding scheme used")- $- context- )+ pos <- getPosition+ c <- anyChar+ return ( addHtmlWarn ( show pos+ ++ " illegal data in input or illegal XML char "+ ++ show c+ ++ " found and ignored, possibly wrong encoding scheme used")+ $+ context+ ) ) -hSimpleData :: Parser XmlTree+hSimpleData :: Parser XmlTree hSimpleData = charData' <|>@@ -247,207 +247,207 @@ <|> try cDSect -hCloseTag :: Context -> Parser Context+hCloseTag :: Context -> Parser Context hCloseTag context = do n <- try ( do- _ <- string "</"- lowerCaseName- )+ _ <- string "</"+ lowerCaseName+ ) skipS0 pos <- getPosition checkSymbol gt ("closing > in tag \"</" ++ n ++ "\" expected") (closeTag pos n context) -hOpenTag :: Context -> Parser Context+hOpenTag :: Context -> Parser Context hOpenTag context = ( do- pos <- getPosition- e <- hOpenTagStart- hOpenTagRest pos e context+ pos <- getPosition+ e <- hOpenTagStart+ hOpenTagRest pos e context ) -hOpenTagStart :: Parser (String, XmlTrees)+hOpenTagStart :: Parser (String, XmlTrees) hOpenTagStart = do n <- try ( do- _ <- char '<'- n <- lowerCaseName- return n- )+ _ <- char '<'+ n <- lowerCaseName+ return n+ ) skipS0 as <- hAttrList return (n, as) -hOpenTagRest :: SourcePos -> (String, XmlTrees) -> Context -> Parser Context+hOpenTagRest :: SourcePos -> (String, XmlTrees) -> Context -> Parser Context hOpenTagRest pos (tn, al) context = ( do- _ <- try $ string "/>"- return (addHtmlTag tn al [] context)+ _ <- try $ string "/>"+ return (addHtmlTag tn al [] context) ) <|> ( do- context1 <- checkSymbol gt ("closing > in tag \"<" ++ tn ++ "...\" expected") context- return ( let context2 = closePrevTag pos tn context1- in- ( if isEmptyHtmlTag tn- then addHtmlTag tn al []- else openTag tn al- ) context2- )+ context1 <- checkSymbol gt ("closing > in tag \"<" ++ tn ++ "...\" expected") context+ return ( let context2 = closePrevTag pos tn context1+ in+ ( if isEmptyHtmlTag tn+ then addHtmlTag tn al []+ else openTag tn al+ ) context2+ ) ) -hAttrList :: Parser XmlTrees+hAttrList :: Parser XmlTrees hAttrList = many (try hAttribute) where hAttribute- = do- n <- lowerCaseName- v <- hAttrValue- skipS0- return $ mkAttr (mkName n) v+ = do+ n <- lowerCaseName+ v <- hAttrValue+ skipS0+ return $ mkAttr (mkName n) v -hAttrValue :: Parser XmlTrees+hAttrValue :: Parser XmlTrees hAttrValue = option [] ( try ( do- eq- hAttrValue'- )+ eq+ hAttrValue'+ ) ) -hAttrValue' :: Parser XmlTrees+hAttrValue' :: Parser XmlTrees hAttrValue' = try ( between dq dq (hAttrValue'' "&\"") ) <|> try ( between sq sq (hAttrValue'' "&\'") ) <|>- ( do -- HTML allows unquoted attribute values- cs <- many (noneOf " \r\t\n>\"\'")- return [mkText cs]+ ( do -- HTML allows unquoted attribute values+ cs <- many (noneOf " \r\t\n>\"\'")+ return [mkText cs] ) -hAttrValue'' :: String -> Parser XmlTrees+hAttrValue'' :: String -> Parser XmlTrees hAttrValue'' notAllowed = many ( hReference' <|> singleCharsT notAllowed) -hReference' :: Parser XmlTree+hReference' :: Parser XmlTree hReference' = try referenceT <|> ( do- _ <- char '&'- return (mkText "&")+ _ <- char '&'+ return (mkText "&") ) -hContent :: Context -> Parser Context+hContent :: Context -> Parser Context hContent context = option context ( do- context1 <- hElement context- hContent context1+ context1 <- hElement context+ hContent context1 ) -- hComment allows "--" in comments -- comment from XML spec does not -hComment :: Parser XmlTree+hComment :: Parser XmlTree hComment = do c <- between (try $ string "<!--") (string "-->") (allBut many "-->") return (mkCmt c) -checkSymbol :: Parser a -> String -> Context -> Parser Context+checkSymbol :: Parser a -> String -> Context -> Parser Context checkSymbol p msg context = do pos <- getPosition option (addHtmlWarn (show pos ++ " " ++ msg) context)- ( do - _ <- try p- return context+ ( do+ _ <- try p+ return context ) -lowerCaseName :: Parser String+lowerCaseName :: Parser String lowerCaseName = do n <- name return (map toLower n) -upperCaseString :: String -> Parser String+upperCaseString :: String -> Parser String upperCaseString = sequence . map (\ c -> satisfy (( == c) . toUpper)) -- ------------------------------------------------------------ -addHtmlTag :: String -> XmlTrees -> XmlTrees -> Context -> Context+addHtmlTag :: String -> XmlTrees -> XmlTrees -> Context -> Context addHtmlTag tn al body (body1, openTags) = ([mkElement (mkName tn) al (reverse body)] ++ body1, openTags) -addHtmlWarn :: String -> Context -> Context+addHtmlWarn :: String -> Context -> Context addHtmlWarn msg = addHtmlElems [mkError c_warn msg] -addHtmlElems :: XmlTrees -> Context -> Context+addHtmlElems :: XmlTrees -> Context -> Context addHtmlElems elems (body, openTags) = (reverse elems ++ body, openTags) -openTag :: String -> XmlTrees -> Context -> Context+openTag :: String -> XmlTrees -> Context -> Context openTag tn al (body, openTags) = ([], (tn, al, body) : openTags) -closeTag :: SourcePos -> String -> Context -> Context+closeTag :: SourcePos -> String -> Context -> Context closeTag pos n context | n `elem` (map ( \ (n1, _, _) -> n1) $ snd context)- = closeTag' n context+ = closeTag' n context | otherwise- = addHtmlWarn (show pos ++ " no opening tag found for </" ++ n ++ ">")- .- addHtmlTag n [] []+ = addHtmlWarn (show pos ++ " no opening tag found for </" ++ n ++ ">")+ .+ addHtmlTag n [] [] $- context+ context where closeTag' n' (body', (n1, al1, body1) : restOpen)- = close context1- where- context1- = addHtmlTag n1 al1 body' (body1, restOpen)- close- | n' == n1- = id- | n1 `isInnerHtmlTagOf` n'- = closeTag pos n'- | otherwise- = addHtmlWarn (show pos ++ " no closing tag found for \"<" ++ n1 ++ " ...>\"")- .- closeTag' n'+ = close context1+ where+ context1+ = addHtmlTag n1 al1 body' (body1, restOpen)+ close+ | n' == n1+ = id+ | n1 `isInnerHtmlTagOf` n'+ = closeTag pos n'+ | otherwise+ = addHtmlWarn (show pos ++ " no closing tag found for \"<" ++ n1 ++ " ...>\"")+ .+ closeTag' n' closeTag' _ _- = error "illegal argument for closeTag'"+ = error "illegal argument for closeTag'" -closePrevTag :: SourcePos -> String -> Context -> Context+closePrevTag :: SourcePos -> String -> Context -> Context closePrevTag _pos _n context@(_body, []) = context closePrevTag pos n context@(body, (n1, al1, body1) : restOpen) | n `closes` n1- = closePrevTag pos n- ( addHtmlWarn (show pos ++ " tag \"<" ++ n1 ++ " ...>\" implicitly closed by opening tag \"<" ++ n ++ " ...>\"")- .- addHtmlTag n1 al1 body- $- (body1, restOpen)- )+ = closePrevTag pos n+ ( addHtmlWarn (show pos ++ " tag \"<" ++ n1 ++ " ...>\" implicitly closed by opening tag \"<" ++ n ++ " ...>\"")+ .+ addHtmlTag n1 al1 body+ $+ (body1, restOpen)+ ) | otherwise- = context+ = context -- ------------------------------------------------------------ -- -- taken from HaXml and extended -isEmptyHtmlTag :: String -> Bool+isEmptyHtmlTag :: String -> Bool isEmptyHtmlTag n = n `elem` emptyHtmlTags -emptyHtmlTags :: [String]+emptyHtmlTags :: [String] emptyHtmlTags = [ "area" , "base"@@ -462,76 +462,76 @@ , "param" ] -isInnerHtmlTagOf :: String -> String -> Bool+isInnerHtmlTagOf :: String -> String -> Bool n `isInnerHtmlTagOf` tn = n `elem` ( fromMaybe [] . lookup tn $ [ ("body", ["p"])- , ("caption", ["p"])- , ("dd", ["p"])- , ("div", ["p"])- , ("dl", ["dt","dd"])- , ("dt", ["p"])- , ("li", ["p"])- , ("map", ["p"])- , ("object", ["p"])- , ("ol", ["li"])- , ("table", ["th","tr","td","thead","tfoot","tbody"])- , ("tbody", ["th","tr","td"])- , ("td", ["p"])- , ("tfoot", ["th","tr","td"])- , ("th", ["p"])- , ("thead", ["th","tr","td"])- , ("tr", ["th","td"])- , ("ul", ["li"])- ]+ , ("caption", ["p"])+ , ("dd", ["p"])+ , ("div", ["p"])+ , ("dl", ["dt","dd"])+ , ("dt", ["p"])+ , ("li", ["p"])+ , ("map", ["p"])+ , ("object", ["p"])+ , ("ol", ["li"])+ , ("table", ["th","tr","td","thead","tfoot","tbody"])+ , ("tbody", ["th","tr","td"])+ , ("td", ["p"])+ , ("tfoot", ["th","tr","td"])+ , ("th", ["p"])+ , ("thead", ["th","tr","td"])+ , ("tr", ["th","td"])+ , ("ul", ["li"])+ ] ) closesHtmlTag , closes :: String -> String -> Bool -closesHtmlTag = closes+closesHtmlTag = closes -"a" `closes` "a" = True-"li" `closes` "li" = True-"th" `closes` t | t `elem` ["th","td"] = True-"td" `closes` t | t `elem` ["th","td"] = True-"tr" `closes` t | t `elem` ["th","td","tr"] = True-"dt" `closes` t | t `elem` ["dt","dd"] = True-"dd" `closes` t | t `elem` ["dt","dd"] = True-"hr" `closes` "p" = True-"colgroup" - `closes` "colgroup" = True-"form" `closes` "form" = True-"label" `closes` "label" = True-"map" `closes` "map" = True+"a" `closes` "a" = True+"li" `closes` "li" = True+"th" `closes` t | t `elem` ["th","td"] = True+"td" `closes` t | t `elem` ["th","td"] = True+"tr" `closes` t | t `elem` ["th","td","tr"] = True+"dt" `closes` t | t `elem` ["dt","dd"] = True+"dd" `closes` t | t `elem` ["dt","dd"] = True+"hr" `closes` "p" = True+"colgroup"+ `closes` "colgroup" = True+"form" `closes` "form" = True+"label" `closes` "label" = True+"map" `closes` "map" = True "object"- `closes` "object" = True-_ `closes` t | t `elem` ["option"- ,"script"- ,"style"- ,"textarea"- ,"title"- ] = True-t `closes` "select" | t /= "option" = True-"thead" `closes` t | t `elem` ["colgroup"] = True-"tfoot" `closes` t | t `elem` ["thead"- ,"colgroup"] = True-"tbody" `closes` t | t `elem` ["tbody"- ,"tfoot"- ,"thead"- ,"colgroup"] = True-t `closes` t2 | t `elem` ["h1","h2","h3"- ,"h4","h5","h6"- ,"dl","ol","ul"- ,"table"- ,"div","p"- ]- &&+ `closes` "object" = True+_ `closes` t | t `elem` ["option"+ ,"script"+ ,"style"+ ,"textarea"+ ,"title"+ ] = True+t `closes` "select" | t /= "option" = True+"thead" `closes` t | t `elem` ["colgroup"] = True+"tfoot" `closes` t | t `elem` ["thead"+ ,"colgroup"] = True+"tbody" `closes` t | t `elem` ["tbody"+ ,"tfoot"+ ,"thead"+ ,"colgroup"] = True+t `closes` t2 | t `elem` ["h1","h2","h3"+ ,"h4","h5","h6"+ ,"dl","ol","ul"+ ,"table"+ ,"div","p"+ ]+ && t2 `elem` ["h1","h2","h3"- ,"h4","h5","h6"- ,"p" -- not "div"- ] = True-_ `closes` _ = False+ ,"h4","h5","h6"+ ,"p" -- not "div"+ ] = True+_ `closes` _ = False -- ------------------------------------------------------------
src/Text/XML/HXT/Parser/ProtocolHandlerUtil.hs view
@@ -1,6 +1,6 @@ -- ------------------------------------------------------------ -{- +{- Module : Text.XML.HXT.Parser.ProtocolHandlerUtil Copyright : Copyright (C) 2008 Uwe Schmidt License : MIT@@ -23,9 +23,9 @@ import Text.XML.HXT.DOM.XmlKeywords -import Text.XML.HXT.DOM.Util ( stringToUpper- , stringTrim- )+import Text.XML.HXT.DOM.Util ( stringToUpper+ , stringTrim+ ) import qualified Text.ParserCombinators.Parsec as P @@ -38,27 +38,27 @@ -- Sometimes the server deliver the charset spec in quotes -- these are removed -parseContentType :: P.Parser [(String, String)]+parseContentType :: P.Parser [(String, String)] parseContentType = P.try ( do- mimeType <- ( do- mt <- P.many (P.noneOf ";")- rtMT mt- )- charset <- ( do- _ <- P.char ';'- _ <- P.many (P.oneOf " \t'")- _ <- P.string "charset="- _ <- P.option '"' (P.oneOf "\"'")- cs <- P.many1 (P.noneOf "\"'")- return [ (transferEncoding, stringToUpper cs) ]- )- return (mimeType ++ charset)- )+ mimeType <- ( do+ mt <- P.many (P.noneOf ";")+ rtMT mt+ )+ charset <- ( do+ _ <- P.char ';'+ _ <- P.many (P.oneOf " \t'")+ _ <- P.string "charset="+ _ <- P.option '"' (P.oneOf "\"'")+ cs <- P.many1 (P.noneOf "\"'")+ return [ (transferEncoding, stringToUpper cs) ]+ )+ return (mimeType ++ charset)+ ) P.<|> ( do- mt <- P.many (P.noneOf ";")- rtMT mt+ mt <- P.many (P.noneOf ";")+ rtMT mt ) where rtMT mt = return [ (transferMimeType, stringTrim mt) ]
src/Text/XML/HXT/Parser/TagSoup.hs view
@@ -27,246 +27,261 @@ import Data.Maybe import Text.HTML.TagSoup-import Text.HTML.TagSoup.Entity ( lookupNumericEntity- )-import Text.XML.HXT.DOM.Unicode ( isXmlSpaceChar- )-import Text.XML.HXT.Parser.HtmlParsec ( isEmptyHtmlTag- , isInnerHtmlTagOf- , closesHtmlTag- )+import Text.HTML.TagSoup.Entity ( lookupNumericEntity+ )+import Text.XML.HXT.DOM.Unicode ( isXmlSpaceChar+ )+import Text.XML.HXT.Parser.HtmlParsec ( isEmptyHtmlTag+ , isInnerHtmlTagOf+ , closesHtmlTag+ ) import Text.XML.HXT.Parser.XhtmlEntities-import Text.XML.HXT.DOM.Interface ( XmlTrees- , QName- , NsEnv- , toNsEnv- , newXName- , nullXName- , mkQName'- , mkName- , isWellformedQualifiedName- , c_warn- , a_xml- , a_xmlns- , xmlNamespace- , xmlnsNamespace- )-import Text.XML.HXT.DOM.XmlNode ( isElem- , mkError- , mkCmt- , mkText- , mkElement- , mkAttr- )+import Text.XML.HXT.DOM.Interface ( XmlTrees+ , QName+ , NsEnv+ , toNsEnv+ , newXName+ , nullXName+ , mkQName'+ , mkName+ , isWellformedQualifiedName+ , c_warn+ , a_xml+ , a_xmlns+ , xmlNamespace+ , xmlnsNamespace+ )+import Text.XML.HXT.DOM.XmlNode ( isElem+ , mkError+ , mkCmt+ , mkText+ , mkElement+ , mkAttr+ ) --- ---------------------------------------- +-- ---------------------------------------- -- The name table contains the id map. All element and attribute names are stored -- the first time they are ecountered, and later always this name is used, -- not a string built by the parser. -type STag = Tag String+type STag = Tag String -type Tags = [STag]+type Tags = [STag] -type Context = ([String], NsEnv)+type Context = ([String], NsEnv) -type State = Tags+type State = Tags -newtype Parser a = P { parse :: State -> (a, State)}+newtype Parser a = P { parse :: State -> (a, State)} instance Monad Parser where- return x = P $ \ ts -> (x, ts)- p >>= f = P $ \ ts -> let- (res, ts') = parse p ts+ return x = P $ \ ts -> (x, ts)+ p >>= f = P $ \ ts -> let+ (res, ts') = parse p ts in- parse (f res) ts'+ parse (f res) ts' -runParser :: Parser a -> Tags -> a-runParser p ts = fst . parse p $ ts+runParser :: Parser a -> Tags -> a+runParser p ts = fst . parse p $ ts -- ---------------------------------------- -cond :: Parser Bool -> Parser a -> Parser a -> Parser a-cond c t e = do- p <- c- if p then t else e+cond :: Parser Bool -> Parser a -> Parser a -> Parser a+cond c t e = do+ p <- c+ if p then t else e -lookAhead :: (STag -> Bool) -> Parser Bool-lookAhead p = P $ \ s -> (not (null s) && p (head s), s)+lookAhead :: (STag -> Bool) -> Parser Bool+lookAhead p = P $ \ s -> (not (null s) && p (head s), s) -- ---------------------------------------- -- primitive look ahead tests -isEof :: Parser Bool-isEof = P $ \ s -> (null s, s)+isEof :: Parser Bool+isEof = P $ \ s -> (null s, s) -isText :: Parser Bool-isText = lookAhead is- where- is (TagText _) = True- is _ = False+isText :: Parser Bool+isText = lookAhead is+ where+ is (TagText _) = True+ is _ = False -isCmt :: Parser Bool-isCmt = lookAhead is- where- is (TagComment _) = True- is _ = False+isCmt :: Parser Bool+isCmt = lookAhead is+ where+ is (TagComment _) = True+ is _ = False -isWarn :: Parser Bool-isWarn = lookAhead is- where- is (TagWarning _) = True- is _ = False+isWarn :: Parser Bool+isWarn = lookAhead is+ where+ is (TagWarning _) = True+ is _ = False -isPos :: Parser Bool-isPos = lookAhead is- where- is (TagPosition _ _) = True- is _ = False+isPos :: Parser Bool+isPos = lookAhead is+ where+ is (TagPosition _ _) = True+ is _ = False -isCls :: Parser Bool-isCls = lookAhead is- where- is (TagClose _) = True- is _ = False+isCls :: Parser Bool+isCls = lookAhead is+ where+ is (TagClose _) = True+ is _ = False -isOpn :: Parser Bool-isOpn = lookAhead is- where- is (TagOpen _ _) = True- is _ = False+isOpn :: Parser Bool+isOpn = lookAhead is+ where+ is (TagOpen _ _) = True+ is _ = False -- ---------------------------------------- -- primitive symbol parsers -getTag :: Parser STag-getTag = P $ \ (t1:ts1) -> (t1, ts1)+getTag :: Parser STag+getTag = P $ \ (t1:ts1) -> (t1, ts1) -getSym :: (STag -> a) -> Parser a-getSym f = do- t <- getTag- return (f t)+getSym :: (STag -> a) -> Parser a+getSym f = do+ t <- getTag+ return (f t) -getText :: Parser String-getText = getSym sym- where- sym (TagText t) = t- sym _ = undefined+getText :: Parser String+getText = getSym sym+ where+ sym (TagText t) = t+ sym _ = undefined -getCmt :: Parser String-getCmt = getSym sym- where- sym (TagComment c) = c- sym _ = undefined+getCmt :: Parser String+getCmt = getSym sym+ where+ sym (TagComment c) = c+ sym _ = undefined -getWarn :: Parser String-getWarn = getSym sym- where- sym (TagWarning w) = w- sym _ = undefined+getWarn :: Parser String+getWarn = getSym sym+ where+ sym (TagWarning w) = w+ sym _ = undefined -getPos :: Parser (Int, Int)-getPos = getSym sym- where- sym (TagPosition l c) = (l, c)- sym _ = undefined+getPos :: Parser (Int, Int)+getPos = getSym sym+ where+ sym (TagPosition l c) = (l, c)+ sym _ = undefined -getCls :: Parser String-getCls = getSym sym- where- sym (TagClose n) = n- sym _ = undefined+getCls :: Parser String+getCls = getSym sym+ where+ sym (TagClose n) = n+ sym _ = undefined -getOpn :: Parser (String, [(String,String)])-getOpn = getSym sym- where- sym (TagOpen n al) = (n, al)- sym _ = undefined+getOpn :: Parser (String, [(String,String)])+getOpn = getSym sym+ where+ sym (TagOpen n al) = (n, al)+ sym _ = undefined -- ---------------------------------------- -- pushback parsers for inserting missing tags -pushBack :: STag -> Parser ()-pushBack t = P $ \ ts -> ((), t:ts)+pushBack :: STag -> Parser ()+pushBack t = P $ \ ts -> ((), t:ts) -insCls :: String -> Parser ()-insCls n = pushBack (TagClose n)+insCls :: String -> Parser ()+insCls n = pushBack (TagClose n) -insOpn :: String -> [(String, String)] -> Parser ()-insOpn n al = pushBack (TagOpen n al)+insOpn :: String -> [(String, String)] -> Parser ()+insOpn n al = pushBack (TagOpen n al) -- ---------------------------------------- -mkQN :: Bool -> Bool -> NsEnv -> String -> Parser QName+mkQN :: Bool -> Bool -> NsEnv -> String -> Parser QName mkQN withNamespaces isAttr env s | withNamespaces- = return qn1+ = return qn1 | otherwise- = return qn0+ = return qn0 where qn1- | isAttr && isSimpleName = s'- | isSimpleName = mkQName' nullXName (newXName s) (nsUri nullXName)- | isWellformedQualifiedName s = mkQName' px' lp' (nsUri px')- | otherwise = s'- qn0 = s'+ | isAttr && isSimpleName = s'+ | isSimpleName = mkQName' nullXName (newXName s) (nsUri nullXName)+ | isWellformedQualifiedName s = mkQName' px' lp' (nsUri px')+ | otherwise = s'+ qn0 = s' - nsUri x = fromMaybe nullXName . lookup x $ env- isSimpleName = all (/= ':') s- (px, (_ : lp)) = span(/= ':') s- px' = newXName px- lp' = newXName lp+ nsUri x = fromMaybe nullXName . lookup x $ env+ isSimpleName = all (/= ':') s+ (px, (_ : lp)) = span(/= ':') s+ px' = newXName px+ lp' = newXName lp s' = mkName s -extendNsEnv :: Bool -> [(String, String)] -> NsEnv -> NsEnv+extendNsEnv :: Bool -> [(String, String)] -> NsEnv -> NsEnv extendNsEnv withNamespaces al1 env | withNamespaces- = toNsEnv (concatMap (uncurry addNs) al1) ++ env+ = toNsEnv (concatMap (uncurry addNs) al1) ++ env | otherwise- = env+ = env where addNs n v- | px == a_xmlns- &&- (null lp || (not . null . tail $ lp))- = [(drop 1 lp, v)]- | otherwise- = []- where- (px, lp) = span (/= ':') n+ | px == a_xmlns+ &&+ (null lp || (not . null . tail $ lp))+ = [(drop 1 lp, v)]+ | otherwise+ = []+ where+ (px, lp) = span (/= ':') n -- ---------------------------------------- -- own entity lookup to prevent problems with & and tagsoup hack for IE -lookupEntity :: Bool -> Bool -> String -> Tags-lookupEntity withWarnings _asHtml e0@('#':e)+lookupEntity :: Bool -> Bool -> (String, Bool) -> Tags+lookupEntity withWarnings _asHtml (e0@('#':e), withSemicolon) = case lookupNumericEntity e of- Just c -> [ TagText [c] ]- Nothing -> ( TagText $ "&" ++ e0 ++ ";") :- if withWarnings- then [TagWarning $ "illegal char reference: &" ++ e ++ ";"]- else []+ Just c -> (TagText [c])+ : missingSemi+ Nothing -> ( TagText $ "&" ++ e0 ++ [';' | withSemicolon])+ : if withWarnings+ then (TagWarning $ "illegal char reference: &" ++ e ++ ";")+ : missingSemi+ else []+ where+ missingSemi+ | withWarnings+ &&+ not withSemicolon = [TagWarning $ "missing \";\" at end of char reference: &" ++ e]+ | otherwise = [] -lookupEntity withWarnings asHtml e+lookupEntity withWarnings asHtml (e, withSemicolon) = case (lookup e entities) of- Just x -> [TagText [toEnum x]]- Nothing -> (TagText $ "&" ++ e ++ ";") :- if withWarnings- then [TagWarning $ "Unknown entity reference: &" ++ e ++ ";"]- else []+ Just x -> (TagText [toEnum x])+ : missingSemi+ Nothing -> (TagText $ "&" ++ e ++ [';' | withSemicolon])+ : if withWarnings+ then (TagWarning $ "Unknown entity reference: &" ++ e ++ ";")+ : missingSemi+ else [] where entities- | asHtml = xhtmlEntities- | otherwise = xhtmlEntities -- xmlEntities (TODO: xhtml is xml and html)+ | asHtml = xhtmlEntities+ | otherwise = xhtmlEntities -- xmlEntities (TODO: xhtml is xml and html)+ missingSemi+ | withWarnings+ &&+ not withSemicolon = [TagWarning $ "missing \";\" at end of entity reference: &" ++ e]+ | otherwise = [] -lookupEntityAttr :: Bool -> Bool -> (String, Bool) -> (String, Tags)+lookupEntityAttr :: Bool -> Bool -> (String, Bool) -> (String, Tags) lookupEntityAttr withWarnings asHtml (e, b)- | null r = (s, r)- | otherwise = ("&" ++ s ++ [';'|b], r)+ | null r = (s, r)+ | otherwise = ("&" ++ s ++ [';' | b], r) where- (TagText s) : r = lookupEntity withWarnings asHtml e+ (TagText s) : r = lookupEntity withWarnings asHtml (e, b) -- ---------------------------------------- {-@@ -294,7 +309,7 @@ f (TagOpen name attrs) = TagOpen (nameToLower name) (map attrToLower attrs) f (TagClose name)- = TagClose (nameToLower name)+ = TagClose (nameToLower name) f a = a nameToLower = map toLower attrToLower (an, av) = (nameToLower an, av)@@ -302,28 +317,28 @@ -- ---------------------------------------- -- the main parser -parseHtmlTagSoup :: Bool -> Bool -> Bool -> Bool -> Bool -> String -> String -> XmlTrees+parseHtmlTagSoup :: Bool -> Bool -> Bool -> Bool -> Bool -> String -> String -> XmlTrees parseHtmlTagSoup withNamespaces withWarnings withComment removeWhiteSpace asHtml doc = ( docRootElem- . runParser (buildCont initContext)- . ( if asHtml- then lowerCaseNames- else id- )- . tagsoupParse+ . runParser (buildCont initContext)+ . ( if asHtml+ then lowerCaseNames+ else id+ )+ . tagsoupParse ) where- tagsoupParse :: String -> Tags- tagsoupParse = parseTagsOptions tagsoupOptions+ tagsoupParse :: String -> Tags+ tagsoupParse = parseTagsOptions tagsoupOptions - tagsoupOptions :: ParseOptions String- tagsoupOptions = parseOptions' { optTagWarning = withWarnings- , optEntityData = lookupEntity withWarnings asHtml- , optEntityAttrib = lookupEntityAttr withWarnings asHtml- }- where- parseOptions' :: ParseOptions String- parseOptions' = parseOptions+ tagsoupOptions :: ParseOptions String+ tagsoupOptions = parseOptions' { optTagWarning = withWarnings+ , optEntityData = lookupEntity withWarnings asHtml+ , optEntityAttrib = lookupEntityAttr withWarnings asHtml+ }+ where+ parseOptions' :: ParseOptions String+ parseOptions' = parseOptions -- This is essential for lazy parsing: -- the call of "take 1" stops parsing, when the first element is detected@@ -331,150 +346,150 @@ -- so eof is never checked unneccessarily docRootElem- = take 1 . filter isElem+ = take 1 . filter isElem - initContext = ( []- , toNsEnv $- [ (a_xml, xmlNamespace)- , (a_xmlns, xmlnsNamespace)- ]- )+ initContext = ( []+ , toNsEnv $+ [ (a_xml, xmlNamespace)+ , (a_xmlns, xmlnsNamespace)+ ]+ ) - wrap = (:[])+ wrap = (:[]) warn- | withWarnings = wrap . mkError c_warn . show . (doc ++) . (" " ++)- | otherwise = const []+ | withWarnings = wrap . mkError c_warn . show . (doc ++) . (" " ++)+ | otherwise = const [] cmt- | withComment = wrap . mkCmt- | otherwise = const []+ | withComment = wrap . mkCmt+ | otherwise = const [] txt- | removeWhiteSpace- = \ t ->- if all isXmlSpaceChar t- then []- else wrap . mkText $ t- | otherwise = wrap . mkText+ | removeWhiteSpace+ = \ t ->+ if all isXmlSpaceChar t+ then []+ else wrap . mkText $ t+ | otherwise = wrap . mkText isEmptyElem- | asHtml = isEmptyHtmlTag- | otherwise = const False+ | asHtml = isEmptyHtmlTag+ | otherwise = const False isInnerElem- | asHtml = isInnerHtmlTagOf- | otherwise = const (const False)+ | asHtml = isInnerHtmlTagOf+ | otherwise = const (const False) closesElem- | asHtml = \ ns n1 ->- not (null ns)- &&- n1 `closesHtmlTag` (head ns)- | otherwise = const (const False)+ | asHtml = \ ns n1 ->+ not (null ns)+ &&+ n1 `closesHtmlTag` (head ns)+ | otherwise = const (const False) - buildCont :: Context -> Parser XmlTrees+ buildCont :: Context -> Parser XmlTrees buildCont ns- = cond isText ( do- t <- getText- rl <- buildCont ns- return (txt t ++ rl)- )- ( cond isOpn ( do- (n,al) <- getOpn- openTag ns n al- )- ( cond isCls ( do- n <- getCls- closeTag ns n- )- ( cond isCmt ( do- c <- getCmt- rl <- buildCont ns- return (cmt c ++ rl)- )- ( cond isWarn ( do- w <- getWarn- rl <- buildCont ns- return (warn w ++ rl)- )- ( cond isPos ( do- _ <- getPos- buildCont ns- )- ( cond isEof ( do- _ <- isEof- closeAll ns- )- ( return (warn "parse error in tagsoup tree construction")- )- )- )- )- )- )- )- where- closeTag :: Context -> String -> Parser XmlTrees- closeTag ((n':_), _) n1- | n' == n1 = return [] -- a normal closing tag- -- all other cases try to repair wrong html- closeTag ns'@((n':_), _) n1 -- n1 closes n implicitly- | n' `isInnerElem` n1 -- e.g. <td>...</tr>- = do- insCls n1 -- pushback </n1>- insCls n' -- insert a </n'>- buildCont ns' -- try again- closeTag ns' n1- | isEmptyElem n1 = buildCont ns' -- ignore a redundant closing tag for empty element- closeTag ns'@((n':ns1'), _) n1 -- insert a missing closing tag- | n1 `elem` ns1' = do- insCls n1- insCls n'- rl <- buildCont ns'- return ( warn ("closing tag " ++ show n' ++- " expected, but " ++ show n1 ++ " found")- ++ rl- )- closeTag ns' n1 -- ignore a wrong closing tag- = do- rl <- buildCont ns'- return ( warn ("no opening tag for closing tag " ++ show n1)- ++ rl- )+ = cond isText ( do+ t <- getText+ rl <- buildCont ns+ return (txt t ++ rl)+ )+ ( cond isOpn ( do+ (n,al) <- getOpn+ openTag ns n al+ )+ ( cond isCls ( do+ n <- getCls+ closeTag ns n+ )+ ( cond isCmt ( do+ c <- getCmt+ rl <- buildCont ns+ return (cmt c ++ rl)+ )+ ( cond isWarn ( do+ w <- getWarn+ rl <- buildCont ns+ return (warn w ++ rl)+ )+ ( cond isPos ( do+ _ <- getPos+ buildCont ns+ )+ ( cond isEof ( do+ _ <- isEof+ closeAll ns+ )+ ( return (warn "parse error in tagsoup tree construction")+ )+ )+ )+ )+ )+ )+ )+ where+ closeTag :: Context -> String -> Parser XmlTrees+ closeTag ((n':_), _) n1+ | n' == n1 = return [] -- a normal closing tag+ -- all other cases try to repair wrong html+ closeTag ns'@((n':_), _) n1 -- n1 closes n implicitly+ | n' `isInnerElem` n1 -- e.g. <td>...</tr>+ = do+ insCls n1 -- pushback </n1>+ insCls n' -- insert a </n'>+ buildCont ns' -- try again+ closeTag ns' n1+ | isEmptyElem n1 = buildCont ns' -- ignore a redundant closing tag for empty element+ closeTag ns'@((n':ns1'), _) n1 -- insert a missing closing tag+ | n1 `elem` ns1' = do+ insCls n1+ insCls n'+ rl <- buildCont ns'+ return ( warn ("closing tag " ++ show n' +++ " expected, but " ++ show n1 ++ " found")+ ++ rl+ )+ closeTag ns' n1 -- ignore a wrong closing tag+ = do+ rl <- buildCont ns'+ return ( warn ("no opening tag for closing tag " ++ show n1)+ ++ rl+ ) - openTag :: Context -> String -> [(String, String)] -> Parser XmlTrees- openTag cx'@(ns',env') n1 al1- | isPiDT n1 = buildCont cx'- | isEmptyElem n1- = do- qn <- mkElemQN nenv n1- al <- mkAttrs al1- rl <- buildCont cx'- return (mkElement qn al [] : rl)- | closesElem ns' n1 = do- insOpn n1 al1- insCls (head ns')- buildCont cx'- | otherwise = do- qn <- mkElemQN nenv n1- al <- mkAttrs al1- cs <- buildCont ((n1 : ns'), nenv)- rl <- buildCont cx'- return (mkElement qn al cs : rl)- where- nenv = extendNsEnv withNamespaces al1 env'- mkElemQN = mkQN withNamespaces False- mkAttrQN = mkQN withNamespaces True- isPiDT ('?':_) = True- isPiDT ('!':_) = True- isPiDT _ = False- mkAttrs = mapM (uncurry mkA)- mkA an av = do- qan <- mkAttrQN nenv an- return (mkAttr qan (wrap . mkText $ av))+ openTag :: Context -> String -> [(String, String)] -> Parser XmlTrees+ openTag cx'@(ns',env') n1 al1+ | isPiDT n1 = buildCont cx'+ | isEmptyElem n1+ = do+ qn <- mkElemQN nenv n1+ al <- mkAttrs al1+ rl <- buildCont cx'+ return (mkElement qn al [] : rl)+ | closesElem ns' n1 = do+ insOpn n1 al1+ insCls (head ns')+ buildCont cx'+ | otherwise = do+ qn <- mkElemQN nenv n1+ al <- mkAttrs al1+ cs <- buildCont ((n1 : ns'), nenv)+ rl <- buildCont cx'+ return (mkElement qn al cs : rl)+ where+ nenv = extendNsEnv withNamespaces al1 env'+ mkElemQN = mkQN withNamespaces False+ mkAttrQN = mkQN withNamespaces True+ isPiDT ('?':_) = True+ isPiDT ('!':_) = True+ isPiDT _ = False+ mkAttrs = mapM (uncurry mkA)+ mkA an av = do+ qan <- mkAttrQN nenv an+ return (mkAttr qan (wrap . mkText $ av)) - closeAll :: ([String], NsEnv) -> Parser XmlTrees- closeAll (ns',_) = return (concatMap wrn ns')- where- wrn = warn . ("insert missing closing tag " ++) . show+ closeAll :: ([String], NsEnv) -> Parser XmlTrees+ closeAll (ns',_) = return (concatMap wrn ns')+ where+ wrn = warn . ("insert missing closing tag " ++) . show -- ------------------------------------------------------------
src/Text/XML/HXT/Parser/XhtmlEntities.hs view
@@ -19,260 +19,260 @@ -- | table with all XHTML entity refs and corresponding unicode values -xhtmlEntities :: [(String, Int)]-xhtmlEntities = xmlEntities- ++- [ ("nbsp", 160)- , ("iexcl", 161)- , ("cent", 162)- , ("pound", 163)- , ("curren", 164)- , ("yen", 165)- , ("brvbar", 166)- , ("sect", 167)- , ("uml", 168)- , ("copy", 169)- , ("ordf", 170)- , ("laquo", 171)- , ("not", 172)- , ("shy", 173)- , ("reg", 174)- , ("macr", 175)- , ("deg", 176)- , ("plusmn", 177)- , ("sup2", 178)- , ("sup3", 179)- , ("acute", 180)- , ("micro", 181)- , ("para", 182)- , ("middot", 183)- , ("cedil", 184)- , ("sup1", 185)- , ("ordm", 186)- , ("raquo", 187)- , ("frac14", 188)- , ("frac12", 189)- , ("frac34", 190)- , ("iquest", 191)- , ("Agrave", 192)- , ("Aacute", 193)- , ("Acirc", 194)- , ("Atilde", 195)- , ("Auml", 196)- , ("Aring", 197)- , ("AElig", 198)- , ("Ccedil", 199)- , ("Egrave", 200)- , ("Eacute", 201)- , ("Ecirc", 202)- , ("Euml", 203)- , ("Igrave", 204)- , ("Iacute", 205)- , ("Icirc", 206)- , ("Iuml", 207)- , ("ETH", 208)- , ("Ntilde", 209)- , ("Ograve", 210)- , ("Oacute", 211)- , ("Ocirc", 212)- , ("Otilde", 213)- , ("Ouml", 214)- , ("times", 215)- , ("Oslash", 216)- , ("Ugrave", 217)- , ("Uacute", 218)- , ("Ucirc", 219)- , ("Uuml", 220)- , ("Yacute", 221)- , ("THORN", 222)- , ("szlig", 223)- , ("agrave", 224)- , ("aacute", 225)- , ("acirc", 226)- , ("atilde", 227)- , ("auml", 228)- , ("aring", 229)- , ("aelig", 230)- , ("ccedil", 231)- , ("egrave", 232)- , ("eacute", 233)- , ("ecirc", 234)- , ("euml", 235)- , ("igrave", 236)- , ("iacute", 237)- , ("icirc", 238)- , ("iuml", 239)- , ("eth", 240)- , ("ntilde", 241)- , ("ograve", 242)- , ("oacute", 243)- , ("ocirc", 244)- , ("otilde", 245)- , ("ouml", 246)- , ("divide", 247)- , ("oslash", 248)- , ("ugrave", 249)- , ("uacute", 250)- , ("ucirc", 251)- , ("uuml", 252)- , ("yacute", 253)- , ("thorn", 254)- , ("yuml", 255)+xhtmlEntities :: [(String, Int)]+xhtmlEntities = xmlEntities+ +++ [ ("nbsp", 160)+ , ("iexcl", 161)+ , ("cent", 162)+ , ("pound", 163)+ , ("curren", 164)+ , ("yen", 165)+ , ("brvbar", 166)+ , ("sect", 167)+ , ("uml", 168)+ , ("copy", 169)+ , ("ordf", 170)+ , ("laquo", 171)+ , ("not", 172)+ , ("shy", 173)+ , ("reg", 174)+ , ("macr", 175)+ , ("deg", 176)+ , ("plusmn", 177)+ , ("sup2", 178)+ , ("sup3", 179)+ , ("acute", 180)+ , ("micro", 181)+ , ("para", 182)+ , ("middot", 183)+ , ("cedil", 184)+ , ("sup1", 185)+ , ("ordm", 186)+ , ("raquo", 187)+ , ("frac14", 188)+ , ("frac12", 189)+ , ("frac34", 190)+ , ("iquest", 191)+ , ("Agrave", 192)+ , ("Aacute", 193)+ , ("Acirc", 194)+ , ("Atilde", 195)+ , ("Auml", 196)+ , ("Aring", 197)+ , ("AElig", 198)+ , ("Ccedil", 199)+ , ("Egrave", 200)+ , ("Eacute", 201)+ , ("Ecirc", 202)+ , ("Euml", 203)+ , ("Igrave", 204)+ , ("Iacute", 205)+ , ("Icirc", 206)+ , ("Iuml", 207)+ , ("ETH", 208)+ , ("Ntilde", 209)+ , ("Ograve", 210)+ , ("Oacute", 211)+ , ("Ocirc", 212)+ , ("Otilde", 213)+ , ("Ouml", 214)+ , ("times", 215)+ , ("Oslash", 216)+ , ("Ugrave", 217)+ , ("Uacute", 218)+ , ("Ucirc", 219)+ , ("Uuml", 220)+ , ("Yacute", 221)+ , ("THORN", 222)+ , ("szlig", 223)+ , ("agrave", 224)+ , ("aacute", 225)+ , ("acirc", 226)+ , ("atilde", 227)+ , ("auml", 228)+ , ("aring", 229)+ , ("aelig", 230)+ , ("ccedil", 231)+ , ("egrave", 232)+ , ("eacute", 233)+ , ("ecirc", 234)+ , ("euml", 235)+ , ("igrave", 236)+ , ("iacute", 237)+ , ("icirc", 238)+ , ("iuml", 239)+ , ("eth", 240)+ , ("ntilde", 241)+ , ("ograve", 242)+ , ("oacute", 243)+ , ("ocirc", 244)+ , ("otilde", 245)+ , ("ouml", 246)+ , ("divide", 247)+ , ("oslash", 248)+ , ("ugrave", 249)+ , ("uacute", 250)+ , ("ucirc", 251)+ , ("uuml", 252)+ , ("yacute", 253)+ , ("thorn", 254)+ , ("yuml", 255) - , ("OElig", 338)- , ("oelig", 339)- , ("Scaron", 352)- , ("scaron", 353)- , ("Yuml", 376)- , ("circ", 710)- , ("tilde", 732)+ , ("OElig", 338)+ , ("oelig", 339)+ , ("Scaron", 352)+ , ("scaron", 353)+ , ("Yuml", 376)+ , ("circ", 710)+ , ("tilde", 732) - , ("ensp", 8194)- , ("emsp", 8195)- , ("thinsp", 8201)- , ("zwnj", 8204)- , ("zwj", 8205)- , ("lrm", 8206)- , ("rlm", 8207)- , ("ndash", 8211)- , ("mdash", 8212)- , ("lsquo", 8216)- , ("rsquo", 8217)- , ("sbquo", 8218)- , ("ldquo", 8220)- , ("rdquo", 8221)- , ("bdquo", 8222)- , ("dagger", 8224)- , ("Dagger", 8225)- , ("permil", 8240)- , ("lsaquo", 8249)- , ("rsaquo", 8250)- , ("euro", 8364)+ , ("ensp", 8194)+ , ("emsp", 8195)+ , ("thinsp", 8201)+ , ("zwnj", 8204)+ , ("zwj", 8205)+ , ("lrm", 8206)+ , ("rlm", 8207)+ , ("ndash", 8211)+ , ("mdash", 8212)+ , ("lsquo", 8216)+ , ("rsquo", 8217)+ , ("sbquo", 8218)+ , ("ldquo", 8220)+ , ("rdquo", 8221)+ , ("bdquo", 8222)+ , ("dagger", 8224)+ , ("Dagger", 8225)+ , ("permil", 8240)+ , ("lsaquo", 8249)+ , ("rsaquo", 8250)+ , ("euro", 8364) - , ("fnof", 402)- , ("Alpha", 913)- , ("Beta", 914)- , ("Gamma", 915)- , ("Delta", 916)- , ("Epsilon", 917)- , ("Zeta", 918)- , ("Eta", 919)- , ("Theta", 920)- , ("Iota", 921)- , ("Kappa", 922)- , ("Lambda", 923)- , ("Mu", 924)- , ("Nu", 925)- , ("Xi", 926)- , ("Omicron", 927)- , ("Pi", 928)- , ("Rho", 929)- , ("Sigma", 931)- , ("Tau", 932)- , ("Upsilon", 933)- , ("Phi", 934)- , ("Chi", 935)- , ("Psi", 936)- , ("Omega", 937)- , ("alpha", 945)- , ("beta", 946)- , ("gamma", 947)- , ("delta", 948)- , ("epsilon", 949)- , ("zeta", 950)- , ("eta", 951)- , ("theta", 952)- , ("iota", 953)- , ("kappa", 954)- , ("lambda", 955)- , ("mu", 956)- , ("nu", 957)- , ("xi", 958)- , ("omicron", 959)- , ("pi", 960)- , ("rho", 961)- , ("sigmaf", 962)- , ("sigma", 963)- , ("tau", 964)- , ("upsilon", 965)- , ("phi", 966)- , ("chi", 967)- , ("psi", 968)- , ("omega", 969)- , ("thetasym", 977)- , ("upsih", 978)- , ("piv", 982)- , ("bull", 8226)- , ("hellip", 8230)- , ("prime", 8242)- , ("Prime", 8243)- , ("oline", 8254)- , ("frasl", 8260)- , ("weierp", 8472)- , ("image", 8465)- , ("real", 8476)- , ("trade", 8482)- , ("alefsym", 8501)- , ("larr", 8592)- , ("uarr", 8593)- , ("rarr", 8594)- , ("darr", 8595)- , ("harr", 8596)- , ("crarr", 8629)- , ("lArr", 8656)- , ("uArr", 8657)- , ("rArr", 8658)- , ("dArr", 8659)- , ("hArr", 8660)- , ("forall", 8704)- , ("part", 8706)- , ("exist", 8707)- , ("empty", 8709)- , ("nabla", 8711)- , ("isin", 8712)- , ("notin", 8713)- , ("ni", 8715)- , ("prod", 8719)- , ("sum", 8721)- , ("minus", 8722)- , ("lowast", 8727)- , ("radic", 8730)- , ("prop", 8733)- , ("infin", 8734)- , ("ang", 8736)- , ("and", 8743)- , ("or", 8744)- , ("cap", 8745)- , ("cup", 8746)- , ("int", 8747)- , ("there4", 8756)- , ("sim", 8764)- , ("cong", 8773)- , ("asymp", 8776)- , ("ne", 8800)- , ("equiv", 8801)- , ("le", 8804)- , ("ge", 8805)- , ("sub", 8834)- , ("sup", 8835)- , ("nsub", 8836)- , ("sube", 8838)- , ("supe", 8839)- , ("oplus", 8853)- , ("otimes", 8855)- , ("perp", 8869)- , ("sdot", 8901)- , ("lceil", 8968)- , ("rceil", 8969)- , ("lfloor", 8970)- , ("rfloor", 8971)- , ("lang", 9001)- , ("rang", 9002)- , ("loz", 9674)- , ("spades", 9824)- , ("clubs", 9827)- , ("hearts", 9829)- , ("diams", 9830)- ]+ , ("fnof", 402)+ , ("Alpha", 913)+ , ("Beta", 914)+ , ("Gamma", 915)+ , ("Delta", 916)+ , ("Epsilon", 917)+ , ("Zeta", 918)+ , ("Eta", 919)+ , ("Theta", 920)+ , ("Iota", 921)+ , ("Kappa", 922)+ , ("Lambda", 923)+ , ("Mu", 924)+ , ("Nu", 925)+ , ("Xi", 926)+ , ("Omicron", 927)+ , ("Pi", 928)+ , ("Rho", 929)+ , ("Sigma", 931)+ , ("Tau", 932)+ , ("Upsilon", 933)+ , ("Phi", 934)+ , ("Chi", 935)+ , ("Psi", 936)+ , ("Omega", 937)+ , ("alpha", 945)+ , ("beta", 946)+ , ("gamma", 947)+ , ("delta", 948)+ , ("epsilon", 949)+ , ("zeta", 950)+ , ("eta", 951)+ , ("theta", 952)+ , ("iota", 953)+ , ("kappa", 954)+ , ("lambda", 955)+ , ("mu", 956)+ , ("nu", 957)+ , ("xi", 958)+ , ("omicron", 959)+ , ("pi", 960)+ , ("rho", 961)+ , ("sigmaf", 962)+ , ("sigma", 963)+ , ("tau", 964)+ , ("upsilon", 965)+ , ("phi", 966)+ , ("chi", 967)+ , ("psi", 968)+ , ("omega", 969)+ , ("thetasym", 977)+ , ("upsih", 978)+ , ("piv", 982)+ , ("bull", 8226)+ , ("hellip", 8230)+ , ("prime", 8242)+ , ("Prime", 8243)+ , ("oline", 8254)+ , ("frasl", 8260)+ , ("weierp", 8472)+ , ("image", 8465)+ , ("real", 8476)+ , ("trade", 8482)+ , ("alefsym", 8501)+ , ("larr", 8592)+ , ("uarr", 8593)+ , ("rarr", 8594)+ , ("darr", 8595)+ , ("harr", 8596)+ , ("crarr", 8629)+ , ("lArr", 8656)+ , ("uArr", 8657)+ , ("rArr", 8658)+ , ("dArr", 8659)+ , ("hArr", 8660)+ , ("forall", 8704)+ , ("part", 8706)+ , ("exist", 8707)+ , ("empty", 8709)+ , ("nabla", 8711)+ , ("isin", 8712)+ , ("notin", 8713)+ , ("ni", 8715)+ , ("prod", 8719)+ , ("sum", 8721)+ , ("minus", 8722)+ , ("lowast", 8727)+ , ("radic", 8730)+ , ("prop", 8733)+ , ("infin", 8734)+ , ("ang", 8736)+ , ("and", 8743)+ , ("or", 8744)+ , ("cap", 8745)+ , ("cup", 8746)+ , ("int", 8747)+ , ("there4", 8756)+ , ("sim", 8764)+ , ("cong", 8773)+ , ("asymp", 8776)+ , ("ne", 8800)+ , ("equiv", 8801)+ , ("le", 8804)+ , ("ge", 8805)+ , ("sub", 8834)+ , ("sup", 8835)+ , ("nsub", 8836)+ , ("sube", 8838)+ , ("supe", 8839)+ , ("oplus", 8853)+ , ("otimes", 8855)+ , ("perp", 8869)+ , ("sdot", 8901)+ , ("lceil", 8968)+ , ("rceil", 8969)+ , ("lfloor", 8970)+ , ("rfloor", 8971)+ , ("lang", 9001)+ , ("rang", 9002)+ , ("loz", 9674)+ , ("spades", 9824)+ , ("clubs", 9827)+ , ("hearts", 9829)+ , ("diams", 9830)+ ] -- ------------------------------------------------------------
src/Text/XML/HXT/Parser/XmlCharParser.hs view
@@ -4,7 +4,7 @@ -- Version : $Id: XmlCharParser.hs,v 1.2 2005/05/31 16:01:12 hxml Exp $ module Text.XML.HXT.Parser.XmlCharParser- ( xmlChar -- xml char parsers+ ( xmlChar -- xml char parsers , xmlNameChar , xmlNameStartChar , xmlNCNameChar@@ -25,38 +25,38 @@ -- | -- parse a single Unicode character -xmlChar :: GenParser Char state Unicode-xmlChar = satisfy isXmlChar <?> "legal XML character"+xmlChar :: GenParser Char state Unicode+xmlChar = satisfy isXmlChar <?> "legal XML character" -- | -- parse a XML name character -xmlNameChar :: GenParser Char state Unicode-xmlNameChar = satisfy isXmlNameChar <?> "legal XML name character"- +xmlNameChar :: GenParser Char state Unicode+xmlNameChar = satisfy isXmlNameChar <?> "legal XML name character"+ -- | -- parse a XML name start character -xmlNameStartChar :: GenParser Char state Unicode-xmlNameStartChar = satisfy isXmlNameStartChar <?> "legal XML name start character"- +xmlNameStartChar :: GenParser Char state Unicode+xmlNameStartChar = satisfy isXmlNameStartChar <?> "legal XML name start character"+ -- | -- parse a XML NCName character -xmlNCNameChar :: GenParser Char state Unicode-xmlNCNameChar = satisfy isXmlNCNameChar <?> "legal XML NCName character"- +xmlNCNameChar :: GenParser Char state Unicode+xmlNCNameChar = satisfy isXmlNCNameChar <?> "legal XML NCName character"+ -- | -- parse a XML NCName start character -xmlNCNameStartChar :: GenParser Char state Unicode-xmlNCNameStartChar = satisfy isXmlNCNameStartChar <?> "legal XML NCName start character"- +xmlNCNameStartChar :: GenParser Char state Unicode+xmlNCNameStartChar = satisfy isXmlNCNameStartChar <?> "legal XML NCName start character"+ -- | -- parse a XML letter character -xmlLetter :: GenParser Char state Unicode-xmlLetter = satisfy isXmlLetter <?> "legal XML letter"+xmlLetter :: GenParser Char state Unicode+xmlLetter = satisfy isXmlLetter <?> "legal XML letter" -- | -- White Space (2.3)@@ -67,8 +67,8 @@ -- otherwise \#x0D in internal parsing, e.g. for entities would normalize, -- would be transformed -xmlSpaceChar :: GenParser Char state Char-xmlSpaceChar = satisfy isXmlSpaceChar <?> "white space"+xmlSpaceChar :: GenParser Char state Char+xmlSpaceChar = satisfy isXmlSpaceChar <?> "white space" -- ------------------------------------------------------------
src/Text/XML/HXT/Parser/XmlDTDParser.hs view
@@ -59,105 +59,105 @@ -- all parsers dealing with whitespace will be redefined -- to handle parameter entity substitution -type LocalState = (Int, [(Int, String, SourcePos)])+type LocalState = (Int, [(Int, String, SourcePos)]) -type SParser a = GenParser Char LocalState a+type SParser a = GenParser Char LocalState a -initialLocalState :: SourcePos -> LocalState-initialLocalState p = (0, [(0, sourceName p, p)])+initialLocalState :: SourcePos -> LocalState+initialLocalState p = (0, [(0, sourceName p, p)]) -pushPar :: String -> SParser ()-pushPar n = do- p <- getPosition- updateState (\ (i, s) -> (i+1, (i+1, n, p) : s))- setPosition ( newPos (sourceName p ++ " (line " ++ show (sourceLine p) ++ ", column " ++ show (sourceColumn p) ++ ") in content of parameter entity ref %" ++ n ++ ";") 1 1)+pushPar :: String -> SParser ()+pushPar n = do+ p <- getPosition+ updateState (\ (i, s) -> (i+1, (i+1, n, p) : s))+ setPosition ( newPos (sourceName p ++ " (line " ++ show (sourceLine p) ++ ", column " ++ show (sourceColumn p) ++ ") in content of parameter entity ref %" ++ n ++ ";") 1 1) -popPar :: SParser ()-popPar = do- oldPos <- getPos- updateState pop- setPosition oldPos- where- pop (i, [(_, s, p)]) = (i+1, [(i+1, s, p)]) -- if param entity substitution is correctly implemented, this case does not occur- pop (i, _t:s) = (i, s)- pop (_i, []) = undefined -- stack is never empty+popPar :: SParser ()+popPar = do+ oldPos <- getPos+ updateState pop+ setPosition oldPos+ where+ pop (i, [(_, s, p)]) = (i+1, [(i+1, s, p)]) -- if param entity substitution is correctly implemented, this case does not occur+ pop (i, _t:s) = (i, s)+ pop (_i, []) = undefined -- stack is never empty -getParNo :: SParser Int-getParNo = do- (_i, (top, _n, _p) : _s) <- getState- return top+getParNo :: SParser Int+getParNo = do+ (_i, (top, _n, _p) : _s) <- getState+ return top -getPos :: SParser SourcePos-getPos = do- (_i, (_top, _n, p) : _s) <- getState- return p+getPos :: SParser SourcePos+getPos = do+ (_i, (_top, _n, p) : _s) <- getState+ return p -delPE :: SParser ()-delPE = do- _ <- char '\0'- return ()+delPE :: SParser ()+delPE = do+ _ <- char '\0'+ return () -startPE :: SParser ()+startPE :: SParser () startPE = do try ( do- delPE- n <- many1 (satisfy (/= '\0'))- delPE- pushPar n- )+ delPE+ n <- many1 (satisfy (/= '\0'))+ delPE+ pushPar n+ ) -endPE :: SParser ()+endPE :: SParser () endPE = do try (do- delPE- delPE- popPar- )+ delPE+ delPE+ popPar+ ) -inSamePE :: SParser a -> SParser a+inSamePE :: SParser a -> SParser a inSamePE p = do i <- getParNo r <- p j <- getParNo if (i == j)- then return r- else fail $ "parameter entity contents does not fit into the structure of a DTD declarations"+ then return r+ else fail $ "parameter entity contents does not fit into the structure of a DTD declarations" -- ------------------------------------------------------------ -xmlSpaceChar :: SParser ()-xmlSpaceChar = ( do- _ <- XC.xmlSpaceChar- return ()- )- <|>- startPE- <|>- endPE- <?> "white space"+xmlSpaceChar :: SParser ()+xmlSpaceChar = ( do+ _ <- XC.xmlSpaceChar+ return ()+ )+ <|>+ startPE+ <|>+ endPE+ <?> "white space" -skipS :: SParser ()+skipS :: SParser () skipS = do skipMany1 xmlSpaceChar return () -skipS0 :: SParser ()+skipS0 :: SParser () skipS0 = do skipMany xmlSpaceChar return () -name :: SParser XmlTree+name :: SParser XmlTree name = do n <- XT.name return (mkDTDElem NAME [(a_name, n)] []) -nmtoken :: SParser XmlTree+nmtoken :: SParser XmlTree nmtoken = do n <- XT.nmtoken@@ -167,11 +167,11 @@ -- -- Element Type Declarations (3.2) -elementDecl :: SParser XmlTrees+elementDecl :: SParser XmlTrees elementDecl = between (try $ string "<!ELEMENT") (char '>') elementDeclBody -elementDeclBody :: SParser XmlTrees+elementDeclBody :: SParser XmlTrees elementDeclBody = do skipS@@ -181,7 +181,7 @@ skipS0 return [mkDTDElem ELEMENT ((a_name, n) : al) cl] -contentspec :: SParser (Attributes, XmlTrees)+contentspec :: SParser (Attributes, XmlTrees) contentspec = simplespec k_empty v_empty <|>@@ -193,114 +193,114 @@ <?> "content specification" where simplespec kw v- = do- _ <- XT.keyword kw- return ([(a_type, v)], [])+ = do+ _ <- XT.keyword kw+ return ([(a_type, v)], []) -- ------------------------------------------------------------ -- -- Element Content (3.2.1) -children :: SParser (Attributes, XmlTrees)+children :: SParser (Attributes, XmlTrees) children = ( do- (al, cl) <- choiceOrSeq- modifier <- optOrRep- return ([(a_type, v_children)], [mkDTDElem CONTENT (modifier ++ al) cl])+ (al, cl) <- choiceOrSeq+ modifier <- optOrRep+ return ([(a_type, v_children)], [mkDTDElem CONTENT (modifier ++ al) cl]) ) <?> "element content" -optOrRep :: SParser Attributes+optOrRep :: SParser Attributes optOrRep = do m <- option "" (XT.mkList (oneOf "?*+")) return [(a_modifier, m)] -choiceOrSeq :: SParser (Attributes, XmlTrees)+choiceOrSeq :: SParser (Attributes, XmlTrees) choiceOrSeq = inSamePE $ do cl <- try ( do- lpar- choiceOrSeqBody- )+ lpar+ choiceOrSeqBody+ ) rpar return cl -choiceOrSeqBody :: SParser (Attributes, XmlTrees)+choiceOrSeqBody :: SParser (Attributes, XmlTrees) choiceOrSeqBody = do cp1 <- cp choiceOrSeq1 cp1 where- choiceOrSeq1 :: XmlTree -> SParser (Attributes, XmlTrees)+ choiceOrSeq1 :: XmlTree -> SParser (Attributes, XmlTrees) choiceOrSeq1 c1- = ( do- bar- c2 <- cp- cl <- many ( do- bar- cp- )- return ([(a_kind, v_choice)], (c1 : c2 : cl))- )- <|>- ( do- cl <- many ( do- comma- cp- )- return ([(a_kind, v_seq)], (c1 : cl))- )+ = ( do+ bar+ c2 <- cp+ cl <- many ( do+ bar+ cp+ )+ return ([(a_kind, v_choice)], (c1 : c2 : cl))+ )+ <|>+ ( do+ cl <- many ( do+ comma+ cp+ )+ return ([(a_kind, v_seq)], (c1 : cl))+ ) <?> "sequence or choice" -cp :: SParser XmlTree+cp :: SParser XmlTree cp = ( do- n <- name- m <- optOrRep- return ( case m of- [(_, "")] -> n- _ -> mkDTDElem CONTENT (m ++ [(a_kind, v_seq)]) [n]- )+ n <- name+ m <- optOrRep+ return ( case m of+ [(_, "")] -> n+ _ -> mkDTDElem CONTENT (m ++ [(a_kind, v_seq)]) [n]+ ) ) <|> ( do- (al, cl) <- choiceOrSeq- m <- optOrRep- return (mkDTDElem CONTENT (m ++ al) cl)+ (al, cl) <- choiceOrSeq+ m <- optOrRep+ return (mkDTDElem CONTENT (m ++ al) cl) ) -- ------------------------------------------------------------ -- -- Mixed Content (3.2.2) -mixed :: SParser (Attributes, XmlTrees)+mixed :: SParser (Attributes, XmlTrees) mixed = ( do- _ <- try ( do- lpar- string k_pcdata- )- nl <- many ( do- bar- name- )- rpar- if null nl+ _ <- try ( do+ lpar+ string k_pcdata+ )+ nl <- many ( do+ bar+ name+ )+ rpar+ if null nl then do- _ <- option ' ' (char '*') -- (#PCDATA) or (#PCDATA)* , both are legal- return ( [ (a_type, v_pcdata) ]- , []- )- else do- _ <- char '*' <?> "closing parent for mixed content (\")*\")"- return ( [ (a_type, v_mixed) ]- , [ mkDTDElem CONTENT [ (a_modifier, "*")- , (a_kind, v_choice)- ] nl- ]- )+ _ <- option ' ' (char '*') -- (#PCDATA) or (#PCDATA)* , both are legal+ return ( [ (a_type, v_pcdata) ]+ , []+ )+ else do+ _ <- char '*' <?> "closing parent for mixed content (\")*\")"+ return ( [ (a_type, v_mixed) ]+ , [ mkDTDElem CONTENT [ (a_modifier, "*")+ , (a_kind, v_choice)+ ] nl+ ]+ ) ) <?> "mixed content" @@ -308,11 +308,11 @@ -- -- Attribute-List Declarations (3.3) -attlistDecl :: SParser XmlTrees+attlistDecl :: SParser XmlTrees attlistDecl = between (try $ string "<!ATTLIST") (char '>') attlistDeclBody -attlistDeclBody :: SParser XmlTrees+attlistDeclBody :: SParser XmlTrees attlistDeclBody = do skipS@@ -322,22 +322,22 @@ return (map (mkDTree n) al) where mkDTree n' (al, cl)- = mkDTDElem ATTLIST ((a_name, n') : al) cl- -attDef :: SParser (Attributes, XmlTrees)+ = mkDTDElem ATTLIST ((a_name, n') : al) cl++attDef :: SParser (Attributes, XmlTrees) attDef = do n <- try ( do- skipS- XT.name- ) <?> "attribute name"+ skipS+ XT.name+ ) <?> "attribute name" skipS (t, cl) <- attType skipS d <- defaultDecl return (((a_value, n) : d) ++ t, cl) -attType :: SParser (Attributes, XmlTrees)+attType :: SParser (Attributes, XmlTrees) attType = tokenizedOrStringType <|>@@ -346,29 +346,29 @@ notationType <?> "attribute type" -tokenizedOrStringType :: SParser (Attributes, XmlTrees)+tokenizedOrStringType :: SParser (Attributes, XmlTrees) tokenizedOrStringType = do n <- choice $ map XT.keyword typl return ([(a_type, n)], []) where- typl = [ k_cdata- , k_idrefs- , k_idref- , k_id- , k_entity- , k_entities- , k_nmtokens- , k_nmtoken- ]+ typl = [ k_cdata+ , k_idrefs+ , k_idref+ , k_id+ , k_entity+ , k_entities+ , k_nmtokens+ , k_nmtoken+ ] -enumeration :: SParser (Attributes, XmlTrees)+enumeration :: SParser (Attributes, XmlTrees) enumeration = do nl <- inSamePE (between lpar rpar (sepBy1 nmtoken bar)) return ([(a_type, k_enumeration)], nl) -notationType :: SParser (Attributes, XmlTrees)+notationType :: SParser (Attributes, XmlTrees) notationType = do _ <- XT.keyword k_notation@@ -376,50 +376,50 @@ nl <- inSamePE (between lpar rpar ( sepBy1 name bar )) return ([(a_type, k_notation)], nl) -defaultDecl :: SParser Attributes+defaultDecl :: SParser Attributes defaultDecl = ( do- str <- try $ string k_required- return [(a_kind, str)]+ str <- try $ string k_required+ return [(a_kind, str)] ) <|> ( do- str <- try $ string k_implied- return [(a_kind, str)]+ str <- try $ string k_implied+ return [(a_kind, str)] ) <|> ( do l <- fixed- v <- XT.attrValueT- return ((a_default, xshow v) : l)+ v <- XT.attrValueT+ return ((a_default, xshow v) : l) ) <?> "default declaration" where fixed = option [(a_kind, k_default)]- ( do- _ <- try $ string k_fixed- skipS- return [(a_kind, k_fixed)]- )+ ( do+ _ <- try $ string k_fixed+ skipS+ return [(a_kind, k_fixed)]+ ) -- ------------------------------------------------------------ -- -- Entity Declarations (4.2) -entityDecl :: SParser XmlTrees+entityDecl :: SParser XmlTrees entityDecl = between ( try $ string "<!ENTITY" ) (char '>') entityDeclBody -entityDeclBody :: SParser XmlTrees+entityDeclBody :: SParser XmlTrees entityDeclBody = do skipS ( peDecl- <|>- geDecl- <?> "entity declaration" ) -- don't move the ) to the next line+ <|>+ geDecl+ <?> "entity declaration" ) -- don't move the ) to the next line -geDecl :: SParser XmlTrees+geDecl :: SParser XmlTrees geDecl = do n <- XT.name@@ -428,20 +428,20 @@ skipS0 return [mkDTDElem ENTITY ((a_name, n) : al) cl] -entityDef :: SParser (Attributes, XmlTrees)+entityDef :: SParser (Attributes, XmlTrees) entityDef = entityValue <|> externalEntitySpec -externalEntitySpec :: SParser (Attributes, XmlTrees)+externalEntitySpec :: SParser (Attributes, XmlTrees) externalEntitySpec = do al <- externalID nd <- option [] nDataDecl return ((al ++ nd), []) -peDecl :: SParser XmlTrees+peDecl :: SParser XmlTrees peDecl = do _ <- char '%'@@ -452,7 +452,7 @@ skipS0 return [mkDTDElem PENTITY ((a_name, n) : al) cs] -peDef :: SParser (Attributes, XmlTrees)+peDef :: SParser (Attributes, XmlTrees) peDef = entityValue <|>@@ -460,7 +460,7 @@ al <- externalID return (al, []) -entityValue :: GenParser Char state (Attributes, XmlTrees)+entityValue :: GenParser Char state (Attributes, XmlTrees) entityValue = do v <- XT.entityValueT@@ -470,33 +470,33 @@ -- -- External Entities (4.2.2) -externalID :: SParser Attributes+externalID :: SParser Attributes externalID = ( do- _ <- XT.keyword k_system- skipS- lit <- XT.systemLiteral- return [(k_system, lit)]+ _ <- XT.keyword k_system+ skipS+ lit <- XT.systemLiteral+ return [(k_system, lit)] ) <|> ( do- _ <- XT.keyword k_public- skipS- pl <- XT.pubidLiteral- skipS- sl <- XT.systemLiteral- return [ (k_system, sl)- , (k_public, pl) ]+ _ <- XT.keyword k_public+ skipS+ pl <- XT.pubidLiteral+ skipS+ sl <- XT.systemLiteral+ return [ (k_system, sl)+ , (k_public, pl) ] ) <?> "SYSTEM or PUBLIC declaration" -nDataDecl :: SParser Attributes+nDataDecl :: SParser Attributes nDataDecl = do _ <- try ( do- skipS- XT.keyword k_ndata- )+ skipS+ XT.keyword k_ndata+ ) skipS n <- XT.name return [(k_ndata, n)]@@ -505,24 +505,24 @@ -- -- Notation Declarations (4.7) -notationDecl :: SParser XmlTrees+notationDecl :: SParser XmlTrees notationDecl = between (try $ string "<!NOTATION") (char '>' <?> "notation declaration") notationDeclBody -notationDeclBody :: SParser XmlTrees+notationDeclBody :: SParser XmlTrees notationDeclBody = do skipS n <- XT.name skipS eid <- ( try externalID- <|>- publicID- )+ <|>+ publicID+ ) skipS0 return [mkDTDElem NOTATION ((a_name, n) : eid) []] -publicID :: SParser Attributes+publicID :: SParser Attributes publicID = do _ <- XT.keyword k_public@@ -532,7 +532,7 @@ -- ------------------------------------------------------------ -condSectCondBody :: SParser XmlTrees+condSectCondBody :: SParser XmlTrees condSectCondBody = do skipS0@@ -540,26 +540,26 @@ skipS0 let n' = stringToUpper n if n' `elem` [k_include, k_ignore]- then return [mkText n']- else fail $ "INCLUDE or IGNORE expected in conditional section"+ then return [mkText n']+ else fail $ "INCLUDE or IGNORE expected in conditional section" -- ------------------------------------------------------------ -separator :: Char -> SParser ()+separator :: Char -> SParser () separator c = do _ <- try ( do- skipS0- char c- )+ skipS0+ char c+ ) skipS0 <?> [c] -bar, comma, lpar, rpar :: SParser ()+bar, comma, lpar, rpar :: SParser () -bar = separator '|'-comma = separator ','+bar = separator '|'+comma = separator ',' lpar = do@@ -575,20 +575,20 @@ -- ------------------------------------------------------------ -parseXmlDTDEntityValue :: XmlTree -> XmlTrees-parseXmlDTDEntityValue t -- (NTree (XDTD PEREF al) cl)+parseXmlDTDEntityValue :: XmlTree -> XmlTrees+parseXmlDTDEntityValue t -- (NTree (XDTD PEREF al) cl) | isDTDPEref t- = ( either- ( (:[]) . mkError c_err . (++ "\n") . show )- ( \cl' -> if null cl'+ = ( either+ ( (:[]) . mkError c_err . (++ "\n") . show )+ ( \cl' -> if null cl' then [mkText ""] else cl'- )- .- parse parser source- ) input+ )+ .+ parse parser source+ ) input | otherwise- = []+ = [] where al = fromMaybe [] . getDTDAttrl $ t cl = getChildren t@@ -602,19 +602,19 @@ -} -- ------------------------------------------------------------ -parseXmlDTDdeclPart :: XmlTree -> XmlTrees-parseXmlDTDdeclPart t -- @(NTree (XDTD PEREF al) cl)+parseXmlDTDdeclPart :: XmlTree -> XmlTrees+parseXmlDTDdeclPart t -- @(NTree (XDTD PEREF al) cl) | isDTDPEref t- = ( (:[])- .- either- ( mkError c_err . (++ "\n") . show )- ( flip setChildren $ t ) -- \ cl' -> setChildren cl' t)- .- parse parser source- ) input+ = ( (:[])+ .+ either+ ( mkError c_err . (++ "\n") . show )+ ( flip setChildren $ t ) -- \ cl' -> setChildren cl' t)+ .+ parse parser source+ ) input | otherwise- = []+ = [] where al = fromMaybe [] . getDTDAttrl $ t cl = getChildren t@@ -637,35 +637,35 @@ -- substitution. -- Output is again a DTD declaration node, but this time completely parsed and ready for further DTD processing -parseXmlDTDdecl :: XmlTree -> XmlTrees-parseXmlDTDdecl t -- (NTree (XDTD dtdElem al) cl)+parseXmlDTDdecl :: XmlTree -> XmlTrees+parseXmlDTDdecl t -- (NTree (XDTD dtdElem al) cl) | isDTD t- = ( either ((:[]) . mkError c_err . (++ "\n") . show) id- .- runParser parser (initialLocalState pos) source- ) input+ = ( either ((:[]) . mkError c_err . (++ "\n") . show) id+ .+ runParser parser (initialLocalState pos) source+ ) input | otherwise- = []+ = [] where dtdElem = fromJust . getDTDPart $ t al = fromMaybe [] . getDTDAttrl $ t cl = getChildren t dtdParsers- = [ (ELEMENT, elementDeclBody)- , (ATTLIST, attlistDeclBody)- , (ENTITY, entityDeclBody)- , (NOTATION, notationDeclBody)- , (CONDSECT, condSectCondBody)- ]+ = [ (ELEMENT, elementDeclBody)+ , (ATTLIST, attlistDeclBody)+ , (ENTITY, entityDeclBody)+ , (NOTATION, notationDeclBody)+ , (CONDSECT, condSectCondBody)+ ] source = lookupDef "DTD declaration" a_source al line = lookupDef "1" a_line al column = lookupDef "1" a_column al pos = newPos source (read line) (read column) parser = do- setPosition pos- res <- fromJust . lookup dtdElem $ dtdParsers- eof- return res+ setPosition pos+ res <- fromJust . lookup dtdElem $ dtdParsers+ eof+ return res input = concatMap collectText cl {- parseXmlDTDdecl _@@ -676,15 +676,15 @@ -- a string ready for parsing. The structure of the parameter entity values -- is stll stored in this string for checking the scope of the parameter values -collectText :: XmlTree -> String+collectText :: XmlTree -> String collectText t | isText t- = fromMaybe "" . getText $ t+ = fromMaybe "" . getText $ t | isDTDPEref t- = prefixPe ++ concatMap collectText (getChildren t) ++ suffixPe+ = prefixPe ++ concatMap collectText (getChildren t) ++ suffixPe | otherwise- = ""+ = "" where al = fromMaybe [] . getDTDAttrl $ t delPe = "\0"@@ -695,7 +695,7 @@ collectText (NTree n _) | isXTextNode n- = textOfXNode n+ = textOfXNode n collectText (NTree (XDTD PEREF al) cl) = prefixPe ++ concatMap collectText cl ++ suffixPe@@ -708,7 +708,7 @@ = "" -} -isDTDPEref :: XmlTree -> Bool+isDTDPEref :: XmlTree -> Bool isDTDPEref = maybe False (== PEREF) . getDTDPart
src/Text/XML/HXT/Parser/XmlDTDTokenParser.hs view
@@ -21,16 +21,16 @@ import Text.ParserCombinators.Parsec import Text.XML.HXT.DOM.Interface-import Text.XML.HXT.DOM.XmlNode ( mkDTDElem- , mkText- )-import qualified Text.XML.HXT.Parser.XmlTokenParser as XT+import Text.XML.HXT.DOM.XmlNode ( mkDTDElem+ , mkText+ )+import qualified Text.XML.HXT.Parser.XmlTokenParser as XT -- ------------------------------------------------------------ -- -- DTD declaration tokenizer -dtdDeclTokenizer :: GenParser Char state XmlTree+dtdDeclTokenizer :: GenParser Char state XmlTree dtdDeclTokenizer = do (dcl, al) <- dtdDeclStart@@ -42,61 +42,61 @@ dtdDeclStart = foldr1 (<|>) $ map (uncurry dtdStart) $- [ ("ELEMENT", ELEMENT )- , ("ATTLIST", ATTLIST )- , ("ENTITY", ENTITY )- , ("NOTATION", NOTATION)- ]+ [ ("ELEMENT", ELEMENT )+ , ("ATTLIST", ATTLIST )+ , ("ENTITY", ENTITY )+ , ("NOTATION", NOTATION)+ ] where- dtdStart :: String -> DTDElem -> GenParser Char state (DTDElem, Attributes)+ dtdStart :: String -> DTDElem -> GenParser Char state (DTDElem, Attributes) dtdStart dcl element- = try ( do- _ <- string "<!"- _ <- string dcl- pos <- getPosition- return (element, [ (a_source, sourceName pos)- , (a_line, show (sourceLine pos))- , (a_column, show (sourceColumn pos))- ]- )- )+ = try ( do+ _ <- string "<!"+ _ <- string dcl+ pos <- getPosition+ return (element, [ (a_source, sourceName pos)+ , (a_line, show (sourceLine pos))+ , (a_column, show (sourceColumn pos))+ ]+ )+ ) -dtdDeclEnd :: GenParser Char state ()+dtdDeclEnd :: GenParser Char state () dtdDeclEnd = do _ <- XT.gt return () -dtdToken :: GenParser Char state XmlTree+dtdToken :: GenParser Char state XmlTree dtdToken = dtdChars <|> attrValue <|>- try peReference -- first try parameter entity ref %xxx;+ try peReference -- first try parameter entity ref %xxx; <|>- percent -- else % may be indicator for parameter entity declaration+ percent -- else % may be indicator for parameter entity declaration <?> "DTD token" -peReference :: GenParser Char state XmlTree+peReference :: GenParser Char state XmlTree peReference = do r <- XT.peReference return $! (mkDTDElem PEREF [(a_peref, r)] []) -attrValue :: GenParser Char state XmlTree+attrValue :: GenParser Char state XmlTree attrValue = do v <- XT.attrValue return $! mkText v -dtdChars :: GenParser Char state XmlTree+dtdChars :: GenParser Char state XmlTree dtdChars = do- v <- many1 (XT.singleChar "%\"'<>[]") -- everything except string constants, < and >, [ and ] (for cond sections)- return $! mkText v -- all illegal chars will be detected later during declaration parsing+ v <- many1 (XT.singleChar "%\"'<>[]") -- everything except string constants, < and >, [ and ] (for cond sections)+ return $! mkText v -- all illegal chars will be detected later during declaration parsing -percent :: GenParser Char state XmlTree+percent :: GenParser Char state XmlTree percent = do c <- char '%'
src/Text/XML/HXT/Parser/XmlEntities.hs view
@@ -15,12 +15,12 @@ -- | -- list of predefined XML entity names and their unicode values -xmlEntities :: [(String, Int)]-xmlEntities = [ ("quot", 34)- , ("amp", 38)- , ("lt", 60)- , ("gt", 62)- , ("apos", 39)- ]+xmlEntities :: [(String, Int)]+xmlEntities = [ ("quot", 34)+ , ("amp", 38)+ , ("lt", 60)+ , ("gt", 62)+ , ("apos", 39)+ ] -- ------------------------------------------------------------
src/Text/XML/HXT/Parser/XmlParsec.hs view
@@ -64,7 +64,7 @@ , (<?>), (<|>) , char , string- , eof + , eof , between , many, many1 , option@@ -104,68 +104,68 @@ import Text.XML.HXT.Parser.XmlCharParser ( xmlChar )-import qualified Text.XML.HXT.Parser.XmlTokenParser as XT-import qualified Text.XML.HXT.Parser.XmlDTDTokenParser as XD+import qualified Text.XML.HXT.Parser.XmlTokenParser as XT+import qualified Text.XML.HXT.Parser.XmlDTDTokenParser as XD -import Data.Char (toLower)+import Data.Char (toLower) import Data.Maybe -- ------------------------------------------------------------ -- -- Character Data (2.4) -charData :: GenParser Char state XmlTrees+charData :: GenParser Char state XmlTrees charData = many (charData' <|> XT.referenceT) -charData' :: GenParser Char state XmlTree+charData' :: GenParser Char state XmlTree charData' = try ( do- t <- XT.allBut1 many1 (\ c -> not (c `elem` "<&")) "]]>"- return (mkText $! t)- )+ t <- XT.allBut1 many1 (\ c -> not (c `elem` "<&")) "]]>"+ return (mkText $! t)+ ) -- ------------------------------------------------------------ -- -- Comments (2.5) -comment :: GenParser Char state XmlTree+comment :: GenParser Char state XmlTree comment = ( do- c <- between (try $ string "<!--") (string "-->") (XT.allBut many "--")- return (mkCmt $! c)+ c <- between (try $ string "<!--") (string "-->") (XT.allBut many "--")+ return (mkCmt $! c) ) <?> "comment" -- ------------------------------------------------------------ -- -- Processing Instructions -pI :: GenParser Char state XmlTree+pI :: GenParser Char state XmlTree pI = between (try $ string "<?") (string "?>") ( do- n <- pITarget- p <- option "" (do- _ <- XT.sPace- XT.allBut many "?>"- )- return $ mkPi (mkName n) [mkAttr (mkName a_value) [mkText p]]+ n <- pITarget+ p <- option "" (do+ _ <- XT.sPace+ XT.allBut many "?>"+ )+ return $ mkPi (mkName n) [mkAttr (mkName a_value) [mkText p]] ) <?> "processing instruction" where- pITarget :: GenParser Char state String+ pITarget :: GenParser Char state String pITarget = ( do- n <- XT.name- if map toLower n == t_xml- then unexpected n- else return n- )+ n <- XT.name+ if map toLower n == t_xml+ then unexpected n+ else return n+ ) -- ------------------------------------------------------------ -- -- CDATA Sections (2.7) -cDSect :: GenParser Char state XmlTree+cDSect :: GenParser Char state XmlTree cDSect = do@@ -177,16 +177,16 @@ -- -- Document (2.1) and Prolog (2.8) -document :: GenParser Char state XmlTree+document :: GenParser Char state XmlTree document = do pos <- getPosition dl <- document' return $ mkRoot [ mkAttr (mkName a_source) [mkText (sourceName pos)]- , mkAttr (mkName a_status) [mkText (show c_ok)]- ] dl+ , mkAttr (mkName a_status) [mkText (show c_ok)]+ ] dl -document' :: GenParser Char state XmlTrees+document' :: GenParser Char state XmlTrees document' = do pl <- prolog@@ -195,7 +195,7 @@ eof return (pl ++ [el] ++ ml) -prolog :: GenParser Char state XmlTrees+prolog :: GenParser Char state XmlTrees prolog = do xml <- option [] xMLDecl'@@ -204,122 +204,122 @@ misc2 <- many misc return (xml ++ misc1 ++ dtdPart ++ misc2) -xMLDecl :: GenParser Char state XmlTrees+xMLDecl :: GenParser Char state XmlTrees xMLDecl = between (try $ string "<?xml") (string "?>") ( do- vi <- versionInfo- ed <- option [] encodingDecl- sd <- option [] sDDecl- XT.skipS0- return (vi ++ ed ++ sd)+ vi <- versionInfo+ ed <- option [] encodingDecl+ sd <- option [] sDDecl+ XT.skipS0+ return (vi ++ ed ++ sd) ) <?> "xml declaration" -xMLDecl' :: GenParser Char state XmlTrees+xMLDecl' :: GenParser Char state XmlTrees xMLDecl' = do al <- xMLDecl return [mkPi (mkName t_xml) al] -xMLDecl'' :: GenParser Char state XmlTree+xMLDecl'' :: GenParser Char state XmlTree xMLDecl'' = do al <- option [] (try xMLDecl) return (mkRoot al []) -versionInfo :: GenParser Char state XmlTrees+versionInfo :: GenParser Char state XmlTrees versionInfo = ( do- _ <- try ( do- XT.skipS- XT.keyword a_version- )- XT.eq- vi <- XT.quoted XT.versionNum- return [mkAttr (mkName a_version) [mkText vi]]+ _ <- try ( do+ XT.skipS+ XT.keyword a_version+ )+ XT.eq+ vi <- XT.quoted XT.versionNum+ return [mkAttr (mkName a_version) [mkText vi]] ) <?> "version info (with quoted version number)" -misc :: GenParser Char state XmlTree+misc :: GenParser Char state XmlTree misc = comment <|> pI <|> ( ( do- ws <- XT.sPace- return (mkText ws)- ) <?> ""+ ws <- XT.sPace+ return (mkText ws)+ ) <?> "" ) -- ------------------------------------------------------------ -- -- Document Type definition (2.8) -doctypedecl :: GenParser Char state XmlTrees+doctypedecl :: GenParser Char state XmlTrees doctypedecl = between (try $ string "<!DOCTYPE") (char '>') ( do- XT.skipS- n <- XT.name- exId <- option [] ( try ( do- XT.skipS- externalID- )- )- XT.skipS0- markup <- option []- ( do- m <- between (char '[' ) (char ']') markupOrDeclSep- XT.skipS0- return m- )- return [mkDTDElem DOCTYPE ((a_name, n) : exId) markup]+ XT.skipS+ n <- XT.name+ exId <- option [] ( try ( do+ XT.skipS+ externalID+ )+ )+ XT.skipS0+ markup <- option []+ ( do+ m <- between (char '[' ) (char ']') markupOrDeclSep+ XT.skipS0+ return m+ )+ return [mkDTDElem DOCTYPE ((a_name, n) : exId) markup] ) -markupOrDeclSep :: GenParser Char state XmlTrees+markupOrDeclSep :: GenParser Char state XmlTrees markupOrDeclSep = ( do- ll <- many ( markupdecl- <|>- declSep- <|>- XT.mkList conditionalSect- )- return (concat ll)+ ll <- many ( markupdecl+ <|>+ declSep+ <|>+ XT.mkList conditionalSect+ )+ return (concat ll) ) -declSep :: GenParser Char state XmlTrees+declSep :: GenParser Char state XmlTrees declSep = XT.mkList XT.peReferenceT <|> ( do- XT.skipS- return []+ XT.skipS+ return [] ) -markupdecl :: GenParser Char state XmlTrees+markupdecl :: GenParser Char state XmlTrees markupdecl = XT.mkList ( pI- <|>- comment- <|>- XD.dtdDeclTokenizer+ <|>+ comment+ <|>+ XD.dtdDeclTokenizer ) -- ------------------------------------------------------------ -- -- Standalone Document Declaration (2.9) -sDDecl :: GenParser Char state XmlTrees+sDDecl :: GenParser Char state XmlTrees sDDecl = do _ <- try (do- XT.skipS- XT.keyword a_standalone- )+ XT.skipS+ XT.keyword a_standalone+ ) XT.eq sd <- XT.quoted (XT.keywords [v_yes, v_no]) return [mkAttr (mkName a_standalone) [mkText sd]]@@ -328,60 +328,60 @@ -- -- element, tags and content (3, 3.1) -element :: GenParser Char state XmlTree+element :: GenParser Char state XmlTree element = ( do- e <- elementStart- elementRest e+ e <- elementStart+ elementRest e ) <?> "element" -elementStart :: GenParser Char state (String, [(String, XmlTrees)])+elementStart :: GenParser Char state (String, [(String, XmlTrees)]) elementStart = do n <- ( try ( do- _ <- char '<'- n <- XT.name- return n- )- <?> "start tag"- )+ _ <- char '<'+ n <- XT.name+ return n+ )+ <?> "start tag"+ ) ass <- attrList XT.skipS0 return (n, ass) where attrList- = option [] ( do- XT.skipS- attrList'- )+ = option [] ( do+ XT.skipS+ attrList'+ ) attrList'- = option [] ( do- a1 <- attribute- al <- attrList- let (n, _v) = a1- if isJust . lookup n $ al- then unexpected ("attribute name " ++ show n ++ " occurs twice in attribute list")- else return (a1 : al)- )+ = option [] ( do+ a1 <- attribute+ al <- attrList+ let (n, _v) = a1+ if isJust . lookup n $ al+ then unexpected ("attribute name " ++ show n ++ " occurs twice in attribute list")+ else return (a1 : al)+ ) -elementRest :: (String, [(String, XmlTrees)]) -> GenParser Char state XmlTree+elementRest :: (String, [(String, XmlTrees)]) -> GenParser Char state XmlTree elementRest (n, al) = ( do- _ <- try $ string "/>"- return $! (mkElement (mkName n) (map (mkA $!) al) [])+ _ <- try $ string "/>"+ return $! (mkElement (mkName n) (map (mkA $!) al) []) ) <|> ( do- _ <- XT.gt- c <- content- eTag n- return $! (mkElement (mkName n) (map (mkA $!) al) $! c)+ _ <- XT.gt+ c <- content+ eTag n+ return $! (mkElement (mkName n) (map (mkA $!) al) $! c) ) <?> "proper attribute list followed by \"/>\" or \">\"" where mkA (n', ts') = mkAttr (mkName n') ts' -eTag :: String -> GenParser Char state ()+eTag :: String -> GenParser Char state () eTag n' = do _ <- try ( string "</" ) <?> ""@@ -389,10 +389,10 @@ XT.skipS0 _ <- XT.gt if n == n'- then return ()- else unexpected ("illegal end tag </" ++ n ++ "> found, </" ++ n' ++ "> expected")+ then return ()+ else unexpected ("illegal end tag </" ++ n ++ "> found, </" ++ n' ++ "> expected") -attribute :: GenParser Char state (String, XmlTrees)+attribute :: GenParser Char state (String, XmlTrees) attribute = do n <- XT.name@@ -400,26 +400,26 @@ v <- XT.attrValueT return (n, v) -content :: GenParser Char state XmlTrees+content :: GenParser Char state XmlTrees content = do c1 <- charData cl <- many- ( do- l <- ( element- <|>- cDSect- <|>- pI- <|>- comment- )- c <- charData- return (l : c)- )+ ( do+ l <- ( element+ <|>+ cDSect+ <|>+ pI+ <|>+ comment+ )+ c <- charData+ return (l : c)+ ) return (c1 ++ concat cl) -contentWithTextDecl :: GenParser Char state XmlTrees+contentWithTextDecl :: GenParser Char state XmlTrees contentWithTextDecl = do _ <- option [] textDecl@@ -433,7 +433,7 @@ -- first the whole content is detected, -- and then, after PE substitution include sections are parsed again -conditionalSect :: GenParser Char state XmlTree+conditionalSect :: GenParser Char state XmlTree conditionalSect = do _ <- try $ string "<!["@@ -443,47 +443,47 @@ return (mkDTDElem CONDSECT [(a_value, sect)] cs) where - condSectCont :: GenParser Char state String+ condSectCont :: GenParser Char state String condSectCont- = ( do- _ <- try $ string "]]>"- return ""- )+ = ( do+ _ <- try $ string "]]>"+ return ""+ ) <|>- ( do- _ <- try $ string "<!["- cs1 <- condSectCont- cs2 <- condSectCont- return ("<![" ++ cs1 ++ "]]>" ++ cs2)- )- <|>- ( do- c <- xmlChar- cs <- condSectCont- return (c : cs)- )+ ( do+ _ <- try $ string "<!["+ cs1 <- condSectCont+ cs2 <- condSectCont+ return ("<![" ++ cs1 ++ "]]>" ++ cs2)+ )+ <|>+ ( do+ c <- xmlChar+ cs <- condSectCont+ return (c : cs)+ ) -- ------------------------------------------------------------ -- -- External Entities (4.2.2) -externalID :: GenParser Char state Attributes+externalID :: GenParser Char state Attributes externalID = ( do- _ <- XT.keyword k_system- XT.skipS- lit <- XT.systemLiteral- return [(k_system, lit)]+ _ <- XT.keyword k_system+ XT.skipS+ lit <- XT.systemLiteral+ return [(k_system, lit)] ) <|> ( do- _ <- XT.keyword k_public- XT.skipS- pl <- XT.pubidLiteral- XT.skipS- sl <- XT.systemLiteral- return [ (k_system, sl)- , (k_public, pl) ]+ _ <- XT.keyword k_public+ XT.skipS+ pl <- XT.pubidLiteral+ XT.skipS+ sl <- XT.systemLiteral+ return [ (k_system, sl)+ , (k_public, pl) ] ) <?> "SYSTEM or PUBLIC declaration" @@ -491,19 +491,19 @@ -- -- Text Declaration (4.3.1) -textDecl :: GenParser Char state XmlTrees+textDecl :: GenParser Char state XmlTrees textDecl = between (try $ string "<?xml") (string "?>") ( do- vi <- option [] versionInfo- ed <- encodingDecl- XT.skipS0- return (vi ++ ed)+ vi <- option [] versionInfo+ ed <- encodingDecl+ XT.skipS0+ return (vi ++ ed) ) <?> "text declaration" -textDecl'' :: GenParser Char state XmlTree+textDecl'' :: GenParser Char state XmlTree textDecl'' = do al <- option [] (try textDecl)@@ -513,13 +513,13 @@ -- -- Encoding Declaration (4.3.3) -encodingDecl :: GenParser Char state XmlTrees+encodingDecl :: GenParser Char state XmlTrees encodingDecl = do _ <- try ( do- XT.skipS- XT.keyword a_encoding- )+ XT.skipS+ XT.keyword a_encoding+ ) XT.eq ed <- XT.quoted XT.encName return [mkAttr (mkName a_encoding) [mkText ed]]@@ -527,8 +527,8 @@ -- ------------------------------------------------------------ -- -- the main entry points:--- parsing the content of a text node--- or parsing the text children from a tag node+-- parsing the content of a text node+-- or parsing the text children from a tag node -- | -- the inverse function to 'xshow', (for XML content).@@ -539,20 +539,20 @@ -- -- see also: 'parseXmlContent' -xread :: String -> XmlTrees+xread :: String -> XmlTrees xread str = parseXmlFromString parser loc str where loc = "string: " ++ show (if length str > 40 then take 40 str ++ "..." else str) parser = do- res <- content -- take the content parser for parsing the string- eof -- and test on everything consumed- return res+ res <- content -- take the content parser for parsing the string+ eof -- and test on everything consumed+ return res -- | -- the filter version of 'xread' -parseXmlContent :: XmlTree -> XmlTrees+parseXmlContent :: XmlTree -> XmlTrees parseXmlContent = xread . xshow . (:[]) @@ -560,48 +560,48 @@ -- a more general version of 'parseXmlContent'. -- The parser to be used and the context are extra parameter -parseXmlText :: Parser XmlTrees -> String -> XmlTree -> XmlTrees-parseXmlText p loc = parseXmlFromString p loc . xshow . (:[])+parseXmlText :: Parser XmlTrees -> String -> XmlTree -> XmlTrees+parseXmlText p loc = parseXmlFromString p loc . xshow . (:[]) -parseXmlDocument :: String -> String -> XmlTrees-parseXmlDocument = parseXmlFromString document'+parseXmlDocument :: String -> String -> XmlTrees+parseXmlDocument = parseXmlFromString document' -parseXmlFromString :: Parser XmlTrees -> String -> String -> XmlTrees+parseXmlFromString :: Parser XmlTrees -> String -> String -> XmlTrees parseXmlFromString parser loc = either ((:[]) . mkError c_err . (++ "\n") . show) id . parse parser loc -- ------------------------------------------------------------ -- -removeEncodingSpec :: XmlTree -> XmlTrees+removeEncodingSpec :: XmlTree -> XmlTrees removeEncodingSpec t | isText t- = ( either ((:[]) . mkError c_err . (++ "\n") . show) ((:[]) . mkText)- . parse parser "remove encoding spec"- . fromMaybe ""- . getText- ) t+ = ( either ((:[]) . mkError c_err . (++ "\n") . show) ((:[]) . mkText)+ . parse parser "remove encoding spec"+ . fromMaybe ""+ . getText+ ) t | otherwise- = [t]+ = [t] where parser :: Parser String parser = do- _ <- option [] textDecl- getInput+ _ <- option [] textDecl+ getInput -- ------------------------------------------------------------ -- | -- general parser for parsing arbitray parts of a XML document -parseXmlPart :: Parser XmlTrees -> String -> String -> XmlTree -> XmlTrees+parseXmlPart :: Parser XmlTrees -> String -> String -> XmlTree -> XmlTrees parseXmlPart parser expected context t = parseXmlText ( do- res <- parser- eof <?> expected- return res- ) context+ res <- parser+ eof <?> expected+ return res+ ) context $ t -- ------------------------------------------------------------@@ -609,7 +609,7 @@ -- | -- Parser for parts of a DTD -parseXmlDTDPart :: String -> XmlTree -> XmlTrees+parseXmlDTDPart :: String -> XmlTree -> XmlTrees parseXmlDTDPart = parseXmlPart markupOrDeclSep "markup declaration" @@ -618,7 +618,7 @@ -- | -- Parser for general entites -parseXmlGeneralEntityValue :: String -> XmlTree -> XmlTrees+parseXmlGeneralEntityValue :: String -> XmlTree -> XmlTrees parseXmlGeneralEntityValue = parseXmlPart content "general entity value" @@ -627,7 +627,7 @@ -- | -- Parser for attribute values -parseXmlAttrValue :: String -> XmlTree -> XmlTrees+parseXmlAttrValue :: String -> XmlTree -> XmlTrees parseXmlAttrValue = parseXmlPart (XT.attrValueT' "<&") "attribute value" @@ -636,7 +636,7 @@ -- | -- Parser for NMTOKENs -parseNMToken :: String -> XmlTree -> XmlTrees+parseNMToken :: String -> XmlTree -> XmlTrees parseNMToken = parseXmlPart (many1 XT.nmtokenT) "nmtoken" @@ -645,7 +645,7 @@ -- | -- Parser for XML names -parseName :: String -> XmlTree -> XmlTrees+parseName :: String -> XmlTree -> XmlTrees parseName = parseXmlPart (many1 XT.nameT) "name" @@ -660,32 +660,32 @@ -- - 2.parameter root : a document root -- -- - returns : the same tree, but with an additional--- attribute \"encoding\" in the root node--- in case of a valid encoding spec--- else the unchanged tree+-- attribute \"encoding\" in the root node+-- in case of a valid encoding spec+-- else the unchanged tree -parseXmlEncodingSpec :: Parser XmlTree -> XmlTree -> XmlTrees+parseXmlEncodingSpec :: Parser XmlTree -> XmlTree -> XmlTrees parseXmlEncodingSpec encDecl x = (:[]) . ( if isRoot x- then parseEncSpec- else id+ then parseEncSpec+ else id ) $ x where parseEncSpec r- = case ( parse encDecl source . xshow . getChildren $ r ) of- Right t- -> changeAttrl (mergeAttrl . fromMaybe [] . getAttrl $ t) r- Left _- -> r- where- -- arrow \"getAttrValue a_source\" programmed on the tree level (oops!)- source = xshow . concat . map getChildren . filter ((== a_source) . maybe "" qualifiedName . getAttrName) . fromMaybe [] . getAttrl $ r+ = case ( parse encDecl source . xshow . getChildren $ r ) of+ Right t+ -> changeAttrl (mergeAttrl . fromMaybe [] . getAttrl $ t) r+ Left _+ -> r+ where+ -- arrow \"getAttrValue a_source\" programmed on the tree level (oops!)+ source = xshow . concat . map getChildren . filter ((== a_source) . maybe "" qualifiedName . getAttrName) . fromMaybe [] . getAttrl $ r -parseXmlEntityEncodingSpec :: XmlTree -> XmlTrees-parseXmlEntityEncodingSpec = parseXmlEncodingSpec textDecl''+parseXmlEntityEncodingSpec :: XmlTree -> XmlTrees+parseXmlEntityEncodingSpec = parseXmlEncodingSpec textDecl'' -parseXmlDocEncodingSpec :: XmlTree -> XmlTrees-parseXmlDocEncodingSpec = parseXmlEncodingSpec xMLDecl''+parseXmlDocEncodingSpec :: XmlTree -> XmlTrees+parseXmlDocEncodingSpec = parseXmlEncodingSpec xMLDecl'' -- ------------------------------------------------------------
src/Text/XML/HXT/Parser/XmlTokenParser.hs view
@@ -112,19 +112,19 @@ -- ------------------------------------------------------------ -sPace :: GenParser Char state String+sPace :: GenParser Char state String sPace = many1 xmlSpaceChar -sPace0 :: GenParser Char state String+sPace0 :: GenParser Char state String sPace0 = many xmlSpaceChar -skipS :: GenParser Char state ()+skipS :: GenParser Char state () skipS = skipMany1 xmlSpaceChar -skipS0 :: GenParser Char state ()+skipS0 :: GenParser Char state () skipS0 = skipMany xmlSpaceChar @@ -132,55 +132,55 @@ -- -- Names and Tokens (2.3) -asciiLetter :: GenParser Char state Char+asciiLetter :: GenParser Char state Char asciiLetter = satisfy (\ c -> ( c >= 'A' && c <= 'Z' ||- c >= 'a' && c <= 'z' )- )+ c >= 'a' && c <= 'z' )+ ) <?> "ASCII letter" -name :: GenParser Char state String+name :: GenParser Char state String name = try ( do- s1 <- xmlNameStartChar- sl <- many xmlNameChar- return (s1 : sl)- )+ s1 <- xmlNameStartChar+ sl <- many xmlNameChar+ return (s1 : sl)+ ) <?> "Name" -- Namespaces in XML: Rules [4-5] NCName: -ncName :: GenParser Char state String+ncName :: GenParser Char state String ncName = try ( do- s1 <- xmlNCNameStartChar- sl <- many xmlNCNameChar- return (s1 : sl)- )+ s1 <- xmlNCNameStartChar+ sl <- many xmlNCNameChar+ return (s1 : sl)+ ) <?> "NCName" -- Namespaces in XML: Rules [6-8] QName: -qName :: GenParser Char state (String, String)+qName :: GenParser Char state (String, String) qName = do s1 <- ncName s2 <- option "" ( do- _ <- char ':'- ncName- )+ _ <- char ':'+ ncName+ ) return ( if null s2 then (s2, s1) else (s1, s2) ) -nmtoken :: GenParser Char state String+nmtoken :: GenParser Char state String nmtoken = try (many1 xmlNameChar) <?> "Nmtoken" -names :: GenParser Char state [String]+names :: GenParser Char state [String] names = sepBy1 name sPace -nmtokens :: GenParser Char state [String]+nmtokens :: GenParser Char state [String] nmtokens = sepBy1 nmtoken sPace @@ -188,40 +188,40 @@ -- -- Literals (2.3) -singleChar :: String -> GenParser Char state Char+singleChar :: String -> GenParser Char state Char singleChar notAllowed = satisfy (\ c -> isXmlChar c && not (c `elem` notAllowed)) -singleChars :: String -> GenParser Char state String+singleChars :: String -> GenParser Char state String singleChars notAllowed = many1 (singleChar notAllowed) -entityValue :: GenParser Char state String+entityValue :: GenParser Char state String entityValue = attrValue -attrValueDQ :: GenParser Char state String+attrValueDQ :: GenParser Char state String attrValueDQ = between dq dq (concRes $ many $ attrChar "<&\"") -attrValueSQ :: GenParser Char state String+attrValueSQ :: GenParser Char state String attrValueSQ = between sq sq (concRes $ many $ attrChar "<&\'") -attrValue :: GenParser Char state String+attrValue :: GenParser Char state String attrValue = ( do- v <- attrValueDQ- return ("\"" ++ v ++ "\"")+ v <- attrValueDQ+ return ("\"" ++ v ++ "\"") ) <|> ( do- v <- attrValueSQ- return ("'" ++ v ++ "'")+ v <- attrValueSQ+ return ("'" ++ v ++ "'") ) <?> "attribute value (in quotes)" -attrChar :: String -> GenParser Char state String+attrChar :: String -> GenParser Char state String attrChar notAllowed = reference <|>@@ -229,58 +229,58 @@ <?> "legal attribute character or reference" -systemLiteral :: GenParser Char state String+systemLiteral :: GenParser Char state String systemLiteral = between dq dq (many $ noneOf "\"") <|> between sq sq (many $ noneOf "\'") <?> "system literal (in quotes)" -pubidLiteral :: GenParser Char state String+pubidLiteral :: GenParser Char state String pubidLiteral = between dq dq (many $ pubidChar "\'") <|> between sq sq (many $ pubidChar "") <?> "pubid literal (in quotes)" where- pubidChar :: String -> GenParser Char state Char+ pubidChar :: String -> GenParser Char state Char pubidChar quoteChars- = asciiLetter- <|>- digit- <|>- oneOf " \r\n" -- no "\t" allowed, so xmlSpaceChar parser not used- <|>- oneOf "-()+,./:=?;!*#@$_%"+ = asciiLetter <|>- oneOf quoteChars+ digit+ <|>+ oneOf " \r\n" -- no "\t" allowed, so xmlSpaceChar parser not used+ <|>+ oneOf "-()+,./:=?;!*#@$_%"+ <|>+ oneOf quoteChars -- ------------------------------------------------------------ -- -- Character and Entity References (4.1) -reference :: GenParser Char state String+reference :: GenParser Char state String reference = ( do- i <- charRef- return ("&#" ++ show i ++ ";")+ i <- charRef+ return ("&#" ++ show i ++ ";") ) <|> ( do n <- entityRef return ("&" ++ n ++ ";") )- -checkCharRef :: Int -> GenParser Char state Int++checkCharRef :: Int -> GenParser Char state Int checkCharRef i = if ( i <= fromEnum (maxBound::Char)- && isXmlChar (toEnum i)- )+ && isXmlChar (toEnum i)+ ) then return i- else unexpected ("illegal value in character reference: " ++ intToCharRef i ++ " , in hex: " ++ intToCharRefHex i)+ else unexpected ("illegal value in character reference: " ++ intToCharRef i ++ " , in hex: " ++ intToCharRefHex i) -charRef :: GenParser Char state Int+charRef :: GenParser Char state Int charRef = do _ <- try (string "&#x")@@ -296,7 +296,7 @@ <?> "character reference" -entityRef :: GenParser Char state String+entityRef :: GenParser Char state String entityRef = do _ <- char '&'@@ -305,28 +305,28 @@ return n <?> "entity reference" -peReference :: GenParser Char state String+peReference :: GenParser Char state String peReference = try ( do- _ <- char '%'- n <- name- _ <- semi- return n- )+ _ <- char '%'+ n <- name+ _ <- semi+ return n+ ) <?> "parameter-entity reference" -- ------------------------------------------------------------ -- -- 4.3 -encName :: GenParser Char state String+encName :: GenParser Char state String encName = do c <- asciiLetter r <- many (asciiLetter <|> digit <|> oneOf "._-") return (c:r) -versionNum :: GenParser Char state String+versionNum :: GenParser Char state String versionNum = many1 xmlNameChar @@ -335,17 +335,17 @@ -- -- keywords -keyword :: String -> GenParser Char state String+keyword :: String -> GenParser Char state String keyword kw = try ( do- n <- name- if n == kw- then return n- else unexpected n- )+ n <- name+ if n == kw+ then return n+ else unexpected n+ ) <?> kw -keywords :: [String] -> GenParser Char state String+keywords :: [String] -> GenParser Char state String keywords = foldr1 (<|>) . map keyword @@ -353,7 +353,7 @@ -- -- parser for quoted attribute values -quoted :: GenParser Char state a -> GenParser Char state a+quoted :: GenParser Char state a -> GenParser Char state a quoted p = between dq dq p <|>@@ -363,29 +363,29 @@ -- -- simple char parsers -dq, sq, lt, gt, semi :: GenParser Char state Char+dq, sq, lt, gt, semi :: GenParser Char state Char -dq = char '\"'-sq = char '\''-lt = char '<'-gt = char '>'-semi = char ';'+dq = char '\"'+sq = char '\''+lt = char '<'+gt = char '>'+semi = char ';' -separator :: Char -> GenParser Char state ()+separator :: Char -> GenParser Char state () separator c = do _ <- try ( do- skipS0- char c- )+ skipS0+ char c+ ) skipS0 <?> [c] -bar, comma, eq, lpar, rpar :: GenParser Char state ()+bar, comma, eq, lpar, rpar :: GenParser Char state () -bar = separator '|'-comma = separator ','-eq = separator '='+bar = separator '|'+comma = separator ','+eq = separator '=' lpar = do@@ -403,23 +403,23 @@ -- -- all chars but not a special substring -allBut :: (GenParser Char state Char -> GenParser Char state String) -> String -> GenParser Char state String+allBut :: (GenParser Char state Char -> GenParser Char state String) -> String -> GenParser Char state String allBut p str = allBut1 p (const True) str -allBut1 :: (GenParser Char state Char -> GenParser Char state String) -> (Char -> Bool) -> String -> GenParser Char state String+allBut1 :: (GenParser Char state Char -> GenParser Char state String) -> (Char -> Bool) -> String -> GenParser Char state String allBut1 p prd (c:rest) = p ( satisfy (\ x -> isXmlChar x && prd x && not (x == c) )- <|>- try ( do- _ <- char c- notFollowedBy ( do- _ <- try (string rest)- return c- )- return c- )- )+ <|>+ try ( do+ _ <- char c+ notFollowedBy ( do+ _ <- try (string rest)+ return c+ )+ return c+ )+ ) allBut1 _p _prd str = error ("allBut1 _ _ " ++ show str ++ " is undefined")@@ -428,13 +428,13 @@ -- -- concatenate parse results -concRes :: GenParser Char state [[a]] -> GenParser Char state [a]+concRes :: GenParser Char state [[a]] -> GenParser Char state [a] concRes p = do sl <- p return (concat sl) -mkList :: GenParser Char state a -> GenParser Char state [a]+mkList :: GenParser Char state a -> GenParser Char state [a] mkList p = do r <- p@@ -448,20 +448,20 @@ -- -- Literals (2.3) -nameT :: GenParser Char state XmlTree+nameT :: GenParser Char state XmlTree nameT = do n <- name return (mkDTDElem NAME [(a_name, n)] []) -nmtokenT :: GenParser Char state XmlTree+nmtokenT :: GenParser Char state XmlTree nmtokenT = do n <- nmtoken return (mkDTDElem NAME [(a_name, n)] []) -entityValueT :: GenParser Char state XmlTrees+entityValueT :: GenParser Char state XmlTrees entityValueT = do sl <- between dq dq (entityTokensT "%&\"")@@ -472,11 +472,11 @@ return sl <?> "entity value (in quotes)" -entityTokensT :: String -> GenParser Char state XmlTrees+entityTokensT :: String -> GenParser Char state XmlTrees entityTokensT notAllowed = many (entityCharT notAllowed) -entityCharT :: String -> GenParser Char state XmlTree+entityCharT :: String -> GenParser Char state XmlTree entityCharT notAllowed = peReferenceT <|>@@ -485,22 +485,22 @@ bypassedEntityRefT <|> ( do- cs <- many1 (singleChar notAllowed)- return (mkText cs)+ cs <- many1 (singleChar notAllowed)+ return (mkText cs) ) -attrValueT :: GenParser Char state XmlTrees+attrValueT :: GenParser Char state XmlTrees attrValueT = between dq dq (attrValueT' "<&\"") <|> between sq sq (attrValueT' "<&\'") <?> "attribute value (in quotes)" -attrValueT' :: String -> GenParser Char state XmlTrees+attrValueT' :: String -> GenParser Char state XmlTrees attrValueT' notAllowed = many ( referenceT <|> singleCharsT notAllowed) -singleCharsT :: String -> GenParser Char state XmlTree+singleCharsT :: String -> GenParser Char state XmlTree singleCharsT notAllowed = do cs <- singleChars notAllowed@@ -510,31 +510,31 @@ -- -- Character and Entity References (4.1) -referenceT :: GenParser Char state XmlTree+referenceT :: GenParser Char state XmlTree referenceT = charRefT <|> entityRefT -charRefT :: GenParser Char state XmlTree+charRefT :: GenParser Char state XmlTree charRefT = do i <- charRef return $! (mkCharRef $! i) -entityRefT :: GenParser Char state XmlTree+entityRefT :: GenParser Char state XmlTree entityRefT = do n <- entityRef return $! (mkEntityRef $! n) -bypassedEntityRefT :: GenParser Char state XmlTree+bypassedEntityRefT :: GenParser Char state XmlTree bypassedEntityRefT = do n <- entityRef return $! (mkText ("&" ++ n ++ ";")) -peReferenceT :: GenParser Char state XmlTree+peReferenceT :: GenParser Char state XmlTree peReferenceT = do r <- peReference
src/Text/XML/HXT/RelaxNG.hs view
src/Text/XML/HXT/RelaxNG/BasicArrows.hs view
@@ -28,21 +28,21 @@ , mkError ) -hasRngName :: ArrowXml a => String -> a XmlTree XmlTree+hasRngName :: ArrowXml a => String -> a XmlTree XmlTree hasRngName s- = hasName s + = hasName s `orElse` ( hasLocalPart s >>> hasNamespaceUri relaxNamespace ) checkRngName :: ArrowXml a => [String] -> a XmlTree XmlTree checkRngName l = ( isElem- >>>- catA (map hasRngName l)+ >>>+ catA (map hasRngName l) ) `guards` this -noOfChildren :: ArrowXml a => (Int -> Bool) -> a XmlTree XmlTree+noOfChildren :: ArrowXml a => (Int -> Bool) -> a XmlTree XmlTree noOfChildren p = getChildren >>.@@ -50,277 +50,277 @@ -- ------------------------------------------------------------ -isAttributeRef :: ArrowXml a => a XmlTree XmlTree+isAttributeRef :: ArrowXml a => a XmlTree XmlTree isAttributeRef = checkRngName ["attribute", "ref"] -isAttributeRefTextListGroupInterleaveOneOrMoreEmpty :: ArrowXml a => a XmlTree XmlTree+isAttributeRefTextListGroupInterleaveOneOrMoreEmpty :: ArrowXml a => a XmlTree XmlTree isAttributeRefTextListGroupInterleaveOneOrMoreEmpty = checkRngName ["attribute", "ref", "text", "list", "group", "interleave", "oneOrMore", "empty"] -isAttributeRefTextListInterleave :: ArrowXml a => a XmlTree XmlTree+isAttributeRefTextListInterleave :: ArrowXml a => a XmlTree XmlTree isAttributeRefTextListInterleave = checkRngName ["attribute", "ref", "text", "list", "interleave"] -isAttributeListGroupInterleaveOneOrMore :: ArrowXml a => a XmlTree XmlTree+isAttributeListGroupInterleaveOneOrMore :: ArrowXml a => a XmlTree XmlTree isAttributeListGroupInterleaveOneOrMore = checkRngName ["attribute", "list", "group", "interleave", "oneOrMore"] -isExternalRefInclude :: ArrowXml a => a XmlTree XmlTree+isExternalRefInclude :: ArrowXml a => a XmlTree XmlTree isExternalRefInclude = checkRngName ["externalRef", "include"] -isNameNsNameValue :: ArrowXml a => a XmlTree XmlTree+isNameNsNameValue :: ArrowXml a => a XmlTree XmlTree isNameNsNameValue = checkRngName ["name", "nsName", "value"] -isNameNsName :: ArrowXml a => a XmlTree XmlTree+isNameNsName :: ArrowXml a => a XmlTree XmlTree isNameNsName = checkRngName ["name", "nsName"] -isNameAnyNameNsName :: ArrowXml a => a XmlTree XmlTree+isNameAnyNameNsName :: ArrowXml a => a XmlTree XmlTree isNameAnyNameNsName = checkRngName ["name", "anyName", "nsName"] -isDefineOneOrMoreZeroOrMoreOptionalListMixed :: ArrowXml a => a XmlTree XmlTree+isDefineOneOrMoreZeroOrMoreOptionalListMixed :: ArrowXml a => a XmlTree XmlTree isDefineOneOrMoreZeroOrMoreOptionalListMixed = checkRngName ["define", "oneOrMore", "zeroOrMore", "optional", "list", "mixed"] -isChoiceGroupInterleave :: ArrowXml a => a XmlTree XmlTree+isChoiceGroupInterleave :: ArrowXml a => a XmlTree XmlTree isChoiceGroupInterleave = checkRngName ["choice", "group", "interleave"] -isChoiceGroupInterleaveOneOrMore :: ArrowXml a => a XmlTree XmlTree+isChoiceGroupInterleaveOneOrMore :: ArrowXml a => a XmlTree XmlTree isChoiceGroupInterleaveOneOrMore = checkRngName ["choice", "group", "interleave", "oneOrMore"] -isGroupInterleave :: ArrowXml a => a XmlTree XmlTree+isGroupInterleave :: ArrowXml a => a XmlTree XmlTree isGroupInterleave = checkRngName ["group", "interleave"] -- ------------------------------------------------------------ -isRngAnyName :: ArrowXml a => a XmlTree XmlTree-isRngAnyName = isElem >>> hasRngName "anyName"+isRngAnyName :: ArrowXml a => a XmlTree XmlTree+isRngAnyName = isElem >>> hasRngName "anyName" -isRngAttribute :: ArrowXml a => a XmlTree XmlTree-isRngAttribute = isElem >>> hasRngName "attribute"+isRngAttribute :: ArrowXml a => a XmlTree XmlTree+isRngAttribute = isElem >>> hasRngName "attribute" -isRngChoice :: ArrowXml a => a XmlTree XmlTree-isRngChoice = isElem >>> hasRngName "choice"+isRngChoice :: ArrowXml a => a XmlTree XmlTree+isRngChoice = isElem >>> hasRngName "choice" -isRngCombine :: ArrowXml a => a XmlTree XmlTree-isRngCombine = isElem >>> hasRngName "combine"+isRngCombine :: ArrowXml a => a XmlTree XmlTree+isRngCombine = isElem >>> hasRngName "combine" -isRngData :: ArrowXml a => a XmlTree XmlTree-isRngData = isElem >>> hasRngName "data"+isRngData :: ArrowXml a => a XmlTree XmlTree+isRngData = isElem >>> hasRngName "data" -isRngDefine :: ArrowXml a => a XmlTree XmlTree-isRngDefine = isElem >>> hasRngName "define"+isRngDefine :: ArrowXml a => a XmlTree XmlTree+isRngDefine = isElem >>> hasRngName "define" -isRngDiv :: ArrowXml a => a XmlTree XmlTree-isRngDiv = isElem >>> hasRngName "div"+isRngDiv :: ArrowXml a => a XmlTree XmlTree+isRngDiv = isElem >>> hasRngName "div" -isRngElement :: ArrowXml a => a XmlTree XmlTree-isRngElement = isElem >>> hasRngName "element"+isRngElement :: ArrowXml a => a XmlTree XmlTree+isRngElement = isElem >>> hasRngName "element" -isRngEmpty :: ArrowXml a => a XmlTree XmlTree-isRngEmpty = isElem >>> hasRngName "empty"+isRngEmpty :: ArrowXml a => a XmlTree XmlTree+isRngEmpty = isElem >>> hasRngName "empty" -isRngExcept :: ArrowXml a => a XmlTree XmlTree-isRngExcept = isElem >>> hasRngName "except"+isRngExcept :: ArrowXml a => a XmlTree XmlTree+isRngExcept = isElem >>> hasRngName "except" -isRngExternalRef :: ArrowXml a => a XmlTree XmlTree-isRngExternalRef = isElem >>> hasRngName "externalRef"+isRngExternalRef :: ArrowXml a => a XmlTree XmlTree+isRngExternalRef = isElem >>> hasRngName "externalRef" -isRngGrammar :: ArrowXml a => a XmlTree XmlTree-isRngGrammar = isElem >>> hasRngName "grammar"+isRngGrammar :: ArrowXml a => a XmlTree XmlTree+isRngGrammar = isElem >>> hasRngName "grammar" -isRngGroup :: ArrowXml a => a XmlTree XmlTree-isRngGroup = isElem >>> hasRngName "group"+isRngGroup :: ArrowXml a => a XmlTree XmlTree+isRngGroup = isElem >>> hasRngName "group" -isRngInclude :: ArrowXml a => a XmlTree XmlTree-isRngInclude = isElem >>> hasRngName "include"+isRngInclude :: ArrowXml a => a XmlTree XmlTree+isRngInclude = isElem >>> hasRngName "include" -isRngInterleave :: ArrowXml a => a XmlTree XmlTree-isRngInterleave = isElem >>> hasRngName "interleave"+isRngInterleave :: ArrowXml a => a XmlTree XmlTree+isRngInterleave = isElem >>> hasRngName "interleave" -isRngList :: ArrowXml a => a XmlTree XmlTree-isRngList = isElem >>> hasRngName "list"+isRngList :: ArrowXml a => a XmlTree XmlTree+isRngList = isElem >>> hasRngName "list" -isRngMixed :: ArrowXml a => a XmlTree XmlTree-isRngMixed = isElem >>> hasRngName "mixed"+isRngMixed :: ArrowXml a => a XmlTree XmlTree+isRngMixed = isElem >>> hasRngName "mixed" -isRngName :: ArrowXml a => a XmlTree XmlTree-isRngName = isElem >>> hasRngName "name"+isRngName :: ArrowXml a => a XmlTree XmlTree+isRngName = isElem >>> hasRngName "name" -isRngNotAllowed :: ArrowXml a => a XmlTree XmlTree-isRngNotAllowed = isElem >>> hasRngName "notAllowed"+isRngNotAllowed :: ArrowXml a => a XmlTree XmlTree+isRngNotAllowed = isElem >>> hasRngName "notAllowed" -isRngNsName :: ArrowXml a => a XmlTree XmlTree-isRngNsName = isElem >>> hasRngName "nsName"+isRngNsName :: ArrowXml a => a XmlTree XmlTree+isRngNsName = isElem >>> hasRngName "nsName" -isRngOneOrMore :: ArrowXml a => a XmlTree XmlTree-isRngOneOrMore = isElem >>> hasRngName "oneOrMore"+isRngOneOrMore :: ArrowXml a => a XmlTree XmlTree+isRngOneOrMore = isElem >>> hasRngName "oneOrMore" -isRngOptional :: ArrowXml a => a XmlTree XmlTree-isRngOptional = isElem >>> hasRngName "optional"+isRngOptional :: ArrowXml a => a XmlTree XmlTree+isRngOptional = isElem >>> hasRngName "optional" -isRngParam :: ArrowXml a => a XmlTree XmlTree-isRngParam = isElem >>> hasRngName "param"+isRngParam :: ArrowXml a => a XmlTree XmlTree+isRngParam = isElem >>> hasRngName "param" -isRngParentRef :: ArrowXml a => a XmlTree XmlTree-isRngParentRef = isElem >>> hasRngName "parentRef"+isRngParentRef :: ArrowXml a => a XmlTree XmlTree+isRngParentRef = isElem >>> hasRngName "parentRef" -isRngRef :: ArrowXml a => a XmlTree XmlTree-isRngRef = isElem >>> hasRngName "ref"+isRngRef :: ArrowXml a => a XmlTree XmlTree+isRngRef = isElem >>> hasRngName "ref" -isRngRelaxError :: ArrowXml a => a XmlTree XmlTree-isRngRelaxError = isElem >>> hasRngName "relaxError"+isRngRelaxError :: ArrowXml a => a XmlTree XmlTree+isRngRelaxError = isElem >>> hasRngName "relaxError" -isRngStart :: ArrowXml a => a XmlTree XmlTree-isRngStart = isElem >>> hasRngName "start"+isRngStart :: ArrowXml a => a XmlTree XmlTree+isRngStart = isElem >>> hasRngName "start" -isRngText :: ArrowXml a => a XmlTree XmlTree-isRngText = isElem >>> hasRngName "text"+isRngText :: ArrowXml a => a XmlTree XmlTree+isRngText = isElem >>> hasRngName "text" -isRngType :: ArrowXml a => a XmlTree XmlTree-isRngType = isElem >>> hasRngName "type"+isRngType :: ArrowXml a => a XmlTree XmlTree+isRngType = isElem >>> hasRngName "type" -isRngValue :: ArrowXml a => a XmlTree XmlTree-isRngValue = isElem >>> hasRngName "value"+isRngValue :: ArrowXml a => a XmlTree XmlTree+isRngValue = isElem >>> hasRngName "value" -isRngZeroOrMore :: ArrowXml a => a XmlTree XmlTree-isRngZeroOrMore = isElem >>> hasRngName "zeroOrMore"+isRngZeroOrMore :: ArrowXml a => a XmlTree XmlTree+isRngZeroOrMore = isElem >>> hasRngName "zeroOrMore" -- ------------------------------------------------------------ -mkRngElement :: ArrowXml a => String -> a n XmlTree -> a n XmlTree -> a n XmlTree-mkRngElement n = mkElement (mkQName "" n relaxNamespace)+mkRngElement :: ArrowXml a => String -> a n XmlTree -> a n XmlTree -> a n XmlTree+mkRngElement n = mkElement (mkQName "" n relaxNamespace) -mkRngChoice :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree-mkRngChoice = mkRngElement "choice"+mkRngChoice :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree+mkRngChoice = mkRngElement "choice" -mkRngDefine :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree-mkRngDefine = mkRngElement "define"+mkRngDefine :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree+mkRngDefine = mkRngElement "define" -mkRngEmpty :: ArrowXml a => a n XmlTree -> a n XmlTree-mkRngEmpty a = mkRngElement "empty" a none+mkRngEmpty :: ArrowXml a => a n XmlTree -> a n XmlTree+mkRngEmpty a = mkRngElement "empty" a none -mkRngGrammar :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree-mkRngGrammar = mkRngElement "grammar"+mkRngGrammar :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree+mkRngGrammar = mkRngElement "grammar" -mkRngGroup :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree-mkRngGroup = mkRngElement "group"+mkRngGroup :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree+mkRngGroup = mkRngElement "group" -mkRngInterleave :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree-mkRngInterleave = mkRngElement "interleave"+mkRngInterleave :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree+mkRngInterleave = mkRngElement "interleave" -mkRngName :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree-mkRngName = mkRngElement "name"+mkRngName :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree+mkRngName = mkRngElement "name" -mkRngNotAllowed :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree-mkRngNotAllowed = mkRngElement "notAllowed"+mkRngNotAllowed :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree+mkRngNotAllowed = mkRngElement "notAllowed" -mkRngOneOrMore :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree-mkRngOneOrMore = mkRngElement "oneOrMore"+mkRngOneOrMore :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree+mkRngOneOrMore = mkRngElement "oneOrMore" -mkRngRef :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree-mkRngRef = mkRngElement "ref"+mkRngRef :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree+mkRngRef = mkRngElement "ref" -mkRngRelaxError :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree-mkRngRelaxError = mkRngElement "relaxError"+mkRngRelaxError :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree+mkRngRelaxError = mkRngElement "relaxError" -mkRngStart :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree-mkRngStart = mkRngElement "start"+mkRngStart :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree+mkRngStart = mkRngElement "start" -mkRngText :: ArrowXml a => a n XmlTree -> a n XmlTree-mkRngText a = mkRngElement "text" a none+mkRngText :: ArrowXml a => a n XmlTree -> a n XmlTree+mkRngText a = mkRngElement "text" a none -- ------------------------------------------------------------ -setRngName :: ArrowXml a => String -> a XmlTree XmlTree-setRngName n = setElemName (mkQName "" n relaxNamespace)+setRngName :: ArrowXml a => String -> a XmlTree XmlTree+setRngName n = setElemName (mkQName "" n relaxNamespace) -setRngNameDiv :: ArrowXml a => a XmlTree XmlTree-setRngNameDiv = setRngName "div"+setRngNameDiv :: ArrowXml a => a XmlTree XmlTree+setRngNameDiv = setRngName "div" -setRngNameRef :: ArrowXml a => a XmlTree XmlTree-setRngNameRef = setRngName "ref"+setRngNameRef :: ArrowXml a => a XmlTree XmlTree+setRngNameRef = setRngName "ref" -- ------------------------------------------------------------ -- Attributes -isRngAttrAttribute :: ArrowXml a => a XmlTree XmlTree-isRngAttrAttribute = isAttr >>> hasRngName "attribute"+isRngAttrAttribute :: ArrowXml a => a XmlTree XmlTree+isRngAttrAttribute = isAttr >>> hasRngName "attribute" -isRngAttrCombine :: ArrowXml a => a XmlTree XmlTree-isRngAttrCombine = isAttr >>> hasRngName "combine"+isRngAttrCombine :: ArrowXml a => a XmlTree XmlTree+isRngAttrCombine = isAttr >>> hasRngName "combine" -isRngAttrDatatypeLibrary :: ArrowXml a => a XmlTree XmlTree-isRngAttrDatatypeLibrary = isAttr >>> hasRngName "datatypeLibrary"+isRngAttrDatatypeLibrary :: ArrowXml a => a XmlTree XmlTree+isRngAttrDatatypeLibrary = isAttr >>> hasRngName "datatypeLibrary" -isRngAttrHref :: ArrowXml a => a XmlTree XmlTree-isRngAttrHref = isAttr >>> hasRngName "href"+isRngAttrHref :: ArrowXml a => a XmlTree XmlTree+isRngAttrHref = isAttr >>> hasRngName "href" -isRngAttrName :: ArrowXml a => a XmlTree XmlTree-isRngAttrName = isAttr >>> hasRngName "name"+isRngAttrName :: ArrowXml a => a XmlTree XmlTree+isRngAttrName = isAttr >>> hasRngName "name" -isRngAttrNs :: ArrowXml a => a XmlTree XmlTree-isRngAttrNs = isAttr >>> hasRngName "ns"+isRngAttrNs :: ArrowXml a => a XmlTree XmlTree+isRngAttrNs = isAttr >>> hasRngName "ns" -isRngAttrType :: ArrowXml a => a XmlTree XmlTree-isRngAttrType = isAttr >>> hasRngName "type"+isRngAttrType :: ArrowXml a => a XmlTree XmlTree+isRngAttrType = isAttr >>> hasRngName "type" -- ------------------------------------------------------------ -hasRngAttrAttribute :: ArrowXml a => a XmlTree XmlTree-hasRngAttrAttribute = hasAttr "attribute"+hasRngAttrAttribute :: ArrowXml a => a XmlTree XmlTree+hasRngAttrAttribute = hasAttr "attribute" -hasRngAttrCombine :: ArrowXml a => a XmlTree XmlTree-hasRngAttrCombine = hasAttr "combine"+hasRngAttrCombine :: ArrowXml a => a XmlTree XmlTree+hasRngAttrCombine = hasAttr "combine" -hasRngAttrDatatypeLibrary :: ArrowXml a => a XmlTree XmlTree-hasRngAttrDatatypeLibrary = hasAttr "datatypeLibrary"+hasRngAttrDatatypeLibrary :: ArrowXml a => a XmlTree XmlTree+hasRngAttrDatatypeLibrary = hasAttr "datatypeLibrary" -hasRngAttrHref :: ArrowXml a => a XmlTree XmlTree-hasRngAttrHref = hasAttr "href"+hasRngAttrHref :: ArrowXml a => a XmlTree XmlTree+hasRngAttrHref = hasAttr "href" -hasRngAttrName :: ArrowXml a => a XmlTree XmlTree-hasRngAttrName = hasAttr "name"+hasRngAttrName :: ArrowXml a => a XmlTree XmlTree+hasRngAttrName = hasAttr "name" -hasRngAttrNs :: ArrowXml a => a XmlTree XmlTree-hasRngAttrNs = hasAttr "ns"+hasRngAttrNs :: ArrowXml a => a XmlTree XmlTree+hasRngAttrNs = hasAttr "ns" -hasRngAttrType :: ArrowXml a => a XmlTree XmlTree-hasRngAttrType = hasAttr "type"+hasRngAttrType :: ArrowXml a => a XmlTree XmlTree+hasRngAttrType = hasAttr "type" -- ------------------------------------------------------------ -getRngAttrAttribute :: ArrowXml a => a XmlTree String-getRngAttrAttribute = getAttrValue "attribute"+getRngAttrAttribute :: ArrowXml a => a XmlTree String+getRngAttrAttribute = getAttrValue "attribute" -getRngAttrCombine :: ArrowXml a => a XmlTree String-getRngAttrCombine = getAttrValue "combine"+getRngAttrCombine :: ArrowXml a => a XmlTree String+getRngAttrCombine = getAttrValue "combine" -getRngAttrDatatypeLibrary :: ArrowXml a => a XmlTree String-getRngAttrDatatypeLibrary = getAttrValue "datatypeLibrary"+getRngAttrDatatypeLibrary :: ArrowXml a => a XmlTree String+getRngAttrDatatypeLibrary = getAttrValue "datatypeLibrary" -getRngAttrDescr :: ArrowXml a => a XmlTree String-getRngAttrDescr = getAttrValue "descr"+getRngAttrDescr :: ArrowXml a => a XmlTree String+getRngAttrDescr = getAttrValue "descr" -getRngAttrHref :: ArrowXml a => a XmlTree String-getRngAttrHref = getAttrValue "href"+getRngAttrHref :: ArrowXml a => a XmlTree String+getRngAttrHref = getAttrValue "href" -getRngAttrName :: ArrowXml a => a XmlTree String-getRngAttrName = getAttrValue "name"+getRngAttrName :: ArrowXml a => a XmlTree String+getRngAttrName = getAttrValue "name" -getRngAttrNs :: ArrowXml a => a XmlTree String-getRngAttrNs = getAttrValue "ns"+getRngAttrNs :: ArrowXml a => a XmlTree String+getRngAttrNs = getAttrValue "ns" -getRngAttrType :: ArrowXml a => a XmlTree String-getRngAttrType = getAttrValue "type"+getRngAttrType :: ArrowXml a => a XmlTree String+getRngAttrType = getAttrValue "type" -- ------------------------------------------------------------
src/Text/XML/HXT/RelaxNG/CreatePattern.hs view
@@ -1,6 +1,6 @@ -- |--- --- Creates the 'Pattern' datastructure from a simplified Relax NG schema. +--+-- Creates the 'Pattern' datastructure from a simplified Relax NG schema. -- The created datastructure is used in the validation algorithm -- (see also: "Text.XML.HXT.RelaxNG.Validation") @@ -40,8 +40,8 @@ -- Each list entry maps the define name to the children of the define-pattern. -- The map is used to replace a ref-pattern with the referenced define-pattern. createEnv :: LA XmlTree Env- createEnv = listA $ deep isRngDefine - >>> + createEnv = listA $ deep isRngDefine+ >>> (getRngAttrName &&& getChildren) @@ -67,11 +67,11 @@ this :-> mkRelaxError "" ] - + processRoot :: Env -> LA XmlTree Pattern processRoot env = getChildren- >>> + >>> choiceA [ isRngRelaxError :-> (mkRelaxError $< getRngAttrDescr), isRngGrammar :-> (processGrammar env),@@ -82,7 +82,7 @@ processGrammar :: Env -> LA XmlTree Pattern processGrammar env = getChildren- >>> + >>> choiceA [ isRngDefine :-> none, isRngRelaxError :-> (mkRelaxError $< getAttrValue "desc"),@@ -94,7 +94,7 @@ {- | Transforms a ref-element. The value of the name-attribute is looked up in the environment list- to find the corresponding define-pattern. + to find the corresponding define-pattern. Haskells lazy-evaluation is used to transform circular structures. -} mkRelaxRef :: Env -> LA XmlTree Pattern@@ -108,7 +108,7 @@ transformEnv :: [(String, XmlTree)] -> [(String, Pattern)] transformEnv env = [ (treeName, (transformEnvElem tree env)) | (treeName, tree) <- env] transformEnvElem :: XmlTree -> [(String, XmlTree)] -> Pattern- transformEnvElem tree env = head $ runLA (createPatternFromXml env) tree + transformEnvElem tree env = head $ runLA (createPatternFromXml env) tree -- | Transforms a notAllowed-element.@@ -123,17 +123,17 @@ isRngRelaxError :-> (getRngAttrDescr >>> arr notAllowed), isElem :-> ( getName >>>- arr (\n -> notAllowed $ "Pattern " ++ n ++ + arr (\n -> notAllowed $ "Pattern " ++ n ++ " is not allowed in Relax NG schema" ) ), isAttr :-> ( getName >>>- arr (\n -> notAllowed $ "Attribute " ++ n ++ + arr (\n -> notAllowed $ "Attribute " ++ n ++ " is not allowed in Relax NG schema" ) ),- isError :-> (getErrorMsg >>> arr notAllowed), + isError :-> (getErrorMsg >>> arr notAllowed), this :-> (arr (\e -> notAllowed $ if errStr /= "" then errStr else "Can't create pattern from " ++ show e)@@ -145,8 +145,8 @@ mkRelaxChoice :: Env -> LA XmlTree Pattern mkRelaxChoice env = ifA ( getChildren >>.- ( \ l -> if length l == 1 then l else [] )- )+ ( \ l -> if length l == 1 then l else [] )+ ) ( createPatternFromXml env ) ( getTwoChildrenPattern env >>> arr2 Choice ) @@ -154,7 +154,7 @@ mkRelaxInterleave :: Env -> LA XmlTree Pattern mkRelaxInterleave env = getTwoChildrenPattern env- >>> + >>> arr2 Interleave @@ -170,7 +170,7 @@ mkRelaxOneOrMore :: Env -> LA XmlTree Pattern mkRelaxOneOrMore env = getOneChildPattern env- >>> + >>> arr OneOrMore @@ -184,17 +184,17 @@ -- | Transforms a data- or dataExcept-element. mkRelaxData :: Env -> LA XmlTree Pattern-mkRelaxData env +mkRelaxData env = ifA (getChildren >>> isRngExcept) (processDataExcept >>> arr3 DataExcept) (processData >>> arr2 Data) where processDataExcept :: LA XmlTree (Datatype, (ParamList, Pattern))- processDataExcept = getDatatype &&& getParamList &&& + processDataExcept = getDatatype &&& getParamList &&& ( getChildren- >>> + >>> isRngExcept- >>> + >>> getChildren >>> createPatternFromXml env@@ -205,23 +205,23 @@ getParamList = listA $ getChildren >>> isRngParam- >>> + >>> (getRngAttrName &&& (getChildren >>> getText))- + -- | Transforms a value-element.-mkRelaxValue :: LA XmlTree Pattern +mkRelaxValue :: LA XmlTree Pattern mkRelaxValue = getDatatype &&& getValue &&& getContext >>>- arr3 Value + arr3 Value where getContext :: LA XmlTree Context getContext = getAttrValue contextBaseAttr &&& getMapping getMapping :: LA XmlTree [(Prefix, Uri)]- getMapping = listA $ getAttrl >>> + getMapping = listA $ getAttrl >>> ( (getName >>> isA (contextAttributes `isPrefixOf`)) `guards`- ( (getName >>> arr (drop $ length contextAttributes)) + ( (getName >>> arr (drop $ length contextAttributes)) &&& (getChildren >>> getText) )@@ -242,8 +242,8 @@ mkRelaxAttribute :: Env -> LA XmlTree Pattern mkRelaxAttribute env = ( ( firstChild >>> createNameClass )- &&&- ( lastChild >>> createPatternFromXml env )+ &&&+ ( lastChild >>> createPatternFromXml env ) ) >>> arr2 Attribute@@ -253,14 +253,14 @@ mkRelaxElement :: Env -> LA XmlTree Pattern mkRelaxElement env = ( ( firstChild >>> createNameClass )- &&&- ( lastChild >>> createPatternFromXml env )+ &&&+ ( lastChild >>> createPatternFromXml env ) ) >>> arr2 Element --- | Creates a 'NameClass' from an \"anyName\"-, \"nsName\"- or \"name\"-Pattern, +-- | Creates a 'NameClass' from an \"anyName\"-, \"nsName\"- or \"name\"-Pattern, createNameClass :: LA XmlTree NameClass createNameClass = choiceA@@ -273,60 +273,60 @@ where processAnyName :: LA XmlTree NameClass processAnyName- = ifA (getChildren >>> isRngExcept)+ = ifA (getChildren >>> isRngExcept) ( getChildren- >>> getChildren- >>> createNameClass- >>> arr AnyNameExcept+ >>> getChildren+ >>> createNameClass+ >>> arr AnyNameExcept ) ( constA AnyName ) processNsName :: LA XmlTree NameClass processNsName- = ifA (getChildren >>> isRngExcept)- ( ( getRngAttrNs + = ifA (getChildren >>> isRngExcept)+ ( ( getRngAttrNs &&& ( getChildren >>> getChildren >>> createNameClass ) )- >>> + >>> arr2 NsNameExcept )- ( getRngAttrNs >>> arr NsName ) + ( getRngAttrNs >>> arr NsName ) processName :: LA XmlTree NameClass processName- = (getRngAttrNs &&& (getChildren >>> getText)) >>> arr2 Name+ = (getRngAttrNs &&& (getChildren >>> getText)) >>> arr2 Name processChoice :: LA XmlTree NameClass processChoice- = ( ( firstChild >>> createNameClass )- &&&- ( lastChild >>> createNameClass )- )+ = ( ( firstChild >>> createNameClass )+ &&&+ ( lastChild >>> createNameClass )+ ) >>>- arr2 NameClassChoice- + arr2 NameClassChoice+ mkNameClassError :: LA XmlTree NameClass-mkNameClassError +mkNameClassError = choiceA [ isRngRelaxError :-> ( getRngAttrDescr- >>>- arr NCError- )- , isElem :-> ( getName- >>>- arr (\n -> NCError ("Can't create name class from element " ++ n))- )- , isAttr :-> ( getName- >>>- arr (\n -> NCError ("Can't create name class from attribute: " ++ n))- )- , isError :-> ( getErrorMsg- >>>- arr NCError- )- , this :-> ( arr (\e -> NCError $ "Can't create name class from " ++ show e) ) - ]+ >>>+ arr NCError+ )+ , isElem :-> ( getName+ >>>+ arr (\n -> NCError ("Can't create name class from element " ++ n))+ )+ , isAttr :-> ( getName+ >>>+ arr (\n -> NCError ("Can't create name class from attribute: " ++ n))+ )+ , isError :-> ( getErrorMsg+ >>>+ arr NCError+ )+ , this :-> ( arr (\e -> NCError $ "Can't create name class from " ++ show e) )+ ] getOneChildPattern :: Env -> LA XmlTree Pattern@@ -337,13 +337,13 @@ getTwoChildrenPattern :: Env -> LA XmlTree (Pattern, Pattern) getTwoChildrenPattern env = ( getOneChildPattern env )- &&&- ( lastChild >>> createPatternFromXml env )+ &&&+ ( lastChild >>> createPatternFromXml env ) -- | Simple access arrows -firstChild :: (ArrowTree a, Tree t) => a (t b) (t b)-firstChild = single getChildren+firstChild :: (ArrowTree a, Tree t) => a (t b) (t b)+firstChild = single getChildren -lastChild :: (ArrowTree a, Tree t) => a (t b) (t b)-lastChild = getChildren >>. (take 1 . reverse)+lastChild :: (ArrowTree a, Tree t) => a (t b) (t b)+lastChild = getChildren >>. (take 1 . reverse)
src/Text/XML/HXT/RelaxNG/DataTypeLibMysql.hs view
@@ -9,7 +9,7 @@ ) where -import Text.XML.HXT.RelaxNG.DataTypeLibUtils +import Text.XML.HXT.RelaxNG.DataTypeLibUtils import Data.Maybe @@ -44,36 +44,36 @@ , ("UNSIGNED-INT", numericParams) , ("SIGNED-BIGINT", numericParams) , ("UNSIGNED-BIGINT", numericParams)- + -- string types , ("CHAR", stringParams)- , ("VARCHAR", stringParams) + , ("VARCHAR", stringParams) , ("BINARY", stringParams)- , ("VARBINARY", stringParams) + , ("VARBINARY", stringParams) , ("TINYTEXT", stringParams)- , ("TINYBLOB", stringParams) + , ("TINYBLOB", stringParams) , ("TEXT", stringParams)- , ("BLOB", stringParams) + , ("BLOB", stringParams) , ("MEDIUMTEXT", stringParams)- , ("MEDIUMBLOB", stringParams) + , ("MEDIUMBLOB", stringParams) , ("LONGTEXT", stringParams)- , ("LONGBLOB", stringParams) + , ("LONGBLOB", stringParams) ] -- | List of supported string datatypes stringTypes :: [String] stringTypes = [ "CHAR"- , "VARCHAR"- , "BINARY"- , "VARBINARY"+ , "VARCHAR"+ , "BINARY"+ , "VARBINARY" , "TINYTEXT"- , "TINYBLOB"- , "TEXT"- , "BLOB"+ , "TINYBLOB"+ , "TEXT"+ , "BLOB" , "MEDIUMTEXT"- , "MEDIUMBLOB"- , "LONGTEXT"+ , "MEDIUMBLOB"+ , "LONGTEXT" , "LONGBLOB" ] @@ -81,74 +81,74 @@ -- | List of supported numeric datatypes numericTypes :: [String] numericTypes = [ "SIGNED-TINYINT"- , "UNSIGNED-TINYINT"- , "SIGNED-SMALLINT"+ , "UNSIGNED-TINYINT"+ , "SIGNED-SMALLINT" , "UNSIGNED-SMALLINT"- , "SIGNED-MEDIUMINT"+ , "SIGNED-MEDIUMINT" , "UNSIGNED-MEDIUMINT"- , "SIGNED-INT"- , "UNSIGNED-INT"+ , "SIGNED-INT"+ , "UNSIGNED-INT" , "SIGNED-BIGINT"- , "UNSIGNED-BIGINT"+ , "UNSIGNED-BIGINT" ] -- | List of allowed params for the numeric datatypes numericParams :: AllowedParams numericParams = [ rng_maxExclusive- , rng_minExclusive+ , rng_minExclusive , rng_maxInclusive- , rng_minInclusive+ , rng_minInclusive ]- + -- | List of allowed params for the string datatypes stringParams :: AllowedParams stringParams = [ rng_length- , rng_maxLength- , rng_minLength- ]+ , rng_maxLength+ , rng_minLength+ ] -- ------------------------------------------------------------ -- -- | Tests whether a XML instance value matches a data-pattern.- + datatypeAllowsMysql :: DatatypeAllows datatypeAllowsMysql d params value _ = performCheck check value where check- | isJust ndt = checkNum (fromJust ndt)- | isJust sdt = checkStr (fromJust sdt)- | otherwise = failure $ errorMsgDataTypeNotAllowed mysqlNS d params- checkNum r = uncurry (numberValid d) r params- checkStr r = uncurry (stringValid d) r params+ | isJust ndt = checkNum (fromJust ndt)+ | isJust sdt = checkStr (fromJust sdt)+ | otherwise = failure $ errorMsgDataTypeNotAllowed mysqlNS d params+ checkNum r = uncurry (numberValid d) r params+ checkStr r = uncurry (stringValid d) r params ndt = lookup d $- [ ("SIGNED-TINYINT", ((-128), 127))- , ("UNSIGNED-TINYINT", (0, 255))- , ("SIGNED-SMALLINT", ((-32768), 32767))- , ("UNSIGNED-SMALLINT", (0, 65535))- , ("SIGNED-MEDIUMINT", ((-8388608), 8388607))- , ("UNSIGNED-MEDIUMINT", (0, 16777215))- , ("SIGNED-INT", ((-2147483648), 2147483647))- , ("UNSIGNED-INT", (0, 4294967295))- , ("SIGNED-BIGINT", ((-9223372036854775808), 9223372036854775807))- , ("UNSIGNED-BIGINT", (0, 18446744073709551615))- ]+ [ ("SIGNED-TINYINT", ((-128), 127))+ , ("UNSIGNED-TINYINT", (0, 255))+ , ("SIGNED-SMALLINT", ((-32768), 32767))+ , ("UNSIGNED-SMALLINT", (0, 65535))+ , ("SIGNED-MEDIUMINT", ((-8388608), 8388607))+ , ("UNSIGNED-MEDIUMINT", (0, 16777215))+ , ("SIGNED-INT", ((-2147483648), 2147483647))+ , ("UNSIGNED-INT", (0, 4294967295))+ , ("SIGNED-BIGINT", ((-9223372036854775808), 9223372036854775807))+ , ("UNSIGNED-BIGINT", (0, 18446744073709551615))+ ] sdt = lookup d $- [ ("CHAR", (0, 255))- , ("VARCHAR", (0, 65535))- , ("BINARY", (0, 255)) - , ("VARBINARY", (0, 65535))- , ("TINYTEXT", (0, 256))- , ("TINYBLOB", (0, 256)) - , ("TEXT", (0, 65536))- , ("BLOB", (0, 65536))- , ("MEDIUMTEXT", (0, 16777216))- , ("MEDIUMBLOB", (0, 16777216))- , ("LONGTEXT", (0, 4294967296))- , ("LONGBLOB", (0, 4294967296))- ]+ [ ("CHAR", (0, 255))+ , ("VARCHAR", (0, 65535))+ , ("BINARY", (0, 255))+ , ("VARBINARY", (0, 65535))+ , ("TINYTEXT", (0, 256))+ , ("TINYBLOB", (0, 256))+ , ("TEXT", (0, 65536))+ , ("BLOB", (0, 65536))+ , ("MEDIUMTEXT", (0, 16777216))+ , ("MEDIUMBLOB", (0, 16777216))+ , ("LONGTEXT", (0, 4294967296))+ , ("LONGBLOB", (0, 4294967296))+ ] -- ------------------------------------------------------------ @@ -158,12 +158,12 @@ datatypeEqualMysql d s1 _ s2 _ = performCheck check (s1, s2) where- cmp nf = arr (\ (x1, x2) -> (nf x1, nf x2))- >>>- assert (uncurry (==)) (uncurry $ errorMsgEqual d)+ cmp nf = arr (\ (x1, x2) -> (nf x1, nf x2))+ >>>+ assert (uncurry (==)) (uncurry $ errorMsgEqual d) check- | d `elem` stringTypes = cmp id- | d `elem` numericTypes = cmp normalizeNumber- | otherwise = failure $ const (errorMsgDataTypeNotAllowed0 mysqlNS d)+ | d `elem` stringTypes = cmp id+ | d `elem` numericTypes = cmp normalizeNumber+ | otherwise = failure $ const (errorMsgDataTypeNotAllowed0 mysqlNS d) -- ------------------------------------------------------------
src/Text/XML/HXT/RelaxNG/DataTypeLibUtils.hs view
@@ -20,29 +20,29 @@ , module Control.Arrow , module Text.XML.HXT.DOM.Util , module Text.XML.HXT.RelaxNG.Utils- , module Text.XML.HXT.RelaxNG.DataTypes + , module Text.XML.HXT.RelaxNG.DataTypes , FunctionTable - , stringValidFT -- generalized checkString- , fctTableString -- minLength, maxLenght, length- , fctTableList -- minLength, maxLenght, length+ , stringValidFT -- generalized checkString+ , fctTableString -- minLength, maxLenght, length+ , fctTableList -- minLength, maxLenght, length - , stringValid -- checkString- , numberValid -- checkNumeric+ , stringValid -- checkString+ , numberValid -- checkNumeric , numParamValid - , CheckA -- Check datatype- , CheckString -- CheckA String String- , CheckInteger -- CheckA Integer Integer+ , CheckA -- Check datatype+ , CheckString -- CheckA String String+ , CheckInteger -- CheckA Integer Integer - , performCheck -- run a CheckA- , ok -- always true- , failure -- create an error meesage- , assert -- create a primitive check from a predicate- , assertMaybe -- create a primitive check from a maybe- , checkWith -- convert value before checking+ , performCheck -- run a CheckA+ , ok -- always true+ , failure -- create an error meesage+ , assert -- create a primitive check from a predicate+ , assertMaybe -- create a primitive check from a maybe+ , checkWith -- convert value before checking ) where@@ -60,88 +60,88 @@ -- ------------------------------------------------------------ -newtype CheckA a b = C { runCheck :: a -> Either String b }+newtype CheckA a b = C { runCheck :: a -> Either String b } instance Category CheckA where id = C $ Right - f2 . f1 = C $ -- logical and: f1 and f2 must hold- \ x -> case runCheck f1 x of- Right y -> runCheck f2 y- Left e -> Left e+ f2 . f1 = C $ -- logical and: f1 and f2 must hold+ \ x -> case runCheck f1 x of+ Right y -> runCheck f2 y+ Left e -> Left e instance Arrow CheckA where- arr f = C ( Right . f ) -- unit: no check, always o.k., just a conversion+ arr f = C ( Right . f ) -- unit: no check, always o.k., just a conversion - first f1 = C $ -- check 1. component of a pair- \ ~(x1, x2) -> case runCheck f1 x1 of- Right y1 -> Right (y1, x2)- Left e -> Left e+ first f1 = C $ -- check 1. component of a pair+ \ ~(x1, x2) -> case runCheck f1 x1 of+ Right y1 -> Right (y1, x2)+ Left e -> Left e - second f2 = C $ -- check 2. component of a pair- \ ~(x1, x2) -> case runCheck f2 x2 of- Right y2 -> Right (x1, y2)- Left e -> Left e+ second f2 = C $ -- check 2. component of a pair+ \ ~(x1, x2) -> case runCheck f2 x2 of+ Right y2 -> Right (x1, y2)+ Left e -> Left e instance ArrowZero CheckA where- zeroArrow = C $ const (Left "") -- always false: zero+ zeroArrow = C $ const (Left "") -- always false: zero instance ArrowPlus CheckA where- f1 <+> f2 = C $ -- logical or- \ x -> case runCheck f1 x of- Right y1 -> Right y1- Left e1 -> case runCheck f2 x of- Right y2 -> Right y2- Left e2 -> Left ( if null e1- then e2- else- if null e2- then e1- else e1 ++ " or " ++ e2- )+ f1 <+> f2 = C $ -- logical or+ \ x -> case runCheck f1 x of+ Right y1 -> Right y1+ Left e1 -> case runCheck f2 x of+ Right y2 -> Right y2+ Left e2 -> Left ( if null e1+ then e2+ else+ if null e2+ then e1+ else e1 ++ " or " ++ e2+ ) -type CheckString = CheckA String String-type CheckInteger = CheckA Integer Integer+type CheckString = CheckA String String+type CheckInteger = CheckA Integer Integer -- | run a check and deliver Just an error message or Nothing -performCheck :: CheckA a b -> a -> Maybe String-performCheck c = either Just (const Nothing) . runCheck c+performCheck :: CheckA a b -> a -> Maybe String+performCheck c = either Just (const Nothing) . runCheck c -- | always failure -failure :: (a -> String) -> CheckA a b-failure msg = C (Left . msg)+failure :: (a -> String) -> CheckA a b+failure msg = C (Left . msg) -- | every thing is fine -ok :: CheckA a a-ok = arr id+ok :: CheckA a a+ok = arr id -- | perform a simple check with a predicate p, -- when the predicate holds, assert acts as identity, -- else an error message is generated -assert :: (a -> Bool) -> (a -> String) -> CheckA a a-assert p msg = C $ \ x -> if p x then Right x else Left (msg x)+assert :: (a -> Bool) -> (a -> String) -> CheckA a a+assert p msg = C $ \ x -> if p x then Right x else Left (msg x) -- | perform a simple check with a Maybe function, Nothing indicates error -assertMaybe :: (a -> Maybe b) -> (a -> String) -> CheckA a b+assertMaybe :: (a -> Maybe b) -> (a -> String) -> CheckA a b assertMaybe f msg = C $ \ x -> case f x of- Nothing -> Left (msg x)- Just y -> Right y+ Nothing -> Left (msg x)+ Just y -> Right y -- | perform a check, but convert the value before checking -checkWith :: (a -> b) -> CheckA b c -> CheckA a a-checkWith f c = C $- \ x -> case runCheck c (f x) of- Right _ -> Right x- Left e -> Left e+checkWith :: (a -> b) -> CheckA b c -> CheckA a a+checkWith f c = C $+ \ x -> case runCheck c (f x) of+ Right _ -> Right x+ Left e -> Left e -- ------------------------------------------------------------ @@ -150,20 +150,20 @@ rng_length, rng_maxLength, rng_minLength ,rng_maxExclusive, rng_minExclusive, rng_maxInclusive, rng_minInclusive :: String -rng_length = "length"-rng_maxLength = "maxLength"-rng_minLength = "minLength"+rng_length = "length"+rng_maxLength = "maxLength"+rng_minLength = "minLength" -rng_maxExclusive = "maxExclusive"-rng_minExclusive = "minExclusive"-rng_maxInclusive = "maxInclusive"-rng_minInclusive = "minInclusive"+rng_maxExclusive = "maxExclusive"+rng_minExclusive = "minExclusive"+rng_maxInclusive = "maxInclusive"+rng_minInclusive = "minInclusive" -- ------------------------------------------------------------ -- | Function table type -type FunctionTable = [(String, String -> String -> Bool)]+type FunctionTable = [(String, String -> String -> Bool)] -- | Function table for numeric tests, -- XML document value is first operand, schema value second@@ -195,7 +195,7 @@ , (rng_minLength, (listParamValid (>=))) ] -{- | +{- | tests whether a string value matches a numeric param valid example:@@ -214,7 +214,7 @@ && ( toInteger (length a) `fct` (read b) ) -{- | +{- | tests whether a list value matches a length constraint valid example:@@ -236,28 +236,28 @@ -- ------------------------------------------------------------ -- new check functions -{- | -Tests whether a \"string\" datatype value is between the lower and +{- |+Tests whether a \"string\" datatype value is between the lower and upper bound of the datatype and matches all parameters. All tests are performed on the string value.- + * 1.parameter : datatype- + - 2.parameter : lower bound of the datatype range- - - 3.parameter : upper bound of the datatype range (-1 = no upper bound) - ++ - 3.parameter : upper bound of the datatype range (-1 = no upper bound)+ - 4.parameter : list of parameters- + - 5.parameter : datatype value to be checked - return : Just \"Errormessage\" in case of an error, else Nothing- + -} -stringValid :: DatatypeName -> Integer -> Integer -> ParamList -> CheckString-stringValid = stringValidFT fctTableString+stringValid :: DatatypeName -> Integer -> Integer -> ParamList -> CheckString+stringValid = stringValidFT fctTableString stringValidFT :: FunctionTable -> DatatypeName -> Integer -> Integer -> ParamList -> CheckString stringValidFT ft datatype lowerBound upperBound params@@ -266,54 +266,54 @@ paramsStringValid params where boundsOK v- = ( (lowerBound == 0)- ||- (toInteger (length v) >= lowerBound)- )- &&- ( (upperBound == (-1))- ||- (toInteger (length v) <= upperBound)- )+ = ( (lowerBound == 0)+ ||+ (toInteger (length v) >= lowerBound)+ )+ &&+ ( (upperBound == (-1))+ ||+ (toInteger (length v) <= upperBound)+ ) boundsErr v- = "Length of " ++ v+ = "Length of " ++ v ++ " (" ++ (show $ length v) ++ " chars) out of range: " ++ show lowerBound ++ " .. " ++ show upperBound ++ " for datatype " ++ datatype paramStringValid :: (LocalName, String) -> CheckString paramStringValid (pn, pv)- = assert paramOK (errorMsgParam pn pv)- where- paramOK v = paramFct pn v pv- paramFct n = fromMaybe (const . const $ True) $ lookup n ft+ = assert paramOK (errorMsgParam pn pv)+ where+ paramOK v = paramFct pn v pv+ paramFct n = fromMaybe (const . const $ True) $ lookup n ft paramsStringValid :: ParamList -> CheckString paramsStringValid- = foldr (>>>) ok . map paramStringValid+ = foldr (>>>) ok . map paramStringValid -- ------------------------------------------------------------ -{- | -Tests whether a \"numeric\" datatype value is between the lower and upper +{- |+Tests whether a \"numeric\" datatype value is between the lower and upper bound of the datatype and matches all parameters. First, the string value is parsed into a numeric representation. If no error occur, all following tests are performed on the numeric value. * 1.parameter : datatype- + - 2.parameter : lower bound of the datatype range- - - 3.parameter : upper bound of the datatype range (-1 = no upper bound) - ++ - 3.parameter : upper bound of the datatype range (-1 = no upper bound)+ - 4.parameter : list of parameters- + - 5.parameter : datatype value to be checked - return : Just \"Errormessage\" in case of an error, else Nothing- + -} numberValid :: DatatypeName -> Integer -> Integer -> ParamList -> CheckString@@ -321,64 +321,64 @@ = assert isNumber numErr >>> checkWith read ( assert inRange rangeErr- >>>- paramsNumValid params- )+ >>>+ paramsNumValid params+ ) where- inRange :: Integer -> Bool- inRange x = x >= lowerBound- &&- x <= upperBound+ inRange :: Integer -> Bool+ inRange x = x >= lowerBound+ &&+ x <= upperBound - rangeErr v = ( "Value = " ++ show v ++ " out of range: "- ++ show lowerBound ++ " .. " ++ show upperBound- ++ " for datatype " ++ datatype- )+ rangeErr v = ( "Value = " ++ show v ++ " out of range: "+ ++ show lowerBound ++ " .. " ++ show upperBound+ ++ " for datatype " ++ datatype+ ) numErr v- = "Value = " ++ v ++ " is not a number"+ = "Value = " ++ v ++ " is not a number" -paramsNumValid :: ParamList -> CheckInteger+paramsNumValid :: ParamList -> CheckInteger paramsNumValid = foldr (>>>) ok . map paramNumValid -paramNumValid :: (LocalName, String) -> CheckInteger+paramNumValid :: (LocalName, String) -> CheckInteger paramNumValid (pn, pv) = assert paramOK (errorMsgParam pn pv . show) where paramOK v = isNumber pv- &&- paramFct pn v (read pv)+ &&+ paramFct pn v (read pv) paramFct n = fromJust $ lookup n fctTableNum -- ------------------------------------------------------------- -{- | ++{- | Error Message for the equality test of two datatype values- + * 1.parameter : datatype- + - 2.parameter : datatype value - 3.parameter : datatype value- + example: > errorMsgEqual "Int" "21" "42" -> "Datatype Int with value = 21 expected, but value = 42 found" -} -errorMsgParam :: LocalName -> String -> String -> String+errorMsgParam :: LocalName -> String -> String -> String errorMsgParam pn pv v = ( "Parameter restriction: \""- ++ pn ++ " = " ++ pv- ++ "\" does not hold for value = \"" ++ v ++ "\""+ ++ pn ++ " = " ++ pv+ ++ "\" does not hold for value = \"" ++ v ++ "\"" ) errorMsgEqual :: DatatypeName -> String -> String -> String errorMsgEqual d s1 s2 = ( "Datatype" ++ show d ++- " with value = " ++ show s1 ++- " expected, but value = " ++ show s2 ++ " found" + " with value = " ++ show s1 +++ " expected, but value = " ++ show s2 ++ " found" ) errorMsgDataTypeNotAllowed :: String -> String -> [(String, String)] -> String -> String errorMsgDataTypeNotAllowed l t p v@@ -395,8 +395,8 @@ errorMsgDataTypeNotAllowed2 :: String -> String -> String -> String -> String errorMsgDataTypeNotAllowed2 l t v1 v2 = ( "Datatype " ++ show t ++- " with values = " ++ show v1 ++- " and " ++ show v2 ++ + " with values = " ++ show v1 +++ " and " ++ show v2 ++ " not allowed for DatatypeLibrary " ++ show l )
src/Text/XML/HXT/RelaxNG/DataTypeLibraries.hs view
@@ -13,7 +13,7 @@ ( relaxNamespace ) -import Text.XML.HXT.RelaxNG.DataTypeLibUtils +import Text.XML.HXT.RelaxNG.DataTypeLibUtils import Text.XML.HXT.RelaxNG.DataTypeLibMysql ( mysqlDatatypeLib )@@ -25,12 +25,12 @@ ( fromJust ) -- ------------------------------------------------------------- --- | List of all supported datatype libraries which can be ++-- | List of all supported datatype libraries which can be -- used within the Relax NG validator modul. -datatypeLibraries :: DatatypeLibraries +datatypeLibraries :: DatatypeLibraries datatypeLibraries = [ relaxDatatypeLib , relaxDatatypeLib'@@ -43,21 +43,21 @@ Tests whether a XML instance value matches a value-pattern. The following tests are performed:- + * 1. : does the uri exist in the list of supported datatype libraries - 2. : does the library support the datatype- + - 3. : does the XML instance value match the value-pattern- -The hard work is done by the specialized 'DatatypeEqual' function ++The hard work is done by the specialized 'DatatypeEqual' function (see also: 'DatatypeCheck') of the datatype library. -} -datatypeEqual :: Uri -> DatatypeEqual -datatypeEqual uri d s1 c1 s2 c2 - = if elem uri (map fst datatypeLibraries) - then dtEqFct d s1 c1 s2 c2 +datatypeEqual :: Uri -> DatatypeEqual+datatypeEqual uri d s1 c1 s2 c2+ = if elem uri (map fst datatypeLibraries)+ then dtEqFct d s1 c1 s2 c2 else Just ( "Unknown DatatypeLibrary " ++ show uri ) where DTC _ dtEqFct _ = fromJust $ lookup uri datatypeLibraries@@ -66,38 +66,38 @@ Tests whether a XML instance value matches a data-pattern. The following tests are performed:- + * 1. : does the uri exist in the list of supported datatype libraries - 2. : does the library support the datatype- + - 3. : does the XML instance value match the data-pattern- + - 4. : does the XML instance value match all params- -The hard work is done by the specialized 'DatatypeAllows' function ++The hard work is done by the specialized 'DatatypeAllows' function (see also: 'DatatypeCheck') of the datatype library.- + -} datatypeAllows :: Uri -> DatatypeAllows-datatypeAllows uri d params s1 c1 +datatypeAllows uri d params s1 c1 = if elem uri (map fst datatypeLibraries)- then dtAllowFct d params s1 c1 + then dtAllowFct d params s1 c1 else Just ( "Unknown DatatypeLibrary " ++ show uri ) where DTC dtAllowFct _ _ = fromJust $ lookup uri datatypeLibraries --- -------------------------------------------------------------------------------------- +-- -------------------------------------------------------------------------------------- -- Relax NG build in datatype library -relaxDatatypeLib :: DatatypeLibrary-relaxDatatypeLib = (relaxNamespace, DTC datatypeAllowsRelax datatypeEqualRelax relaxDatatypes)+relaxDatatypeLib :: DatatypeLibrary+relaxDatatypeLib = (relaxNamespace, DTC datatypeAllowsRelax datatypeEqualRelax relaxDatatypes) -- | if there is no datatype uri, the built in datatype library is used-relaxDatatypeLib' :: DatatypeLibrary-relaxDatatypeLib' = ("", DTC datatypeAllowsRelax datatypeEqualRelax relaxDatatypes)+relaxDatatypeLib' :: DatatypeLibrary+relaxDatatypeLib' = ("", DTC datatypeAllowsRelax datatypeEqualRelax relaxDatatypes) -- | The build in Relax NG datatype lib supportes only the token and string datatype, -- without any params.@@ -107,13 +107,13 @@ = map ( (\ x -> (x, [])) . fst ) relaxDatatypeTable datatypeAllowsRelax :: DatatypeAllows-datatypeAllowsRelax d p v _ +datatypeAllowsRelax d p v _ = maybe notAllowed' allowed . lookup d $ relaxDatatypeTable where notAllowed'- = Just $ errorMsgDataTypeNotAllowed relaxNamespace d p v+ = Just $ errorMsgDataTypeNotAllowed relaxNamespace d p v allowed _- = Nothing+ = Nothing -- | If the token datatype is used, the values have to be normalized -- (trailing and leading whitespaces are removed).@@ -124,11 +124,11 @@ = maybe notAllowed' checkValues . lookup d $ relaxDatatypeTable where notAllowed'- = Just $ errorMsgDataTypeNotAllowed2 relaxNamespace d s1 s2+ = Just $ errorMsgDataTypeNotAllowed2 relaxNamespace d s1 s2 checkValues predicate- = if predicate s1 s2- then Nothing- else Just $ errorMsgEqual d s1 s2+ = if predicate s1 s2+ then Nothing+ else Just $ errorMsgEqual d s1 s2 relaxDatatypeTable :: [(String, String -> String -> Bool)] relaxDatatypeTable@@ -137,4 +137,4 @@ ] --- -------------------------------------------------------------------------------------- +-- --------------------------------------------------------------------------------------
src/Text/XML/HXT/RelaxNG/DataTypes.hs view
@@ -1,11 +1,11 @@ module Text.XML.HXT.RelaxNG.DataTypes-where +where import Text.XML.HXT.DOM.TypeDefs -- ------------------------------------------------------------ -relaxSchemaFile :: String+relaxSchemaFile :: String relaxSchemaFile = "Text/XML/HXT/RelaxNG/SpecificationSchema.rng" @@ -26,7 +26,7 @@ type Env = [(String, XmlTree)] --- | Start of a context attribute value +-- | Start of a context attribute value -- (see also: 'Text.XML.HXT.RelaxNG.Simplification.simplificationStep1') -- -- The value is always followed by the original attribute name and value@@ -35,7 +35,7 @@ contextAttributes = "RelaxContext:" --- | Start of base uri attribute value +-- | Start of base uri attribute value -- (see also: 'simplificationStep1' in "Text.XML.HXT.RelaxNG.Simplification") contextBaseAttr :: String@@ -53,7 +53,7 @@ -- ------------------------------------------------------------ -- datatype library handling --- | Type of all datatype libraries functions that tests whether +-- | Type of all datatype libraries functions that tests whether -- a XML instance value matches a value-pattern. -- -- Returns Just \"errorMessage\" in case of an error else Nothing.@@ -61,7 +61,7 @@ type DatatypeEqual = DatatypeName -> String -> Context -> String -> Context -> Maybe String --- | Type of all datatype libraries functions that tests whether +-- | Type of all datatype libraries functions that tests whether -- a XML instance value matches a data-pattern. -- -- Returns Just \"errorMessage\" in case of an error else Nothing.@@ -94,10 +94,10 @@ -- | The Constructor exports the list of supported datatypes for a library.--- It also exports the specialized datatype library functions to validate +-- It also exports the specialized datatype library functions to validate -- a XML instance value with respect to a datatype. -data DatatypeCheck +data DatatypeCheck = DTC { dtAllowsFct :: DatatypeAllows -- ^ function to test whether a value matches a data-pattern , dtEqualFct :: DatatypeEqual -- ^ function to test whether a value matches a value-pattern , dtAllowedTypes :: AllowedDatatypes -- ^ list of all supported params for a datatype@@ -118,7 +118,7 @@ type Prefix = String --- | A Context represents the context of an XML element. +-- | A Context represents the context of an XML element. -- It consists of a base URI and a mapping from prefixes to namespace URIs. type Context = (Uri, [(Prefix, Uri)])@@ -127,10 +127,10 @@ type Datatype = (Uri, LocalName) -showDatatype :: Datatype -> String+showDatatype :: Datatype -> String showDatatype (u, ln)- | null u = ln- | otherwise = "{" ++ u ++ "}" ++ ln+ | null u = ln+ | otherwise = "{" ++ u ++ "}" ++ ln -- | Represents a name class @@ -145,19 +145,19 @@ instance Show NameClass where- show AnyName = "AnyName"- show (AnyNameExcept nameClass) - = "AnyNameExcept: " ++ show nameClass+ show AnyName = "AnyName"+ show (AnyNameExcept nameClass)+ = "AnyNameExcept: " ++ show nameClass show (Name uri localName)- | null uri = localName- | otherwise = "{" ++ uri ++ "}" ++ localName- show (NsName uri) = "{" ++ uri ++ "}AnyName"- show (NsNameExcept uri nameClass) - = "NsNameExcept: {" ++ uri ++ "}" ++ show nameClass+ | null uri = localName+ | otherwise = "{" ++ uri ++ "}" ++ localName+ show (NsName uri) = "{" ++ uri ++ "}AnyName"+ show (NsNameExcept uri nameClass)+ = "NsNameExcept: {" ++ uri ++ "}" ++ show nameClass show (NameClassChoice nameClass1 nameClass2)- = "NameClassChoice: " ++ show nameClass1 ++ "|" ++ show nameClass2+ = "NameClassChoice: " ++ show nameClass1 ++ "|" ++ show nameClass2 show (NCError string)- = "NCError: " ++ string+ = "NCError: " ++ string -- | Represents a pattern after simplification@@ -178,32 +178,32 @@ | After Pattern Pattern instance Show Pattern where- show Empty = "empty"- show (NotAllowed e) = show e- show Text = "text"- show (Choice p1 p2) = "( " ++ show p1 ++ " | " ++ show p2 ++ " )"- show (Interleave p1 p2) = "( " ++ show p1 ++ " & " ++ show p2 ++ " )"- show (Group p1 p2) = "( " ++ show p1 ++ " , " ++ show p2 ++ " )"- show (OneOrMore p) = show p ++ "+"- show (List p) = "list { " ++ show p ++ " }"- show (Data dt pl) = showDatatype dt ++ showPL pl- where- showPL [] = ""- showPL l = " {" ++ concatMap showP l ++ " }"- showP (ln, v) = " " ++ ln ++ " = " ++ show v- show (DataExcept dt pl p) = show (Data dt pl) ++ " - (" ++ show p ++ " )"- show (Value dt v _cx) = showDatatype dt ++ " " ++ show v- show (Attribute nc p) = "attribute " ++ show nc ++ " { " ++ show p ++ " }"- show (Element nc p) = "element " ++ show nc ++ " { " ++ show p ++ " }"- show (After p1 p2) = "( " ++ show p1 ++ " ; " ++ show p2 ++ " )"+ show Empty = "empty"+ show (NotAllowed e) = show e+ show Text = "text"+ show (Choice p1 p2) = "( " ++ show p1 ++ " | " ++ show p2 ++ " )"+ show (Interleave p1 p2) = "( " ++ show p1 ++ " & " ++ show p2 ++ " )"+ show (Group p1 p2) = "( " ++ show p1 ++ " , " ++ show p2 ++ " )"+ show (OneOrMore p) = show p ++ "+"+ show (List p) = "list { " ++ show p ++ " }"+ show (Data dt pl) = showDatatype dt ++ showPL pl+ where+ showPL [] = ""+ showPL l = " {" ++ concatMap showP l ++ " }"+ showP (ln, v) = " " ++ ln ++ " = " ++ show v+ show (DataExcept dt pl p) = show (Data dt pl) ++ " - (" ++ show p ++ " )"+ show (Value dt v _cx) = showDatatype dt ++ " " ++ show v+ show (Attribute nc p) = "attribute " ++ show nc ++ " { " ++ show p ++ " }"+ show (Element nc p) = "element " ++ show nc ++ " { " ++ show p ++ " }"+ show (After p1 p2) = "( " ++ show p1 ++ " ; " ++ show p2 ++ " )" -data ErrMessage = ErrMsg ErrLevel [String]- -- deriving Show+data ErrMessage = ErrMsg ErrLevel [String]+ -- deriving Show instance Show ErrMessage where show (ErrMsg _lev es) = foldr1 (\ x y -> x ++ "\n" ++ y) es -type ErrLevel = Int+type ErrLevel = Int -- ------------------------------------------------------------ @@ -211,17 +211,17 @@ -- | smart constructor for NotAllowed -notAllowed :: String -> Pattern-notAllowed = notAllowedN 0+notAllowed :: String -> Pattern+notAllowed = notAllowedN 0 -notAllowed1 :: String -> Pattern-notAllowed1 = notAllowedN 1+notAllowed1 :: String -> Pattern+notAllowed1 = notAllowedN 1 -notAllowed2 :: String -> Pattern-notAllowed2 = notAllowedN 2+notAllowed2 :: String -> Pattern+notAllowed2 = notAllowedN 2 -notAllowedN :: ErrLevel -> String -> Pattern-notAllowedN l s = NotAllowed (ErrMsg l [s])+notAllowedN :: ErrLevel -> String -> Pattern+notAllowedN l s = NotAllowed (ErrMsg l [s]) -- | merge error messages --@@ -229,12 +229,12 @@ -- if level is 2 (max level) both error messages are taken -- else the 1. error mesage is taken -mergeNotAllowed :: Pattern -> Pattern -> Pattern+mergeNotAllowed :: Pattern -> Pattern -> Pattern mergeNotAllowed p1@(NotAllowed (ErrMsg l1 s1)) p2@(NotAllowed (ErrMsg l2 s2))- | l1 < l2 = p2- | l1 > l2 = p1- | l1 == 2 = NotAllowed $ ErrMsg 2 (s1 ++ s2)- | otherwise = p1+ | l1 < l2 = p2+ | l1 > l2 = p1+ | l1 == 2 = NotAllowed $ ErrMsg 2 (s1 ++ s2)+ | otherwise = p1 -- TODO : weird error when collecting error messages errors are duplicated @@ -244,20 +244,20 @@ -- | smart constructor for Choice choice :: Pattern -> Pattern -> Pattern-choice p1@(NotAllowed _) p2@(NotAllowed _) = mergeNotAllowed p1 p2-choice p1 (NotAllowed _) = p1-choice (NotAllowed _) p2 = p2-choice p1 p2 = Choice p1 p2+choice p1@(NotAllowed _) p2@(NotAllowed _) = mergeNotAllowed p1 p2+choice p1 (NotAllowed _) = p1+choice (NotAllowed _) p2 = p2+choice p1 p2 = Choice p1 p2 -- | smart constructor for Group group :: Pattern -> Pattern -> Pattern-group p1@(NotAllowed _) p2@(NotAllowed _) = mergeNotAllowed p1 p2-group _ n@(NotAllowed _) = n-group n@(NotAllowed _) _ = n-group p Empty = p-group Empty p = p-group p1 p2 = Group p1 p2+group p1@(NotAllowed _) p2@(NotAllowed _) = mergeNotAllowed p1 p2+group _ n@(NotAllowed _) = n+group n@(NotAllowed _) _ = n+group p Empty = p+group Empty p = p+group p1 p2 = Group p1 p2 -- | smart constructor for OneOrMore @@ -268,20 +268,20 @@ -- | smart constructor for Interleave interleave :: Pattern -> Pattern -> Pattern-interleave p1@(NotAllowed _) p2@(NotAllowed _) = mergeNotAllowed p1 p2-interleave _ p2@(NotAllowed _) = p2-interleave p1@(NotAllowed _) _ = p1-interleave p1 Empty = p1-interleave Empty p2 = p2-interleave p1 p2 = Interleave p1 p2+interleave p1@(NotAllowed _) p2@(NotAllowed _) = mergeNotAllowed p1 p2+interleave _ p2@(NotAllowed _) = p2+interleave p1@(NotAllowed _) _ = p1+interleave p1 Empty = p1+interleave Empty p2 = p2+interleave p1 p2 = Interleave p1 p2 -- | smart constructor for After after :: Pattern -> Pattern -> Pattern-after p1@(NotAllowed _) p2@(NotAllowed _) = mergeNotAllowed p1 p2-after _ p2@(NotAllowed _) = p2-after p1@(NotAllowed _) _ = p1-after p1 p2 = After p1 p2+after p1@(NotAllowed _) p2@(NotAllowed _) = mergeNotAllowed p1 p2+after _ p2@(NotAllowed _) = p2+after p1@(NotAllowed _) _ = p1+after p1 p2 = After p1 p2 -- | Possible content types of a Relax NG pattern.
src/Text/XML/HXT/RelaxNG/PatternFunctions.hs view
@@ -11,63 +11,63 @@ -- ------------------------------------------------------------ isRelaxEmpty :: Pattern -> Bool-isRelaxEmpty Empty = True +isRelaxEmpty Empty = True isRelaxEmpty _ = False isRelaxNotAllowed :: Pattern -> Bool-isRelaxNotAllowed (NotAllowed _) = True +isRelaxNotAllowed (NotAllowed _) = True isRelaxNotAllowed _ = False isRelaxText :: Pattern -> Bool-isRelaxText Text = True +isRelaxText Text = True isRelaxText _ = False isRelaxChoice :: Pattern -> Bool-isRelaxChoice (Choice _ _) = True +isRelaxChoice (Choice _ _) = True isRelaxChoice _ = False isRelaxInterleave :: Pattern -> Bool-isRelaxInterleave (Interleave _ _) = True +isRelaxInterleave (Interleave _ _) = True isRelaxInterleave _ = False isRelaxGroup :: Pattern -> Bool-isRelaxGroup (Group _ _) = True +isRelaxGroup (Group _ _) = True isRelaxGroup _ = False isRelaxOneOrMore :: Pattern -> Bool-isRelaxOneOrMore (OneOrMore _) = True +isRelaxOneOrMore (OneOrMore _) = True isRelaxOneOrMore _ = False isRelaxList :: Pattern -> Bool-isRelaxList (List _) = True +isRelaxList (List _) = True isRelaxList _ = False isRelaxData :: Pattern -> Bool-isRelaxData (Data _ _) = True +isRelaxData (Data _ _) = True isRelaxData _ = False isRelaxDataExcept :: Pattern -> Bool-isRelaxDataExcept (DataExcept _ _ _) = True +isRelaxDataExcept (DataExcept _ _ _) = True isRelaxDataExcept _ = False isRelaxValue :: Pattern -> Bool-isRelaxValue (Value _ _ _) = True +isRelaxValue (Value _ _ _) = True isRelaxValue _ = False isRelaxAttribute :: Pattern -> Bool-isRelaxAttribute (Attribute _ _) = True +isRelaxAttribute (Attribute _ _) = True isRelaxAttribute _ = False isRelaxElement :: Pattern -> Bool-isRelaxElement (Element _ _) = True +isRelaxElement (Element _ _) = True isRelaxElement _ = False- + isRelaxAfter :: Pattern -> Bool-isRelaxAfter (After _ _) = True +isRelaxAfter (After _ _) = True isRelaxAfter _ = False --- | Returns a list of children pattern for each pattern, +-- | Returns a list of children pattern for each pattern, -- e.g. (Choice p1 p2) = [p1, p2] getChildrenPattern :: Pattern -> [Pattern] getChildrenPattern (Choice p1 p2) = [p1, p2]
src/Text/XML/HXT/RelaxNG/PatternToString.hs view
@@ -49,10 +49,10 @@ nameClassToString AnyName = "AnyName" -nameClassToString (AnyNameExcept nc) +nameClassToString (AnyNameExcept nc) = "AnyNameExcept " ++ nameClassToString nc -nameClassToString (Name uri local) +nameClassToString (Name uri local) = "{" ++ uri ++ "}" ++ local nameClassToString (NsName uri)@@ -87,7 +87,7 @@ > | +---text > | > +---text- + The function can be used to display circular ref-pattern structures. Example:@@ -112,7 +112,7 @@ xmlTreeToPatternStringTree :: LA XmlTree String xmlTreeToPatternStringTree- = createPatternFromXmlTree + = createPatternFromXmlTree >>> patternToStringTree @@ -123,7 +123,7 @@ [ isA isRelaxEmpty :-> (constA $ NTree "empty" []) , isA isRelaxNotAllowed :-> notAllowed2PatternTree , isA isRelaxText :-> (constA $ NTree "text" [])- , isA isRelaxChoice :-> choice2PatternTree + , isA isRelaxChoice :-> choice2PatternTree , isA isRelaxInterleave :-> children2PatternTree "interleave" , isA isRelaxGroup :-> children2PatternTree "group" , isA isRelaxOneOrMore :-> children2PatternTree "oneOrMore"@@ -131,7 +131,7 @@ , isA isRelaxData :-> data2PatternTree , isA isRelaxDataExcept :-> dataExcept2PatternTree , isA isRelaxValue :-> value2PatternTree- , isA isRelaxAttribute :-> createPatternTreeFromElement "attribute" + , isA isRelaxAttribute :-> createPatternTreeFromElement "attribute" , isA isRelaxElement :-> element2PatternTree , isA isRelaxAfter :-> children2PatternTree "after" ]@@ -142,22 +142,22 @@ data2PatternTree :: SLA [NameClass] Pattern PatternTree-data2PatternTree +data2PatternTree = arr $ \ (Data d p) -> NTree "data" [ datatype2PatternTree d- , mapping2PatternTree "parameter" p- ]- + , mapping2PatternTree "parameter" p+ ]+ dataExcept2PatternTree :: SLA [NameClass] Pattern PatternTree-dataExcept2PatternTree +dataExcept2PatternTree = this &&& (listA $ arrL getChildrenPattern >>> pattern2PatternTree) >>> arr2 ( \ (DataExcept d param _) pattern -> NTree "dataExcept" ([ datatype2PatternTree d- , mapping2PatternTree "parameter" param- ] ++ pattern)+ , mapping2PatternTree "parameter" param+ ] ++ pattern) ) -value2PatternTree :: SLA [NameClass] Pattern PatternTree +value2PatternTree :: SLA [NameClass] Pattern PatternTree value2PatternTree = arr $ \ (Value d v c) -> NTree ("value = " ++ v) [ datatype2PatternTree d , context2PatternTree c@@ -167,34 +167,34 @@ createPatternTreeFromElement :: String -> SLA [NameClass] Pattern PatternTree createPatternTreeFromElement name = ( arr getNameClassFromPattern- &&&- listA (arrL getChildrenPattern >>> pattern2PatternTree)+ &&&+ listA (arrL getChildrenPattern >>> pattern2PatternTree) ) >>> arr2 (\nc rl -> NTree (name ++ " " ++ show nc) rl) children2PatternTree :: String -> SLA [NameClass] Pattern PatternTree-children2PatternTree name - = listA (arrL getChildrenPattern >>> pattern2PatternTree) +children2PatternTree name+ = listA (arrL getChildrenPattern >>> pattern2PatternTree) >>^ (NTree name) choice2PatternTree :: SLA [NameClass] Pattern PatternTree-choice2PatternTree - = ifA ( -- wenn das zweite kind ein noch nicht ausgegebenes element ist, +choice2PatternTree+ = ifA ( -- wenn das zweite kind ein noch nicht ausgegebenes element ist, -- muss dieses anders behandelt werden -- nur fuer bessere formatierung des outputs arr (last . getChildrenPattern) >>> isA (isRelaxElement) >>>- (arr getNameClassFromPattern &&& getState) >>> + (arr getNameClassFromPattern &&& getState) >>> isA(\ (nc, liste) -> not $ elem nc liste) ) ( -- element in status aufnehmen, wird dann nicht mehr vom erste kind ausgegeben arr getChildrenPattern- >>>+ >>> changeState (\s p -> (getNameClassFromPattern (last p)) : s)- >>>- ( ( head ^>> pattern2PatternTree ) -- erstes kind normal verarbeiten- &&& -- zweites kind, das element, verarbeiten+ >>>+ ( ( head ^>> pattern2PatternTree ) -- erstes kind normal verarbeiten+ &&& -- zweites kind, das element, verarbeiten ( last ^>> createPatternTreeFromElement "element" ) ) >>>@@ -202,15 +202,15 @@ ) ( children2PatternTree "choice" ) - + element2PatternTree :: SLA [NameClass] Pattern PatternTree-element2PatternTree +element2PatternTree = ifA ( (arr getNameClassFromPattern &&& getState)- >>> + >>> isA (\ (nc, liste) -> elem nc liste) ) ( arr getNameClassFromPattern- >>> + >>> arr (\nc -> NTree ("reference to element " ++ show nc) []) ) ( changeState (\ s p -> (getNameClassFromPattern p) : s)@@ -241,7 +241,7 @@ -- (see also: 'createPatternFromXmlTree' and 'patternToFormatedString') xmlTreeToPatternFormatedString :: LA XmlTree String xmlTreeToPatternFormatedString- = createPatternFromXmlTree + = createPatternFromXmlTree >>> fromSLA [] patternToFormatedString @@ -251,10 +251,10 @@ Example: -> Element {}foo (Choice (Choice ( Value = abc, -> datatypelibrary = http://relaxng.org/ns/structure/1.0, type = token, -> context (base-uri =file://test.rng, -> parameter: xml = http://www.w3.org/XML/1998/namespaces, foo = www.bar.baz), +> Element {}foo (Choice (Choice ( Value = abc,+> datatypelibrary = http://relaxng.org/ns/structure/1.0, type = token,+> context (base-uri =file://test.rng,+> parameter: xml = http://www.w3.org/XML/1998/namespaces, foo = www.bar.baz), The function can be used to display circular ref-pattern structures. -}@@ -280,21 +280,21 @@ children2FormatedString :: String -> SLA [NameClass] Pattern String children2FormatedString name- = listA (arrL getChildrenPattern >>> patternToFormatedString) + = listA (arrL getChildrenPattern >>> patternToFormatedString) >>^ (\ l -> name ++ " (" ++ formatStringListPatt l ++ ") " ) data2FormatedString :: SLA [NameClass] Pattern String data2FormatedString = arr ( \ (Data datatype paramList) ->- "Data " ++ datatype2String datatype ++ "\n " ++ + "Data " ++ datatype2String datatype ++ "\n " ++ mapping2String "parameter" paramList ++ "\n"- )+ ) dataExcept2FormatedString :: SLA [NameClass] Pattern String-dataExcept2FormatedString +dataExcept2FormatedString = arr ( \ (DataExcept datatype paramList _) ->- "DataExcept " ++ show datatype ++ "\n " ++ + "DataExcept " ++ show datatype ++ "\n " ++ mapping2String "parameter" paramList ++ "\n " ) &&&@@ -304,9 +304,9 @@ value2FormatedString :: SLA [NameClass] Pattern String-value2FormatedString +value2FormatedString = arr $ \(Value datatype val context) ->- "Value = " ++ val ++ ", " ++ datatype2String datatype ++ + "Value = " ++ val ++ ", " ++ datatype2String datatype ++ "\n " ++ context2String context ++ "\n" @@ -315,25 +315,25 @@ = ifA ( (arr getNameClassFromPattern &&& getState) >>> isA (\ (nc, liste) -> elem nc liste)- )+ ) ( arr getNameClassFromPattern- >>^ - ( \nc -> "reference to element " ++ nameClassToString nc ++ " " )+ >>^+ ( \nc -> "reference to element " ++ nameClassToString nc ++ " " ) ) ( changeState (\ s p -> (getNameClassFromPattern p) : s)- >>>- createFormatedStringFromElement "element"+ >>>+ createFormatedStringFromElement "element" ) createFormatedStringFromElement :: String -> SLA [NameClass] Pattern String createFormatedStringFromElement name = ( arr getNameClassFromPattern- &&&- ( listA (arrL getChildrenPattern >>> patternToFormatedString)- >>^- formatStringListId- )+ &&&+ ( listA (arrL getChildrenPattern >>> patternToFormatedString)+ >>^+ formatStringListId+ ) ) >>> arr2 (\ nc rl -> name ++ " " ++ nameClassToString nc ++ " (" ++ rl ++ ")")@@ -343,7 +343,7 @@ mapping2String :: String -> [(Prefix, Uri)] -> String mapping2String name mapping- = name ++ ": " ++ + = name ++ ": " ++ formatStringList id ", " (map (\(a, b) -> a ++ " = " ++ b) mapping) datatype2String :: Datatype -> String@@ -351,10 +351,10 @@ = "datatypelibrary = " ++ getLib ++ ", type = " ++ localName where getLib = if lib == "" then relaxNamespace else lib- + context2String :: Context -> String context2String (base, mapping) = "context (base-uri = " ++ base ++ ", " ++ mapping2String "namespace environment" mapping ++ ")"- + -- ------------------------------------------------------------
src/Text/XML/HXT/RelaxNG/Schema.hs view
@@ -20,32 +20,32 @@ relaxSchemaTree :: XmlTree relaxSchemaTree = let- ns1 = "http://relaxng.org/ns/structure/1.0"- qn1 = mkSNsName "RelaxContext:xml"- qn2 = mkSNsName "RelaxContextBaseURI"- qn3 = mkSNsName "RelaxContextDefault"- qn4 = mkNsName "anyName" ns1- qn5 = mkNsName "attribute" ns1- qn6 = mkNsName "choice" ns1- qn7 = mkNsName "data" ns1- qn8 = mkSNsName "datatypeLibrary"- qn9 = mkNsName "define" ns1- qn10 = mkNsName "element" ns1- qn11 = mkNsName "empty" ns1- qn12 = mkNsName "except" ns1- qn13 = mkNsName "grammar" ns1- qn14 = mkNsName "group" ns1- qn15 = mkNsName "interleave" ns1- qn16 = mkSNsName "name"- qn17 = mkNsName "name" ns1- qn18 = mkSNsName "ns"- qn19 = mkNsName "nsName" ns1- qn20 = mkNsName "oneOrMore" ns1- qn21 = mkNsName "ref" ns1- qn22 = mkNsName "start" ns1- qn23 = mkNsName "text" ns1- qn24 = mkSNsName "type"- qn25 = mkNsName "value" ns1+ ns1 = "http://relaxng.org/ns/structure/1.0"+ qn1 = mkSNsName "RelaxContext:xml"+ qn2 = mkSNsName "RelaxContextBaseURI"+ qn3 = mkSNsName "RelaxContextDefault"+ qn4 = mkNsName "anyName" ns1+ qn5 = mkNsName "attribute" ns1+ qn6 = mkNsName "choice" ns1+ qn7 = mkNsName "data" ns1+ qn8 = mkSNsName "datatypeLibrary"+ qn9 = mkNsName "define" ns1+ qn10 = mkNsName "element" ns1+ qn11 = mkNsName "empty" ns1+ qn12 = mkNsName "except" ns1+ qn13 = mkNsName "grammar" ns1+ qn14 = mkNsName "group" ns1+ qn15 = mkNsName "interleave" ns1+ qn16 = mkSNsName "name"+ qn17 = mkNsName "name" ns1+ qn18 = mkSNsName "ns"+ qn19 = mkNsName "nsName" ns1+ qn20 = mkNsName "oneOrMore" ns1+ qn21 = mkNsName "ref" ns1+ qn22 = mkNsName "start" ns1+ qn23 = mkNsName "text" ns1+ qn24 = mkSNsName "type"+ qn25 = mkNsName "value" ns1 in mkRoot [] [ mkElement qn13 []
src/Text/XML/HXT/RelaxNG/SchemaGrammar.hs view
@@ -20,32 +20,32 @@ relaxSchemaTree :: XmlTree relaxSchemaTree = let- ns1 = "http://relaxng.org/ns/structure/1.0"- qn1 = mkSNsName "RelaxContext:xml"- qn2 = mkSNsName "RelaxContextBaseURI"- qn3 = mkSNsName "RelaxContextDefault"- qn4 = mkNsName "anyName" ns1- qn5 = mkNsName "attribute" ns1- qn6 = mkNsName "choice" ns1- qn7 = mkNsName "data" ns1- qn8 = mkSNsName "datatypeLibrary"- qn9 = mkNsName "define" ns1- qn10 = mkNsName "element" ns1- qn11 = mkNsName "empty" ns1- qn12 = mkNsName "except" ns1- qn13 = mkNsName "grammar" ns1- qn14 = mkNsName "group" ns1- qn15 = mkNsName "interleave" ns1- qn16 = mkSNsName "name"- qn17 = mkNsName "name" ns1- qn18 = mkSNsName "ns"- qn19 = mkNsName "nsName" ns1- qn20 = mkNsName "oneOrMore" ns1- qn21 = mkNsName "ref" ns1- qn22 = mkNsName "start" ns1- qn23 = mkNsName "text" ns1- qn24 = mkSNsName "type"- qn25 = mkNsName "value" ns1+ ns1 = "http://relaxng.org/ns/structure/1.0"+ qn1 = mkSNsName "RelaxContext:xml"+ qn2 = mkSNsName "RelaxContextBaseURI"+ qn3 = mkSNsName "RelaxContextDefault"+ qn4 = mkNsName "anyName" ns1+ qn5 = mkNsName "attribute" ns1+ qn6 = mkNsName "choice" ns1+ qn7 = mkNsName "data" ns1+ qn8 = mkSNsName "datatypeLibrary"+ qn9 = mkNsName "define" ns1+ qn10 = mkNsName "element" ns1+ qn11 = mkNsName "empty" ns1+ qn12 = mkNsName "except" ns1+ qn13 = mkNsName "grammar" ns1+ qn14 = mkNsName "group" ns1+ qn15 = mkNsName "interleave" ns1+ qn16 = mkSNsName "name"+ qn17 = mkNsName "name" ns1+ qn18 = mkSNsName "ns"+ qn19 = mkNsName "nsName" ns1+ qn20 = mkNsName "oneOrMore" ns1+ qn21 = mkNsName "ref" ns1+ qn22 = mkNsName "start" ns1+ qn23 = mkNsName "text" ns1+ qn24 = mkSNsName "type"+ qn25 = mkNsName "value" ns1 in mkRoot [] [ mkElement qn13 []
src/Text/XML/HXT/RelaxNG/Simplification.hs view
@@ -70,2252 +70,2252 @@ import System.Directory ( doesFileExist ) - --- --------------------------------------------------------------{- -- 4.1. Annotations: Foreign attributes and elements are removed.-- 4.2. Whitespace:- - For each element other than value and param, each child that is a string - containing only whitespace characters is removed. -> fertig- - Leading and trailing whitespace characters are removed from the value of each name,- type and combine attribute and from the content of each name element. -> fertig-- 4.3. datatypeLibrary attribute:- - The value of each datatypeLibary attribute is transformed by escaping disallowed characters- - For any data or value element that does not have a datatypeLibrary attribute, - a datatypeLibrary attribute is added.- - Any datatypeLibrary attribute that is on an element other than data or value is removed.-- 4.4. type attribute of value element--}-simplificationStep1 :: IOSArrow XmlTree XmlTree-simplificationStep1- = ( {- - - 4.5. href attribute- - The value of the href attribute on an externalRef or include element is first - - transformed by escaping disallowed characters- - The URI reference is then resolved into an absolute form- - The value of the href attribute will be used to construct an element.- -}- ( processHref $< getBaseURI )- >>>- -- 4.10 QNames- processWithNsEnv processEnvNames (toNsEnv [("xml",xmlNamespace)])- >>>- -- 4.4 For any data or value element that does not have a datatypeLibrary attribute,- -- a datatypeLibrary attribute is added.- -- Wird vorgezogen, da danach der Rest in einem Baumdurchlauf erledigt werden kann- processdatatypeLib ""- >>>- processTopDownWithAttrl- (- ( -- 4.1 Foreign attributes and elements are removed- none- `when` - ( ( isElem >>> neg isRoot - >>> - getNamespaceUri- >>>- isA (\ uri -> (not $ compareURI uri relaxNamespace))- )- `orElse`- ( isAttr- >>>- getNamespaceUri- >>>- isA (\ uri -> (uri /= "" && (not $ compareURI uri relaxNamespace)))- )- )- )- >>>- ( -- 4.2 For each element other than value and param, each child that - -- is a string containing only whitespace characters is removed.- ( processChildren removeWhiteSpace- `whenNot` - (isRngParam `orElse` isRngValue)- )- `when` isElem - )- >>> - ( -- 4.2 Leading and trailing whitespace characters are removed from the value - -- of each name, type and combine attribute ...- changeAttrValue normalizeWhitespace- `when`- ( isRngAttrName `orElse` isRngAttrType `orElse` isRngAttrCombine)- )- >>>- ( -- 4.2 ... and from the content of each name element.- processChildren (changeText normalizeWhitespace)- `when`- isRngName- )- >>>- ( -- 4.3 The value of each datatypeLibary attribute is transformed- -- by escaping disallowed characters- changeAttrValue escapeURI- `when`- isRngAttrDatatypeLibrary- )- >>>- ( -- The value of the datatypeLibary attribute has to be a valid URI- ( mkRelaxError "" $< ( getRngAttrDatatypeLibrary- >>> - arr (\ a -> ( "datatypeLibrary attribute: " ++ - a ++ " is not a valid URI"- )- )- )- )- `when`- ( isElem- >>>- hasRngAttrDatatypeLibrary- >>> - getRngAttrDatatypeLibrary >>> isA (not . isRelaxAnyURI)- )- )- >>> - ( -- 4.3 Any datatypeLibrary attribute that is on an element - -- other than data or value is removed.- removeAttr "datatypeLibrary"- `when`- ( isElem- >>>- neg (isRngData `orElse` isRngValue) - >>> - hasRngAttrDatatypeLibrary- )- )- >>> - ( -- 4.4 For any value element that does not have a type attribute,- -- a type attribute is added with value token and the value of - -- the datatypeLibrary attribute is changed to the empty string.- ( addAttr "type" "token"- >>>- addAttr "datatypeLibrary" ""- )- `when`- ( isRngValue >>> neg hasRngAttrType )- ) - ) - ) `when` collectErrors- where- processHref :: String -> IOSArrow XmlTree XmlTree- processHref uri- = processChildren- ( choiceA- [ ( isElem >>> hasAttr "xml:base" )- :-> ( ifA ( isExternalRefInclude >>> hasRngAttrHref )- ( -- The value of the href attribute is transformed by- -- escaping disallowed characters- (processAttrl (changeAttrValue escapeURI `when` isRngAttrHref))- >>> -- compute the new base uri from the old uri and the href attribute- (addAttr "href" $< (absURI "href" $< (absURI "xml:base" uri)))- >>> - (processHref $< absURI "xml:base" uri)- ) -- element without a href attribute, just compute the new base uri- (processHref $< absURI "xml:base" uri)- )- , ( isExternalRefInclude >>> hasRngAttrHref )- :-> ( -- The value of the href attribute is transformed by - -- escaping disallowed characters- (processAttrl (changeAttrValue escapeURI `when` isRngAttrHref))- >>>- (addAttr "href" $< absURI "href" uri)- )- , this- :-> processHref uri- ]- )- where- absURI :: String -> String -> IOSArrow XmlTree String- absURI attrName u- = ( getAttrValue attrName- >>> - arr (\ a -> fromMaybe "" (expandURIString a u))- >>> -- the uri should not have a fragment-identifier (4.5)- ( arr ("illegal URI, fragment identifier not allowed: " ++)- `whenNot`- (getFragmentFromURI >>> isA null)- )- )-- processEnvNames :: NsEnv -> IOSArrow XmlTree XmlTree- processEnvNames env- = ( ( (replaceQNames env $< getAttrValue "name")- `when`- ( (isRngElement `orElse` isRngAttribute)- >>>- getRngAttrName- >>>- isA (elem ':')- )- )- >>>- ( (addAttrl (getBaseURI >>> createAttrL)) - `when`- isRngValue- )- )- where- createAttrL :: IOSArrow String XmlTree- createAttrL- = setBaseUri &&& constA (map createAttr env) >>> arr2L (:)- where-- createAttr :: (XName, XName) -> XmlTree- createAttr (pre, uri)- = XN.mkAttr (mkName nm) [XN.mkText (show uri)]- where- nm | isNullXName pre = "RelaxContextDefault"- | otherwise = contextAttributes ++ show pre-- setBaseUri :: IOSArrow String XmlTree- setBaseUri = mkAttr (mkName contextBaseAttr) (txt $< this)-- replaceQNames :: NsEnv -> String -> IOSArrow XmlTree XmlTree - replaceQNames e name- | isNothing uri- = mkRelaxError "" ( "No Namespace-Mapping for the prefix " ++ show pre ++ - " in the Context of Element: " ++ show name- )- | otherwise- = addAttr "name" ( "{" ++ (show . fromJust $ uri) ++ "}" ++ local )- where- (pre, local') = span (/= ':') name- local = tail local'- uri :: Maybe XName- uri = lookup (newXName pre) e-- -- The value of the added datatypeLibrary attribute is the value of the - -- datatypeLibrary attribute of the nearest ancestor element that - -- has a datatypeLibrary attribute, or the empty string - -- if there is no such ancestor.- processdatatypeLib :: (ArrowXml a) => String -> a XmlTree XmlTree- processdatatypeLib lib - = processChildren $- choiceA- [ ( isElem >>> hasRngAttrDatatypeLibrary- -- set the new datatypeLibrary value- )- :->- ( processdatatypeLib $< getRngAttrDatatypeLibrary )- , ( (isRngData `orElse` isRngValue)- >>> - neg hasRngAttrDatatypeLibrary- -- add a datatypeLibrary attribute- )- :->- ( addAttr "datatypeLibrary" lib >>> processdatatypeLib lib )- , this- :->- processdatatypeLib lib- ]---- ---------------------------------------------------------------{- -- 4.5. href attribute- - see simplificationStep1-- 4.6. externalRef element- - An element is constructed using the URI reference - that is the value of href attribute- - This element must match the syntax for pattern.- - The element is transformed by recursively applying the rules from - this subsection and from previous subsections of this section.- - This must not result in a loop.- - Any ns attribute on the externalRef element is transferred - to the referenced element if the referenced element does- not already have an ns attribute.- - The externalRef element is then replaced by the referenced element.-- 4.7. include element- - An element is constructed using the URI reference that is the- value of href attribute- - This element must be a grammar element, matching the syntax for grammar.- - This grammar element is transformed by recursively applying the rules - from this subsection and from previous subsections of this section.- - This must not result in a loop.- - - If the include element has a start component, then the grammar element- must have a start component.- - If the include element has a start component, then all start components- are removed from the grammar element.- - If the include element has a define component, then the grammar element- must have a define component with the same name.- - For every define component of the include element, all define components- with the same name are removed from the grammar element.- - - The include element is transformed into a div element.- - The attributes of the div element are the attributes of the - include element other than the href attribute.- - The children of the div element are the grammar element- - The grammar element is then renamed to div.--}--simplificationStep2 :: Attributes -> Bool -> Bool -> [Uri] -> [Uri] -> IOSArrow XmlTree XmlTree-simplificationStep2 readOptions validateExternalRef validateInclude extHRefs includeHRefs =- ( processTopDown (- ( (importExternalRef $<< (getRngAttrNs &&& getRngAttrHref))- `when`- isRngExternalRef- )- >>>- ( (importInclude $< getAttrValue "href")- `when`- isRngInclude- )- )- ) `when` collectErrors- where- importExternalRef :: String -> String -> IOSArrow XmlTree XmlTree- importExternalRef ns href- = ifA ( neg $ constA href- >>> getPathFromURI- >>> ( isA (not . ("illegal URI" `isPrefixOf`))- `guards`- isIOA doesFileExist- )- )- ( mkRelaxError ""- ( show href ++- ": can't read URI, referenced in externalRef-Pattern"- )- )- ( ifP (const $ elem href extHRefs)- -- if the referenced name already exists in the list of processed ref attributes- -- we have found a loop- ( mkRelaxError ""- ( "loop in externalRef-Pattern, " ++ - formatStringListArr (reverse $ href:extHRefs)- )- )- ( ifA ( if validateExternalRef -- if validation parameters are set- then validateDocWithRelax S.relaxSchemaArrow [] href -- the referenced schema is validated with respect to- else none -- the Relax NG specification- )- ( mkRelaxError ""- ( "The content of the schema " ++ show href ++ - ", referenced in externalRef does not " ++- "match the syntax for pattern"- )- )- ( readForRelax readOptions href- >>>- simplificationStep1 -- perform the transformations from previous steps- >>>- simplificationStep2 readOptions validateExternalRef validateInclude (href:extHRefs) includeHRefs- >>>- getChildren -- remove the root node- >>>- ( -- Any ns attribute on the externalRef element- -- is transferred to the referenced element- addAttr "ns" ns- `when`- (getRngAttrNs >>> isA (\a -> a == "" && ns /= ""))- )- )- )- )- - importInclude :: String -> IOSArrow XmlTree XmlTree- importInclude href- = ifA ( -- test whether the referenced schema exists- neg $ constA href >>> getPathFromURI >>> isIOA doesFileExist- )- ( mkRelaxError ""- ( "Can't read " ++ show href ++- ", referenced in include-Pattern"- )- )- ( ifP (const $ elem href includeHRefs)- -- if the referenced name still exists in the list of processed- -- ref attributes we have found a loop- ( mkRelaxError ""- ( "loop in include-Pattern, " ++ - formatStringListArr (reverse $ href:includeHRefs)- )- )- ( ifA ( if validateInclude -- if the parameter is set- then validateDocWithRelax SG.relaxSchemaArrow [] href -- the referenced schema is validated with respect to- else none -- the Relax NG grammar element- )- ( mkRelaxError ""- ( "The content of the schema " ++ show href ++ - ", referenced in include does not match " ++- "the syntax for grammar"- )- )- ( processInclude href $< ( readForRelax readOptions href- >>>- simplificationStep1 -- perform the transformations from previous steps- >>> - simplificationStep2 readOptions validateExternalRef validateInclude extHRefs (href:includeHRefs)- >>>- getChildren -- remove the root node- )- )- )- )- - processInclude :: String -> XmlTree -> IOSArrow XmlTree XmlTree- processInclude href newDoc- = -- The include element is transformed into a div element.- setRngNameDiv- >>>- -- The attributes of the div element are the attributes of - -- the include element other than the href attribute.- removeAttr "href"- >>> - checkInclude href newDoc- - - insertNewDoc :: XmlTree -> Bool -> [String] -> IOSArrow XmlTree XmlTree- insertNewDoc newDoc hasStart defNames- = insertChildrenAt 0 $- constA newDoc- >>>- -- If the include element has a start component, then all start components- -- are removed from the grammar element. - (removeStartComponent `whenP` (const hasStart))- >>>- -- For every define component of the include element, all define components- -- with the same name are removed from the grammar element.- ((removeDefineComponent defNames) `whenP` (const $ defNames /= []))- >>>- -- The grammar element is then renamed to div.- setRngNameDiv-- - checkInclude :: String -> XmlTree -> IOSArrow XmlTree XmlTree- checkInclude href newDoc- = ifA ( -- If the include element has a start component, then the grammar element- -- must have a start component.- hasStartComponent &&& (constA newDoc >>> hasStartComponent)- >>> - isA (\ (a, b) -> if a then b else True)- )- ( ifA ( -- If the include element has a define component, then the grammar element- -- must have a define component with the same name.- getDefineComponents &&& (constA newDoc >>> getDefineComponents)- >>> - isA (\ (a, b) -> (diff a b) == [])- )- (insertNewDoc newDoc $<< hasStartComponent &&& getDefineComponents)- ( mkRelaxError ""- ( "Define-pattern missing in schema " ++ show href ++ - ", referenced in include-pattern"- )- )- )- ( mkRelaxError ""- ( "Grammar-element without a start-pattern in schema " ++- show href ++ ", referenced in include-pattern"- )- )- where- diff a b = (noDoubles a) \\ (noDoubles b)-- removeStartComponent :: IOSArrow XmlTree XmlTree- removeStartComponent- = processChildren $- choiceA [- isRngStart :-> none,- isRngDiv :-> removeStartComponent,- this :-> this- ]-- removeDefineComponent :: [String] -> IOSArrow XmlTree XmlTree- removeDefineComponent defNames- = processChildren $- choiceA [- ( isRngDefine- >>>- getRngAttrName- >>> - isA (\n -> elem n defNames)) :-> none,- (isElem >>> getName >>> isA (== "div")) :-> (removeDefineComponent defNames),- (constA "foo" >>> isA (== "foo")) :-> this- ]- - hasStartComponent :: IOSArrow XmlTree Bool- hasStartComponent = listA hasStartComponent' >>> arr (any id)- where- hasStartComponent' :: IOSArrow XmlTree Bool- hasStartComponent'- = getChildren- >>>- choiceA [- isRngStart :-> (constA True),- isRngDiv :-> hasStartComponent',- this :-> (constA False)- ]-- getDefineComponents :: IOSArrow XmlTree [String]- getDefineComponents = listA getDefineComponents'- >>> - arr (\xs -> [x | x <- xs, x /= ""])- where- getDefineComponents' :: IOSArrow XmlTree String- getDefineComponents'- = getChildren- >>>- choiceA- [ isRngDefine :-> getRngAttrName- , isRngDiv :-> getDefineComponents'- , this :-> constA ""- ]- ---- ---------------------------------------------------------------{--- 4.8. name attribute of element and attribute elements- - The name attribute on an element or attribute element- is transformed into a name child element.- - If an attribute element has a name attribute but no ns attribute,- then an ns="" attribute is added to the name child element.-- 4.9. ns attribute- - For any name, nsName or value element that does not have- an ns attribute, an ns attribute is added.- - any ns attribute that is on an element other than name,- nsName or value is removed.-- 4.10. QNames- - For any name element containing a prefix, the prefix is removed- and an ns attribute is added replacing any existing ns attribute.- - The value of the added ns attribute is the value to which the- namespace map of the context of the name element maps the prefix.- - The context must have a mapping for the prefix.--}-simplificationStep3 :: IOSArrow XmlTree XmlTree-simplificationStep3 =- ( processTopDown ( - ( -- 4.8 The name attribute on an element or attribute- -- element is transformed into a name child element- ( insertChildrenAt 0 (mkRngName none (txt $< getRngAttrName))- )- >>>- ( -- 4.8 If an attribute element has a name attribute but no ns attribute,- -- then an ns="" attribute is added to the name child element- (processChildren (addAttr "ns" "" `when` isRngName))- `when` - (isRngAttribute >>> hasRngAttrName >>> neg hasRngAttrNs)- )- >>>- removeAttr "name" - )- `when`- ( (isRngElement `orElse` isRngAttribute) >>> hasRngAttrName )- )- >>>- -- 4.9 For any name, nsName or value element that does not have - -- an ns attribute, an ns attribute is added.- processnsAttribute ""- >>>- processTopDown ( - ( -- 4.9 any ns attribute that is on an element other than name, - -- nsName or value is removed.- (removeAttr "ns")- `when`- (isElem >>> neg (isRngName `orElse` isRngNsName `orElse` isRngValue))- )- >>>- ( -- 4.10 For any name element containing a prefix, the prefix is removed and an ns attribute - -- is added replacing any existing ns attribute.- (replaceNameAttr $< (getChildren >>> isText >>> getText))- `when`- isRngName- )- )- ) `when` collectErrors- where- replaceNameAttr :: (ArrowXml a) => String -> a XmlTree XmlTree- replaceNameAttr name - = (addAttr "ns" pre >>> processChildren (changeText $ const local))- `whenP`- (const $ elem '}' name)- where - (pre', local') = span (/= '}') name- pre = tail pre'- local = tail local'- - processnsAttribute :: String -> IOSArrow XmlTree XmlTree - processnsAttribute name - = processChildren $- choiceA [- -- set the new ns attribute value- (isElem >>> hasRngAttrNs) - :-> (processnsAttribute $< getRngAttrNs),- -- For any name, nsName or value element that does not have- -- an ns attribute, an ns attribute is added. - ( isNameNsNameValue >>> neg hasRngAttrNs)- :-> (addAttr "ns" name >>> processnsAttribute name),- this :-> (processnsAttribute name)- ]----- ------------------------------------------------------------ ---{--- 4.11 Each div element is replaced by its children-- 4.12 Number of child elements- - A define, oneOrMore, zeroOrMore, optional, list or mixed element - is transformed so that it has exactly one child element- - An element element is transformed so that it has exactly two child elements- - A except element is transformed so that it has exactly one child element- - If an attribute element has only one child element (a name class), then a text element is added.- - A choice, group or interleave element is transformed so that it has exactly two child elements.-- 4.13 A mixed element is transformed into an interleaving with a text element-- 4.14 An optional element is transformed into a choice with empty-- 4.15 A zeroOrMore element is transformed into a choice between oneOrMore and empty-- 4.16. Constraints: no transformation is performed, but various constraints are checked.- - An except element that is a child of an anyName element must not have any anyName descendant elements.- - An except element that is a child of an nsName element must not have any nsName or anyName- descendant elements.- - A name element that occurs as the first child of an attribute element or as the descendant of the - first child of an attribute element and that has an ns attribute with value equal to the empty - string must not have content equal to xmlns.- - A name or nsName element that occurs as the first child of an attribute element or as the - descendant of the first child of an attribute element must not have an ns attribute with - value http://www.w3.org/2000/xmlns.- - A data or value element must be correct in its use of datatypes.--}-simplificationStep4 :: IOSArrow XmlTree XmlTree-simplificationStep4 =- ( processTopDown ( - ( -- Each div element is replaced by its children.- (getChildren >>> simplificationStep4)- `when`- isRngDiv- )- >>>- ( -- A define, oneOrMore, zeroOrMore, optional, list or mixed element- -- is transformed so that it has exactly one child element- ( replaceChildren- ( mkRngGroup- (setChangesAttr $< (getName >>> arr ("group-Pattern: " ++))) - getChildren- )- )- `when`- ( isDefineOneOrMoreZeroOrMoreOptionalListMixed- >>>- noOfChildren (> 1)- )- )- >>>- ( -- An element element is transformed so that it has exactly two child elements - ( replaceChildren- ( ( getChildren >>> isNameAnyNameNsName )- <+> - ( mkRngGroup none - ( getChildren- >>>- neg isNameAnyNameNsName- )- )- )- )- `when`- ( isRngElement >>> noOfChildren (> 2) )- )- >>>- ( -- A except element is transformed so that it has exactly one child element.- replaceChildren ( mkRngChoice none getChildren )- `when`- ( isRngExcept >>> noOfChildren (> 1) )- )- >>>- ( -- If an attribute element has only one child element - -- (a name class), then a text element is added.- insertChildrenAt 1 (mkRngText none)- `when`- ( isRngAttribute >>> noOfChildren (== 1) )- )- >>>- ( -- A choice, group or interleave element is transformed so- -- that it has exactly two child elements.- ((wrapPattern2Two $< getName) >>> simplificationStep4)- `when` - ( isChoiceGroupInterleave- >>>- noOfChildren (\ i -> i > 2 || i == 1)- )- )- >>>- ( -- A mixed element is transformed into an interleaving with a text element - ( mkRngInterleave - ( setChangesAttr "mixed is transformed into an interleave" )- ( getChildren- <+>- mkRngText - ( setChangesAttr ( "new text-Pattern: mixed is transformed into " ++- " an interleave with text"- )- )- )- )- `when`- isRngMixed- )- >>> - ( -- An optional element is transformed into a choice with empty - ( mkRngChoice - ( setChangesAttr "optional is transformed into a choice" )- ( getChildren- <+>- mkRngEmpty - ( setChangesAttr ( "new empty-Pattern: optional is transformed " ++- " into a choice with empty"- )- )- )- )- `when`- isRngOptional- )- >>>- ( -- A zeroOrMore element is transformed into a choice between oneOrMore and empty- ( mkRngChoice - ( setChangesAttr "zeroOrMore is transformed into a choice" )- ( ( mkRngOneOrMore - ( setChangesAttr ( "zeroOrMore is transformed into a " ++- "choice between oneOrMore and empty"- )- )- getChildren- )- <+>- ( mkRngEmpty - ( setChangesAttr ( "new empty-Pattern: zeroOrMore is transformed " ++- "into a choice between oneOrMore and empty"- )- )- )- )- )- `when`- isRngZeroOrMore- )- )- ) `when` collectErrors----- ---------------------------------------------------------------restrictionsStep1 :: IOSArrow XmlTree XmlTree-restrictionsStep1 =- ( processTopDown (- ( ( mkRelaxError ""- ( "An except element that is a child of an anyName " ++- "element must not have any anyName descendant elements"- )- )- `when` - ( isRngAnyName- >>>- getChildren- >>>- isRngExcept- >>>- deep isRngAnyName- )- )- >>>- ( ( mkRelaxError ""- ( "An except element that is a child of an nsName element " ++- "must not have any nsName or anyName descendant elements."- )- )- `when` - ( isRngNsName- >>>- getChildren- >>> - isRngExcept- >>> - deep (isRngAnyName `orElse` isRngNsName)- )- )- >>>- ( ( mkRelaxError ""- ( "A name element that occurs as the first child or descendant of " ++- "an attribute and has an ns attribute with an empty value must " ++- "not have content equal to \"xmlns\""- )- )- `when` - ( isRngAttribute- >>>- firstChild- >>>- ( multi (isRngName >>> hasRngAttrNs) )- >>>- ( ( getRngAttrNs >>> isA null)- `guards`- (getChildren >>> getText >>> isA (== "xmlns"))- )- )- ) - >>>- ( ( mkRelaxError ""- ( "A name or nsName element that occurs as the first child or " ++- "descendant of an attribute must not have an ns attribute " ++- "with value http://www.w3.org/2000/xmlns"- )- )- `when` - ( isRngAttribute- >>>- firstChild- >>>- ( multi (isNameNsName >>> hasRngAttrNs) )- >>>- getRngAttrNs- >>>- isA (compareURI xmlnsNamespace)- )- ) - >>> -- A data or value element must be correct in its use of datatypes.- ( ( checkDatatype $<< getRngAttrDatatypeLibrary &&& getRngAttrType )- `when`- ( isRngData `orElse` isRngValue )- )- )- ) `when` collectErrors- where -- -- the datatypeLibrary attribute must identify a valid datatype library-- checkDatatype :: Uri -> DatatypeName -> IOSArrow XmlTree XmlTree- checkDatatype libName typeName - = ifP (const $ elem libName $ map fst datatypeLibraries) - ( checkType libName typeName allowedDataTypes )- ( mkRelaxError ""- ( "DatatypeLibrary " ++ show libName ++ " not found" )- )- where- DTC _ _ allowedDataTypes = fromJust $ lookup libName datatypeLibraries- - -- the type attribute must identify a datatype within the datatype library identified- -- by the value of the datatypeLibrary attribute.-- checkType :: Uri -> DatatypeName -> AllowedDatatypes -> IOSArrow XmlTree XmlTree- checkType libName typeName allowedTypes- = ifP (const $ elem typeName $ map fst allowedTypes)- ( checkParams typeName libName getParams $< - ( listA (getChildren >>> isRngParam >>> getRngAttrName) )- )- ( mkRelaxError ""- ( "Datatype " ++ show typeName ++ - " not declared for DatatypeLibrary " ++ show libName- )- )- where- getParams = fromJust $ lookup typeName allowedTypes- - -- For a data element, the parameter list must be one that is allowed by the datatype-- checkParams :: DatatypeName -> Uri -> AllowedParams -> [ParamName] -> IOSArrow XmlTree XmlTree- checkParams typeName libName allowedParams paramNames- = ( mkRelaxError ""- ( "Param(s): " ++ formatStringListQuot diff ++ - " not allowed for Datatype " ++ show typeName ++ - " in Library " ++- show ( if null libName- then relaxNamespace- else libName- )- )- )- `when`- ( isRngData >>> isA (const $ diff /= []) ) - where- diff = filter (\param -> not $ elem param allowedParams) paramNames-- --- ---------------------------------------------------------------{--- 4.17. combine attribute- - For each grammar element, all define elements with the same name are combined together.- - Similarly, for each grammar element all start elements are combined together.-- 4.18. grammar element- - A grammar must have a start child element.- - Transform the top-level pattern p into <grammar><start>p</start></grammar>.- - Rename define elements so that no two define elements anywhere in the schema - have the same name. To rename a define element, change the value of its name- attribute and change the value of the name attribute of all ref and parentRef- elements that refer to that define element.- - Move all define elements to be children of the top-level grammar element- - Replace each nested grammar element by the child of its start element- - Rename each parentRef element to ref.--}-simplificationStep5 :: IOSArrow XmlTree XmlTree-simplificationStep5- = ( processTopDown- ( ( ( ( (deep isRngRelaxError) - <+>- ( mkRelaxError "" "A grammar must have a start child element" )- )- `when`- (neg (getChildren >>> isRngStart))- )- >>>- -- For each grammar element, all define elements with the same - -- name are combined together.- ( combinePatternList "define" $< (getPatternNamesInGrammar "define" >>> arr nub) )- >>>- -- Similarly, for each grammar element all start elements - -- are combined together.- ( combinePatternList "start" $< (getPatternNamesInGrammar "start" >>> arr nub) )- ) - `when`- isRngGrammar- )- >>>- ( -- transform the top-level pattern p into <grammar><start>p</start></grammar>.- ( replaceChildren- ( mkRngGrammar none - ( mkRngStart none getChildren )- )- )- `when`- neg (getChildren >>> isRngGrammar)- )- >>>- ( renameDefines $<<- ( getPatternNamesInGrammar "define"- >>>- (createUniqueNames $< (getAndSetCounter "define_id" >>> arr read))- &&&- constA []- )- )- >>>- -- Move all define elements to be children of the top-level grammar element- ( processChildren- ( -- root node- processChildren- ( -- the first grammar pattern remains unchanged- ( deleteAllDefines- <+>- ( getAllDefines >>> processChildren deleteAllDefines )- )- >>>- processTopDown- ( ( -- Replace each nested grammar element by the child of its start element- ( getChildren >>> isRngStart >>> getChildren )- `when`- isRngGrammar- )- >>> - ( -- Rename each parentRef element to ref.- ( setRngNameRef- `when`- isRngParentRef- )- )- ) - )- )- )- ) `when` collectErrors- where- getPatternNamesInGrammar :: (ArrowXml a) => String -> a XmlTree [String]- getPatternNamesInGrammar pattern- = processChildren- ( processTopDown ( none `when` isRngGrammar ) )- >>>- listA ( (multi (isElem >>> hasRngName pattern))- >>> - getRngAttrName- )-- createUniqueNames :: Int -> IOSArrow [String] RefList- createUniqueNames num- = arr (\ l -> unique l num)- >>>- perform (setParamInt "define_id" $< arr (max num . getNextValue))- where- unique :: [String] -> Int -> RefList- unique [] _ = []- unique (x:xs) num' = (x, (show num')):(unique xs (num'+1))- getNextValue :: RefList -> Int- getNextValue [] = 0- getNextValue rl = maximum (map (read . snd) rl) + 1 -- renameDefines :: RefList -> RefList -> IOSArrow XmlTree XmlTree- renameDefines ref parentRef- = processChildren- ( choiceA- [ isRngDefine- :-> ( -- the original name is needed for error messages- addAttr defineOrigName $< getRngAttrName- >>>- -- rename the define-pattern- -- the new name is looked up in the ref table- addAttr "name" $< ( getRngAttrName- >>>- arr (\n -> fromJust $ lookup n ref)- )- >>>- renameDefines ref parentRef- )- , isRngGrammar - :-> ( renameDefines $<< ( ( -- compute all define names in the grammar- getPatternNamesInGrammar "define"- >>>- -- create a new (unique) name for all define names- (createUniqueNames $< (getParamInt 0 "define_id"))- )- &&&- -- set the old ref list to be the new parentRef list- constA ref- )- )- , isRngRef- :-> ( ifA ( getRngAttrName- >>>- isA (\name -> (elem name (map fst ref)))- )- ( -- the original name is needed for error messages- addAttr defineOrigName $< getRngAttrName- >>>- -- rename the ref-pattern- -- the new name is looked up in the ref table- addAttr "name" $< ( getRngAttrName- >>>- arr (\n -> fromJust $ lookup n ref)- )- )- ( -- the referenced pattern does not exist in the schema- mkRelaxError "" $< ( getRngAttrName- >>>- arr (\ n -> ( "Define-Pattern with name " ++ show n ++ - " referenced in ref-Pattern not " ++- "found in schema"- )- )- )- )- )- , isRngParentRef -- same as ref, but the parentRef list is used- :-> ( ifA ( getRngAttrName- >>>- isA (\name -> (elem name (map fst parentRef)))- )- ( addAttr defineOrigName $< getRngAttrName- >>>- addAttr "name" $< ( getRngAttrName- >>>- arr (\n -> fromJust $ lookup n parentRef)- )- )- ( mkRelaxError "" $<- ( getRngAttrName- >>> - arr (\ n -> ( "Define-Pattern with name " ++ show n ++ - " referenced in parentRef-Pattern " ++- "not found in schema"- )- )- )- )- )- , this- :-> renameDefines ref parentRef- ]- )--- getAllDefines :: IOSArrow XmlTree XmlTree- getAllDefines = multi isRngDefine-- deleteAllDefines :: IOSArrow XmlTree XmlTree - deleteAllDefines = processTopDown $ none `when` isRngDefine-- combinePatternList :: String -> [String] -> IOSArrow XmlTree XmlTree- combinePatternList _ [] = this- combinePatternList pattern (x:xs)- = (replaceChildren $ combinePattern pattern x)- >>>- combinePatternList pattern xs- - -- combine a define- or start-pattern (first parameter) with a- -- specific name (second parameter)- combinePattern :: String -> String -> IOSArrow XmlTree XmlTree - combinePattern pattern name- = createPatternElems pattern name- <+>- (getChildren >>> deletePatternElems pattern name) -- createPatternElems :: String -> String -> IOSArrow XmlTree XmlTree - createPatternElems pattern name - = ( ( (listA (getElems pattern name >>> getRngAttrCombine))- >>>- checkPatternCombine pattern name- ) - -- After determining this unique value, the combine attributes are removed.- &&&- (listA (getElems pattern name >>> removeAttr "combine"))) - >>> -- ((errorCode::Int,errorMessage::String), result::XmlTrees)- choiceA- [ isA (\ ((code,_) , _) -> code == 0)- :->- (mkRelaxError "" $< arr (snd . fst))- , isA (\ ((code,str) , _) -> code == 1 && str == "")- :->- arrL snd- , isA (\ ((code,str) , _) -> code == 1 && str /= "")- :->- ( createPatternElem pattern name $<< - ( arr (snd . fst) &&& (arr snd) )- )- , this- :->- ( mkRelaxError ""- ( "Can't create Pattern: " ++ show pattern ++ - " with name " ++ show name ++ " in createPatternElems"- )- )- ]-- createPatternElem :: (ArrowXml a) => String -> String -> String -> XmlTrees -> a n XmlTree - createPatternElem pattern name combine trees- = mkRngElement pattern (mkAttr (mkName "name") (txt name)) - ( ( mkRngElement combine none - (arrL (const trees) >>> getChildren)- )- >>>- wrapPattern2Two combine- )- - checkPatternCombine :: (ArrowXml a) => String -> String -> a [String] (Int, String)- checkPatternCombine pattern name - = choiceA- [ -- just one pattern with that name -> ok, no combine is needed- (isA (\ cl -> length cl == 1))- :->- constA (1, "")- , (isA (\ cl -> (length $ elemIndices "" cl) > 1)) - :->- constA ( 0- , "More than one " ++ pattern ++ "-Pattern: " ++ show name ++ - " without an combine-attribute in the same grammar"- )- , (isA (\ cl -> (length $ nub $ deleteBy (==) "" cl) > 1)) - :->- arr (\ cl -> ( 0- , "Different combine-Attributes: " ++ - (formatStringListQuot $ noDoubles cl) ++- " for the " ++ pattern ++ "-Pattern " ++- show name ++ " in the same grammar"- )- )- , -- ok -> combine value is returned- this- :->- arr (\ cl -> (1, fromJust $ find (/= "") cl))- ]-- isElemWithNameValue :: (ArrowXml a) => String -> String -> a XmlTree XmlTree- isElemWithNameValue ename nvalue- = ( isElem- >>>- hasRngName ename- >>>- getRngAttrName- >>>- isA (== nvalue)- )- `guards` this-- getElems :: (ArrowXml a) => String -> String -> a XmlTree XmlTree- getElems pattern name- = getChildren- >>> - choiceA- [ isElemWithNameValue pattern name- :->- (this <+> getElems pattern name)- , isRngGrammar- :-> none- , this- :->- getElems pattern name- ]-- deletePatternElems :: (ArrowXml a) => String -> String -> a XmlTree XmlTree- deletePatternElems pattern name- = choiceA- [ isElemWithNameValue pattern name- :->- none- , isRngGrammar- :-> this- , this- :->- processChildren ( deletePatternElems pattern name )- ]----- ---------------------------------------------------------------{--- 4.19. define and ref elements- - Remove any define element that is not reachable.- - Now, for each element element that is not the child of a define element,- add a define element to the grammar element, - and replace the element element by a ref element referring- to the added define element.- - For each ref element that is expandable and is a descendant- of a start element or an element element, expand it by replacing- the ref element by the child of the define element to which it refers- - This must not result in a loop.- - Remove any define element whose child is not an element element.--}-simplificationStep6 :: IOSArrow XmlTree XmlTree-simplificationStep6 =- ( -- Remove any define element that is not reachable.- (removeUnreachableDefines $<<< getAllDeepDefines - &&& - constA []- &&&- getRefsFromStartPattern- )- >>>- -- for each element element that is not the child of a define element,- -- add a define element to the grammar element, - ( processElements False- >>>- processChildren (insertChildrenAt 1 (getParam "elementTable"))- )- >>>- -- For each ref element that is expandable... - -- Remove any define element whose child is not an element element - (replaceExpandableRefs [] $< getExpandableDefines >>> deleteExpandableDefines)- ) `when` collectErrors- where- replaceExpandableRefs :: RefList -> Env -> IOSArrow XmlTree XmlTree- replaceExpandableRefs foundNames defTable- = choiceA [- isRngRef- :-> (ifA ( getRngAttrName- >>>- isA (\name -> elem name (map fst foundNames))- )- -- we have found a loop if the name is in the list- (mkRelaxError "" $< ( getAttrValue defineOrigName- >>>- arr (\ n -> ( "Recursion in ref-Pattern: " ++ - formatStringListArr (reverse $ (n:) $ map snd foundNames)- )- )- )- )- (replaceRef $<< getRngAttrName &&& getAttrValue defineOrigName)- ),- this :-> (processChildren $ replaceExpandableRefs foundNames defTable)- ]- where - replaceRef :: NewName -> OldName -> IOSArrow XmlTree XmlTree- replaceRef name oldname- = ( constA (fromJust $ lookup name defTable)- >>>- getChildren- >>>- replaceExpandableRefs ((name,oldname):foundNames) defTable- )- `whenP`- (const $ elem name $ map fst defTable)--- processElements :: Bool -> IOSArrow XmlTree XmlTree- processElements parentIsDefine- = processChildren- ( choiceA- [ isRngElement- :-> ( ifP (const parentIsDefine)- (processElements False)- ( processElements' $<< ( getAndSetCounter "define_id" - &&&- getDefineName- )- )- )- , isRngDefine- :-> processElements True- , this- :-> processElements False- ])- where- getDefineName :: IOSArrow XmlTree String- getDefineName- = firstChild- >>>- fromLA createNameClass- >>>- arr show- - processElements' :: NewName -> OldName -> IOSArrow XmlTree XmlTree- processElements' name oldname- = storeElement name oldname- >>> - mkRngRef (createAttr name oldname) none-- storeElement :: NewName -> OldName -> IOSArrow XmlTree XmlTree- storeElement name oldname- = perform $ - ( mkRngDefine- (createAttr name oldname) (processElements False)- )- &&&- (listA $ getParam "elementTable")- >>>- arr2 (:)- >>>- setParamList "elementTable"-- createAttr :: NewName -> OldName -> IOSArrow XmlTree XmlTree- createAttr name oldname- = mkAttr (mkName "name") (txt name) - <+>- mkAttr (mkName defineOrigName) (txt $ "created for element " ++ oldname)- - getExpandableDefines :: (ArrowXml a) => a XmlTree Env - getExpandableDefines - = listA $ (multi ( ( isRngDefine- >>>- getChildren- >>>- neg isRngElement- )- `guards`- this- )- )- >>> - (getRngAttrName &&& this)- - deleteExpandableDefines :: (ArrowXml a) => a XmlTree XmlTree- deleteExpandableDefines - = processTopDown $ none- `when` - ( isRngDefine- >>> - getChildren- >>>- neg isRngElement- )----- ---------------------------------------------------------------{--- 4.20. notAllowed element- - An attribute, list, group, interleave, or oneOrMore element that has- a notAllowed child element is transformed into a notAllowed element.- - A choice element that has two notAllowed child elements - is transformed into a notAllowed element- - A choice element that has one notAllowed child element- is transformed into its other child element.- - An except element that has a notAllowed child element is removed.- - The preceding transformations are applied repeatedly- until none of them is applicable any more.- - Any define element that is no longer reachable is removed.-- 4.21. empty element- - A group, interleave or choice element that has two empty child- elements is transformed into an empty element.- - A group or interleave element that has one empty child element- is transformed into its other child element.- - A choice element whose second child element is an empty element- is transformed by interchanging its two child elements.- - A oneOrMore element that has an empty child element- is transformed into an empty element.- - The preceding transformations are applied repeatedly- until none of them is applicable any more.--}--simplificationStep7 :: IOSArrow XmlTree XmlTree-simplificationStep7- = ( markTreeChanged 0 -- 0 = no changes, 1 = changes performed- >>>- processTopDownWithAttrl- ( ( -- An attribute, list, group, interleave, or oneOrMore element that has a - -- notAllowed child element is transformed into a notAllowed element. - ( ( mkRngNotAllowed none none- >>>- markTreeChanged 1- )- `whenNot` -- keep all errors- (deep isRngRelaxError)- )- `when`- ( isAttributeListGroupInterleaveOneOrMore- >>>- getChildren- >>>- isRngNotAllowed- )- )- >>> - ( -- A choice element that has two notAllowed child elements is - -- transformed into a notAllowed element- ( mkRngNotAllowed none none- >>>- markTreeChanged 1- )- `when`- ( isRngChoice- >>>- listA (getChildren >>> isRngNotAllowed)- >>> - isA (\s -> length s == 2)- )- )- >>>- ( -- A choice element that has one notAllowed child element is - -- transformed into its other child element. - ( getChildren >>> neg isRngNotAllowed- >>>- markTreeChanged 1- )- `when`- ( isRngChoice >>> getChildren >>> isRngNotAllowed )- )- >>> - ( -- An except element that has a notAllowed child element is removed.- ( ( markTreeChanged 1- >>>- none- ) - `whenNot` -- keep all errors- deep isRngRelaxError- )- `when`- ( isRngExcept >>> getChildren >>> isRngNotAllowed )- )- >>> -- transforming the empty pattern (4.21)- ( -- A group, interleave or choice element that has two empty child elements- -- is transformed into an empty element.- ( mkRngEmpty none- >>>- markTreeChanged 1- )- `when`- ( isChoiceGroupInterleave- >>>- listA (getChildren >>> isRngEmpty)- >>>- isA (\s -> length s == 2)- )- )- >>>- ( -- A group or interleave element that has one empty child element - -- is transformed into its other child element.- ( getChildren- >>>- neg isRngEmpty- >>>- markTreeChanged 1- )- `when`- ( isGroupInterleave >>> getChildren >>> isRngEmpty )- )- >>>- ( -- A choice element whose second child element is an empty element is transformed - -- by interchanging its two child elements.- changeChoiceChildren- `when`- ( isRngChoice >>> getChildren >>> isRngEmpty )- )- >>>- ( -- A oneOrMore element that has an empty child element- -- is transformed into an empty element.- ( mkRngEmpty none- >>>- markTreeChanged 1- )- `when`- ( isRngOneOrMore >>> getChildren >>> isRngEmpty )- )- )- >>>- -- The preceding transformations are applied repeatedly- -- until none of them is applicable any more.- ( simplificationStep7- `when`- hasTreeChanged- )- ) `when` collectErrors- where- changeChoiceChildren :: IOSArrow XmlTree XmlTree- changeChoiceChildren- = ( ( replaceChildren- ( mkRngEmpty none- <+> - (getChildren >>> neg isRngEmpty)- ) - >>>- markTreeChanged 1- )- `when`- ( single (getChildren >>> isElem) -- first child not "empty" elem- >>>- neg isRngEmpty- )- )--hasTreeChanged :: IOSArrow b Int-hasTreeChanged- = getParamInt 0 "rng:changeTree"- >>>- isA (== 1)--markTreeChanged :: Int -> IOSArrow b b-markTreeChanged i- = perform (setParamInt "rng:changeTree" i)---- ---------------------------------------------------------------simplificationStep8 :: IOSArrow XmlTree XmlTree-simplificationStep8 -- Remove any define element that is not reachable.- = ( ( removeUnreachableDefines $<<<- ( getAllDeepDefines- &&&- constA []- &&&- getRefsFromStartPattern- )- )- `when` collectErrors- )- ---- ---------------------------------------------------------------restrictionsStep2 :: IOSArrow XmlTree XmlTree-restrictionsStep2 =- processTopDown (- choiceA [--- 7.1.1. attribute pattern, the following paths are prohibited:--- attribute//(ref | attribute)- isRngAttribute :-> - ( ( deep isRngRelaxError- <+>- ( mkRelaxError $<< (getChangesAttr- &&&- ( listA ( getChildren- >>> - deep isAttributeRef- >>>- (getName &&& getChangesAttr >>> arr2 (++))- )- >>>- arr (\n -> formatStringListPatt n ++ - "Pattern not allowed as descendent(s)" ++- " of a attribute-Pattern"- )- )- )- ) - )- `when` - ( getChildren >>> deep isAttributeRef )- ),---- 7.1.2. oneOrMore pattern, the following paths are prohibited:--- oneOrMore//(group | interleave)//attribute- isRngOneOrMore :->- ( ( deep isRngRelaxError- <+>- ( mkRelaxError $<< (getChangesAttr- &&&- ( listA ( getChildren- >>> - deep isGroupInterleave- >>>- (getName &&& getChangesAttr >>> arr2 (++))- )- &&&- getChangesAttr- >>>- arr2 (\ n c -> ( formatStringListPatt n ++ - "Pattern not allowed as descendent(s) " ++- "of a oneOrMore-Pattern" ++- (if null c then "" else " " ++ show c) ++ - " followed by an attribute descendent"- )- )- )- )- ) - )- `when` - ( getChildren >>> deep isGroupInterleave- >>> - getChildren >>> deep isRngAttribute- )- ),---- 7.1.3. list pattern, the following paths are prohibited:--- list//( list | ref | attribute | text | interleave)- isRngList :-> - ( ( deep isRngRelaxError- <+>- ( mkRelaxError $<< (getChangesAttr- &&&- ( listA ( getChildren- >>> - deep isAttributeRefTextListInterleave- >>>- (getName &&& getChangesAttr >>> arr2 (++))- )- >>> - arr (\n -> formatStringListPatt n ++ - "Pattern not allowed as descendent(s) of a list-Pattern")- )- )- ) - )- `when` - ( getChildren- >>>- deep isAttributeRefTextListInterleave- )- ), ---- 7.1.4. except in data pattern, the following paths are prohibited:--- data/except//(attribute | ref | text | list | group | interleave | oneOrMore | empty)- isRngData :-> - ( ( deep isRngRelaxError - <+>- ( mkRelaxError $<< (getChangesAttr- &&&- ( listA (getChildren- >>> - deep isAttributeRefTextListGroupInterleaveOneOrMoreEmpty- >>>- (getName &&& getChangesAttr >>> arr2 (++))- )- >>>- arr (\n -> formatStringListPatt n ++ - "Pattern not allowed as descendent(s) of a data/except-Pattern")- )- )- ) - )- `when` - ( getChildren- >>>- isRngExcept- >>> - deep isAttributeRefTextListGroupInterleaveOneOrMoreEmpty- )- ),---- 7.1.5. start element, the following paths are prohibited:--- start//(attribute | data | value | text | list | group | interleave | oneOrMore | empty)- isRngStart :-> - ( ( deep isRngRelaxError- <+>- ( mkRelaxError $<< (getChangesAttr- &&&- ( listA (getChildren- >>>- deep (checkElemName [ "attribute", "data", "value", "text", "list", - "group", "interleave", "oneOrMore", "empty"])- >>>- (getName &&& getChangesAttr >>> arr2 (++))- )- >>> - arr (\n -> formatStringListPatt n ++ - "Pattern not allowed as descendent(s) of a start-Pattern")- )- )- ) - )- `when` - ( getChildren- >>>- deep (checkElemName [ "attribute", "data", "value", "text", "list", - "group", "interleave", "oneOrMore", "empty"])- ) - ),- - this :-> this- ]- ) `when` collectErrors-- --- ---------------------------------------------------------------restrictionsStep3 :: IOSArrow XmlTree XmlTree-restrictionsStep3- = processTopDown- ( ( deep isRngRelaxError- <+>- ( mkRelaxError "" $< - ( -- getRngAttrName- ( getChildren >>> isRngName >>> getChildren >>> getText )- >>> - arr (\ n -> ( "Content of element " ++ show n ++ " contains a pattern that can match " ++- "a child and a pattern that matches a single string"- )- )- )- )- )- `when`- ( isRngElement- >>>- ( getChildren >>. (take 1 . reverse) )- >>>- getContentType >>> isA (== CTNone)- )- ) `when` collectErrors-- - -getContentType :: IOSArrow XmlTree ContentType-getContentType- = choiceA- [ isRngValue :-> (constA CTSimple)- , isRngData :-> processData- , isRngList :-> (constA CTSimple)- , isRngText :-> (constA CTComplex)- , isRngRef :-> (constA CTComplex)- , isRngEmpty :-> (constA CTEmpty)- , isRngAttribute :-> processAttribute- , isRngGroup :-> processGroup- , isRngInterleave :-> processInterleave- , isRngOneOrMore :-> processOneOrMore- , isRngChoice :-> processChoice- ]- where- processData :: IOSArrow XmlTree ContentType- processData- = ifA (neg (getChildren >>> isRngExcept))- (constA CTSimple)- ( getChildren- >>>- isRngExcept- >>>- getChildren- >>>- getContentType- >>>- ifP (/= CTNone) (constA CTSimple) (constA CTNone)- )- processAttribute :: IOSArrow XmlTree ContentType- processAttribute- = ifA ( lastChild- >>>- getContentType- >>>- isA (/= CTNone)- )- (constA CTEmpty)- (constA CTNone)- - processGroup :: IOSArrow XmlTree ContentType- processGroup- = get2ContentTypes- >>>- arr2 (\a b -> if isGroupable a b then max a b else CTNone)- - processInterleave :: IOSArrow XmlTree ContentType- processInterleave- = get2ContentTypes- >>>- arr2 (\a b -> if isGroupable a b then max a b else CTNone)- - processOneOrMore :: IOSArrow XmlTree ContentType- processOneOrMore- = ifA ( getChildren- >>>- getContentType >>> isA (/= CTNone)- >>>- isA (\t -> isGroupable t t)- )- ( getChildren >>> getContentType )- ( constA CTNone )- - processChoice :: IOSArrow XmlTree ContentType- processChoice- = get2ContentTypes- >>> - arr2 max-- isGroupable :: ContentType -> ContentType -> Bool- isGroupable CTEmpty _ = True- isGroupable _ CTEmpty = True- isGroupable CTComplex CTComplex = True- isGroupable _ _ = False ---checkPattern :: IOSArrow (XmlTree, ([NameClass], [NameClass])) XmlTree-checkPattern- = (\ (_, (a, b)) -> isIn a b) `guardsP` (arr fst)- where- isIn :: [NameClass] -> [NameClass] -> Bool- isIn _ [] = False- isIn [] _ = False- isIn (x:xs) ys = (any (overlap x) ys) || isIn xs ys---occur :: String -> IOSArrow XmlTree XmlTree -> IOSArrow XmlTree XmlTree-occur name fct- = choiceA- [ ( isElem >>> hasRngName name )- :->- fct- , isChoiceGroupInterleaveOneOrMore- :->- (getChildren >>> occur name fct)- ]--get2ContentTypes :: IOSArrow XmlTree (ContentType, ContentType)-get2ContentTypes- = ( ( firstChild >>> getContentType )- &&&- ( lastChild >>> getContentType )- )---- ------------------------------------------------------------ ----- Duplicate attributes are not allowed. -> fertig--- Attributes using infinite name classes must be repeated; an attribute element that --- has an anyName or nsName descendant element must have a oneOrMore ancestor element. -> fertig---- berechnet alle define-Namen (fuer ref-Pattern) und Nameclasses der element-Pattern--restrictionsStep4 :: IOSArrow XmlTree XmlTree -restrictionsStep4- = ( restrictionsStep4' $<- listA ( deep isRngDefine -- get all defines- >>>- ( getRngAttrName -- get define name- &&& - ( single ( getChildren- >>>- getChildren- >>> - fromLA createNameClass -- compute the name class from 1. grandchild- )- `orElse`- (constA AnyName)- )- )- )- ) `when` collectErrors--restrictionsStep4' :: [(String, NameClass)] -> IOSArrow XmlTree XmlTree -restrictionsStep4' nc =- processTopDown (- ( - ( deep isRngRelaxError- <+>- ( mkRelaxError "" $< - ( getRngAttrName- >>>- arr (\ n -> ( "Both attribute-pattern occuring in an " ++ - show n ++ " belong to the same name-class"- )- )- )- )- ) - `when` - ( (isRngGroup `orElse` isRngInterleave)- >>>- ( getChildren- &&& - ( firstChild- >>> - listA ( occur "attribute" (single getChildren)- >>> - fromLA createNameClass- )- ) - &&&- ( lastChild- >>> - listA ( occur "attribute" (single getChildren)- >>> - fromLA createNameClass- )- )- ) - >>> checkPattern- ) - ) - >>>- ( - ( deep isRngRelaxError- <+>- ( mkRelaxError ""- ( "An attribute that has an anyName or nsName descendant element " ++- "must have a oneOrMore ancestor element"- )- )- )- `when`- (isRngElement >>> checkInfiniteAttribute)- )- >>>- ( ( deep isRngRelaxError- <+>- ( mkRelaxError ""- ( "Both element-pattern occuring in an interleave " ++- "belong to the same name-class"- )- )- )- `when` - ( isRngInterleave- >>> - ( getChildren- &&&- (firstChild >>> listA (occur "ref" this >>> getRngAttrName)) - &&&- (lastChild >>> listA (occur "ref" this >>> getRngAttrName))- )- >>>- checkNames- )- )- >>> - ( ( deep isRngRelaxError- <+> - ( mkRelaxError "" "A text pattern must not occur in both children of an interleave" )- )- `when` - (isRngInterleave >>> checkText)- )- )- where- checkInfiniteAttribute :: IOSArrow XmlTree XmlTree- checkInfiniteAttribute- = getChildren- >>>- choiceA- [ isRngOneOrMore :-> none- , ( isRngAttribute- >>>- deep (isRngAnyName `orElse` isRngNsName)- ) :-> this- , this :-> checkInfiniteAttribute- ]-- checkNames :: IOSArrow (XmlTree, ([String], [String])) XmlTree- checkNames = (arr fst)- &&&- (arr (\(_, (a, _)) -> getNameClasses nc a)) - &&&- (arr (\(_, (_, b)) -> getNameClasses nc b))- >>>- checkPattern- where- getNameClasses :: [(String, NameClass)] -> [String] -> [NameClass]- getNameClasses nc' l = map (\x -> fromJust $ lookup x nc') l- - checkText :: IOSArrow XmlTree XmlTree- checkText- = ( firstChild >>> occur "text" this )- `guards` - ( lastChild >>> occur "text" this )- --- ---------------------------------------------------------------overlap :: NameClass -> NameClass -> Bool-overlap nc1 nc2- = any (bothContain nc1 nc2) (representatives nc1 ++ representatives nc2)--bothContain :: NameClass -> NameClass -> QName -> Bool-bothContain nc1 nc2 qn- = contains nc1 qn && contains nc2 qn--illegalLocalName :: LocalName-illegalLocalName = ""--illegalUri :: Uri-illegalUri = "\x1"--representatives :: NameClass -> [QName]-representatives AnyName- = [mkQName "" illegalLocalName illegalUri]--representatives (AnyNameExcept nc)- = (mkQName "" illegalLocalName illegalUri) : (representatives nc)--representatives (NsName ns)- = [mkQName "" illegalLocalName ns]--representatives (NsNameExcept ns nc)- = (mkQName "" illegalLocalName ns) : (representatives nc)--representatives (Name ns ln)- = [mkQName "" ln ns]--representatives (NameClassChoice nc1 nc2)- = (representatives nc1) ++ (representatives nc2)--representatives _- = []---- ------------------------------------------------------------------------------------------------------- -resetStates :: IOSArrow XmlTree XmlTree-resetStates- = ( perform (constA $ setParamInt "define_id" 0)- >>>- perform (constA [] >>> setParamList "elementTable" )- >>>- perform (constA $ setParamInt a_numberOfErrors 0)- )---getAllDeepDefines :: IOSArrow XmlTree Env-getAllDeepDefines- = listA $ deep isRngDefine- >>> - ( getRngAttrName &&& this )----- | Return all reachable defines from the start pattern--getRefsFromStartPattern :: IOSArrow XmlTree [String]-getRefsFromStartPattern- = listA- ( getChildren- >>>- isRngGrammar- >>>- getChildren- >>>- isRngStart- >>> - deep isRngRef- >>>- getRngAttrName- )--removeUnreachableDefines :: Env -> [String] -> [String] -> IOSArrow XmlTree XmlTree-removeUnreachableDefines allDefs processedDefs reachableDefs- = ifP (const $ unprocessedDefs /= [])- ( removeUnreachableDefines allDefs (nextTreeName : processedDefs) $< newReachableDefs )- ( processChildren $ -- root node- processChildren $ -- first grammar- ( none - `when`- ( isRngDefine- >>>- getRngAttrName- >>> - isA (\n -> not $ elem n reachableDefs)- )- )- )- where- unprocessedDefs :: [String]- unprocessedDefs- = reachableDefs \\ processedDefs-- newReachableDefs :: IOSArrow n [String]- newReachableDefs- = constA getTree- >>> - listA ( deep isRngRef- >>>- getRngAttrName- )- >>>- arr (noDoubles . (reachableDefs ++))-- getTree :: XmlTree- getTree- = fromJust $ lookup nextTreeName allDefs-- nextTreeName :: String- nextTreeName- = head unprocessedDefs----- ------------------------------------------------------------------------------------------------------- - --checkElemName :: [String] -> IOSArrow XmlTree XmlTree-checkElemName l- = ( isElem >>> getLocalPart >>> isA (\s -> elem s l) )- `guards`- this--wrapPattern2Two :: (ArrowXml a) => String -> a XmlTree XmlTree-wrapPattern2Two name - = choiceA- [ noOfChildren (> 2)- :-> ( replaceChildren ( (mkRngElement name none - (getChildren >>. take 2)- ) - <+> - (getChildren >>. drop 2)- )- >>>- wrapPattern2Two name- )- , noOfChildren (== 1)- :-> getChildren- , this- :-> this- ]--mkRelaxError :: String -> String -> IOSArrow n XmlTree-mkRelaxError changesStr errStr- = perform (getAndSetCounter a_numberOfErrors)- >>>- mkRngRelaxError none none- >>>- addAttr "desc" errStr- >>>- ( addAttr "changes" changesStr- `whenP`- (const $ changesStr /= "")- )--collectErrors :: IOSArrow XmlTree XmlTree-collectErrors- = none- `when`- ( stopAfterFirstError- >>>- getParamInt 0 a_numberOfErrors >>> isA (>0)- )- where- stopAfterFirstError = getParamString a_do_not_collect_errors- >>>- isA (== "1")- ---- | Returns the list of simplification errors or 'none'-getErrors :: IOSArrow XmlTree XmlTree-getErrors = (getParamInt 0 a_numberOfErrors >>> isA (>0))- `guards`- (root [] [multi isRngRelaxError])--setChangesAttr :: String -> IOSArrow XmlTree XmlTree-setChangesAttr str- = ifA (hasAttr a_relaxSimplificationChanges)- ( processAttrl $- changeAttrValue (++ (", " ++ str))- `when`- (hasRngName a_relaxSimplificationChanges)- )- (mkAttr (mkName a_relaxSimplificationChanges) (txt str))---getChangesAttr :: IOSArrow XmlTree String-getChangesAttr- = getAttrValue a_relaxSimplificationChanges - &&& - getParamString a_output_changes- >>>- ifP (\(changes, param) -> changes /= "" && param == "1")- (arr2 $ \l _ -> " (" ++ l ++ ")")- (constA "")- --getAndSetCounter :: String -> IOSArrow b String-getAndSetCounter name - = genNewId $< getParamInt 0 name- where- genNewId :: Int -> IOSArrow b String- genNewId i = setParamInt name (i+1) >>> constA (show i)-- --- ------------------------------------------------------------------------------------------------------- ---- | Creates the simple form of a Relax NG schema--- (see also: 'relaxOptions')--createSimpleForm :: Attributes -> Bool -> Bool -> Bool -> IOSArrow XmlTree XmlTree-createSimpleForm remainingOptions checkRestrictions validateExternalRef validateInclude- = traceMsg 2 ("createSimpleForm: " ++ show (remainingOptions, checkRestrictions,validateExternalRef, validateInclude))- >>>- ( if checkRestrictions- then createSimpleWithRest- else createSimpleWithoutRest- )- where-- createSimpleWithRest :: IOSArrow XmlTree XmlTree- createSimpleWithRest- = seqA $ concat [ simplificationPart1- , return $ traceDoc "relax NG: simplificationPart1 done"- , restrictionsPart1- , return $ traceDoc "relax NG: restrictionsPart1 done"- , simplificationPart2- , return $ traceDoc "relax NG simplificationPart2 done"- , restrictionsPart2- , return $ traceDoc "relax NG: restrictionsPart2 done"- , finalCleanUp- , return $ traceDoc "relax NG: finalCleanUp done"- ]-- createSimpleWithoutRest :: IOSArrow XmlTree XmlTree- createSimpleWithoutRest- = seqA $ concat [ simplificationPart1- , simplificationPart2- , finalCleanUp- ]- simplificationPart1 :: [IOSArrow XmlTree XmlTree]- simplificationPart1- = [ propagateNamespaces- , simplificationStep1- , simplificationStep2 remainingOptions validateExternalRef validateInclude [] []- , simplificationStep3- , simplificationStep4- ]-- simplificationPart2 :: [IOSArrow XmlTree XmlTree]- simplificationPart2- = [ simplificationStep5- , simplificationStep6- , simplificationStep7- , simplificationStep8- ]-- restrictionsPart1 :: [IOSArrow XmlTree XmlTree]- restrictionsPart1- = [ restrictionsStep1 ]-- restrictionsPart2 :: [IOSArrow XmlTree XmlTree]- restrictionsPart2- = [ restrictionsStep2- , restrictionsStep3- , restrictionsStep4 - ]-- finalCleanUp :: [IOSArrow XmlTree XmlTree] - finalCleanUp- = [ cleanUp- , resetStates- ]-- cleanUp :: IOSArrow XmlTree XmlTree- cleanUp = processTopDown $ - removeAttr a_relaxSimplificationChanges- >>>- removeAttr defineOrigName---- ------------------------------------------------------------------------------------------------------- ++-- ------------------------------------------------------------++{-+- 4.1. Annotations: Foreign attributes and elements are removed.+- 4.2. Whitespace:+ - For each element other than value and param, each child that is a string+ containing only whitespace characters is removed. -> fertig+ - Leading and trailing whitespace characters are removed from the value of each name,+ type and combine attribute and from the content of each name element. -> fertig+- 4.3. datatypeLibrary attribute:+ - The value of each datatypeLibary attribute is transformed by escaping disallowed characters+ - For any data or value element that does not have a datatypeLibrary attribute,+ a datatypeLibrary attribute is added.+ - Any datatypeLibrary attribute that is on an element other than data or value is removed.+- 4.4. type attribute of value element+-}+simplificationStep1 :: IOSArrow XmlTree XmlTree+simplificationStep1+ = ( {-+ - 4.5. href attribute+ - The value of the href attribute on an externalRef or include element is first+ - transformed by escaping disallowed characters+ - The URI reference is then resolved into an absolute form+ - The value of the href attribute will be used to construct an element.+ -}+ ( processHref $< getBaseURI )+ >>>+ -- 4.10 QNames+ processWithNsEnv processEnvNames (toNsEnv [("xml",xmlNamespace)])+ >>>+ -- 4.4 For any data or value element that does not have a datatypeLibrary attribute,+ -- a datatypeLibrary attribute is added.+ -- Wird vorgezogen, da danach der Rest in einem Baumdurchlauf erledigt werden kann+ processdatatypeLib ""+ >>>+ processTopDownWithAttrl+ (+ ( -- 4.1 Foreign attributes and elements are removed+ none+ `when`+ ( ( isElem >>> neg isRoot+ >>>+ getNamespaceUri+ >>>+ isA (\ uri -> (not $ compareURI uri relaxNamespace))+ )+ `orElse`+ ( isAttr+ >>>+ getNamespaceUri+ >>>+ isA (\ uri -> (uri /= "" && (not $ compareURI uri relaxNamespace)))+ )+ )+ )+ >>>+ ( -- 4.2 For each element other than value and param, each child that+ -- is a string containing only whitespace characters is removed.+ ( processChildren removeWhiteSpace+ `whenNot`+ (isRngParam `orElse` isRngValue)+ )+ `when` isElem+ )+ >>>+ ( -- 4.2 Leading and trailing whitespace characters are removed from the value+ -- of each name, type and combine attribute ...+ changeAttrValue normalizeWhitespace+ `when`+ ( isRngAttrName `orElse` isRngAttrType `orElse` isRngAttrCombine)+ )+ >>>+ ( -- 4.2 ... and from the content of each name element.+ processChildren (changeText normalizeWhitespace)+ `when`+ isRngName+ )+ >>>+ ( -- 4.3 The value of each datatypeLibary attribute is transformed+ -- by escaping disallowed characters+ changeAttrValue escapeURI+ `when`+ isRngAttrDatatypeLibrary+ )+ >>>+ ( -- The value of the datatypeLibary attribute has to be a valid URI+ ( mkRelaxError "" $< ( getRngAttrDatatypeLibrary+ >>>+ arr (\ a -> ( "datatypeLibrary attribute: " +++ a ++ " is not a valid URI"+ )+ )+ )+ )+ `when`+ ( isElem+ >>>+ hasRngAttrDatatypeLibrary+ >>>+ getRngAttrDatatypeLibrary >>> isA (not . isRelaxAnyURI)+ )+ )+ >>>+ ( -- 4.3 Any datatypeLibrary attribute that is on an element+ -- other than data or value is removed.+ removeAttr "datatypeLibrary"+ `when`+ ( isElem+ >>>+ neg (isRngData `orElse` isRngValue)+ >>>+ hasRngAttrDatatypeLibrary+ )+ )+ >>>+ ( -- 4.4 For any value element that does not have a type attribute,+ -- a type attribute is added with value token and the value of+ -- the datatypeLibrary attribute is changed to the empty string.+ ( addAttr "type" "token"+ >>>+ addAttr "datatypeLibrary" ""+ )+ `when`+ ( isRngValue >>> neg hasRngAttrType )+ )+ )+ ) `when` collectErrors+ where+ processHref :: String -> IOSArrow XmlTree XmlTree+ processHref uri+ = processChildren+ ( choiceA+ [ ( isElem >>> hasAttr "xml:base" )+ :-> ( ifA ( isExternalRefInclude >>> hasRngAttrHref )+ ( -- The value of the href attribute is transformed by+ -- escaping disallowed characters+ (processAttrl (changeAttrValue escapeURI `when` isRngAttrHref))+ >>> -- compute the new base uri from the old uri and the href attribute+ (addAttr "href" $< (absURI "href" $< (absURI "xml:base" uri)))+ >>>+ (processHref $< absURI "xml:base" uri)+ ) -- element without a href attribute, just compute the new base uri+ (processHref $< absURI "xml:base" uri)+ )+ , ( isExternalRefInclude >>> hasRngAttrHref )+ :-> ( -- The value of the href attribute is transformed by+ -- escaping disallowed characters+ (processAttrl (changeAttrValue escapeURI `when` isRngAttrHref))+ >>>+ (addAttr "href" $< absURI "href" uri)+ )+ , this+ :-> processHref uri+ ]+ )+ where+ absURI :: String -> String -> IOSArrow XmlTree String+ absURI attrName u+ = ( getAttrValue attrName+ >>>+ arr (\ a -> fromMaybe "" (expandURIString a u))+ >>> -- the uri should not have a fragment-identifier (4.5)+ ( arr ("illegal URI, fragment identifier not allowed: " ++)+ `whenNot`+ (getFragmentFromURI >>> isA null)+ )+ )++ processEnvNames :: NsEnv -> IOSArrow XmlTree XmlTree+ processEnvNames env+ = ( ( (replaceQNames env $< getAttrValue "name")+ `when`+ ( (isRngElement `orElse` isRngAttribute)+ >>>+ getRngAttrName+ >>>+ isA (elem ':')+ )+ )+ >>>+ ( (addAttrl (getBaseURI >>> createAttrL))+ `when`+ isRngValue+ )+ )+ where+ createAttrL :: IOSArrow String XmlTree+ createAttrL+ = setBaseUri &&& constA (map createAttr env) >>> arr2L (:)+ where++ createAttr :: (XName, XName) -> XmlTree+ createAttr (pre, uri)+ = XN.mkAttr (mkName nm) [XN.mkText (show uri)]+ where+ nm | isNullXName pre = "RelaxContextDefault"+ | otherwise = contextAttributes ++ show pre++ setBaseUri :: IOSArrow String XmlTree+ setBaseUri = mkAttr (mkName contextBaseAttr) (txt $< this)++ replaceQNames :: NsEnv -> String -> IOSArrow XmlTree XmlTree+ replaceQNames e name+ | isNothing uri+ = mkRelaxError "" ( "No Namespace-Mapping for the prefix " ++ show pre +++ " in the Context of Element: " ++ show name+ )+ | otherwise+ = addAttr "name" ( "{" ++ (show . fromJust $ uri) ++ "}" ++ local )+ where+ (pre, local') = span (/= ':') name+ local = tail local'+ uri :: Maybe XName+ uri = lookup (newXName pre) e++ -- The value of the added datatypeLibrary attribute is the value of the+ -- datatypeLibrary attribute of the nearest ancestor element that+ -- has a datatypeLibrary attribute, or the empty string+ -- if there is no such ancestor.+ processdatatypeLib :: (ArrowXml a) => String -> a XmlTree XmlTree+ processdatatypeLib lib+ = processChildren $+ choiceA+ [ ( isElem >>> hasRngAttrDatatypeLibrary+ -- set the new datatypeLibrary value+ )+ :->+ ( processdatatypeLib $< getRngAttrDatatypeLibrary )+ , ( (isRngData `orElse` isRngValue)+ >>>+ neg hasRngAttrDatatypeLibrary+ -- add a datatypeLibrary attribute+ )+ :->+ ( addAttr "datatypeLibrary" lib >>> processdatatypeLib lib )+ , this+ :->+ processdatatypeLib lib+ ]++-- ------------------------------------------------------------+++{-+- 4.5. href attribute+ - see simplificationStep1+- 4.6. externalRef element+ - An element is constructed using the URI reference+ that is the value of href attribute+ - This element must match the syntax for pattern.+ - The element is transformed by recursively applying the rules from+ this subsection and from previous subsections of this section.+ - This must not result in a loop.+ - Any ns attribute on the externalRef element is transferred+ to the referenced element if the referenced element does+ not already have an ns attribute.+ - The externalRef element is then replaced by the referenced element.+- 4.7. include element+ - An element is constructed using the URI reference that is the+ value of href attribute+ - This element must be a grammar element, matching the syntax for grammar.+ - This grammar element is transformed by recursively applying the rules+ from this subsection and from previous subsections of this section.+ - This must not result in a loop.++ - If the include element has a start component, then the grammar element+ must have a start component.+ - If the include element has a start component, then all start components+ are removed from the grammar element.+ - If the include element has a define component, then the grammar element+ must have a define component with the same name.+ - For every define component of the include element, all define components+ with the same name are removed from the grammar element.++ - The include element is transformed into a div element.+ - The attributes of the div element are the attributes of the+ include element other than the href attribute.+ - The children of the div element are the grammar element+ - The grammar element is then renamed to div.+-}++simplificationStep2 :: Attributes -> Bool -> Bool -> [Uri] -> [Uri] -> IOSArrow XmlTree XmlTree+simplificationStep2 readOptions validateExternalRef validateInclude extHRefs includeHRefs =+ ( processTopDown (+ ( (importExternalRef $<< (getRngAttrNs &&& getRngAttrHref))+ `when`+ isRngExternalRef+ )+ >>>+ ( (importInclude $< getAttrValue "href")+ `when`+ isRngInclude+ )+ )+ ) `when` collectErrors+ where+ importExternalRef :: String -> String -> IOSArrow XmlTree XmlTree+ importExternalRef ns href+ = ifA ( neg $ constA href+ >>> getPathFromURI+ >>> ( isA (not . ("illegal URI" `isPrefixOf`))+ `guards`+ isIOA doesFileExist+ )+ )+ ( mkRelaxError ""+ ( show href +++ ": can't read URI, referenced in externalRef-Pattern"+ )+ )+ ( ifP (const $ elem href extHRefs)+ -- if the referenced name already exists in the list of processed ref attributes+ -- we have found a loop+ ( mkRelaxError ""+ ( "loop in externalRef-Pattern, " +++ formatStringListArr (reverse $ href:extHRefs)+ )+ )+ ( ifA ( if validateExternalRef -- if validation parameters are set+ then validateDocWithRelax S.relaxSchemaArrow [] href -- the referenced schema is validated with respect to+ else none -- the Relax NG specification+ )+ ( mkRelaxError ""+ ( "The content of the schema " ++ show href +++ ", referenced in externalRef does not " +++ "match the syntax for pattern"+ )+ )+ ( readForRelax readOptions href+ >>>+ simplificationStep1 -- perform the transformations from previous steps+ >>>+ simplificationStep2 readOptions validateExternalRef validateInclude (href:extHRefs) includeHRefs+ >>>+ getChildren -- remove the root node+ >>>+ ( -- Any ns attribute on the externalRef element+ -- is transferred to the referenced element+ addAttr "ns" ns+ `when`+ (getRngAttrNs >>> isA (\a -> a == "" && ns /= ""))+ )+ )+ )+ )++ importInclude :: String -> IOSArrow XmlTree XmlTree+ importInclude href+ = ifA ( -- test whether the referenced schema exists+ neg $ constA href >>> getPathFromURI >>> isIOA doesFileExist+ )+ ( mkRelaxError ""+ ( "Can't read " ++ show href +++ ", referenced in include-Pattern"+ )+ )+ ( ifP (const $ elem href includeHRefs)+ -- if the referenced name still exists in the list of processed+ -- ref attributes we have found a loop+ ( mkRelaxError ""+ ( "loop in include-Pattern, " +++ formatStringListArr (reverse $ href:includeHRefs)+ )+ )+ ( ifA ( if validateInclude -- if the parameter is set+ then validateDocWithRelax SG.relaxSchemaArrow [] href -- the referenced schema is validated with respect to+ else none -- the Relax NG grammar element+ )+ ( mkRelaxError ""+ ( "The content of the schema " ++ show href +++ ", referenced in include does not match " +++ "the syntax for grammar"+ )+ )+ ( processInclude href $< ( readForRelax readOptions href+ >>>+ simplificationStep1 -- perform the transformations from previous steps+ >>>+ simplificationStep2 readOptions validateExternalRef validateInclude extHRefs (href:includeHRefs)+ >>>+ getChildren -- remove the root node+ )+ )+ )+ )++ processInclude :: String -> XmlTree -> IOSArrow XmlTree XmlTree+ processInclude href newDoc+ = -- The include element is transformed into a div element.+ setRngNameDiv+ >>>+ -- The attributes of the div element are the attributes of+ -- the include element other than the href attribute.+ removeAttr "href"+ >>>+ checkInclude href newDoc+++ insertNewDoc :: XmlTree -> Bool -> [String] -> IOSArrow XmlTree XmlTree+ insertNewDoc newDoc hasStart defNames+ = insertChildrenAt 0 $+ constA newDoc+ >>>+ -- If the include element has a start component, then all start components+ -- are removed from the grammar element.+ (removeStartComponent `whenP` (const hasStart))+ >>>+ -- For every define component of the include element, all define components+ -- with the same name are removed from the grammar element.+ ((removeDefineComponent defNames) `whenP` (const $ defNames /= []))+ >>>+ -- The grammar element is then renamed to div.+ setRngNameDiv+++ checkInclude :: String -> XmlTree -> IOSArrow XmlTree XmlTree+ checkInclude href newDoc+ = ifA ( -- If the include element has a start component, then the grammar element+ -- must have a start component.+ hasStartComponent &&& (constA newDoc >>> hasStartComponent)+ >>>+ isA (\ (a, b) -> if a then b else True)+ )+ ( ifA ( -- If the include element has a define component, then the grammar element+ -- must have a define component with the same name.+ getDefineComponents &&& (constA newDoc >>> getDefineComponents)+ >>>+ isA (\ (a, b) -> (diff a b) == [])+ )+ (insertNewDoc newDoc $<< hasStartComponent &&& getDefineComponents)+ ( mkRelaxError ""+ ( "Define-pattern missing in schema " ++ show href +++ ", referenced in include-pattern"+ )+ )+ )+ ( mkRelaxError ""+ ( "Grammar-element without a start-pattern in schema " +++ show href ++ ", referenced in include-pattern"+ )+ )+ where+ diff a b = (noDoubles a) \\ (noDoubles b)++ removeStartComponent :: IOSArrow XmlTree XmlTree+ removeStartComponent+ = processChildren $+ choiceA [+ isRngStart :-> none,+ isRngDiv :-> removeStartComponent,+ this :-> this+ ]++ removeDefineComponent :: [String] -> IOSArrow XmlTree XmlTree+ removeDefineComponent defNames+ = processChildren $+ choiceA [+ ( isRngDefine+ >>>+ getRngAttrName+ >>>+ isA (\n -> elem n defNames)) :-> none,+ (isElem >>> getName >>> isA (== "div")) :-> (removeDefineComponent defNames),+ (constA "foo" >>> isA (== "foo")) :-> this+ ]++ hasStartComponent :: IOSArrow XmlTree Bool+ hasStartComponent = listA hasStartComponent' >>> arr (any id)+ where+ hasStartComponent' :: IOSArrow XmlTree Bool+ hasStartComponent'+ = getChildren+ >>>+ choiceA [+ isRngStart :-> (constA True),+ isRngDiv :-> hasStartComponent',+ this :-> (constA False)+ ]++ getDefineComponents :: IOSArrow XmlTree [String]+ getDefineComponents = listA getDefineComponents'+ >>>+ arr (\xs -> [x | x <- xs, x /= ""])+ where+ getDefineComponents' :: IOSArrow XmlTree String+ getDefineComponents'+ = getChildren+ >>>+ choiceA+ [ isRngDefine :-> getRngAttrName+ , isRngDiv :-> getDefineComponents'+ , this :-> constA ""+ ]+++-- ------------------------------------------------------------+++{-+- 4.8. name attribute of element and attribute elements+ - The name attribute on an element or attribute element+ is transformed into a name child element.+ - If an attribute element has a name attribute but no ns attribute,+ then an ns="" attribute is added to the name child element.+- 4.9. ns attribute+ - For any name, nsName or value element that does not have+ an ns attribute, an ns attribute is added.+ - any ns attribute that is on an element other than name,+ nsName or value is removed.+- 4.10. QNames+ - For any name element containing a prefix, the prefix is removed+ and an ns attribute is added replacing any existing ns attribute.+ - The value of the added ns attribute is the value to which the+ namespace map of the context of the name element maps the prefix.+ - The context must have a mapping for the prefix.+-}+simplificationStep3 :: IOSArrow XmlTree XmlTree+simplificationStep3 =+ ( processTopDown (+ ( -- 4.8 The name attribute on an element or attribute+ -- element is transformed into a name child element+ ( insertChildrenAt 0 (mkRngName none (txt $< getRngAttrName))+ )+ >>>+ ( -- 4.8 If an attribute element has a name attribute but no ns attribute,+ -- then an ns="" attribute is added to the name child element+ (processChildren (addAttr "ns" "" `when` isRngName))+ `when`+ (isRngAttribute >>> hasRngAttrName >>> neg hasRngAttrNs)+ )+ >>>+ removeAttr "name"+ )+ `when`+ ( (isRngElement `orElse` isRngAttribute) >>> hasRngAttrName )+ )+ >>>+ -- 4.9 For any name, nsName or value element that does not have+ -- an ns attribute, an ns attribute is added.+ processnsAttribute ""+ >>>+ processTopDown (+ ( -- 4.9 any ns attribute that is on an element other than name,+ -- nsName or value is removed.+ (removeAttr "ns")+ `when`+ (isElem >>> neg (isRngName `orElse` isRngNsName `orElse` isRngValue))+ )+ >>>+ ( -- 4.10 For any name element containing a prefix, the prefix is removed and an ns attribute+ -- is added replacing any existing ns attribute.+ (replaceNameAttr $< (getChildren >>> isText >>> getText))+ `when`+ isRngName+ )+ )+ ) `when` collectErrors+ where+ replaceNameAttr :: (ArrowXml a) => String -> a XmlTree XmlTree+ replaceNameAttr name+ = (addAttr "ns" pre >>> processChildren (changeText $ const local))+ `whenP`+ (const $ elem '}' name)+ where+ (pre', local') = span (/= '}') name+ pre = tail pre'+ local = tail local'++ processnsAttribute :: String -> IOSArrow XmlTree XmlTree+ processnsAttribute name+ = processChildren $+ choiceA [+ -- set the new ns attribute value+ (isElem >>> hasRngAttrNs)+ :-> (processnsAttribute $< getRngAttrNs),+ -- For any name, nsName or value element that does not have+ -- an ns attribute, an ns attribute is added.+ ( isNameNsNameValue >>> neg hasRngAttrNs)+ :-> (addAttr "ns" name >>> processnsAttribute name),+ this :-> (processnsAttribute name)+ ]+++-- ------------------------------------------------------------+++{-+- 4.11 Each div element is replaced by its children+- 4.12 Number of child elements+ - A define, oneOrMore, zeroOrMore, optional, list or mixed element+ is transformed so that it has exactly one child element+ - An element element is transformed so that it has exactly two child elements+ - A except element is transformed so that it has exactly one child element+ - If an attribute element has only one child element (a name class), then a text element is added.+ - A choice, group or interleave element is transformed so that it has exactly two child elements.+- 4.13 A mixed element is transformed into an interleaving with a text element+- 4.14 An optional element is transformed into a choice with empty+- 4.15 A zeroOrMore element is transformed into a choice between oneOrMore and empty+- 4.16. Constraints: no transformation is performed, but various constraints are checked.+ - An except element that is a child of an anyName element must not have any anyName descendant elements.+ - An except element that is a child of an nsName element must not have any nsName or anyName+ descendant elements.+ - A name element that occurs as the first child of an attribute element or as the descendant of the+ first child of an attribute element and that has an ns attribute with value equal to the empty+ string must not have content equal to xmlns.+ - A name or nsName element that occurs as the first child of an attribute element or as the+ descendant of the first child of an attribute element must not have an ns attribute with+ value http://www.w3.org/2000/xmlns.+ - A data or value element must be correct in its use of datatypes.+-}+simplificationStep4 :: IOSArrow XmlTree XmlTree+simplificationStep4 =+ ( processTopDown (+ ( -- Each div element is replaced by its children.+ (getChildren >>> simplificationStep4)+ `when`+ isRngDiv+ )+ >>>+ ( -- A define, oneOrMore, zeroOrMore, optional, list or mixed element+ -- is transformed so that it has exactly one child element+ ( replaceChildren+ ( mkRngGroup+ (setChangesAttr $< (getName >>> arr ("group-Pattern: " ++)))+ getChildren+ )+ )+ `when`+ ( isDefineOneOrMoreZeroOrMoreOptionalListMixed+ >>>+ noOfChildren (> 1)+ )+ )+ >>>+ ( -- An element element is transformed so that it has exactly two child elements+ ( replaceChildren+ ( ( getChildren >>> isNameAnyNameNsName )+ <+>+ ( mkRngGroup none+ ( getChildren+ >>>+ neg isNameAnyNameNsName+ )+ )+ )+ )+ `when`+ ( isRngElement >>> noOfChildren (> 2) )+ )+ >>>+ ( -- A except element is transformed so that it has exactly one child element.+ replaceChildren ( mkRngChoice none getChildren )+ `when`+ ( isRngExcept >>> noOfChildren (> 1) )+ )+ >>>+ ( -- If an attribute element has only one child element+ -- (a name class), then a text element is added.+ insertChildrenAt 1 (mkRngText none)+ `when`+ ( isRngAttribute >>> noOfChildren (== 1) )+ )+ >>>+ ( -- A choice, group or interleave element is transformed so+ -- that it has exactly two child elements.+ ((wrapPattern2Two $< getName) >>> simplificationStep4)+ `when`+ ( isChoiceGroupInterleave+ >>>+ noOfChildren (\ i -> i > 2 || i == 1)+ )+ )+ >>>+ ( -- A mixed element is transformed into an interleaving with a text element+ ( mkRngInterleave+ ( setChangesAttr "mixed is transformed into an interleave" )+ ( getChildren+ <+>+ mkRngText+ ( setChangesAttr ( "new text-Pattern: mixed is transformed into " +++ " an interleave with text"+ )+ )+ )+ )+ `when`+ isRngMixed+ )+ >>>+ ( -- An optional element is transformed into a choice with empty+ ( mkRngChoice+ ( setChangesAttr "optional is transformed into a choice" )+ ( getChildren+ <+>+ mkRngEmpty+ ( setChangesAttr ( "new empty-Pattern: optional is transformed " +++ " into a choice with empty"+ )+ )+ )+ )+ `when`+ isRngOptional+ )+ >>>+ ( -- A zeroOrMore element is transformed into a choice between oneOrMore and empty+ ( mkRngChoice+ ( setChangesAttr "zeroOrMore is transformed into a choice" )+ ( ( mkRngOneOrMore+ ( setChangesAttr ( "zeroOrMore is transformed into a " +++ "choice between oneOrMore and empty"+ )+ )+ getChildren+ )+ <+>+ ( mkRngEmpty+ ( setChangesAttr ( "new empty-Pattern: zeroOrMore is transformed " +++ "into a choice between oneOrMore and empty"+ )+ )+ )+ )+ )+ `when`+ isRngZeroOrMore+ )+ )+ ) `when` collectErrors+++-- ------------------------------------------------------------+++restrictionsStep1 :: IOSArrow XmlTree XmlTree+restrictionsStep1 =+ ( processTopDown (+ ( ( mkRelaxError ""+ ( "An except element that is a child of an anyName " +++ "element must not have any anyName descendant elements"+ )+ )+ `when`+ ( isRngAnyName+ >>>+ getChildren+ >>>+ isRngExcept+ >>>+ deep isRngAnyName+ )+ )+ >>>+ ( ( mkRelaxError ""+ ( "An except element that is a child of an nsName element " +++ "must not have any nsName or anyName descendant elements."+ )+ )+ `when`+ ( isRngNsName+ >>>+ getChildren+ >>>+ isRngExcept+ >>>+ deep (isRngAnyName `orElse` isRngNsName)+ )+ )+ >>>+ ( ( mkRelaxError ""+ ( "A name element that occurs as the first child or descendant of " +++ "an attribute and has an ns attribute with an empty value must " +++ "not have content equal to \"xmlns\""+ )+ )+ `when`+ ( isRngAttribute+ >>>+ firstChild+ >>>+ ( multi (isRngName >>> hasRngAttrNs) )+ >>>+ ( ( getRngAttrNs >>> isA null)+ `guards`+ (getChildren >>> getText >>> isA (== "xmlns"))+ )+ )+ )+ >>>+ ( ( mkRelaxError ""+ ( "A name or nsName element that occurs as the first child or " +++ "descendant of an attribute must not have an ns attribute " +++ "with value http://www.w3.org/2000/xmlns"+ )+ )+ `when`+ ( isRngAttribute+ >>>+ firstChild+ >>>+ ( multi (isNameNsName >>> hasRngAttrNs) )+ >>>+ getRngAttrNs+ >>>+ isA (compareURI xmlnsNamespace)+ )+ )+ >>> -- A data or value element must be correct in its use of datatypes.+ ( ( checkDatatype $<< getRngAttrDatatypeLibrary &&& getRngAttrType )+ `when`+ ( isRngData `orElse` isRngValue )+ )+ )+ ) `when` collectErrors+ where++ -- the datatypeLibrary attribute must identify a valid datatype library++ checkDatatype :: Uri -> DatatypeName -> IOSArrow XmlTree XmlTree+ checkDatatype libName typeName+ = ifP (const $ elem libName $ map fst datatypeLibraries)+ ( checkType libName typeName allowedDataTypes )+ ( mkRelaxError ""+ ( "DatatypeLibrary " ++ show libName ++ " not found" )+ )+ where+ DTC _ _ allowedDataTypes = fromJust $ lookup libName datatypeLibraries++ -- the type attribute must identify a datatype within the datatype library identified+ -- by the value of the datatypeLibrary attribute.++ checkType :: Uri -> DatatypeName -> AllowedDatatypes -> IOSArrow XmlTree XmlTree+ checkType libName typeName allowedTypes+ = ifP (const $ elem typeName $ map fst allowedTypes)+ ( checkParams typeName libName getParams $<+ ( listA (getChildren >>> isRngParam >>> getRngAttrName) )+ )+ ( mkRelaxError ""+ ( "Datatype " ++ show typeName +++ " not declared for DatatypeLibrary " ++ show libName+ )+ )+ where+ getParams = fromJust $ lookup typeName allowedTypes++ -- For a data element, the parameter list must be one that is allowed by the datatype++ checkParams :: DatatypeName -> Uri -> AllowedParams -> [ParamName] -> IOSArrow XmlTree XmlTree+ checkParams typeName libName allowedParams paramNames+ = ( mkRelaxError ""+ ( "Param(s): " ++ formatStringListQuot diff +++ " not allowed for Datatype " ++ show typeName +++ " in Library " +++ show ( if null libName+ then relaxNamespace+ else libName+ )+ )+ )+ `when`+ ( isRngData >>> isA (const $ diff /= []) )+ where+ diff = filter (\param -> not $ elem param allowedParams) paramNames+++-- ------------------------------------------------------------+++{-+- 4.17. combine attribute+ - For each grammar element, all define elements with the same name are combined together.+ - Similarly, for each grammar element all start elements are combined together.+- 4.18. grammar element+ - A grammar must have a start child element.+ - Transform the top-level pattern p into <grammar><start>p</start></grammar>.+ - Rename define elements so that no two define elements anywhere in the schema+ have the same name. To rename a define element, change the value of its name+ attribute and change the value of the name attribute of all ref and parentRef+ elements that refer to that define element.+ - Move all define elements to be children of the top-level grammar element+ - Replace each nested grammar element by the child of its start element+ - Rename each parentRef element to ref.+-}+simplificationStep5 :: IOSArrow XmlTree XmlTree+simplificationStep5+ = ( processTopDown+ ( ( ( ( (deep isRngRelaxError)+ <+>+ ( mkRelaxError "" "A grammar must have a start child element" )+ )+ `when`+ (neg (getChildren >>> isRngStart))+ )+ >>>+ -- For each grammar element, all define elements with the same+ -- name are combined together.+ ( combinePatternList "define" $< (getPatternNamesInGrammar "define" >>> arr nub) )+ >>>+ -- Similarly, for each grammar element all start elements+ -- are combined together.+ ( combinePatternList "start" $< (getPatternNamesInGrammar "start" >>> arr nub) )+ )+ `when`+ isRngGrammar+ )+ >>>+ ( -- transform the top-level pattern p into <grammar><start>p</start></grammar>.+ ( replaceChildren+ ( mkRngGrammar none+ ( mkRngStart none getChildren )+ )+ )+ `when`+ neg (getChildren >>> isRngGrammar)+ )+ >>>+ ( renameDefines $<<+ ( getPatternNamesInGrammar "define"+ >>>+ (createUniqueNames $< (getAndSetCounter "define_id" >>> arr read))+ &&&+ constA []+ )+ )+ >>>+ -- Move all define elements to be children of the top-level grammar element+ ( processChildren+ ( -- root node+ processChildren+ ( -- the first grammar pattern remains unchanged+ ( deleteAllDefines+ <+>+ ( getAllDefines >>> processChildren deleteAllDefines )+ )+ >>>+ processTopDown+ ( ( -- Replace each nested grammar element by the child of its start element+ ( getChildren >>> isRngStart >>> getChildren )+ `when`+ isRngGrammar+ )+ >>>+ ( -- Rename each parentRef element to ref.+ ( setRngNameRef+ `when`+ isRngParentRef+ )+ )+ )+ )+ )+ )+ ) `when` collectErrors+ where+ getPatternNamesInGrammar :: (ArrowXml a) => String -> a XmlTree [String]+ getPatternNamesInGrammar pattern+ = processChildren+ ( processTopDown ( none `when` isRngGrammar ) )+ >>>+ listA ( (multi (isElem >>> hasRngName pattern))+ >>>+ getRngAttrName+ )++ createUniqueNames :: Int -> IOSArrow [String] RefList+ createUniqueNames num+ = arr (\ l -> unique l num)+ >>>+ perform (setParamInt "define_id" $< arr (max num . getNextValue))+ where+ unique :: [String] -> Int -> RefList+ unique [] _ = []+ unique (x:xs) num' = (x, (show num')):(unique xs (num'+1))+ getNextValue :: RefList -> Int+ getNextValue [] = 0+ getNextValue rl = maximum (map (read . snd) rl) + 1++ renameDefines :: RefList -> RefList -> IOSArrow XmlTree XmlTree+ renameDefines ref parentRef+ = processChildren+ ( choiceA+ [ isRngDefine+ :-> ( -- the original name is needed for error messages+ addAttr defineOrigName $< getRngAttrName+ >>>+ -- rename the define-pattern+ -- the new name is looked up in the ref table+ addAttr "name" $< ( getRngAttrName+ >>>+ arr (\n -> fromJust $ lookup n ref)+ )+ >>>+ renameDefines ref parentRef+ )+ , isRngGrammar+ :-> ( renameDefines $<< ( ( -- compute all define names in the grammar+ getPatternNamesInGrammar "define"+ >>>+ -- create a new (unique) name for all define names+ (createUniqueNames $< (getParamInt 0 "define_id"))+ )+ &&&+ -- set the old ref list to be the new parentRef list+ constA ref+ )+ )+ , isRngRef+ :-> ( ifA ( getRngAttrName+ >>>+ isA (\name -> (elem name (map fst ref)))+ )+ ( -- the original name is needed for error messages+ addAttr defineOrigName $< getRngAttrName+ >>>+ -- rename the ref-pattern+ -- the new name is looked up in the ref table+ addAttr "name" $< ( getRngAttrName+ >>>+ arr (\n -> fromJust $ lookup n ref)+ )+ )+ ( -- the referenced pattern does not exist in the schema+ mkRelaxError "" $< ( getRngAttrName+ >>>+ arr (\ n -> ( "Define-Pattern with name " ++ show n +++ " referenced in ref-Pattern not " +++ "found in schema"+ )+ )+ )+ )+ )+ , isRngParentRef -- same as ref, but the parentRef list is used+ :-> ( ifA ( getRngAttrName+ >>>+ isA (\name -> (elem name (map fst parentRef)))+ )+ ( addAttr defineOrigName $< getRngAttrName+ >>>+ addAttr "name" $< ( getRngAttrName+ >>>+ arr (\n -> fromJust $ lookup n parentRef)+ )+ )+ ( mkRelaxError "" $<+ ( getRngAttrName+ >>>+ arr (\ n -> ( "Define-Pattern with name " ++ show n +++ " referenced in parentRef-Pattern " +++ "not found in schema"+ )+ )+ )+ )+ )+ , this+ :-> renameDefines ref parentRef+ ]+ )+++ getAllDefines :: IOSArrow XmlTree XmlTree+ getAllDefines = multi isRngDefine++ deleteAllDefines :: IOSArrow XmlTree XmlTree+ deleteAllDefines = processTopDown $ none `when` isRngDefine++ combinePatternList :: String -> [String] -> IOSArrow XmlTree XmlTree+ combinePatternList _ [] = this+ combinePatternList pattern (x:xs)+ = (replaceChildren $ combinePattern pattern x)+ >>>+ combinePatternList pattern xs++ -- combine a define- or start-pattern (first parameter) with a+ -- specific name (second parameter)+ combinePattern :: String -> String -> IOSArrow XmlTree XmlTree+ combinePattern pattern name+ = createPatternElems pattern name+ <+>+ (getChildren >>> deletePatternElems pattern name)++ createPatternElems :: String -> String -> IOSArrow XmlTree XmlTree+ createPatternElems pattern name+ = ( ( (listA (getElems pattern name >>> getRngAttrCombine))+ >>>+ checkPatternCombine pattern name+ )+ -- After determining this unique value, the combine attributes are removed.+ &&&+ (listA (getElems pattern name >>> removeAttr "combine")))+ >>> -- ((errorCode::Int,errorMessage::String), result::XmlTrees)+ choiceA+ [ isA (\ ((code,_) , _) -> code == 0)+ :->+ (mkRelaxError "" $< arr (snd . fst))+ , isA (\ ((code,str) , _) -> code == 1 && str == "")+ :->+ arrL snd+ , isA (\ ((code,str) , _) -> code == 1 && str /= "")+ :->+ ( createPatternElem pattern name $<<+ ( arr (snd . fst) &&& (arr snd) )+ )+ , this+ :->+ ( mkRelaxError ""+ ( "Can't create Pattern: " ++ show pattern +++ " with name " ++ show name ++ " in createPatternElems"+ )+ )+ ]++ createPatternElem :: (ArrowXml a) => String -> String -> String -> XmlTrees -> a n XmlTree+ createPatternElem pattern name combine trees+ = mkRngElement pattern (mkAttr (mkName "name") (txt name))+ ( ( mkRngElement combine none+ (arrL (const trees) >>> getChildren)+ )+ >>>+ wrapPattern2Two combine+ )++ checkPatternCombine :: (ArrowXml a) => String -> String -> a [String] (Int, String)+ checkPatternCombine pattern name+ = choiceA+ [ -- just one pattern with that name -> ok, no combine is needed+ (isA (\ cl -> length cl == 1))+ :->+ constA (1, "")+ , (isA (\ cl -> (length $ elemIndices "" cl) > 1))+ :->+ constA ( 0+ , "More than one " ++ pattern ++ "-Pattern: " ++ show name +++ " without an combine-attribute in the same grammar"+ )+ , (isA (\ cl -> (length $ nub $ deleteBy (==) "" cl) > 1))+ :->+ arr (\ cl -> ( 0+ , "Different combine-Attributes: " +++ (formatStringListQuot $ noDoubles cl) +++ " for the " ++ pattern ++ "-Pattern " +++ show name ++ " in the same grammar"+ )+ )+ , -- ok -> combine value is returned+ this+ :->+ arr (\ cl -> (1, fromJust $ find (/= "") cl))+ ]++ isElemWithNameValue :: (ArrowXml a) => String -> String -> a XmlTree XmlTree+ isElemWithNameValue ename nvalue+ = ( isElem+ >>>+ hasRngName ename+ >>>+ getRngAttrName+ >>>+ isA (== nvalue)+ )+ `guards` this++ getElems :: (ArrowXml a) => String -> String -> a XmlTree XmlTree+ getElems pattern name+ = getChildren+ >>>+ choiceA+ [ isElemWithNameValue pattern name+ :->+ (this <+> getElems pattern name)+ , isRngGrammar+ :-> none+ , this+ :->+ getElems pattern name+ ]++ deletePatternElems :: (ArrowXml a) => String -> String -> a XmlTree XmlTree+ deletePatternElems pattern name+ = choiceA+ [ isElemWithNameValue pattern name+ :->+ none+ , isRngGrammar+ :-> this+ , this+ :->+ processChildren ( deletePatternElems pattern name )+ ]+++-- ------------------------------------------------------------+++{-+- 4.19. define and ref elements+ - Remove any define element that is not reachable.+ - Now, for each element element that is not the child of a define element,+ add a define element to the grammar element,+ and replace the element element by a ref element referring+ to the added define element.+ - For each ref element that is expandable and is a descendant+ of a start element or an element element, expand it by replacing+ the ref element by the child of the define element to which it refers+ - This must not result in a loop.+ - Remove any define element whose child is not an element element.+-}+simplificationStep6 :: IOSArrow XmlTree XmlTree+simplificationStep6 =+ ( -- Remove any define element that is not reachable.+ (removeUnreachableDefines $<<< getAllDeepDefines+ &&&+ constA []+ &&&+ getRefsFromStartPattern+ )+ >>>+ -- for each element element that is not the child of a define element,+ -- add a define element to the grammar element,+ ( processElements False+ >>>+ processChildren (insertChildrenAt 1 (getParam "elementTable"))+ )+ >>>+ -- For each ref element that is expandable...+ -- Remove any define element whose child is not an element element+ (replaceExpandableRefs [] $< getExpandableDefines >>> deleteExpandableDefines)+ ) `when` collectErrors+ where+ replaceExpandableRefs :: RefList -> Env -> IOSArrow XmlTree XmlTree+ replaceExpandableRefs foundNames defTable+ = choiceA [+ isRngRef+ :-> (ifA ( getRngAttrName+ >>>+ isA (\name -> elem name (map fst foundNames))+ )+ -- we have found a loop if the name is in the list+ (mkRelaxError "" $< ( getAttrValue defineOrigName+ >>>+ arr (\ n -> ( "Recursion in ref-Pattern: " +++ formatStringListArr (reverse $ (n:) $ map snd foundNames)+ )+ )+ )+ )+ (replaceRef $<< getRngAttrName &&& getAttrValue defineOrigName)+ ),+ this :-> (processChildren $ replaceExpandableRefs foundNames defTable)+ ]+ where+ replaceRef :: NewName -> OldName -> IOSArrow XmlTree XmlTree+ replaceRef name oldname+ = ( constA (fromJust $ lookup name defTable)+ >>>+ getChildren+ >>>+ replaceExpandableRefs ((name,oldname):foundNames) defTable+ )+ `whenP`+ (const $ elem name $ map fst defTable)+++ processElements :: Bool -> IOSArrow XmlTree XmlTree+ processElements parentIsDefine+ = processChildren+ ( choiceA+ [ isRngElement+ :-> ( ifP (const parentIsDefine)+ (processElements False)+ ( processElements' $<< ( getAndSetCounter "define_id"+ &&&+ getDefineName+ )+ )+ )+ , isRngDefine+ :-> processElements True+ , this+ :-> processElements False+ ])+ where+ getDefineName :: IOSArrow XmlTree String+ getDefineName+ = firstChild+ >>>+ fromLA createNameClass+ >>>+ arr show++ processElements' :: NewName -> OldName -> IOSArrow XmlTree XmlTree+ processElements' name oldname+ = storeElement name oldname+ >>>+ mkRngRef (createAttr name oldname) none++ storeElement :: NewName -> OldName -> IOSArrow XmlTree XmlTree+ storeElement name oldname+ = perform $+ ( mkRngDefine+ (createAttr name oldname) (processElements False)+ )+ &&&+ (listA $ getParam "elementTable")+ >>>+ arr2 (:)+ >>>+ setParamList "elementTable"++ createAttr :: NewName -> OldName -> IOSArrow XmlTree XmlTree+ createAttr name oldname+ = mkAttr (mkName "name") (txt name)+ <+>+ mkAttr (mkName defineOrigName) (txt $ "created for element " ++ oldname)++ getExpandableDefines :: (ArrowXml a) => a XmlTree Env+ getExpandableDefines+ = listA $ (multi ( ( isRngDefine+ >>>+ getChildren+ >>>+ neg isRngElement+ )+ `guards`+ this+ )+ )+ >>>+ (getRngAttrName &&& this)++ deleteExpandableDefines :: (ArrowXml a) => a XmlTree XmlTree+ deleteExpandableDefines+ = processTopDown $ none+ `when`+ ( isRngDefine+ >>>+ getChildren+ >>>+ neg isRngElement+ )+++-- ------------------------------------------------------------+++{-+- 4.20. notAllowed element+ - An attribute, list, group, interleave, or oneOrMore element that has+ a notAllowed child element is transformed into a notAllowed element.+ - A choice element that has two notAllowed child elements+ is transformed into a notAllowed element+ - A choice element that has one notAllowed child element+ is transformed into its other child element.+ - An except element that has a notAllowed child element is removed.+ - The preceding transformations are applied repeatedly+ until none of them is applicable any more.+ - Any define element that is no longer reachable is removed.+- 4.21. empty element+ - A group, interleave or choice element that has two empty child+ elements is transformed into an empty element.+ - A group or interleave element that has one empty child element+ is transformed into its other child element.+ - A choice element whose second child element is an empty element+ is transformed by interchanging its two child elements.+ - A oneOrMore element that has an empty child element+ is transformed into an empty element.+ - The preceding transformations are applied repeatedly+ until none of them is applicable any more.+-}++simplificationStep7 :: IOSArrow XmlTree XmlTree+simplificationStep7+ = ( markTreeChanged 0 -- 0 = no changes, 1 = changes performed+ >>>+ processTopDownWithAttrl+ ( ( -- An attribute, list, group, interleave, or oneOrMore element that has a+ -- notAllowed child element is transformed into a notAllowed element.+ ( ( mkRngNotAllowed none none+ >>>+ markTreeChanged 1+ )+ `whenNot` -- keep all errors+ (deep isRngRelaxError)+ )+ `when`+ ( isAttributeListGroupInterleaveOneOrMore+ >>>+ getChildren+ >>>+ isRngNotAllowed+ )+ )+ >>>+ ( -- A choice element that has two notAllowed child elements is+ -- transformed into a notAllowed element+ ( mkRngNotAllowed none none+ >>>+ markTreeChanged 1+ )+ `when`+ ( isRngChoice+ >>>+ listA (getChildren >>> isRngNotAllowed)+ >>>+ isA (\s -> length s == 2)+ )+ )+ >>>+ ( -- A choice element that has one notAllowed child element is+ -- transformed into its other child element.+ ( getChildren >>> neg isRngNotAllowed+ >>>+ markTreeChanged 1+ )+ `when`+ ( isRngChoice >>> getChildren >>> isRngNotAllowed )+ )+ >>>+ ( -- An except element that has a notAllowed child element is removed.+ ( ( markTreeChanged 1+ >>>+ none+ )+ `whenNot` -- keep all errors+ deep isRngRelaxError+ )+ `when`+ ( isRngExcept >>> getChildren >>> isRngNotAllowed )+ )+ >>> -- transforming the empty pattern (4.21)+ ( -- A group, interleave or choice element that has two empty child elements+ -- is transformed into an empty element.+ ( mkRngEmpty none+ >>>+ markTreeChanged 1+ )+ `when`+ ( isChoiceGroupInterleave+ >>>+ listA (getChildren >>> isRngEmpty)+ >>>+ isA (\s -> length s == 2)+ )+ )+ >>>+ ( -- A group or interleave element that has one empty child element+ -- is transformed into its other child element.+ ( getChildren+ >>>+ neg isRngEmpty+ >>>+ markTreeChanged 1+ )+ `when`+ ( isGroupInterleave >>> getChildren >>> isRngEmpty )+ )+ >>>+ ( -- A choice element whose second child element is an empty element is transformed+ -- by interchanging its two child elements.+ changeChoiceChildren+ `when`+ ( isRngChoice >>> getChildren >>> isRngEmpty )+ )+ >>>+ ( -- A oneOrMore element that has an empty child element+ -- is transformed into an empty element.+ ( mkRngEmpty none+ >>>+ markTreeChanged 1+ )+ `when`+ ( isRngOneOrMore >>> getChildren >>> isRngEmpty )+ )+ )+ >>>+ -- The preceding transformations are applied repeatedly+ -- until none of them is applicable any more.+ ( simplificationStep7+ `when`+ hasTreeChanged+ )+ ) `when` collectErrors+ where+ changeChoiceChildren :: IOSArrow XmlTree XmlTree+ changeChoiceChildren+ = ( ( replaceChildren+ ( mkRngEmpty none+ <+>+ (getChildren >>> neg isRngEmpty)+ )+ >>>+ markTreeChanged 1+ )+ `when`+ ( single (getChildren >>> isElem) -- first child not "empty" elem+ >>>+ neg isRngEmpty+ )+ )++hasTreeChanged :: IOSArrow b Int+hasTreeChanged+ = getParamInt 0 "rng:changeTree"+ >>>+ isA (== 1)++markTreeChanged :: Int -> IOSArrow b b+markTreeChanged i+ = perform (setParamInt "rng:changeTree" i)++-- ------------------------------------------------------------+++simplificationStep8 :: IOSArrow XmlTree XmlTree+simplificationStep8 -- Remove any define element that is not reachable.+ = ( ( removeUnreachableDefines $<<<+ ( getAllDeepDefines+ &&&+ constA []+ &&&+ getRefsFromStartPattern+ )+ )+ `when` collectErrors+ )+++-- ------------------------------------------------------------+++restrictionsStep2 :: IOSArrow XmlTree XmlTree+restrictionsStep2 =+ processTopDown (+ choiceA [+-- 7.1.1. attribute pattern, the following paths are prohibited:+-- attribute//(ref | attribute)+ isRngAttribute :->+ ( ( deep isRngRelaxError+ <+>+ ( mkRelaxError $<< (getChangesAttr+ &&&+ ( listA ( getChildren+ >>>+ deep isAttributeRef+ >>>+ (getName &&& getChangesAttr >>> arr2 (++))+ )+ >>>+ arr (\n -> formatStringListPatt n +++ "Pattern not allowed as descendent(s)" +++ " of a attribute-Pattern"+ )+ )+ )+ )+ )+ `when`+ ( getChildren >>> deep isAttributeRef )+ ),++-- 7.1.2. oneOrMore pattern, the following paths are prohibited:+-- oneOrMore//(group | interleave)//attribute+ isRngOneOrMore :->+ ( ( deep isRngRelaxError+ <+>+ ( mkRelaxError $<< (getChangesAttr+ &&&+ ( listA ( getChildren+ >>>+ deep isGroupInterleave+ >>>+ (getName &&& getChangesAttr >>> arr2 (++))+ )+ &&&+ getChangesAttr+ >>>+ arr2 (\ n c -> ( formatStringListPatt n +++ "Pattern not allowed as descendent(s) " +++ "of a oneOrMore-Pattern" +++ (if null c then "" else " " ++ show c) +++ " followed by an attribute descendent"+ )+ )+ )+ )+ )+ )+ `when`+ ( getChildren >>> deep isGroupInterleave+ >>>+ getChildren >>> deep isRngAttribute+ )+ ),++-- 7.1.3. list pattern, the following paths are prohibited:+-- list//( list | ref | attribute | text | interleave)+ isRngList :->+ ( ( deep isRngRelaxError+ <+>+ ( mkRelaxError $<< (getChangesAttr+ &&&+ ( listA ( getChildren+ >>>+ deep isAttributeRefTextListInterleave+ >>>+ (getName &&& getChangesAttr >>> arr2 (++))+ )+ >>>+ arr (\n -> formatStringListPatt n +++ "Pattern not allowed as descendent(s) of a list-Pattern")+ )+ )+ )+ )+ `when`+ ( getChildren+ >>>+ deep isAttributeRefTextListInterleave+ )+ ),++-- 7.1.4. except in data pattern, the following paths are prohibited:+-- data/except//(attribute | ref | text | list | group | interleave | oneOrMore | empty)+ isRngData :->+ ( ( deep isRngRelaxError+ <+>+ ( mkRelaxError $<< (getChangesAttr+ &&&+ ( listA (getChildren+ >>>+ deep isAttributeRefTextListGroupInterleaveOneOrMoreEmpty+ >>>+ (getName &&& getChangesAttr >>> arr2 (++))+ )+ >>>+ arr (\n -> formatStringListPatt n +++ "Pattern not allowed as descendent(s) of a data/except-Pattern")+ )+ )+ )+ )+ `when`+ ( getChildren+ >>>+ isRngExcept+ >>>+ deep isAttributeRefTextListGroupInterleaveOneOrMoreEmpty+ )+ ),++-- 7.1.5. start element, the following paths are prohibited:+-- start//(attribute | data | value | text | list | group | interleave | oneOrMore | empty)+ isRngStart :->+ ( ( deep isRngRelaxError+ <+>+ ( mkRelaxError $<< (getChangesAttr+ &&&+ ( listA (getChildren+ >>>+ deep (checkElemName [ "attribute", "data", "value", "text", "list",+ "group", "interleave", "oneOrMore", "empty"])+ >>>+ (getName &&& getChangesAttr >>> arr2 (++))+ )+ >>>+ arr (\n -> formatStringListPatt n +++ "Pattern not allowed as descendent(s) of a start-Pattern")+ )+ )+ )+ )+ `when`+ ( getChildren+ >>>+ deep (checkElemName [ "attribute", "data", "value", "text", "list",+ "group", "interleave", "oneOrMore", "empty"])+ )+ ),++ this :-> this+ ]+ ) `when` collectErrors+++-- ------------------------------------------------------------+++restrictionsStep3 :: IOSArrow XmlTree XmlTree+restrictionsStep3+ = processTopDown+ ( ( deep isRngRelaxError+ <+>+ ( mkRelaxError "" $<+ ( -- getRngAttrName+ ( getChildren >>> isRngName >>> getChildren >>> getText )+ >>>+ arr (\ n -> ( "Content of element " ++ show n ++ " contains a pattern that can match " +++ "a child and a pattern that matches a single string"+ )+ )+ )+ )+ )+ `when`+ ( isRngElement+ >>>+ ( getChildren >>. (take 1 . reverse) )+ >>>+ getContentType >>> isA (== CTNone)+ )+ ) `when` collectErrors++++getContentType :: IOSArrow XmlTree ContentType+getContentType+ = choiceA+ [ isRngValue :-> (constA CTSimple)+ , isRngData :-> processData+ , isRngList :-> (constA CTSimple)+ , isRngText :-> (constA CTComplex)+ , isRngRef :-> (constA CTComplex)+ , isRngEmpty :-> (constA CTEmpty)+ , isRngAttribute :-> processAttribute+ , isRngGroup :-> processGroup+ , isRngInterleave :-> processInterleave+ , isRngOneOrMore :-> processOneOrMore+ , isRngChoice :-> processChoice+ ]+ where+ processData :: IOSArrow XmlTree ContentType+ processData+ = ifA (neg (getChildren >>> isRngExcept))+ (constA CTSimple)+ ( getChildren+ >>>+ isRngExcept+ >>>+ getChildren+ >>>+ getContentType+ >>>+ ifP (/= CTNone) (constA CTSimple) (constA CTNone)+ )+ processAttribute :: IOSArrow XmlTree ContentType+ processAttribute+ = ifA ( lastChild+ >>>+ getContentType+ >>>+ isA (/= CTNone)+ )+ (constA CTEmpty)+ (constA CTNone)++ processGroup :: IOSArrow XmlTree ContentType+ processGroup+ = get2ContentTypes+ >>>+ arr2 (\a b -> if isGroupable a b then max a b else CTNone)++ processInterleave :: IOSArrow XmlTree ContentType+ processInterleave+ = get2ContentTypes+ >>>+ arr2 (\a b -> if isGroupable a b then max a b else CTNone)++ processOneOrMore :: IOSArrow XmlTree ContentType+ processOneOrMore+ = ifA ( getChildren+ >>>+ getContentType >>> isA (/= CTNone)+ >>>+ isA (\t -> isGroupable t t)+ )+ ( getChildren >>> getContentType )+ ( constA CTNone )++ processChoice :: IOSArrow XmlTree ContentType+ processChoice+ = get2ContentTypes+ >>>+ arr2 max++ isGroupable :: ContentType -> ContentType -> Bool+ isGroupable CTEmpty _ = True+ isGroupable _ CTEmpty = True+ isGroupable CTComplex CTComplex = True+ isGroupable _ _ = False+++checkPattern :: IOSArrow (XmlTree, ([NameClass], [NameClass])) XmlTree+checkPattern+ = (\ (_, (a, b)) -> isIn a b) `guardsP` (arr fst)+ where+ isIn :: [NameClass] -> [NameClass] -> Bool+ isIn _ [] = False+ isIn [] _ = False+ isIn (x:xs) ys = (any (overlap x) ys) || isIn xs ys+++occur :: String -> IOSArrow XmlTree XmlTree -> IOSArrow XmlTree XmlTree+occur name fct+ = choiceA+ [ ( isElem >>> hasRngName name )+ :->+ fct+ , isChoiceGroupInterleaveOneOrMore+ :->+ (getChildren >>> occur name fct)+ ]++get2ContentTypes :: IOSArrow XmlTree (ContentType, ContentType)+get2ContentTypes+ = ( ( firstChild >>> getContentType )+ &&&+ ( lastChild >>> getContentType )+ )++-- ------------------------------------------------------------+++-- Duplicate attributes are not allowed. -> fertig+-- Attributes using infinite name classes must be repeated; an attribute element that+-- has an anyName or nsName descendant element must have a oneOrMore ancestor element. -> fertig++-- berechnet alle define-Namen (fuer ref-Pattern) und Nameclasses der element-Pattern++restrictionsStep4 :: IOSArrow XmlTree XmlTree+restrictionsStep4+ = ( restrictionsStep4' $<+ listA ( deep isRngDefine -- get all defines+ >>>+ ( getRngAttrName -- get define name+ &&&+ ( single ( getChildren+ >>>+ getChildren+ >>>+ fromLA createNameClass -- compute the name class from 1. grandchild+ )+ `orElse`+ (constA AnyName)+ )+ )+ )+ ) `when` collectErrors++restrictionsStep4' :: [(String, NameClass)] -> IOSArrow XmlTree XmlTree+restrictionsStep4' nc =+ processTopDown (+ (+ ( deep isRngRelaxError+ <+>+ ( mkRelaxError "" $<+ ( getRngAttrName+ >>>+ arr (\ n -> ( "Both attribute-pattern occuring in an " +++ show n ++ " belong to the same name-class"+ )+ )+ )+ )+ )+ `when`+ ( (isRngGroup `orElse` isRngInterleave)+ >>>+ ( getChildren+ &&&+ ( firstChild+ >>>+ listA ( occur "attribute" (single getChildren)+ >>>+ fromLA createNameClass+ )+ )+ &&&+ ( lastChild+ >>>+ listA ( occur "attribute" (single getChildren)+ >>>+ fromLA createNameClass+ )+ )+ )+ >>> checkPattern+ )+ )+ >>>+ (+ ( deep isRngRelaxError+ <+>+ ( mkRelaxError ""+ ( "An attribute that has an anyName or nsName descendant element " +++ "must have a oneOrMore ancestor element"+ )+ )+ )+ `when`+ (isRngElement >>> checkInfiniteAttribute)+ )+ >>>+ ( ( deep isRngRelaxError+ <+>+ ( mkRelaxError ""+ ( "Both element-pattern occuring in an interleave " +++ "belong to the same name-class"+ )+ )+ )+ `when`+ ( isRngInterleave+ >>>+ ( getChildren+ &&&+ (firstChild >>> listA (occur "ref" this >>> getRngAttrName))+ &&&+ (lastChild >>> listA (occur "ref" this >>> getRngAttrName))+ )+ >>>+ checkNames+ )+ )+ >>>+ ( ( deep isRngRelaxError+ <+>+ ( mkRelaxError "" "A text pattern must not occur in both children of an interleave" )+ )+ `when`+ (isRngInterleave >>> checkText)+ )+ )+ where+ checkInfiniteAttribute :: IOSArrow XmlTree XmlTree+ checkInfiniteAttribute+ = getChildren+ >>>+ choiceA+ [ isRngOneOrMore :-> none+ , ( isRngAttribute+ >>>+ deep (isRngAnyName `orElse` isRngNsName)+ ) :-> this+ , this :-> checkInfiniteAttribute+ ]++ checkNames :: IOSArrow (XmlTree, ([String], [String])) XmlTree+ checkNames = (arr fst)+ &&&+ (arr (\(_, (a, _)) -> getNameClasses nc a))+ &&&+ (arr (\(_, (_, b)) -> getNameClasses nc b))+ >>>+ checkPattern+ where+ getNameClasses :: [(String, NameClass)] -> [String] -> [NameClass]+ getNameClasses nc' l = map (\x -> fromJust $ lookup x nc') l++ checkText :: IOSArrow XmlTree XmlTree+ checkText+ = ( firstChild >>> occur "text" this )+ `guards`+ ( lastChild >>> occur "text" this )++-- ------------------------------------------------------------+++overlap :: NameClass -> NameClass -> Bool+overlap nc1 nc2+ = any (bothContain nc1 nc2) (representatives nc1 ++ representatives nc2)++bothContain :: NameClass -> NameClass -> QName -> Bool+bothContain nc1 nc2 qn+ = contains nc1 qn && contains nc2 qn++illegalLocalName :: LocalName+illegalLocalName = ""++illegalUri :: Uri+illegalUri = "\x1"++representatives :: NameClass -> [QName]+representatives AnyName+ = [mkQName "" illegalLocalName illegalUri]++representatives (AnyNameExcept nc)+ = (mkQName "" illegalLocalName illegalUri) : (representatives nc)++representatives (NsName ns)+ = [mkQName "" illegalLocalName ns]++representatives (NsNameExcept ns nc)+ = (mkQName "" illegalLocalName ns) : (representatives nc)++representatives (Name ns ln)+ = [mkQName "" ln ns]++representatives (NameClassChoice nc1 nc2)+ = (representatives nc1) ++ (representatives nc2)++representatives _+ = []++-- -------------------------------------------------------------------------------------------------------+resetStates :: IOSArrow XmlTree XmlTree+resetStates+ = ( perform (constA $ setParamInt "define_id" 0)+ >>>+ perform (constA [] >>> setParamList "elementTable" )+ >>>+ perform (constA $ setParamInt a_numberOfErrors 0)+ )+++getAllDeepDefines :: IOSArrow XmlTree Env+getAllDeepDefines+ = listA $ deep isRngDefine+ >>>+ ( getRngAttrName &&& this )+++-- | Return all reachable defines from the start pattern++getRefsFromStartPattern :: IOSArrow XmlTree [String]+getRefsFromStartPattern+ = listA+ ( getChildren+ >>>+ isRngGrammar+ >>>+ getChildren+ >>>+ isRngStart+ >>>+ deep isRngRef+ >>>+ getRngAttrName+ )++removeUnreachableDefines :: Env -> [String] -> [String] -> IOSArrow XmlTree XmlTree+removeUnreachableDefines allDefs processedDefs reachableDefs+ = ifP (const $ unprocessedDefs /= [])+ ( removeUnreachableDefines allDefs (nextTreeName : processedDefs) $< newReachableDefs )+ ( processChildren $ -- root node+ processChildren $ -- first grammar+ ( none+ `when`+ ( isRngDefine+ >>>+ getRngAttrName+ >>>+ isA (\n -> not $ elem n reachableDefs)+ )+ )+ )+ where+ unprocessedDefs :: [String]+ unprocessedDefs+ = reachableDefs \\ processedDefs++ newReachableDefs :: IOSArrow n [String]+ newReachableDefs+ = constA getTree+ >>>+ listA ( deep isRngRef+ >>>+ getRngAttrName+ )+ >>>+ arr (noDoubles . (reachableDefs ++))++ getTree :: XmlTree+ getTree+ = fromJust $ lookup nextTreeName allDefs++ nextTreeName :: String+ nextTreeName+ = head unprocessedDefs+++-- -------------------------------------------------------------------------------------------------------+++checkElemName :: [String] -> IOSArrow XmlTree XmlTree+checkElemName l+ = ( isElem >>> getLocalPart >>> isA (\s -> elem s l) )+ `guards`+ this++wrapPattern2Two :: (ArrowXml a) => String -> a XmlTree XmlTree+wrapPattern2Two name+ = choiceA+ [ noOfChildren (> 2)+ :-> ( replaceChildren ( (mkRngElement name none+ (getChildren >>. take 2)+ )+ <+>+ (getChildren >>. drop 2)+ )+ >>>+ wrapPattern2Two name+ )+ , noOfChildren (== 1)+ :-> getChildren+ , this+ :-> this+ ]++mkRelaxError :: String -> String -> IOSArrow n XmlTree+mkRelaxError changesStr errStr+ = perform (getAndSetCounter a_numberOfErrors)+ >>>+ mkRngRelaxError none none+ >>>+ addAttr "desc" errStr+ >>>+ ( addAttr "changes" changesStr+ `whenP`+ (const $ changesStr /= "")+ )++collectErrors :: IOSArrow XmlTree XmlTree+collectErrors+ = none+ `when`+ ( stopAfterFirstError+ >>>+ getParamInt 0 a_numberOfErrors >>> isA (>0)+ )+ where+ stopAfterFirstError = getParamString a_do_not_collect_errors+ >>>+ isA (== "1")+++-- | Returns the list of simplification errors or 'none'+getErrors :: IOSArrow XmlTree XmlTree+getErrors = (getParamInt 0 a_numberOfErrors >>> isA (>0))+ `guards`+ (root [] [multi isRngRelaxError])++setChangesAttr :: String -> IOSArrow XmlTree XmlTree+setChangesAttr str+ = ifA (hasAttr a_relaxSimplificationChanges)+ ( processAttrl $+ changeAttrValue (++ (", " ++ str))+ `when`+ (hasRngName a_relaxSimplificationChanges)+ )+ (mkAttr (mkName a_relaxSimplificationChanges) (txt str))+++getChangesAttr :: IOSArrow XmlTree String+getChangesAttr+ = getAttrValue a_relaxSimplificationChanges+ &&&+ getParamString a_output_changes+ >>>+ ifP (\(changes, param) -> changes /= "" && param == "1")+ (arr2 $ \l _ -> " (" ++ l ++ ")")+ (constA "")+++getAndSetCounter :: String -> IOSArrow b String+getAndSetCounter name+ = genNewId $< getParamInt 0 name+ where+ genNewId :: Int -> IOSArrow b String+ genNewId i = setParamInt name (i+1) >>> constA (show i)+++-- -------------------------------------------------------------------------------------------------------++-- | Creates the simple form of a Relax NG schema+-- (see also: 'relaxOptions')++createSimpleForm :: Attributes -> Bool -> Bool -> Bool -> IOSArrow XmlTree XmlTree+createSimpleForm remainingOptions checkRestrictions validateExternalRef validateInclude+ = traceMsg 2 ("createSimpleForm: " ++ show (remainingOptions, checkRestrictions,validateExternalRef, validateInclude))+ >>>+ ( if checkRestrictions+ then createSimpleWithRest+ else createSimpleWithoutRest+ )+ where++ createSimpleWithRest :: IOSArrow XmlTree XmlTree+ createSimpleWithRest+ = seqA $ concat [ simplificationPart1+ , return $ traceDoc "relax NG: simplificationPart1 done"+ , restrictionsPart1+ , return $ traceDoc "relax NG: restrictionsPart1 done"+ , simplificationPart2+ , return $ traceDoc "relax NG simplificationPart2 done"+ , restrictionsPart2+ , return $ traceDoc "relax NG: restrictionsPart2 done"+ , finalCleanUp+ , return $ traceDoc "relax NG: finalCleanUp done"+ ]++ createSimpleWithoutRest :: IOSArrow XmlTree XmlTree+ createSimpleWithoutRest+ = seqA $ concat [ simplificationPart1+ , simplificationPart2+ , finalCleanUp+ ]+ simplificationPart1 :: [IOSArrow XmlTree XmlTree]+ simplificationPart1+ = [ propagateNamespaces+ , simplificationStep1+ , simplificationStep2 remainingOptions validateExternalRef validateInclude [] []+ , simplificationStep3+ , simplificationStep4+ ]++ simplificationPart2 :: [IOSArrow XmlTree XmlTree]+ simplificationPart2+ = [ simplificationStep5+ , simplificationStep6+ , simplificationStep7+ , simplificationStep8+ ]++ restrictionsPart1 :: [IOSArrow XmlTree XmlTree]+ restrictionsPart1+ = [ restrictionsStep1 ]++ restrictionsPart2 :: [IOSArrow XmlTree XmlTree]+ restrictionsPart2+ = [ restrictionsStep2+ , restrictionsStep3+ , restrictionsStep4+ ]++ finalCleanUp :: [IOSArrow XmlTree XmlTree]+ finalCleanUp+ = [ cleanUp+ , resetStates+ ]++ cleanUp :: IOSArrow XmlTree XmlTree+ cleanUp = processTopDown $+ removeAttr a_relaxSimplificationChanges+ >>>+ removeAttr defineOrigName++-- -------------------------------------------------------------------------------------------------------
src/Text/XML/HXT/RelaxNG/Unicode/Blocks.hs view
@@ -26,203 +26,203 @@ codeBlocks :: [(String, (Char, Char))] codeBlocks =- [ ( "BasicLatin", ( '\x0000', '\x007F') )- , ( "Latin-1Supplement", ( '\x0080', '\x00FF') )- , ( "LatinExtended-A", ( '\x0100', '\x017F') )- , ( "LatinExtended-B", ( '\x0180', '\x024F') )- , ( "IPAExtensions", ( '\x0250', '\x02AF') )- , ( "SpacingModifierLetters", ( '\x02B0', '\x02FF') )- , ( "CombiningDiacriticalMarks", ( '\x0300', '\x036F') )- , ( "GreekandCoptic", ( '\x0370', '\x03FF') )- , ( "Cyrillic", ( '\x0400', '\x04FF') )- , ( "CyrillicSupplement", ( '\x0500', '\x052F') )- , ( "Armenian", ( '\x0530', '\x058F') )- , ( "Hebrew", ( '\x0590', '\x05FF') )- , ( "Arabic", ( '\x0600', '\x06FF') )- , ( "Syriac", ( '\x0700', '\x074F') )- , ( "ArabicSupplement", ( '\x0750', '\x077F') )- , ( "Thaana", ( '\x0780', '\x07BF') )- , ( "NKo", ( '\x07C0', '\x07FF') )- , ( "Samaritan", ( '\x0800', '\x083F') )- , ( "Devanagari", ( '\x0900', '\x097F') )- , ( "Bengali", ( '\x0980', '\x09FF') )- , ( "Gurmukhi", ( '\x0A00', '\x0A7F') )- , ( "Gujarati", ( '\x0A80', '\x0AFF') )- , ( "Oriya", ( '\x0B00', '\x0B7F') )- , ( "Tamil", ( '\x0B80', '\x0BFF') )- , ( "Telugu", ( '\x0C00', '\x0C7F') )- , ( "Kannada", ( '\x0C80', '\x0CFF') )- , ( "Malayalam", ( '\x0D00', '\x0D7F') )- , ( "Sinhala", ( '\x0D80', '\x0DFF') )- , ( "Thai", ( '\x0E00', '\x0E7F') )- , ( "Lao", ( '\x0E80', '\x0EFF') )- , ( "Tibetan", ( '\x0F00', '\x0FFF') )- , ( "Myanmar", ( '\x1000', '\x109F') )- , ( "Georgian", ( '\x10A0', '\x10FF') )- , ( "HangulJamo", ( '\x1100', '\x11FF') )- , ( "Ethiopic", ( '\x1200', '\x137F') )- , ( "EthiopicSupplement", ( '\x1380', '\x139F') )- , ( "Cherokee", ( '\x13A0', '\x13FF') )- , ( "UnifiedCanadianAboriginalSyllabics", ( '\x1400', '\x167F') )- , ( "Ogham", ( '\x1680', '\x169F') )- , ( "Runic", ( '\x16A0', '\x16FF') )- , ( "Tagalog", ( '\x1700', '\x171F') )- , ( "Hanunoo", ( '\x1720', '\x173F') )- , ( "Buhid", ( '\x1740', '\x175F') )- , ( "Tagbanwa", ( '\x1760', '\x177F') )- , ( "Khmer", ( '\x1780', '\x17FF') )- , ( "Mongolian", ( '\x1800', '\x18AF') )- , ( "UnifiedCanadianAboriginalSyllabicsExtended", ( '\x18B0', '\x18FF') )- , ( "Limbu", ( '\x1900', '\x194F') )- , ( "TaiLe", ( '\x1950', '\x197F') )- , ( "NewTaiLue", ( '\x1980', '\x19DF') )- , ( "KhmerSymbols", ( '\x19E0', '\x19FF') )- , ( "Buginese", ( '\x1A00', '\x1A1F') )- , ( "TaiTham", ( '\x1A20', '\x1AAF') )- , ( "Balinese", ( '\x1B00', '\x1B7F') )- , ( "Sundanese", ( '\x1B80', '\x1BBF') )- , ( "Lepcha", ( '\x1C00', '\x1C4F') )- , ( "OlChiki", ( '\x1C50', '\x1C7F') )- , ( "VedicExtensions", ( '\x1CD0', '\x1CFF') )- , ( "PhoneticExtensions", ( '\x1D00', '\x1D7F') )- , ( "PhoneticExtensionsSupplement", ( '\x1D80', '\x1DBF') )- , ( "CombiningDiacriticalMarksSupplement", ( '\x1DC0', '\x1DFF') )- , ( "LatinExtendedAdditional", ( '\x1E00', '\x1EFF') )- , ( "GreekExtended", ( '\x1F00', '\x1FFF') )- , ( "GeneralPunctuation", ( '\x2000', '\x206F') )- , ( "SuperscriptsandSubscripts", ( '\x2070', '\x209F') )- , ( "CurrencySymbols", ( '\x20A0', '\x20CF') )- , ( "CombiningDiacriticalMarksforSymbols", ( '\x20D0', '\x20FF') )- , ( "LetterlikeSymbols", ( '\x2100', '\x214F') )- , ( "NumberForms", ( '\x2150', '\x218F') )- , ( "Arrows", ( '\x2190', '\x21FF') )- , ( "MathematicalOperators", ( '\x2200', '\x22FF') )- , ( "MiscellaneousTechnical", ( '\x2300', '\x23FF') )- , ( "ControlPictures", ( '\x2400', '\x243F') )- , ( "OpticalCharacterRecognition", ( '\x2440', '\x245F') )- , ( "EnclosedAlphanumerics", ( '\x2460', '\x24FF') )- , ( "BoxDrawing", ( '\x2500', '\x257F') )- , ( "BlockElements", ( '\x2580', '\x259F') )- , ( "GeometricShapes", ( '\x25A0', '\x25FF') )- , ( "MiscellaneousSymbols", ( '\x2600', '\x26FF') )- , ( "Dingbats", ( '\x2700', '\x27BF') )- , ( "MiscellaneousMathematicalSymbols-A", ( '\x27C0', '\x27EF') )- , ( "SupplementalArrows-A", ( '\x27F0', '\x27FF') )- , ( "BraillePatterns", ( '\x2800', '\x28FF') )- , ( "SupplementalArrows-B", ( '\x2900', '\x297F') )- , ( "MiscellaneousMathematicalSymbols-B", ( '\x2980', '\x29FF') )- , ( "SupplementalMathematicalOperators", ( '\x2A00', '\x2AFF') )- , ( "MiscellaneousSymbolsandArrows", ( '\x2B00', '\x2BFF') )- , ( "Glagolitic", ( '\x2C00', '\x2C5F') )- , ( "LatinExtended-C", ( '\x2C60', '\x2C7F') )- , ( "Coptic", ( '\x2C80', '\x2CFF') )- , ( "GeorgianSupplement", ( '\x2D00', '\x2D2F') )- , ( "Tifinagh", ( '\x2D30', '\x2D7F') )- , ( "EthiopicExtended", ( '\x2D80', '\x2DDF') )- , ( "CyrillicExtended-A", ( '\x2DE0', '\x2DFF') )- , ( "SupplementalPunctuation", ( '\x2E00', '\x2E7F') )- , ( "CJKRadicalsSupplement", ( '\x2E80', '\x2EFF') )- , ( "KangxiRadicals", ( '\x2F00', '\x2FDF') )- , ( "IdeographicDescriptionCharacters", ( '\x2FF0', '\x2FFF') )- , ( "CJKSymbolsandPunctuation", ( '\x3000', '\x303F') )- , ( "Hiragana", ( '\x3040', '\x309F') )- , ( "Katakana", ( '\x30A0', '\x30FF') )- , ( "Bopomofo", ( '\x3100', '\x312F') )- , ( "HangulCompatibilityJamo", ( '\x3130', '\x318F') )- , ( "Kanbun", ( '\x3190', '\x319F') )- , ( "BopomofoExtended", ( '\x31A0', '\x31BF') )- , ( "CJKStrokes", ( '\x31C0', '\x31EF') )- , ( "KatakanaPhoneticExtensions", ( '\x31F0', '\x31FF') )- , ( "EnclosedCJKLettersandMonths", ( '\x3200', '\x32FF') )- , ( "CJKCompatibility", ( '\x3300', '\x33FF') )- , ( "CJKUnifiedIdeographsExtensionA", ( '\x3400', '\x4DBF') )- , ( "YijingHexagramSymbols", ( '\x4DC0', '\x4DFF') )- , ( "CJKUnifiedIdeographs", ( '\x4E00', '\x9FFF') )- , ( "YiSyllables", ( '\xA000', '\xA48F') )- , ( "YiRadicals", ( '\xA490', '\xA4CF') )- , ( "Lisu", ( '\xA4D0', '\xA4FF') )- , ( "Vai", ( '\xA500', '\xA63F') )- , ( "CyrillicExtended-B", ( '\xA640', '\xA69F') )- , ( "Bamum", ( '\xA6A0', '\xA6FF') )- , ( "ModifierToneLetters", ( '\xA700', '\xA71F') )- , ( "LatinExtended-D", ( '\xA720', '\xA7FF') )- , ( "SylotiNagri", ( '\xA800', '\xA82F') )- , ( "CommonIndicNumberForms", ( '\xA830', '\xA83F') )- , ( "Phags-pa", ( '\xA840', '\xA87F') )- , ( "Saurashtra", ( '\xA880', '\xA8DF') )- , ( "DevanagariExtended", ( '\xA8E0', '\xA8FF') )- , ( "KayahLi", ( '\xA900', '\xA92F') )- , ( "Rejang", ( '\xA930', '\xA95F') )- , ( "HangulJamoExtended-A", ( '\xA960', '\xA97F') )- , ( "Javanese", ( '\xA980', '\xA9DF') )- , ( "Cham", ( '\xAA00', '\xAA5F') )- , ( "MyanmarExtended-A", ( '\xAA60', '\xAA7F') )- , ( "TaiViet", ( '\xAA80', '\xAADF') )- , ( "MeeteiMayek", ( '\xABC0', '\xABFF') )- , ( "HangulSyllables", ( '\xAC00', '\xD7AF') )- , ( "HangulJamoExtended-B", ( '\xD7B0', '\xD7FF') )- , ( "HighSurrogates", ( '\xD800', '\xDB7F') )- , ( "HighPrivateUseSurrogates", ( '\xDB80', '\xDBFF') )- , ( "LowSurrogates", ( '\xDC00', '\xDFFF') )- , ( "PrivateUseArea", ( '\xE000', '\xF8FF') )- , ( "CJKCompatibilityIdeographs", ( '\xF900', '\xFAFF') )- , ( "AlphabeticPresentationForms", ( '\xFB00', '\xFB4F') )- , ( "ArabicPresentationForms-A", ( '\xFB50', '\xFDFF') )- , ( "VariationSelectors", ( '\xFE00', '\xFE0F') )- , ( "VerticalForms", ( '\xFE10', '\xFE1F') )- , ( "CombiningHalfMarks", ( '\xFE20', '\xFE2F') )- , ( "CJKCompatibilityForms", ( '\xFE30', '\xFE4F') )- , ( "SmallFormVariants", ( '\xFE50', '\xFE6F') )- , ( "ArabicPresentationForms-B", ( '\xFE70', '\xFEFF') )- , ( "HalfwidthandFullwidthForms", ( '\xFF00', '\xFFEF') )- , ( "Specials", ( '\xFFF0', '\xFFFF') )- , ( "LinearBSyllabary", ( '\x10000', '\x1007F') )- , ( "LinearBIdeograms", ( '\x10080', '\x100FF') )- , ( "AegeanNumbers", ( '\x10100', '\x1013F') )- , ( "AncientGreekNumbers", ( '\x10140', '\x1018F') )- , ( "AncientSymbols", ( '\x10190', '\x101CF') )- , ( "PhaistosDisc", ( '\x101D0', '\x101FF') )- , ( "Lycian", ( '\x10280', '\x1029F') )- , ( "Carian", ( '\x102A0', '\x102DF') )- , ( "OldItalic", ( '\x10300', '\x1032F') )- , ( "Gothic", ( '\x10330', '\x1034F') )- , ( "Ugaritic", ( '\x10380', '\x1039F') )- , ( "OldPersian", ( '\x103A0', '\x103DF') )- , ( "Deseret", ( '\x10400', '\x1044F') )- , ( "Shavian", ( '\x10450', '\x1047F') )- , ( "Osmanya", ( '\x10480', '\x104AF') )- , ( "CypriotSyllabary", ( '\x10800', '\x1083F') )- , ( "ImperialAramaic", ( '\x10840', '\x1085F') )- , ( "Phoenician", ( '\x10900', '\x1091F') )- , ( "Lydian", ( '\x10920', '\x1093F') )- , ( "Kharoshthi", ( '\x10A00', '\x10A5F') )- , ( "OldSouthArabian", ( '\x10A60', '\x10A7F') )- , ( "Avestan", ( '\x10B00', '\x10B3F') )- , ( "InscriptionalParthian", ( '\x10B40', '\x10B5F') )- , ( "InscriptionalPahlavi", ( '\x10B60', '\x10B7F') )- , ( "OldTurkic", ( '\x10C00', '\x10C4F') )- , ( "RumiNumeralSymbols", ( '\x10E60', '\x10E7F') )- , ( "Kaithi", ( '\x11080', '\x110CF') )- , ( "Cuneiform", ( '\x12000', '\x123FF') )- , ( "CuneiformNumbersandPunctuation", ( '\x12400', '\x1247F') )- , ( "EgyptianHieroglyphs", ( '\x13000', '\x1342F') )- , ( "ByzantineMusicalSymbols", ( '\x1D000', '\x1D0FF') )- , ( "MusicalSymbols", ( '\x1D100', '\x1D1FF') )- , ( "AncientGreekMusicalNotation", ( '\x1D200', '\x1D24F') )- , ( "TaiXuanJingSymbols", ( '\x1D300', '\x1D35F') )- , ( "CountingRodNumerals", ( '\x1D360', '\x1D37F') )- , ( "MathematicalAlphanumericSymbols", ( '\x1D400', '\x1D7FF') )- , ( "MahjongTiles", ( '\x1F000', '\x1F02F') )- , ( "DominoTiles", ( '\x1F030', '\x1F09F') )- , ( "EnclosedAlphanumericSupplement", ( '\x1F100', '\x1F1FF') )- , ( "EnclosedIdeographicSupplement", ( '\x1F200', '\x1F2FF') )- , ( "CJKUnifiedIdeographsExtensionB", ( '\x20000', '\x2A6DF') )- , ( "CJKUnifiedIdeographsExtensionC", ( '\x2A700', '\x2B73F') )- , ( "CJKCompatibilityIdeographsSupplement", ( '\x2F800', '\x2FA1F') )- , ( "Tags", ( '\xE0000', '\xE007F') )- , ( "VariationSelectorsSupplement", ( '\xE0100', '\xE01EF') )- , ( "SupplementaryPrivateUseArea-A", ( '\xF0000', '\xFFFFF') )- , ( "SupplementaryPrivateUseArea-B", ( '\x100000', '\x10FFFF') )+ [ ( "BasicLatin", ( '\x0000', '\x007F') )+ , ( "Latin-1Supplement", ( '\x0080', '\x00FF') )+ , ( "LatinExtended-A", ( '\x0100', '\x017F') )+ , ( "LatinExtended-B", ( '\x0180', '\x024F') )+ , ( "IPAExtensions", ( '\x0250', '\x02AF') )+ , ( "SpacingModifierLetters", ( '\x02B0', '\x02FF') )+ , ( "CombiningDiacriticalMarks", ( '\x0300', '\x036F') )+ , ( "GreekandCoptic", ( '\x0370', '\x03FF') )+ , ( "Cyrillic", ( '\x0400', '\x04FF') )+ , ( "CyrillicSupplement", ( '\x0500', '\x052F') )+ , ( "Armenian", ( '\x0530', '\x058F') )+ , ( "Hebrew", ( '\x0590', '\x05FF') )+ , ( "Arabic", ( '\x0600', '\x06FF') )+ , ( "Syriac", ( '\x0700', '\x074F') )+ , ( "ArabicSupplement", ( '\x0750', '\x077F') )+ , ( "Thaana", ( '\x0780', '\x07BF') )+ , ( "NKo", ( '\x07C0', '\x07FF') )+ , ( "Samaritan", ( '\x0800', '\x083F') )+ , ( "Devanagari", ( '\x0900', '\x097F') )+ , ( "Bengali", ( '\x0980', '\x09FF') )+ , ( "Gurmukhi", ( '\x0A00', '\x0A7F') )+ , ( "Gujarati", ( '\x0A80', '\x0AFF') )+ , ( "Oriya", ( '\x0B00', '\x0B7F') )+ , ( "Tamil", ( '\x0B80', '\x0BFF') )+ , ( "Telugu", ( '\x0C00', '\x0C7F') )+ , ( "Kannada", ( '\x0C80', '\x0CFF') )+ , ( "Malayalam", ( '\x0D00', '\x0D7F') )+ , ( "Sinhala", ( '\x0D80', '\x0DFF') )+ , ( "Thai", ( '\x0E00', '\x0E7F') )+ , ( "Lao", ( '\x0E80', '\x0EFF') )+ , ( "Tibetan", ( '\x0F00', '\x0FFF') )+ , ( "Myanmar", ( '\x1000', '\x109F') )+ , ( "Georgian", ( '\x10A0', '\x10FF') )+ , ( "HangulJamo", ( '\x1100', '\x11FF') )+ , ( "Ethiopic", ( '\x1200', '\x137F') )+ , ( "EthiopicSupplement", ( '\x1380', '\x139F') )+ , ( "Cherokee", ( '\x13A0', '\x13FF') )+ , ( "UnifiedCanadianAboriginalSyllabics", ( '\x1400', '\x167F') )+ , ( "Ogham", ( '\x1680', '\x169F') )+ , ( "Runic", ( '\x16A0', '\x16FF') )+ , ( "Tagalog", ( '\x1700', '\x171F') )+ , ( "Hanunoo", ( '\x1720', '\x173F') )+ , ( "Buhid", ( '\x1740', '\x175F') )+ , ( "Tagbanwa", ( '\x1760', '\x177F') )+ , ( "Khmer", ( '\x1780', '\x17FF') )+ , ( "Mongolian", ( '\x1800', '\x18AF') )+ , ( "UnifiedCanadianAboriginalSyllabicsExtended", ( '\x18B0', '\x18FF') )+ , ( "Limbu", ( '\x1900', '\x194F') )+ , ( "TaiLe", ( '\x1950', '\x197F') )+ , ( "NewTaiLue", ( '\x1980', '\x19DF') )+ , ( "KhmerSymbols", ( '\x19E0', '\x19FF') )+ , ( "Buginese", ( '\x1A00', '\x1A1F') )+ , ( "TaiTham", ( '\x1A20', '\x1AAF') )+ , ( "Balinese", ( '\x1B00', '\x1B7F') )+ , ( "Sundanese", ( '\x1B80', '\x1BBF') )+ , ( "Lepcha", ( '\x1C00', '\x1C4F') )+ , ( "OlChiki", ( '\x1C50', '\x1C7F') )+ , ( "VedicExtensions", ( '\x1CD0', '\x1CFF') )+ , ( "PhoneticExtensions", ( '\x1D00', '\x1D7F') )+ , ( "PhoneticExtensionsSupplement", ( '\x1D80', '\x1DBF') )+ , ( "CombiningDiacriticalMarksSupplement", ( '\x1DC0', '\x1DFF') )+ , ( "LatinExtendedAdditional", ( '\x1E00', '\x1EFF') )+ , ( "GreekExtended", ( '\x1F00', '\x1FFF') )+ , ( "GeneralPunctuation", ( '\x2000', '\x206F') )+ , ( "SuperscriptsandSubscripts", ( '\x2070', '\x209F') )+ , ( "CurrencySymbols", ( '\x20A0', '\x20CF') )+ , ( "CombiningDiacriticalMarksforSymbols", ( '\x20D0', '\x20FF') )+ , ( "LetterlikeSymbols", ( '\x2100', '\x214F') )+ , ( "NumberForms", ( '\x2150', '\x218F') )+ , ( "Arrows", ( '\x2190', '\x21FF') )+ , ( "MathematicalOperators", ( '\x2200', '\x22FF') )+ , ( "MiscellaneousTechnical", ( '\x2300', '\x23FF') )+ , ( "ControlPictures", ( '\x2400', '\x243F') )+ , ( "OpticalCharacterRecognition", ( '\x2440', '\x245F') )+ , ( "EnclosedAlphanumerics", ( '\x2460', '\x24FF') )+ , ( "BoxDrawing", ( '\x2500', '\x257F') )+ , ( "BlockElements", ( '\x2580', '\x259F') )+ , ( "GeometricShapes", ( '\x25A0', '\x25FF') )+ , ( "MiscellaneousSymbols", ( '\x2600', '\x26FF') )+ , ( "Dingbats", ( '\x2700', '\x27BF') )+ , ( "MiscellaneousMathematicalSymbols-A", ( '\x27C0', '\x27EF') )+ , ( "SupplementalArrows-A", ( '\x27F0', '\x27FF') )+ , ( "BraillePatterns", ( '\x2800', '\x28FF') )+ , ( "SupplementalArrows-B", ( '\x2900', '\x297F') )+ , ( "MiscellaneousMathematicalSymbols-B", ( '\x2980', '\x29FF') )+ , ( "SupplementalMathematicalOperators", ( '\x2A00', '\x2AFF') )+ , ( "MiscellaneousSymbolsandArrows", ( '\x2B00', '\x2BFF') )+ , ( "Glagolitic", ( '\x2C00', '\x2C5F') )+ , ( "LatinExtended-C", ( '\x2C60', '\x2C7F') )+ , ( "Coptic", ( '\x2C80', '\x2CFF') )+ , ( "GeorgianSupplement", ( '\x2D00', '\x2D2F') )+ , ( "Tifinagh", ( '\x2D30', '\x2D7F') )+ , ( "EthiopicExtended", ( '\x2D80', '\x2DDF') )+ , ( "CyrillicExtended-A", ( '\x2DE0', '\x2DFF') )+ , ( "SupplementalPunctuation", ( '\x2E00', '\x2E7F') )+ , ( "CJKRadicalsSupplement", ( '\x2E80', '\x2EFF') )+ , ( "KangxiRadicals", ( '\x2F00', '\x2FDF') )+ , ( "IdeographicDescriptionCharacters", ( '\x2FF0', '\x2FFF') )+ , ( "CJKSymbolsandPunctuation", ( '\x3000', '\x303F') )+ , ( "Hiragana", ( '\x3040', '\x309F') )+ , ( "Katakana", ( '\x30A0', '\x30FF') )+ , ( "Bopomofo", ( '\x3100', '\x312F') )+ , ( "HangulCompatibilityJamo", ( '\x3130', '\x318F') )+ , ( "Kanbun", ( '\x3190', '\x319F') )+ , ( "BopomofoExtended", ( '\x31A0', '\x31BF') )+ , ( "CJKStrokes", ( '\x31C0', '\x31EF') )+ , ( "KatakanaPhoneticExtensions", ( '\x31F0', '\x31FF') )+ , ( "EnclosedCJKLettersandMonths", ( '\x3200', '\x32FF') )+ , ( "CJKCompatibility", ( '\x3300', '\x33FF') )+ , ( "CJKUnifiedIdeographsExtensionA", ( '\x3400', '\x4DBF') )+ , ( "YijingHexagramSymbols", ( '\x4DC0', '\x4DFF') )+ , ( "CJKUnifiedIdeographs", ( '\x4E00', '\x9FFF') )+ , ( "YiSyllables", ( '\xA000', '\xA48F') )+ , ( "YiRadicals", ( '\xA490', '\xA4CF') )+ , ( "Lisu", ( '\xA4D0', '\xA4FF') )+ , ( "Vai", ( '\xA500', '\xA63F') )+ , ( "CyrillicExtended-B", ( '\xA640', '\xA69F') )+ , ( "Bamum", ( '\xA6A0', '\xA6FF') )+ , ( "ModifierToneLetters", ( '\xA700', '\xA71F') )+ , ( "LatinExtended-D", ( '\xA720', '\xA7FF') )+ , ( "SylotiNagri", ( '\xA800', '\xA82F') )+ , ( "CommonIndicNumberForms", ( '\xA830', '\xA83F') )+ , ( "Phags-pa", ( '\xA840', '\xA87F') )+ , ( "Saurashtra", ( '\xA880', '\xA8DF') )+ , ( "DevanagariExtended", ( '\xA8E0', '\xA8FF') )+ , ( "KayahLi", ( '\xA900', '\xA92F') )+ , ( "Rejang", ( '\xA930', '\xA95F') )+ , ( "HangulJamoExtended-A", ( '\xA960', '\xA97F') )+ , ( "Javanese", ( '\xA980', '\xA9DF') )+ , ( "Cham", ( '\xAA00', '\xAA5F') )+ , ( "MyanmarExtended-A", ( '\xAA60', '\xAA7F') )+ , ( "TaiViet", ( '\xAA80', '\xAADF') )+ , ( "MeeteiMayek", ( '\xABC0', '\xABFF') )+ , ( "HangulSyllables", ( '\xAC00', '\xD7AF') )+ , ( "HangulJamoExtended-B", ( '\xD7B0', '\xD7FF') )+ , ( "HighSurrogates", ( '\xD800', '\xDB7F') )+ , ( "HighPrivateUseSurrogates", ( '\xDB80', '\xDBFF') )+ , ( "LowSurrogates", ( '\xDC00', '\xDFFF') )+ , ( "PrivateUseArea", ( '\xE000', '\xF8FF') )+ , ( "CJKCompatibilityIdeographs", ( '\xF900', '\xFAFF') )+ , ( "AlphabeticPresentationForms", ( '\xFB00', '\xFB4F') )+ , ( "ArabicPresentationForms-A", ( '\xFB50', '\xFDFF') )+ , ( "VariationSelectors", ( '\xFE00', '\xFE0F') )+ , ( "VerticalForms", ( '\xFE10', '\xFE1F') )+ , ( "CombiningHalfMarks", ( '\xFE20', '\xFE2F') )+ , ( "CJKCompatibilityForms", ( '\xFE30', '\xFE4F') )+ , ( "SmallFormVariants", ( '\xFE50', '\xFE6F') )+ , ( "ArabicPresentationForms-B", ( '\xFE70', '\xFEFF') )+ , ( "HalfwidthandFullwidthForms", ( '\xFF00', '\xFFEF') )+ , ( "Specials", ( '\xFFF0', '\xFFFF') )+ , ( "LinearBSyllabary", ( '\x10000', '\x1007F') )+ , ( "LinearBIdeograms", ( '\x10080', '\x100FF') )+ , ( "AegeanNumbers", ( '\x10100', '\x1013F') )+ , ( "AncientGreekNumbers", ( '\x10140', '\x1018F') )+ , ( "AncientSymbols", ( '\x10190', '\x101CF') )+ , ( "PhaistosDisc", ( '\x101D0', '\x101FF') )+ , ( "Lycian", ( '\x10280', '\x1029F') )+ , ( "Carian", ( '\x102A0', '\x102DF') )+ , ( "OldItalic", ( '\x10300', '\x1032F') )+ , ( "Gothic", ( '\x10330', '\x1034F') )+ , ( "Ugaritic", ( '\x10380', '\x1039F') )+ , ( "OldPersian", ( '\x103A0', '\x103DF') )+ , ( "Deseret", ( '\x10400', '\x1044F') )+ , ( "Shavian", ( '\x10450', '\x1047F') )+ , ( "Osmanya", ( '\x10480', '\x104AF') )+ , ( "CypriotSyllabary", ( '\x10800', '\x1083F') )+ , ( "ImperialAramaic", ( '\x10840', '\x1085F') )+ , ( "Phoenician", ( '\x10900', '\x1091F') )+ , ( "Lydian", ( '\x10920', '\x1093F') )+ , ( "Kharoshthi", ( '\x10A00', '\x10A5F') )+ , ( "OldSouthArabian", ( '\x10A60', '\x10A7F') )+ , ( "Avestan", ( '\x10B00', '\x10B3F') )+ , ( "InscriptionalParthian", ( '\x10B40', '\x10B5F') )+ , ( "InscriptionalPahlavi", ( '\x10B60', '\x10B7F') )+ , ( "OldTurkic", ( '\x10C00', '\x10C4F') )+ , ( "RumiNumeralSymbols", ( '\x10E60', '\x10E7F') )+ , ( "Kaithi", ( '\x11080', '\x110CF') )+ , ( "Cuneiform", ( '\x12000', '\x123FF') )+ , ( "CuneiformNumbersandPunctuation", ( '\x12400', '\x1247F') )+ , ( "EgyptianHieroglyphs", ( '\x13000', '\x1342F') )+ , ( "ByzantineMusicalSymbols", ( '\x1D000', '\x1D0FF') )+ , ( "MusicalSymbols", ( '\x1D100', '\x1D1FF') )+ , ( "AncientGreekMusicalNotation", ( '\x1D200', '\x1D24F') )+ , ( "TaiXuanJingSymbols", ( '\x1D300', '\x1D35F') )+ , ( "CountingRodNumerals", ( '\x1D360', '\x1D37F') )+ , ( "MathematicalAlphanumericSymbols", ( '\x1D400', '\x1D7FF') )+ , ( "MahjongTiles", ( '\x1F000', '\x1F02F') )+ , ( "DominoTiles", ( '\x1F030', '\x1F09F') )+ , ( "EnclosedAlphanumericSupplement", ( '\x1F100', '\x1F1FF') )+ , ( "EnclosedIdeographicSupplement", ( '\x1F200', '\x1F2FF') )+ , ( "CJKUnifiedIdeographsExtensionB", ( '\x20000', '\x2A6DF') )+ , ( "CJKUnifiedIdeographsExtensionC", ( '\x2A700', '\x2B73F') )+ , ( "CJKCompatibilityIdeographsSupplement", ( '\x2F800', '\x2FA1F') )+ , ( "Tags", ( '\xE0000', '\xE007F') )+ , ( "VariationSelectorsSupplement", ( '\xE0100', '\xE01EF') )+ , ( "SupplementaryPrivateUseArea-A", ( '\xF0000', '\xFFFFF') )+ , ( "SupplementaryPrivateUseArea-B", ( '\x100000', '\x10FFFF') ) ] -- ------------------------------------------------------------
src/Text/XML/HXT/RelaxNG/Unicode/CharProps.hs view
@@ -67,7 +67,7 @@ -- ------------------------------------------------------------ -isUnicodeC :: Char -> Bool+isUnicodeC :: Char -> Bool isUnicodeC c = isInList c [ ('\NUL','\US')@@ -100,7 +100,7 @@ -- ------------------------------------------------------------ -isUnicodeCc :: Char -> Bool+isUnicodeCc :: Char -> Bool isUnicodeCc c = isInList c [ ('\NUL','\US')@@ -109,7 +109,7 @@ -- ------------------------------------------------------------ -isUnicodeCf :: Char -> Bool+isUnicodeCf :: Char -> Bool isUnicodeCf c = isInList c [ ('\173','\173')@@ -131,7 +131,7 @@ -- ------------------------------------------------------------ -isUnicodeCo :: Char -> Bool+isUnicodeCo :: Char -> Bool isUnicodeCo c = isInList c [ ('\57344','\57344')@@ -144,7 +144,7 @@ -- ------------------------------------------------------------ -isUnicodeCs :: Char -> Bool+isUnicodeCs :: Char -> Bool isUnicodeCs c = isInList c [ ('\55296','\55296')@@ -155,7 +155,7 @@ -- ------------------------------------------------------------ -isUnicodeL :: Char -> Bool+isUnicodeL :: Char -> Bool isUnicodeL c = isInList c [ ('A','Z')@@ -589,7 +589,7 @@ -- ------------------------------------------------------------ -isUnicodeLl :: Char -> Bool+isUnicodeLl :: Char -> Bool isUnicodeLl c = isInList c [ ('a','z')@@ -1195,7 +1195,7 @@ -- ------------------------------------------------------------ -isUnicodeLm :: Char -> Bool+isUnicodeLm :: Char -> Bool isUnicodeLm c = isInList c [ ('\688','\705')@@ -1251,7 +1251,7 @@ -- ------------------------------------------------------------ -isUnicodeLo :: Char -> Bool+isUnicodeLo :: Char -> Bool isUnicodeLo c = isInList c [ ('\443','\443')@@ -1574,7 +1574,7 @@ -- ------------------------------------------------------------ -isUnicodeLt :: Char -> Bool+isUnicodeLt :: Char -> Bool isUnicodeLt c = isInList c [ ('\453','\453')@@ -1591,7 +1591,7 @@ -- ------------------------------------------------------------ -isUnicodeLu :: Char -> Bool+isUnicodeLu :: Char -> Bool isUnicodeLu c = isInList c [ ('A','Z')@@ -2192,7 +2192,7 @@ -- ------------------------------------------------------------ -isUnicodeM :: Char -> Bool+isUnicodeM :: Char -> Bool isUnicodeM c = isInList c [ ('\768','\879')@@ -2387,7 +2387,7 @@ -- ------------------------------------------------------------ -isUnicodeMc :: Char -> Bool+isUnicodeMc :: Char -> Bool isUnicodeMc c = isInList c [ ('\2307','\2307')@@ -2500,7 +2500,7 @@ -- ------------------------------------------------------------ -isUnicodeMe :: Char -> Bool+isUnicodeMe :: Char -> Bool isUnicodeMe c = isInList c [ ('\1160','\1161')@@ -2512,7 +2512,7 @@ -- ------------------------------------------------------------ -isUnicodeMn :: Char -> Bool+isUnicodeMn :: Char -> Bool isUnicodeMn c = isInList c [ ('\768','\879')@@ -2713,7 +2713,7 @@ -- ------------------------------------------------------------ -isUnicodeN :: Char -> Bool+isUnicodeN :: Char -> Bool isUnicodeN c = isInList c [ ('0','9')@@ -2801,7 +2801,7 @@ -- ------------------------------------------------------------ -isUnicodeNd :: Char -> Bool+isUnicodeNd :: Char -> Bool isUnicodeNd c = isInList c [ ('0','9')@@ -2845,7 +2845,7 @@ -- ------------------------------------------------------------ -isUnicodeNl :: Char -> Bool+isUnicodeNl :: Char -> Bool isUnicodeNl c = isInList c [ ('\5870','\5872')@@ -2864,7 +2864,7 @@ -- ------------------------------------------------------------ -isUnicodeNo :: Char -> Bool+isUnicodeNo :: Char -> Bool isUnicodeNo c = isInList c [ ('\178','\179')@@ -2909,7 +2909,7 @@ -- ------------------------------------------------------------ -isUnicodeP :: Char -> Bool+isUnicodeP :: Char -> Bool isUnicodeP c = isInList c [ ('!','#')@@ -3045,7 +3045,7 @@ -- ------------------------------------------------------------ -isUnicodePc :: Char -> Bool+isUnicodePc :: Char -> Bool isUnicodePc c = isInList c [ ('_','_')@@ -3058,7 +3058,7 @@ -- ------------------------------------------------------------ -isUnicodePd :: Char -> Bool+isUnicodePd :: Char -> Bool isUnicodePd c = isInList c [ ('-','-')@@ -3080,7 +3080,7 @@ -- ------------------------------------------------------------ -isUnicodePe :: Char -> Bool+isUnicodePe :: Char -> Bool isUnicodePe c = isInList c [ (')',')')@@ -3157,7 +3157,7 @@ -- ------------------------------------------------------------ -isUnicodePf :: Char -> Bool+isUnicodePf :: Char -> Bool isUnicodePf c = isInList c [ ('\187','\187')@@ -3174,7 +3174,7 @@ -- ------------------------------------------------------------ -isUnicodePi :: Char -> Bool+isUnicodePi :: Char -> Bool isUnicodePi c = isInList c [ ('\171','\171')@@ -3192,7 +3192,7 @@ -- ------------------------------------------------------------ -isUnicodePo :: Char -> Bool+isUnicodePo :: Char -> Bool isUnicodePo c = isInList c [ ('!','#')@@ -3323,7 +3323,7 @@ -- ------------------------------------------------------------ -isUnicodePs :: Char -> Bool+isUnicodePs :: Char -> Bool isUnicodePs c = isInList c [ ('(','(')@@ -3402,7 +3402,7 @@ -- ------------------------------------------------------------ -isUnicodeS :: Char -> Bool+isUnicodeS :: Char -> Bool isUnicodeS c = isInList c [ ('$','$')@@ -3607,7 +3607,7 @@ -- ------------------------------------------------------------ -isUnicodeSc :: Char -> Bool+isUnicodeSc :: Char -> Bool isUnicodeSc c = isInList c [ ('$','$')@@ -3630,7 +3630,7 @@ -- ------------------------------------------------------------ -isUnicodeSk :: Char -> Bool+isUnicodeSk :: Char -> Bool isUnicodeSk c = isInList c [ ('^','^')@@ -3663,7 +3663,7 @@ -- ------------------------------------------------------------ -isUnicodeSm :: Char -> Bool+isUnicodeSm :: Char -> Bool isUnicodeSm c = isInList c [ ('+','+')@@ -3735,7 +3735,7 @@ -- ------------------------------------------------------------ -isUnicodeSo :: Char -> Bool+isUnicodeSo :: Char -> Bool isUnicodeSo c = isInList c [ ('\166','\167')@@ -3896,7 +3896,7 @@ -- ------------------------------------------------------------ -isUnicodeZ :: Char -> Bool+isUnicodeZ :: Char -> Bool isUnicodeZ c = isInList c [ (' ',' ')@@ -3912,7 +3912,7 @@ -- ------------------------------------------------------------ -isUnicodeZl :: Char -> Bool+isUnicodeZl :: Char -> Bool isUnicodeZl c = isInList c [ ('\8232','\8232')@@ -3920,7 +3920,7 @@ -- ------------------------------------------------------------ -isUnicodeZp :: Char -> Bool+isUnicodeZp :: Char -> Bool isUnicodeZp c = isInList c [ ('\8233','\8233')@@ -3928,7 +3928,7 @@ -- ------------------------------------------------------------ -isUnicodeZs :: Char -> Bool+isUnicodeZs :: Char -> Bool isUnicodeZs c = isInList c [ (' ',' ')
src/Text/XML/HXT/RelaxNG/Utils.hs view
@@ -61,12 +61,12 @@ -- | Tests whether a URI matches the Relax NG anyURI symbol isRelaxAnyURI :: String -> Bool-isRelaxAnyURI s +isRelaxAnyURI s = s == "" || ( isURI s && not (isRelativeReference s) &&- ( let (URI _ _ path _ frag) = fromMaybe (URI "" Nothing "" "" "") $ parseURI s+ ( let (URI _ _ path _ frag) = fromMaybe (URI "" Nothing "" "" "") $ parseURI s in (frag == "" && path /= "")- )+ ) ) @@ -77,26 +77,26 @@ = normalizeURI uri1 == normalizeURI uri2 --- | Converts all letters to the corresponding lower-case letter --- and removes a trailing \"\/\" +-- | Converts all letters to the corresponding lower-case letter+-- and removes a trailing \"\/\" normalizeURI :: String -> String normalizeURI "" = "" normalizeURI uri = map toLower ( if last uri == '/'- then init uri- else uri- )+ then init uri+ else uri+ ) -checkByParsing :: Parser String -> String -> Bool+checkByParsing :: Parser String -> String -> Bool checkByParsing p s = either (const False) (const True) (parse p' "" s) where p' = do- r <- p- eof- return r+ r <- p+ eof+ return r -- | Tests whether a string matches a number [-](0-9)* isNumber :: String -> Bool@@ -105,20 +105,20 @@ where parseNumber' :: Parser String parseNumber'- = do- skipS0- m <- option "" (string "-")- n <- many1 digit- skipS0- return $ m ++ n+ = do+ skipS0+ m <- option "" (string "-")+ n <- many1 digit+ skipS0+ return $ m ++ n -isNmtoken :: String -> Bool+isNmtoken :: String -> Bool isNmtoken = checkByParsing nmtoken -isName :: String -> Bool-isName = checkByParsing name+isName :: String -> Bool+isName = checkByParsing name -{- | +{- | Formats a list of strings into a single string. The first parameter formats the elements, the 2. is inserted@@ -155,7 +155,7 @@ formatStringList _sf _sp [] = "" formatStringList sf spacer l- = reverse $ drop (length spacer) $ reverse $ + = reverse $ drop (length spacer) $ reverse $ foldr (\e -> ((if e /= "" then sf e ++ spacer else "") ++)) "" l -- ----------------------------------------
src/Text/XML/HXT/RelaxNG/Validation.hs view
@@ -70,42 +70,42 @@ -- ------------------------------------------------------------ -validateWithRelaxAndHandleErrors :: IOSArrow XmlTree XmlTree -> IOSArrow XmlTree XmlTree+validateWithRelaxAndHandleErrors :: IOSArrow XmlTree XmlTree -> IOSArrow XmlTree XmlTree validateWithRelaxAndHandleErrors theSchema = validateWithRelax theSchema >>> handleErrors -validateWithRelax :: IOSArrow XmlTree XmlTree -> IOSArrow XmlTree XmlTree+validateWithRelax :: IOSArrow XmlTree XmlTree -> IOSArrow XmlTree XmlTree validateWithRelax theSchema = traceMsg 2 "validate with Relax NG schema" >>>- ( ( normalizeForRelaxValidation -- prepare the document for validation- >>>- getChildren- >>>- isElem -- and select the root element- )- &&&- theSchema+ ( ( normalizeForRelaxValidation -- prepare the document for validation+ >>>+ getChildren+ >>>+ isElem -- and select the root element+ )+ &&&+ theSchema ) >>>- arr2A validateRelax -- compute vaidation errors as a document+ arr2A validateRelax -- compute vaidation errors as a document -handleErrors :: IOSArrow XmlTree XmlTree+handleErrors :: IOSArrow XmlTree XmlTree handleErrors = traceDoc "error found when validating with Relax NG schema" >>>- ( getChildren -- prepare error format- >>>- getText- >>>- arr ("Relax NG validation: " ++)- >>>- mkError c_err+ ( getChildren -- prepare error format+ >>>+ getText+ >>>+ arr ("Relax NG validation: " ++)+ >>>+ mkError c_err ) >>>- filterErrorMsg -- issue errors and set system status+ filterErrorMsg -- issue errors and set system status {- |@@ -117,19 +117,19 @@ normalizeForRelaxValidation = processTopDownWithAttrl (- ( none `when` -- remove all namespace attributes+ ( none `when` -- remove all namespace attributes ( isAttr- >>> + >>> getNamespaceUri >>> isA (compareURI xmlnsNamespace) ) ) >>>- (none `when` isPi) -- processing instructions+ (none `when` isPi) -- processing instructions ) >>>- collapseAllXText -- all text node sequences are merged into a single text node+ collapseAllXText -- all text node sequences are merged into a single text node -- ------------------------------------------------------------ @@ -138,13 +138,13 @@ * 1.parameter : the arrow for computing the Relax NG schema - 2.parameter : list of options for reading and validating- + - 3.parameter : XML document URI - arrow-input : ignored- + - arrow-output : list of errors or 'none'--} +-} validateDocWithRelax :: IOSArrow XmlTree XmlTree -> Attributes -> String -> IOSArrow XmlTree XmlTree validateDocWithRelax theSchema al doc@@ -163,7 +163,7 @@ * 1.parameter : XML document - arrow-input : Relax NG schema- + - arrow-output : list of errors or 'none' -} @@ -176,14 +176,14 @@ >>> ( (not . nullable) `guardsP`- root [] [ (take 1024 . show) ^>> mkText ] -- pattern may be recursive, so the string representation- -- is truncated to 1024 chars to assure termination+ root [] [ (take 1024 . show) ^>> mkText ] -- pattern may be recursive, so the string representation+ -- is truncated to 1024 chars to assure termination ) ) -- ------------------------------------------------------------ -readForRelax :: Attributes -> String -> IOSArrow b XmlTree+readForRelax :: Attributes -> String -> IOSArrow b XmlTree readForRelax options schema = getDocumentContents options schema >>>@@ -214,57 +214,57 @@ -- | tests whether a 'NameClass' contains a particular 'QName' contains :: NameClass -> QName -> Bool-contains AnyName _ = True-contains (AnyNameExcept nc) n = not (contains nc n)-contains (NsName ns1) qn = ns1 == namespaceUri qn-contains (NsNameExcept ns1 nc) qn = ns1 == namespaceUri qn && not (contains nc qn)-contains (Name ns1 ln1) qn = (ns1 == namespaceUri qn) && (ln1 == localPart qn)-contains (NameClassChoice nc1 nc2) n = (contains nc1 n) || (contains nc2 n)-contains (NCError _) _ = False+contains AnyName _ = True+contains (AnyNameExcept nc) n = not (contains nc n)+contains (NsName ns1) qn = ns1 == namespaceUri qn+contains (NsNameExcept ns1 nc) qn = ns1 == namespaceUri qn && not (contains nc qn)+contains (Name ns1 ln1) qn = (ns1 == namespaceUri qn) && (ln1 == localPart qn)+contains (NameClassChoice nc1 nc2) n = (contains nc1 n) || (contains nc2 n)+contains (NCError _) _ = False -- --------------------------------------------------------------- +-- -- | tests whether a pattern matches the empty sequence nullable:: Pattern -> Bool-nullable (Group p1 p2) = nullable p1 && nullable p2-nullable (Interleave p1 p2) = nullable p1 && nullable p2-nullable (Choice p1 p2) = nullable p1 || nullable p2-nullable (OneOrMore p) = nullable p-nullable (Element _ _) = False-nullable (Attribute _ _) = False-nullable (List _) = False-nullable (Value _ _ _) = False-nullable (Data _ _) = False-nullable (DataExcept _ _ _) = False-nullable (NotAllowed _) = False-nullable Empty = True-nullable Text = True-nullable (After _ _) = False+nullable (Group p1 p2) = nullable p1 && nullable p2+nullable (Interleave p1 p2) = nullable p1 && nullable p2+nullable (Choice p1 p2) = nullable p1 || nullable p2+nullable (OneOrMore p) = nullable p+nullable (Element _ _) = False+nullable (Attribute _ _) = False+nullable (List _) = False+nullable (Value _ _ _) = False+nullable (Data _ _) = False+nullable (DataExcept _ _ _) = False+nullable (NotAllowed _) = False+nullable Empty = True+nullable Text = True+nullable (After _ _) = False -- --------------------------------------------------------------- +-- -- | computes the derivative of a pattern with respect to a XML-Child and a 'Context' childDeriv :: Context -> Pattern -> XmlTree -> Pattern childDeriv cx p t- | XN.isText t = textDeriv cx p . fromJust . XN.getText $ t- | XN.isElem t = endTagDeriv p4- | otherwise = notAllowed "Call to childDeriv with wrong arguments"+ | XN.isText t = textDeriv cx p . fromJust . XN.getText $ t+ | XN.isElem t = endTagDeriv p4+ | otherwise = notAllowed "Call to childDeriv with wrong arguments" where- children = XN.getChildren $ t- qn = fromJust . XN.getElemName $ t - atts = fromJust . XN.getAttrl $ t- cx1 = ("",[])- p1 = startTagOpenDeriv p qn- p2 = attsDeriv cx1 p1 atts- p3 = startTagCloseDeriv p2- p4 = childrenDeriv cx1 p3 children+ children = XN.getChildren $ t+ qn = fromJust . XN.getElemName $ t+ atts = fromJust . XN.getAttrl $ t+ cx1 = ("",[])+ p1 = startTagOpenDeriv p qn+ p2 = attsDeriv cx1 p1 atts+ p3 = startTagCloseDeriv p2+ p4 = childrenDeriv cx1 p3 children -- --------------------------------------------------------------- +-- -- | computes the derivative of a pattern with respect to a text node textDeriv :: Context -> Pattern -> String -> Pattern@@ -297,39 +297,39 @@ textDeriv cx1 (Value (uri, s) value cx2) s1 = case datatypeEqual uri s value cx2 s1 cx1 of- Nothing -> Empty + Nothing -> Empty Just errStr -> notAllowed errStr textDeriv cx (Data (uri, s) params) s1 = case datatypeAllows uri s params s1 cx of- Nothing -> Empty + Nothing -> Empty Just errStr -> notAllowed2 errStr textDeriv cx (DataExcept (uri, s) params p) s1 = case (datatypeAllows uri s params s1 cx) of- Nothing -> if not $ nullable $ textDeriv cx p s1 - then Empty - else notAllowed- ( "Any value except " ++- show (show p) ++ - " expected, but value " ++- show (show s1) ++- " found"- )+ Nothing -> if not $ nullable $ textDeriv cx p s1+ then Empty+ else notAllowed+ ( "Any value except " +++ show (show p) +++ " expected, but value " +++ show (show s1) +++ " found"+ ) Just errStr -> notAllowed errStr textDeriv cx (List p) s- = if nullable (listDeriv cx p (words s)) + = if nullable (listDeriv cx p (words s)) then Empty else notAllowed- ( "List with value(s) " ++- show p ++ - " expected, but value(s) " ++ - formatStringListQuot (words s) ++- " found"- )+ ( "List with value(s) " +++ show p +++ " expected, but value(s) " +++ formatStringListQuot (words s) +++ " found"+ ) textDeriv _ n@(NotAllowed _) _ = n@@ -337,13 +337,13 @@ textDeriv _ p s = notAllowed ( "Pattern " ++ show (getPatternName p) ++- " expected, but text " ++ show s ++ " found"+ " expected, but text " ++ show s ++ " found" ) -- --------------------------------------------------------------- --- | To compute the derivative of a pattern with respect to a list of strings, +--+-- | To compute the derivative of a pattern with respect to a list of strings, -- simply compute the derivative with respect to each member of the list in turn. listDeriv :: Context -> Pattern -> [String] -> Pattern@@ -353,10 +353,10 @@ listDeriv cx p (x:xs) = listDeriv cx (textDeriv cx p x) xs- + -- --------------------------------------------------------------- +-- -- | computes the derivative of a pattern with respect to a start tag open startTagOpenDeriv :: Pattern -> QName -> Pattern@@ -366,11 +366,11 @@ startTagOpenDeriv (Element nc p) qn | contains nc qn- = after p Empty+ = after p Empty | otherwise- = notAllowed $- "Element with name " ++ nameClassToString nc ++ - " expected, but " ++ universalName qn ++ " found"+ = notAllowed $+ "Element with name " ++ nameClassToString nc +++ " expected, but " ++ universalName qn ++ " found" startTagOpenDeriv (Interleave p1 p2) qn = choice@@ -386,7 +386,7 @@ = let x = applyAfter (flip group p2) (startTagOpenDeriv p1 qn) in- if nullable p1 + if nullable p1 then choice x (startTagOpenDeriv p2 qn) else x @@ -416,7 +416,7 @@ res = attDeriv cx p t -} --- | To compute the derivative of a pattern with respect to a sequence of attributes, +-- | To compute the derivative of a pattern with respect to a sequence of attributes, -- simply compute the derivative with respect to each attribute in turn. attsDeriv :: Context -> Pattern -> XmlTrees -> Pattern@@ -425,9 +425,9 @@ = p attsDeriv cx p (t : ts) | XN.isAttr t- = attsDeriv cx (attDeriv cx p t) ts+ = attsDeriv cx (attDeriv cx p t) ts | otherwise- = notAllowed "Call to attsDeriv with wrong arguments"+ = notAllowed "Call to attsDeriv with wrong arguments" attDeriv :: Context -> Pattern -> XmlTree -> Pattern @@ -456,20 +456,20 @@ | isa && not (contains nc qn)- = notAllowed1 $- "Attribute with name " ++ nameClassToString nc+ = notAllowed1 $+ "Attribute with name " ++ nameClassToString nc ++ " expected, but " ++ universalName qn ++ " found" | isa && ( ( nullable p- &&- whitespace val- )- || nullable p'+ &&+ whitespace val+ )+ || nullable p' )- = Empty+ = Empty | isa- = err' p'+ = err' p' where isa = XN.isAttr $ att qn = fromJust . XN.getAttrName $ att@@ -478,13 +478,13 @@ p' = textDeriv cx p val err' (NotAllowed (ErrMsg _l es))- = err'' (": " ++ head es)+ = err'' (": " ++ head es) err' _- = err'' ""+ = err'' "" err'' e- = notAllowed2 $- "Attribute value \"" ++ val ++- "\" does not match datatype spec " ++ show p ++ e+ = notAllowed2 $+ "Attribute value \"" ++ val +++ "\" does not match datatype spec " ++ show p ++ e attDeriv _ n@(NotAllowed _) _ = n@@ -494,7 +494,7 @@ "No matching pattern for attribute '" ++ showXts [att] ++ "' found" -- --------------------------------------------------------------- +-- -- | computes the derivative of a pattern with respect to a start tag close startTagCloseDeriv :: Pattern -> Pattern@@ -522,7 +522,7 @@ startTagCloseDeriv (Attribute nc _) = notAllowed1 $- "Attribut with name, " ++ show nc ++ + "Attribut with name, " ++ show nc ++ " expected, but no more attributes found" startTagCloseDeriv p@@ -530,8 +530,8 @@ -- --------------------------------------------------------------- --- | Computing the derivative of a pattern with respect to a list of children involves +--+-- | Computing the derivative of a pattern with respect to a list of children involves -- computing the derivative with respect to each pattern in turn, except -- that whitespace requires special treatment. @@ -546,16 +546,16 @@ | ist && whitespace s- = choice p p1+ = choice p p1 | ist- = p1+ = p1 where ist = XN.isText tt s = fromJust . XN.getText $ tt p1 = childDeriv cx p tt childrenDeriv cx p children- = stripChildrenDeriv cx p children + = stripChildrenDeriv cx p children stripChildrenDeriv :: Context -> Pattern -> XmlTrees -> Pattern stripChildrenDeriv _ p []@@ -564,13 +564,13 @@ stripChildrenDeriv cx p (h:t) = stripChildrenDeriv cx ( if strip h- then p- else (childDeriv cx p h)+ then p+ else (childDeriv cx p h) ) t -- --------------------------------------------------------------- +-- -- | computes the derivative of a pattern with respect to a end tag endTagDeriv :: Pattern -> Pattern@@ -578,11 +578,11 @@ = choice (endTagDeriv p1) (endTagDeriv p2) endTagDeriv (After p1 p2)- | nullable p1 - = p2 + | nullable p1+ = p2 | otherwise- = notAllowed $- show p1 ++ " expected"+ = notAllowed $+ show p1 ++ " expected" endTagDeriv n@(NotAllowed _) = n@@ -591,27 +591,27 @@ = notAllowed "Call to endTagDeriv with wrong arguments" -- --------------------------------------------------------------- +-- -- | applies a function (first parameter) to the second part of a after pattern applyAfter :: (Pattern -> Pattern) -> Pattern -> Pattern -applyAfter f (After p1 p2) = after p1 (f p2)-applyAfter f (Choice p1 p2) = choice (applyAfter f p1) (applyAfter f p2)-applyAfter _ n@(NotAllowed _) = n-applyAfter _ _ = notAllowed "Call to applyAfter with wrong arguments"+applyAfter f (After p1 p2) = after p1 (f p2)+applyAfter f (Choice p1 p2) = choice (applyAfter f p1) (applyAfter f p2)+applyAfter _ n@(NotAllowed _) = n+applyAfter _ _ = notAllowed "Call to applyAfter with wrong arguments" -- -------------------- -- mothers little helpers -strip :: XmlTree -> Bool-strip = maybe False whitespace . XN.getText+strip :: XmlTree -> Bool+strip = maybe False whitespace . XN.getText -whitespace :: String -> Bool-whitespace = all isXmlSpaceChar+whitespace :: String -> Bool+whitespace = all isXmlSpaceChar -showXts :: XmlTrees -> String-showXts = concat . runLA (xshow $ arrL id)+showXts :: XmlTrees -> String+showXts = concat . runLA (xshow $ arrL id) -- ------------------------------------------------------------
src/Text/XML/HXT/RelaxNG/Validator.hs view
@@ -42,11 +42,11 @@ options evaluated by validateDocumentWithRelaxSchema: * 'a_check_restrictions' : check Relax NG schema restrictions when simplifying the schema (default: on)- + - 'a_validate_externalRef' : validate a Relax NG schema referenced by a externalRef-Pattern (default: on)- + - 'a_validate_include' : validate a Relax NG schema referenced by a include-Pattern (default: on)- + all other options are propagated to the read functions for schema input example:@@ -56,63 +56,63 @@ -} -validateDocumentWithRelaxSchema :: Attributes -> String -> IOStateArrow s XmlTree XmlTree+validateDocumentWithRelaxSchema :: Attributes -> String -> IOStateArrow s XmlTree XmlTree validateDocumentWithRelaxSchema userOptions relaxSchema = withOtherUserState () $- ( ( validate' $< validSchema ) -- try to validate, only possible if schema is o.k.- `orElse`- this+ ( ( validate' $< validSchema ) -- try to validate, only possible if schema is o.k.+ `orElse`+ this ) `when`- documentStatusOk -- only do something when document status is ok+ documentStatusOk -- only do something when document status is ok where validate' schema- = setDocumentStatusFromSystemState "read and build Relax NG schema"- >>>- validateDocumentWithRelax schema+ = setDocumentStatusFromSystemState "read and build Relax NG schema"+ >>>+ validateDocumentWithRelax schema validSchema- = traceMsg 2 ( "read Relax NG schema document: " ++ show relaxSchema )- >>>- readForRelax remainingOptions relaxSchema- >>>- perform ( let checkSchema = True in -- test option in al- if checkSchema- then validateWithRelaxAndHandleErrors S.relaxSchemaArrow- else none- )+ = traceMsg 2 ( "read Relax NG schema document: " ++ show relaxSchema ) >>>- traceMsg 2 "create simplified schema"- >>>- createSimpleForm remainingOptions- ( hasOption a_check_restrictions )- ( hasOption a_validate_externalRef )- ( hasOption a_validate_include )- >>>- traceDoc "simplified schema"+ readForRelax remainingOptions relaxSchema >>>- perform ( getErrors- >>>- handleSimplificationErrors- )+ perform ( let checkSchema = True in -- test option in al+ if checkSchema+ then validateWithRelaxAndHandleErrors S.relaxSchemaArrow+ else none+ )+ >>>+ traceMsg 2 "create simplified schema"+ >>>+ createSimpleForm remainingOptions+ ( hasOption a_check_restrictions )+ ( hasOption a_validate_externalRef )+ ( hasOption a_validate_include )+ >>>+ traceDoc "simplified schema"+ >>>+ perform ( getErrors+ >>>+ handleSimplificationErrors+ ) hasOption n- = optionIsSet n options+ = optionIsSet n options options = addEntries userOptions defaultOptions defaultOptions- = [ ( a_check_restrictions, v_1 )- , ( a_validate_externalRef, v_1 )- , ( a_validate_include, v_1 )- ]+ = [ ( a_check_restrictions, v_1 )+ , ( a_validate_externalRef, v_1 )+ , ( a_validate_include, v_1 )+ ] remainingOptions- = filter (not . flip hasEntry defaultOptions . fst) options+ = filter (not . flip hasEntry defaultOptions . fst) options -handleSimplificationErrors :: IOSArrow XmlTree XmlTree+handleSimplificationErrors :: IOSArrow XmlTree XmlTree handleSimplificationErrors = traceDoc "simplification errors" >>>@@ -134,15 +134,15 @@ - arrow-output : the validated and unchanged document or the empty document with status information set in the root node -} -validateDocumentWithRelax :: XmlTree -> IOSArrow XmlTree XmlTree+validateDocumentWithRelax :: XmlTree -> IOSArrow XmlTree XmlTree validateDocumentWithRelax schema = ( traceMsg 1 "validate document with Relax NG schema"- >>>- perform ( validateWithRelaxAndHandleErrors (constA schema) )- >>>- setDocumentStatusFromSystemState "validate document with Relax NG schema"+ >>>+ perform ( validateWithRelaxAndHandleErrors (constA schema) )+ >>>+ setDocumentStatusFromSystemState "validate document with Relax NG schema" )- `when` documentStatusOk -- only do something when document status is ok+ `when` documentStatusOk -- only do something when document status is ok {- |@@ -168,25 +168,25 @@ * 1.parameter : list of options; namespace progagation is always done - 2.parameter : XML document- + - 3.parameter : Relax NG schema file available options: * 'a_do_not_check_restrictions' : do not check Relax NG schema restrictions (includes do-not-validate-externalRef, do-not-validate-include)- + - 'a_do_not_validate_externalRef' : do not validate a Relax NG schema referenced by a externalRef-Pattern- + - 'a_validate_externalRef' : validate a Relax NG schema referenced by a externalRef-Pattern (default)- + - 'a_do_not_validate_include' : do not validate a Relax NG schema referenced by a include-Pattern- + - 'a_validate_include' : validate a Relax NG schema referenced by a include-Pattern (default)- + - 'a_output_changes' : output Pattern transformations in case of an error- + - 'a_do_not_collect_errors' : stop Relax NG simplification after the first error has occurred- + - all 'Text.XML.HXT.Arrow.ReadDocument.readDocument' options example:@@ -197,7 +197,7 @@ validate :: Attributes -> String -> String -> IOSArrow n XmlTree validate al xmlDocument relaxSchema = S.relaxSchemaArrow- >>> + >>> validateWithSpezification al xmlDocument relaxSchema @@ -210,7 +210,7 @@ * 1.parameter : list of available options (see also: 'validate') - 2.parameter : Relax NG schema file- + -} validateSchema :: Attributes -> String -> IOSArrow n XmlTree validateSchema al relaxSchema@@ -225,9 +225,9 @@ * 1.parameter : list of available options (see also: 'validate') - 2.parameter : XML document- + - 3.parameter : Relax NG schema file- + - arrow-input : Relax NG Specification in simple form example:@@ -247,14 +247,14 @@ -- returns a list of errors or none if the schema is correct ( validateRelax $< ( readForRelax al relaxSchema- >>>- getChildren- )+ >>>+ getChildren+ ) ) `orElse` -- validation of the xml document with respect to the schema- -- returns a list of errors or none if the xml document is correct + -- returns a list of errors or none if the xml document is correct validateWithoutSpezification al xmlDocument relaxSchema @@ -264,8 +264,8 @@ * 1.parameter : list of available options (see also: 'validate') - - 2.parameter : Relax NG schema file - + - 2.parameter : Relax NG schema file+ - arrow-input : Relax NG Specification in simple form -} @@ -282,27 +282,27 @@ * 1.parameter : list of available options (see also: 'validate') - 2.parameter : XML document- + - 3.parameter : Relax NG schema file- + -} validateWithoutSpezification :: Attributes -> String -> String -> IOSArrow n XmlTree validateWithoutSpezification al xmlDocument relaxSchema = readForRelax al relaxSchema- >>> + >>> createSimpleForm al True True True >>>- ( ( getErrors >>> perform handleSimplificationErrors ) -- issue errors in schema simplification+ ( ( getErrors >>> perform handleSimplificationErrors ) -- issue errors in schema simplification `orElse`- ( if null xmlDocument -- no errors: validate document- then none- else validateRelax $< ( readForRelax al xmlDocument- >>>- normalizeForRelaxValidation- >>>- getChildren- )+ ( if null xmlDocument -- no errors: validate document+ then none+ else validateRelax $< ( readForRelax al xmlDocument+ >>>+ normalizeForRelaxValidation+ >>>+ getChildren+ ) ) )
src/Text/XML/HXT/RelaxNG/XmlSchema/DataTypeLibW3C.hs view
@@ -20,7 +20,7 @@ ( w3cNS , w3cDatatypeLib - , xsd_string -- data type names+ , xsd_string -- data type names , xsd_normalizedString , xsd_token , xsd_language@@ -40,7 +40,7 @@ , xsd_base64Binary , xsd_decimal - , xsd_length -- facet names+ , xsd_length -- facet names , xsd_maxLength , xsd_minLength , xsd_maxExclusive@@ -57,25 +57,25 @@ import Data.Maybe import Data.Ratio -import Network.URI ( isURIReference )+import Network.URI ( isURIReference ) -import Text.XML.HXT.DOM.QualifiedName ( isWellformedQualifiedName- , isNCName- )+import Text.XML.HXT.DOM.QualifiedName ( isWellformedQualifiedName+ , isNCName+ ) import Text.XML.HXT.RelaxNG.DataTypeLibUtils-import Text.XML.HXT.RelaxNG.XmlSchema.Regex ( Regex- , matchWithRE- )+import Text.XML.HXT.RelaxNG.XmlSchema.Regex ( Regex+ , matchWithRE+ ) import Text.XML.HXT.RelaxNG.XmlSchema.RegexParser ( parseRegex- )- + )+ -- ------------------------------------------------------------ -- | Namespace of the W3C XML schema datatype library -w3cNS :: String-w3cNS = "http://www.w3.org/2001/XMLSchema-datatypes"+w3cNS :: String+w3cNS = "http://www.w3.org/2001/XMLSchema-datatypes" xsd_string@@ -111,38 +111,38 @@ , xsd_unsignedShort , xsd_unsignedByte :: String -xsd_string = "string"-xsd_normalizedString = "normalizedString"-xsd_token = "token"-xsd_language = "language"-xsd_NMTOKEN = "NMTOKEN"-xsd_NMTOKENS = "NMTOKENS"-xsd_Name = "Name"-xsd_NCName = "NCName"-xsd_ID = "ID"-xsd_IDREF = "IDREF"-xsd_IDREFS = "IDREFS"-xsd_ENTITY = "ENTITY"-xsd_ENTITIES = "ENTITIES"-xsd_anyURI = "anyURI"-xsd_QName = "QName"-xsd_NOTATION = "NOTATION"-xsd_hexBinary = "hexBinary"-xsd_base64Binary = "base64Binary"-xsd_decimal = "decimal"-xsd_integer = "integer"-xsd_nonPositiveInteger = "nonPositiveInteger"-xsd_negativeInteger = "negativeInteger"-xsd_nonNegativeInteger = "nonNegativeInteger"-xsd_positiveInteger = "positiveInteger"-xsd_long = "long"-xsd_int = "int"-xsd_short = "short"-xsd_byte = "byte"-xsd_unsignedLong = "unsignedLong"-xsd_unsignedInt = "unsignedInt"-xsd_unsignedShort = "unsignedShort"-xsd_unsignedByte = "unsignedByte"+xsd_string = "string"+xsd_normalizedString = "normalizedString"+xsd_token = "token"+xsd_language = "language"+xsd_NMTOKEN = "NMTOKEN"+xsd_NMTOKENS = "NMTOKENS"+xsd_Name = "Name"+xsd_NCName = "NCName"+xsd_ID = "ID"+xsd_IDREF = "IDREF"+xsd_IDREFS = "IDREFS"+xsd_ENTITY = "ENTITY"+xsd_ENTITIES = "ENTITIES"+xsd_anyURI = "anyURI"+xsd_QName = "QName"+xsd_NOTATION = "NOTATION"+xsd_hexBinary = "hexBinary"+xsd_base64Binary = "base64Binary"+xsd_decimal = "decimal"+xsd_integer = "integer"+xsd_nonPositiveInteger = "nonPositiveInteger"+xsd_negativeInteger = "negativeInteger"+xsd_nonNegativeInteger = "nonNegativeInteger"+xsd_positiveInteger = "positiveInteger"+xsd_long = "long"+xsd_int = "int"+xsd_short = "short"+xsd_byte = "byte"+xsd_unsignedLong = "unsignedLong"+xsd_unsignedInt = "unsignedInt"+xsd_unsignedShort = "unsignedShort"+xsd_unsignedByte = "unsignedByte" xsd_length@@ -157,20 +157,20 @@ , xsd_pattern , xsd_enumeration :: String -xsd_length = rng_length-xsd_maxLength = rng_maxLength-xsd_minLength = rng_minLength+xsd_length = rng_length+xsd_maxLength = rng_maxLength+xsd_minLength = rng_minLength -xsd_maxExclusive = rng_maxExclusive-xsd_minExclusive = rng_minExclusive-xsd_maxInclusive = rng_maxInclusive-xsd_minInclusive = rng_minInclusive+xsd_maxExclusive = rng_maxExclusive+xsd_minExclusive = rng_minExclusive+xsd_maxInclusive = rng_maxInclusive+xsd_minInclusive = rng_minInclusive -xsd_totalDigits = "totalDigits"-xsd_fractionDigits = "fractionDigits"+xsd_totalDigits = "totalDigits"+xsd_fractionDigits = "fractionDigits" -xsd_pattern = "pattern"-xsd_enumeration = "enumeration"+xsd_pattern = "pattern"+xsd_enumeration = "enumeration" -- ---------------------------------------- @@ -185,70 +185,70 @@ -- | All supported datatypes of the library w3cDatatypes :: AllowedDatatypes-w3cDatatypes = [ (xsd_string, stringParams)- , (xsd_normalizedString, stringParams)- , (xsd_token, stringParams)- , (xsd_language, stringParams)- , (xsd_NMTOKEN, stringParams)- , (xsd_NMTOKENS, listParams )- , (xsd_Name, stringParams)- , (xsd_NCName, stringParams)- , (xsd_ID, stringParams)- , (xsd_IDREF, stringParams)- , (xsd_IDREFS, listParams )- , (xsd_ENTITY, stringParams)- , (xsd_ENTITIES, listParams )- , (xsd_anyURI, stringParams)- , (xsd_QName, stringParams)- , (xsd_NOTATION, stringParams)- , (xsd_hexBinary, stringParams)- , (xsd_base64Binary, stringParams)- , (xsd_decimal, decimalParams)- , (xsd_integer, integerParams)- , (xsd_nonPositiveInteger, integerParams)- , (xsd_negativeInteger, integerParams)- , (xsd_nonNegativeInteger, integerParams)- , (xsd_positiveInteger, integerParams)- , (xsd_long, integerParams)- , (xsd_int, integerParams)- , (xsd_short, integerParams)- , (xsd_byte, integerParams)- , (xsd_unsignedLong, integerParams)- , (xsd_unsignedInt, integerParams)- , (xsd_unsignedShort, integerParams)- , (xsd_unsignedByte, integerParams)+w3cDatatypes = [ (xsd_string, stringParams)+ , (xsd_normalizedString, stringParams)+ , (xsd_token, stringParams)+ , (xsd_language, stringParams)+ , (xsd_NMTOKEN, stringParams)+ , (xsd_NMTOKENS, listParams )+ , (xsd_Name, stringParams)+ , (xsd_NCName, stringParams)+ , (xsd_ID, stringParams)+ , (xsd_IDREF, stringParams)+ , (xsd_IDREFS, listParams )+ , (xsd_ENTITY, stringParams)+ , (xsd_ENTITIES, listParams )+ , (xsd_anyURI, stringParams)+ , (xsd_QName, stringParams)+ , (xsd_NOTATION, stringParams)+ , (xsd_hexBinary, stringParams)+ , (xsd_base64Binary, stringParams)+ , (xsd_decimal, decimalParams)+ , (xsd_integer, integerParams)+ , (xsd_nonPositiveInteger, integerParams)+ , (xsd_negativeInteger, integerParams)+ , (xsd_nonNegativeInteger, integerParams)+ , (xsd_positiveInteger, integerParams)+ , (xsd_long, integerParams)+ , (xsd_int, integerParams)+ , (xsd_short, integerParams)+ , (xsd_byte, integerParams)+ , (xsd_unsignedLong, integerParams)+ , (xsd_unsignedInt, integerParams)+ , (xsd_unsignedShort, integerParams)+ , (xsd_unsignedByte, integerParams) ] -- ---------------------------------------- -- | List of allowed params for the string datatypes-stringParams :: AllowedParams-stringParams = xsd_pattern : map fst fctTableString+stringParams :: AllowedParams+stringParams = xsd_pattern : map fst fctTableString -- ---------------------------------------- -patternValid :: ParamList -> CheckString+patternValid :: ParamList -> CheckString patternValid params = foldr (>>>) ok . map paramPatternValid $ params where paramPatternValid (pn, pv)- | pn == xsd_pattern = assert (patParamValid pv) (errorMsgParam pn pv)- | otherwise = ok+ | pn == xsd_pattern = assert (patParamValid pv) (errorMsgParam pn pv)+ | otherwise = ok patParamValid :: String -> String -> Bool patParamValid regex a = case parseRegex regex of- (Left _ ) -> False- (Right ex) -> isNothing . matchWithRE ex $ a+ (Left _ ) -> False+ (Right ex) -> isNothing . matchWithRE ex $ a -- ---------------------------------------- -- | List of allowed params for the decimal datatypes -decimalParams :: AllowedParams-decimalParams = xsd_pattern : map fst fctTableDecimal+decimalParams :: AllowedParams+decimalParams = xsd_pattern : map fst fctTableDecimal -fctTableDecimal :: [(String, String -> Rational -> Bool)]+fctTableDecimal :: [(String, String -> Rational -> Bool)] fctTableDecimal = [ (xsd_maxExclusive, cvd (>)) , (xsd_minExclusive, cvd (<))@@ -258,29 +258,29 @@ , (xsd_fractionDigits, cvi (\ l v -> fractionDigits v == l)) ] where- cvd :: (Rational -> Rational -> Bool) -> (String -> Rational -> Bool)- cvd op = \ x y -> isDecimal x && readDecimal x `op` y+ cvd :: (Rational -> Rational -> Bool) -> (String -> Rational -> Bool)+ cvd op = \ x y -> isDecimal x && readDecimal x `op` y - cvi :: (Int -> Rational -> Bool) -> (String -> Rational -> Bool)- cvi op = \ x y -> isNumber x && read x `op` y+ cvi :: (Int -> Rational -> Bool) -> (String -> Rational -> Bool)+ cvi op = \ x y -> isNumber x && read x `op` y -decimalValid :: ParamList -> CheckA Rational Rational+decimalValid :: ParamList -> CheckA Rational Rational decimalValid params = foldr (>>>) ok . map paramDecimalValid $ params where paramDecimalValid (pn, pv)- = assert- ((fromMaybe (const . const $ True) . lookup pn $ fctTableDecimal) pv)- (errorMsgParam pn pv . showDecimal)+ = assert+ ((fromMaybe (const . const $ True) . lookup pn $ fctTableDecimal) pv)+ (errorMsgParam pn pv . showDecimal) -- ---------------------------------------- -- | List of allowed params for the decimal and integer datatypes -integerParams :: AllowedParams-integerParams = xsd_pattern : map fst fctTableInteger+integerParams :: AllowedParams+integerParams = xsd_pattern : map fst fctTableInteger -fctTableInteger :: [(String, String -> Integer -> Bool)]+fctTableInteger :: [(String, String -> Integer -> Bool)] fctTableInteger = [ (xsd_maxExclusive, cvi (>)) , (xsd_minExclusive, cvi (<))@@ -289,65 +289,65 @@ , (xsd_totalDigits, cvi (\ l v -> totalD v == toInteger l)) ] where- cvi :: (Integer -> Integer -> Bool) -> (String -> Integer -> Bool)- cvi op = \ x y -> isNumber x && read x `op` y+ cvi :: (Integer -> Integer -> Bool) -> (String -> Integer -> Bool)+ cvi op = \ x y -> isNumber x && read x `op` y totalD i- | i < 0 = totalD (0-i)- | otherwise = toInteger . length . show $ i+ | i < 0 = totalD (0-i)+ | otherwise = toInteger . length . show $ i -integerValid :: DatatypeName -> ParamList -> CheckA Integer Integer-integerValid datatype params +integerValid :: DatatypeName -> ParamList -> CheckA Integer Integer+integerValid datatype params = assertInRange >>> (foldr (>>>) ok . map paramIntegerValid $ params) where- assertInRange :: CheckA Integer Integer+ assertInRange :: CheckA Integer Integer assertInRange- = assert- (fromMaybe (const True) . lookup datatype $ integerRangeTable)- (\ v -> ( "Datatype " ++ show datatype ++- " with value = " ++ show v ++- " not in integer value range"- )- )+ = assert+ (fromMaybe (const True) . lookup datatype $ integerRangeTable)+ (\ v -> ( "Datatype " ++ show datatype +++ " with value = " ++ show v +++ " not in integer value range"+ )+ ) paramIntegerValid (pn, pv)- = assert- ((fromMaybe (const . const $ True) . lookup pn $ fctTableInteger) pv)- (errorMsgParam pn pv . show)+ = assert+ ((fromMaybe (const . const $ True) . lookup pn $ fctTableInteger) pv)+ (errorMsgParam pn pv . show) -integerRangeTable :: [(String, Integer -> Bool)]-integerRangeTable = [ (xsd_integer, const True)- , (xsd_nonPositiveInteger, (<=0) )- , (xsd_negativeInteger, ( <0) )- , (xsd_nonNegativeInteger, (>=0) )- , (xsd_positiveInteger, ( >0) )- , (xsd_long, inR 9223372036854775808)- , (xsd_int, inR 2147483648)- , (xsd_short, inR 32768)- , (xsd_byte, inR 128)- , (xsd_unsignedLong, inP 18446744073709551616)- , (xsd_unsignedInt, inP 4294967296)- , (xsd_unsignedShort, inP 65536)- , (xsd_unsignedByte, inP 256)- ]+integerRangeTable :: [(String, Integer -> Bool)]+integerRangeTable = [ (xsd_integer, const True)+ , (xsd_nonPositiveInteger, (<=0) )+ , (xsd_negativeInteger, ( <0) )+ , (xsd_nonNegativeInteger, (>=0) )+ , (xsd_positiveInteger, ( >0) )+ , (xsd_long, inR 9223372036854775808)+ , (xsd_int, inR 2147483648)+ , (xsd_short, inR 32768)+ , (xsd_byte, inR 128)+ , (xsd_unsignedLong, inP 18446744073709551616)+ , (xsd_unsignedInt, inP 4294967296)+ , (xsd_unsignedShort, inP 65536)+ , (xsd_unsignedByte, inP 256)+ ] where- inR b i = (0 - b) <= i && i < b- inP b i = 0 <= i && i < b+ inR b i = (0 - b) <= i && i < b+ inP b i = 0 <= i && i < b -- ---------------------------------------- -- | List of allowed params for the list datatypes -listParams :: AllowedParams-listParams = xsd_pattern : map fst fctTableList+listParams :: AllowedParams+listParams = xsd_pattern : map fst fctTableList -listValid :: DatatypeName -> ParamList -> CheckString-listValid d = stringValidFT fctTableList d 0 (-1)+listValid :: DatatypeName -> ParamList -> CheckString+listValid d = stringValidFT fctTableList d 0 (-1) -- ---------------------------------------- -isNameList :: (String -> Bool) -> String -> Bool+isNameList :: (String -> Bool) -> String -> Bool isNameList p w = not (null ts) && all p ts where@@ -355,11 +355,11 @@ -- ---------------------------------------- -rex :: String -> Regex-rex = either undefined id . parseRegex+rex :: String -> Regex+rex = either undefined id . parseRegex -isRex :: Regex -> String -> Bool-isRex ex = isNothing . matchWithRE ex+isRex :: Regex -> String -> Bool+isRex ex = isNothing . matchWithRE ex -- ---------------------------------------- @@ -367,106 +367,106 @@ , rexHexBinary , rexBase64Binary , rexDecimal- , rexInteger :: Regex+ , rexInteger :: Regex -rexLanguage = rex "[A-Za-z]{1,8}(-[A-Za-z]{1,8})*"-rexHexBinary = rex "([A-Fa-f0-9]{2})*"-rexBase64Binary = rex $- "(" ++ b64 ++ "{4})*((" ++ b64 ++ "{2}==)|(" ++ b64 ++ "{3}=)|)"- where- b64 = "[A-Za-z0-9+/]"-rexDecimal = rex "(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))"-rexInteger = rex "(\\+|-)?[0-9]+"+rexLanguage = rex "[A-Za-z]{1,8}(-[A-Za-z]{1,8})*"+rexHexBinary = rex "([A-Fa-f0-9]{2})*"+rexBase64Binary = rex $+ "(" ++ b64 ++ "{4})*((" ++ b64 ++ "{2}==)|(" ++ b64 ++ "{3}=)|)"+ where+ b64 = "[A-Za-z0-9+/]"+rexDecimal = rex "(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))"+rexInteger = rex "(\\+|-)?[0-9]+" isLanguage , isHexBinary , isBase64Binary , isDecimal- , isInteger :: String -> Bool+ , isInteger :: String -> Bool -isLanguage = isRex rexLanguage-isHexBinary = isRex rexHexBinary-isBase64Binary = isRex rexBase64Binary-isDecimal = isRex rexDecimal-isInteger = isRex rexInteger+isLanguage = isRex rexLanguage+isHexBinary = isRex rexHexBinary+isBase64Binary = isRex rexBase64Binary+isDecimal = isRex rexDecimal+isInteger = isRex rexInteger -- ---------------------------------------- -normBase64 :: String -> String-normBase64 = filter isB64- where- isB64 c = ( 'A' <= c && c <= 'Z')- ||- ( 'a' <= c && c <= 'z')- ||- ( '0' <= c && c <= '9')- ||- c == '+'- ||- c == '/'- ||- c == '='+normBase64 :: String -> String+normBase64 = filter isB64+ where+ isB64 c = ( 'A' <= c && c <= 'Z')+ ||+ ( 'a' <= c && c <= 'z')+ ||+ ( '0' <= c && c <= '9')+ ||+ c == '+'+ ||+ c == '/'+ ||+ c == '=' -- ---------------------------------------- readDecimal- , readDecimal' :: String -> Rational+ , readDecimal' :: String -> Rational -readDecimal ('+':s) = readDecimal' s-readDecimal ('-':s) = negate (readDecimal' s)-readDecimal s = readDecimal' s+readDecimal ('+':s) = readDecimal' s+readDecimal ('-':s) = negate (readDecimal' s)+readDecimal s = readDecimal' s readDecimal' s- | f == 0 = (n % 1)- | otherwise = (n % 1) + (f % (10 ^ (toInteger (length fs))))+ | f == 0 = (n % 1)+ | otherwise = (n % 1) + (f % (10 ^ (toInteger (length fs)))) where (ns, fs') = span (/= '.') s fs = drop 1 fs' f :: Integer- f | null fs = 0- | otherwise = read fs+ f | null fs = 0+ | otherwise = read fs n :: Integer- n | null ns = 0- | otherwise = read ns+ n | null ns = 0+ | otherwise = read ns totalDigits , totalDigits'- , fractionDigits :: Rational -> Int+ , fractionDigits :: Rational -> Int totalDigits r- | r == 0 = 0- | r < 0 = totalDigits' . negate $ r- | otherwise = totalDigits' $ r+ | r == 0 = 0+ | r < 0 = totalDigits' . negate $ r+ | otherwise = totalDigits' $ r totalDigits' r- | denominator r == 1 = length . show . numerator $ r- | r < (1%1) = (\ x -> x-1) . totalDigits' . (+ (1%1)) $ r- | otherwise = totalDigits' . (* (10 % 1)) $ r+ | denominator r == 1 = length . show . numerator $ r+ | r < (1%1) = (\ x -> x-1) . totalDigits' . (+ (1%1)) $ r+ | otherwise = totalDigits' . (* (10 % 1)) $ r fractionDigits r- | denominator r == 1 = 0- | otherwise = (+1) . fractionDigits . (* (10 % 1)) $ r+ | denominator r == 1 = 0+ | otherwise = (+1) . fractionDigits . (* (10 % 1)) $ r showDecimal- , showDecimal' :: Rational -> String+ , showDecimal' :: Rational -> String showDecimal d- | d < 0 = ('-':) . showDecimal' . negate $ d- | d < 1 = drop 1 . showDecimal' . (+ (1%1)) $ d- | otherwise = showDecimal' $ d+ | d < 0 = ('-':) . showDecimal' . negate $ d+ | d < 1 = drop 1 . showDecimal' . (+ (1%1)) $ d+ | otherwise = showDecimal' $ d showDecimal' d- | denominator d == 1 = show . numerator $ d- | otherwise = times10 0 $ d+ | denominator d == 1 = show . numerator $ d+ | otherwise = times10 0 $ d where times10 i' d'- | denominator d' == 1 = let- (x, y) = splitAt i' . reverse . show . numerator $ d'- in- reverse y ++ "." ++ reverse x- | otherwise = times10 (i' + 1) (d' * (10 % 1))- + | denominator d' == 1 = let+ (x, y) = splitAt i' . reverse . show . numerator $ d'+ in+ reverse y ++ "." ++ reverse x+ | otherwise = times10 (i' + 1) (d' * (10 % 1))+ -- ---------------------------------------- -- | Tests whether a XML instance value matches a data-pattern.@@ -477,97 +477,97 @@ = performCheck check value where validString normFct- = validPattern- >>>- arr normFct- >>>- validLength+ = validPattern+ >>>+ arr normFct+ >>>+ validLength validNormString- = validString normalizeWhitespace+ = validString normalizeWhitespace validPattern- = patternValid params+ = patternValid params validLength- = stringValid d 0 (-1) params+ = stringValid d 0 (-1) params validList- = validPattern- >>>- arr normalizeWhitespace- >>>- validListLength+ = validPattern+ >>>+ arr normalizeWhitespace+ >>>+ validListLength validListLength- = listValid d params+ = listValid d params validName isN- = assertW3C isN+ = assertW3C isN validNCName- = validNormString >>> validName isNCName+ = validNormString >>> validName isNCName validQName- = validNormString >>> validName isWellformedQualifiedName+ = validNormString >>> validName isWellformedQualifiedName validDecimal- = arr normalizeWhitespace- >>>- assertW3C isDecimal- >>>- checkWith readDecimal (decimalValid params)+ = arr normalizeWhitespace+ >>>+ assertW3C isDecimal+ >>>+ checkWith readDecimal (decimalValid params) validInteger inRange- = validPattern- >>>- arr normalizeWhitespace- >>>- assertW3C isInteger- >>>- checkWith read (integerValid inRange params)+ = validPattern+ >>>+ arr normalizeWhitespace+ >>>+ assertW3C isInteger+ >>>+ checkWith read (integerValid inRange params) - check :: CheckString- check = fromMaybe notFound . lookup d $ checks+ check :: CheckString+ check = fromMaybe notFound . lookup d $ checks - notFound = failure $ errorMsgDataTypeNotAllowed w3cNS d params+ notFound = failure $ errorMsgDataTypeNotAllowed w3cNS d params - checks :: [(String, CheckA String String)]- checks = [ (xsd_string, validString id)- , (xsd_normalizedString, validString normalizeBlanks)- , (xsd_token, validNormString)- , (xsd_language, validNormString >>> assertW3C isLanguage)- , (xsd_NMTOKEN, validNormString >>> validName isNmtoken)- , (xsd_NMTOKENS, validList >>> validName (isNameList isNmtoken))- , (xsd_Name, validNormString >>> validName isName)- , (xsd_NCName, validNCName)- , (xsd_ID, validNCName)- , (xsd_IDREF, validNCName)- , (xsd_IDREFS, validList >>> validName (isNameList isNCName))- , (xsd_ENTITY, validNCName)- , (xsd_ENTITIES, validList >>> validName (isNameList isNCName))- , (xsd_anyURI, validName isURIReference >>> validString escapeURI)- , (xsd_QName, validQName)- , (xsd_NOTATION, validQName)- , (xsd_hexBinary, validString id >>> assertW3C isHexBinary)- , (xsd_base64Binary, validString normBase64 >>> assertW3C isBase64Binary)- , (xsd_decimal, validPattern >>> validDecimal)- , (xsd_integer, validInteger xsd_integer)- , (xsd_nonPositiveInteger, validInteger xsd_nonPositiveInteger)- , (xsd_negativeInteger, validInteger xsd_negativeInteger)- , (xsd_nonNegativeInteger, validInteger xsd_nonNegativeInteger)- , (xsd_positiveInteger, validInteger xsd_positiveInteger)- , (xsd_long, validInteger xsd_long)- , (xsd_int, validInteger xsd_int)- , (xsd_short, validInteger xsd_short)- , (xsd_byte, validInteger xsd_byte)- , (xsd_unsignedLong, validInteger xsd_unsignedLong)- , (xsd_unsignedInt, validInteger xsd_unsignedInt)- , (xsd_unsignedShort, validInteger xsd_unsignedShort)- , (xsd_unsignedByte, validInteger xsd_unsignedByte)- ]- assertW3C p = assert p errW3C- errW3C = errorMsgDataLibQName w3cNS d+ checks :: [(String, CheckA String String)]+ checks = [ (xsd_string, validString id)+ , (xsd_normalizedString, validString normalizeBlanks)+ , (xsd_token, validNormString)+ , (xsd_language, validNormString >>> assertW3C isLanguage)+ , (xsd_NMTOKEN, validNormString >>> validName isNmtoken)+ , (xsd_NMTOKENS, validList >>> validName (isNameList isNmtoken))+ , (xsd_Name, validNormString >>> validName isName)+ , (xsd_NCName, validNCName)+ , (xsd_ID, validNCName)+ , (xsd_IDREF, validNCName)+ , (xsd_IDREFS, validList >>> validName (isNameList isNCName))+ , (xsd_ENTITY, validNCName)+ , (xsd_ENTITIES, validList >>> validName (isNameList isNCName))+ , (xsd_anyURI, validName isURIReference >>> validString escapeURI)+ , (xsd_QName, validQName)+ , (xsd_NOTATION, validQName)+ , (xsd_hexBinary, validString id >>> assertW3C isHexBinary)+ , (xsd_base64Binary, validString normBase64 >>> assertW3C isBase64Binary)+ , (xsd_decimal, validPattern >>> validDecimal)+ , (xsd_integer, validInteger xsd_integer)+ , (xsd_nonPositiveInteger, validInteger xsd_nonPositiveInteger)+ , (xsd_negativeInteger, validInteger xsd_negativeInteger)+ , (xsd_nonNegativeInteger, validInteger xsd_nonNegativeInteger)+ , (xsd_positiveInteger, validInteger xsd_positiveInteger)+ , (xsd_long, validInteger xsd_long)+ , (xsd_int, validInteger xsd_int)+ , (xsd_short, validInteger xsd_short)+ , (xsd_byte, validInteger xsd_byte)+ , (xsd_unsignedLong, validInteger xsd_unsignedLong)+ , (xsd_unsignedInt, validInteger xsd_unsignedInt)+ , (xsd_unsignedShort, validInteger xsd_unsignedShort)+ , (xsd_unsignedByte, validInteger xsd_unsignedByte)+ ]+ assertW3C p = assert p errW3C+ errW3C = errorMsgDataLibQName w3cNS d -- ---------------------------------------- @@ -577,34 +577,34 @@ datatypeEqualW3C d s1 _ s2 _ = performCheck check (s1, s2) where- check :: CheckA (String, String) (String, String)- check = maybe notFound found . lookup d $ norm+ check :: CheckA (String, String) (String, String)+ check = maybe notFound found . lookup d $ norm - notFound = failure $ const (errorMsgDataTypeNotAllowed0 w3cNS d)+ notFound = failure $ const (errorMsgDataTypeNotAllowed0 w3cNS d) - found nf = arr (\ (x1, x2) -> (nf x1, nf x2)) -- normalize both values- >>>- assert (uncurry (==)) (uncurry $ errorMsgEqual d) -- and check on (==)+ found nf = arr (\ (x1, x2) -> (nf x1, nf x2)) -- normalize both values+ >>>+ assert (uncurry (==)) (uncurry $ errorMsgEqual d) -- and check on (==) - norm = [ (xsd_string, id )- , (xsd_normalizedString, normalizeBlanks )- , (xsd_token, normalizeWhitespace )- , (xsd_language, normalizeWhitespace )- , (xsd_NMTOKEN, normalizeWhitespace )- , (xsd_NMTOKENS, normalizeWhitespace )- , (xsd_Name, normalizeWhitespace )- , (xsd_NCName, normalizeWhitespace )- , (xsd_ID, normalizeWhitespace )- , (xsd_IDREF, normalizeWhitespace )- , (xsd_IDREFS, normalizeWhitespace )- , (xsd_ENTITY, normalizeWhitespace )- , (xsd_ENTITIES, normalizeWhitespace )- , (xsd_anyURI, escapeURI . normalizeWhitespace )- , (xsd_QName, normalizeWhitespace )- , (xsd_NOTATION, normalizeWhitespace )- , (xsd_hexBinary, id )- , (xsd_base64Binary, normBase64 )- , (xsd_decimal, show . readDecimal . normalizeWhitespace )- ]+ norm = [ (xsd_string, id )+ , (xsd_normalizedString, normalizeBlanks )+ , (xsd_token, normalizeWhitespace )+ , (xsd_language, normalizeWhitespace )+ , (xsd_NMTOKEN, normalizeWhitespace )+ , (xsd_NMTOKENS, normalizeWhitespace )+ , (xsd_Name, normalizeWhitespace )+ , (xsd_NCName, normalizeWhitespace )+ , (xsd_ID, normalizeWhitespace )+ , (xsd_IDREF, normalizeWhitespace )+ , (xsd_IDREFS, normalizeWhitespace )+ , (xsd_ENTITY, normalizeWhitespace )+ , (xsd_ENTITIES, normalizeWhitespace )+ , (xsd_anyURI, escapeURI . normalizeWhitespace )+ , (xsd_QName, normalizeWhitespace )+ , (xsd_NOTATION, normalizeWhitespace )+ , (xsd_hexBinary, id )+ , (xsd_base64Binary, normBase64 )+ , (xsd_decimal, show . readDecimal . normalizeWhitespace )+ ] -- ----------------------------------------
src/Text/XML/HXT/RelaxNG/XmlSchema/Regex.hs view
@@ -44,43 +44,43 @@ ) where -import Data.List ( foldl' )+import Data.List ( foldl' ) -- ------------------------------------------------------------ -data Regex = Zero String- | Unit- | Sym (Char -> Bool)- | Dot- | Star Regex- | Alt Regex Regex- | Seq Regex Regex- | Rep Int Regex -- 1 or more repetitions- | Rng Int Int Regex -- n..m repetitions- | Dif Regex Regex -- r1 - r2+data Regex = Zero String+ | Unit+ | Sym (Char -> Bool)+ | Dot+ | Star Regex+ | Alt Regex Regex+ | Seq Regex Regex+ | Rep Int Regex -- 1 or more repetitions+ | Rng Int Int Regex -- n..m repetitions+ | Dif Regex Regex -- r1 - r2 -- ------------------------------------------------------------ {- just for documentation class Inv a where- inv :: a -> Bool+ inv :: a -> Bool instance Inv Regex where- inv (Zero _) = True- inv Unit = True- inv (Sym p) = not . null . chars $ p- inv Dot = True- inv (Star e) = inv e- inv (Alt e1 e2) = inv e1 &&- inv e2- inv (Seq e1 e2) = inv e1 &&- inv e2- inv (Rep i e) = i > 0 && inv e- inv (Rng i j e) = (i < j || (i == j && i > 1)) &&- inv e- inv (Dif e1 e2) = inv e1 &&- inv e2+ inv (Zero _) = True+ inv Unit = True+ inv (Sym p) = not . null . chars $ p+ inv Dot = True+ inv (Star e) = inv e+ inv (Alt e1 e2) = inv e1 &&+ inv e2+ inv (Seq e1 e2) = inv e1 &&+ inv e2+ inv (Rep i e) = i > 0 && inv e+ inv (Rng i j e) = (i < j || (i == j && i > 1)) &&+ inv e+ inv (Dif e1 e2) = inv e1 &&+ inv e2 -} -- ------------------------------------------------------------@@ -88,229 +88,229 @@ -- -- this function is expensive, it should only be used for testing -chars :: (Char -> Bool) -> [Char]-chars p = filter p $ [minBound .. maxBound]+chars :: (Char -> Bool) -> [Char]+chars p = filter p $ [minBound .. maxBound] -charRngs :: [Char] -> [(Char, Char)]-charRngs [] = []-charRngs (x:xs) = charRng x xs- where- charRng y [] = (x,y) : []- charRng y xs'@(x1:xs1)- | x1 == succ y = charRng x1 xs1- | otherwise = (x,y) : charRngs xs'+charRngs :: [Char] -> [(Char, Char)]+charRngs [] = []+charRngs (x:xs) = charRng x xs+ where+ charRng y [] = (x,y) : []+ charRng y xs'@(x1:xs1)+ | x1 == succ y = charRng x1 xs1+ | otherwise = (x,y) : charRngs xs' -- ------------------------------------------------------------ -- -- smart constructors -mkZero :: String -> Regex-mkZero = Zero+mkZero :: String -> Regex+mkZero = Zero {-# INLINE mkZero #-} -mkUnit :: Regex-mkUnit = Unit+mkUnit :: Regex+mkUnit = Unit {-# INLINE mkUnit #-} -mkSym :: (Char -> Bool) -> Regex-mkSym = Sym+mkSym :: (Char -> Bool) -> Regex+mkSym = Sym {-# INLINE mkSym #-} -mkSym1 :: Char -> Regex-mkSym1 c = mkSym (==c)+mkSym1 :: Char -> Regex+mkSym1 c = mkSym (==c) -mkSymRng :: Char -> Char -> Regex+mkSymRng :: Char -> Char -> Regex mkSymRng c1 c2 | c1 == minBound &&- c2 == maxBound = mkDot- | c1 <= c2 = mkSym $ (>= c1) <&&> (<= c2)- | otherwise = mkZero $ "empty char range"+ c2 == maxBound = mkDot+ | c1 <= c2 = mkSym $ (>= c1) <&&> (<= c2)+ | otherwise = mkZero $ "empty char range" -mkDot :: Regex-mkDot = Dot+mkDot :: Regex+mkDot = Dot {-# INLINE mkDot #-} -mkStar :: Regex -> Regex-mkStar (Zero _) = mkUnit -- {}* == ()-mkStar e@Unit = e -- ()* == ()-mkStar e@(Star _e1) = e -- (r*)* == r*-mkStar (Rep 1 e1) = mkStar e1 -- (r+)* == r*-mkStar e@(Alt _ _) = Star (rmStar e) -- (a*|b)* == (a|b)*-mkStar e = Star e+mkStar :: Regex -> Regex+mkStar (Zero _) = mkUnit -- {}* == ()+mkStar e@Unit = e -- ()* == ()+mkStar e@(Star _e1) = e -- (r*)* == r*+mkStar (Rep 1 e1) = mkStar e1 -- (r+)* == r*+mkStar e@(Alt _ _) = Star (rmStar e) -- (a*|b)* == (a|b)*+mkStar e = Star e -rmStar :: Regex -> Regex-rmStar (Alt e1 e2) = mkAlt (rmStar e1) (rmStar e2)-rmStar (Star e1) = rmStar e1-rmStar (Rep 1 e1) = rmStar e1-rmStar e1 = e1+rmStar :: Regex -> Regex+rmStar (Alt e1 e2) = mkAlt (rmStar e1) (rmStar e2)+rmStar (Star e1) = rmStar e1+rmStar (Rep 1 e1) = rmStar e1+rmStar e1 = e1 -mkAlt :: Regex -> Regex -> Regex-mkAlt e1 (Zero _) = e1 -- e1 u {} = e1-mkAlt (Zero _) e2 = e2 -- {} u e2 = e2-mkAlt e1@(Star Dot) _e2 = e1 -- A* u e1 = A*-mkAlt _e1 e2@(Star Dot) = e2 -- e1 u A* = A*-mkAlt (Sym p1) (Sym p2) = mkSym $ p1 <||> p2 -- melting of predicates-mkAlt e1 e2@(Sym _) = mkAlt e2 e1 -- symmetry: predicates always first-mkAlt e1@(Sym _) (Alt e2@(Sym _) e3) = mkAlt (mkAlt e1 e2) e3 -- prepare melting of predicates-mkAlt (Alt e1 e2) e3 = mkAlt e1 (mkAlt e2 e3) -- associativity-mkAlt e1 e2 = Alt e1 e2+mkAlt :: Regex -> Regex -> Regex+mkAlt e1 (Zero _) = e1 -- e1 u {} = e1+mkAlt (Zero _) e2 = e2 -- {} u e2 = e2+mkAlt e1@(Star Dot) _e2 = e1 -- A* u e1 = A*+mkAlt _e1 e2@(Star Dot) = e2 -- e1 u A* = A*+mkAlt (Sym p1) (Sym p2) = mkSym $ p1 <||> p2 -- melting of predicates+mkAlt e1 e2@(Sym _) = mkAlt e2 e1 -- symmetry: predicates always first+mkAlt e1@(Sym _) (Alt e2@(Sym _) e3) = mkAlt (mkAlt e1 e2) e3 -- prepare melting of predicates+mkAlt (Alt e1 e2) e3 = mkAlt e1 (mkAlt e2 e3) -- associativity+mkAlt e1 e2 = Alt e1 e2 -mkSeq :: Regex -> Regex -> Regex-mkSeq e1@(Zero _) _e2 = e1-mkSeq _e1 e2@(Zero _) = e2-mkSeq Unit e2 = e2-mkSeq e1 Unit = e1-mkSeq (Seq e1 e2) e3 = mkSeq e1 (mkSeq e2 e3)-mkSeq e1 e2 = Seq e1 e2+mkSeq :: Regex -> Regex -> Regex+mkSeq e1@(Zero _) _e2 = e1+mkSeq _e1 e2@(Zero _) = e2+mkSeq Unit e2 = e2+mkSeq e1 Unit = e1+mkSeq (Seq e1 e2) e3 = mkSeq e1 (mkSeq e2 e3)+mkSeq e1 e2 = Seq e1 e2 -mkRep :: Int -> Regex -> Regex-mkRep 0 e = mkStar e-mkRep _ e@(Zero _) = e-mkRep _ e@Unit = e-mkRep i e = Rep i e+mkRep :: Int -> Regex -> Regex+mkRep 0 e = mkStar e+mkRep _ e@(Zero _) = e+mkRep _ e@Unit = e+mkRep i e = Rep i e -mkRng :: Int -> Int -> Regex -> Regex-mkRng 0 0 _e = mkUnit-mkRng 1 1 e = e+mkRng :: Int -> Int -> Regex -> Regex+mkRng 0 0 _e = mkUnit+mkRng 1 1 e = e mkRng lb ub _e- | lb > ub = Zero $- "illegal range " ++- show lb ++ ".." ++ show ub-mkRng _l _u e@(Zero _) = e-mkRng _l _u e@Unit = e-mkRng lb ub e = Rng lb ub e+ | lb > ub = Zero $+ "illegal range " +++ show lb ++ ".." ++ show ub+mkRng _l _u e@(Zero _) = e+mkRng _l _u e@Unit = e+mkRng lb ub e = Rng lb ub e -mkOpt :: Regex -> Regex-mkOpt = mkRng 0 1+mkOpt :: Regex -> Regex+mkOpt = mkRng 0 1 -mkDif :: Regex -> Regex -> Regex-mkDif e1@(Zero _) _e2 = e1-mkDif e1 (Zero _) = e1-mkDif _e1 (Star Dot) = mkZero "empty set in difference expr"-mkDif Dot (Sym p) = mkSym (not . p)-mkDif (Sym _) Dot = mkZero "empty set of chars in difference expr"+mkDif :: Regex -> Regex -> Regex+mkDif e1@(Zero _) _e2 = e1+mkDif e1 (Zero _) = e1+mkDif _e1 (Star Dot) = mkZero "empty set in difference expr"+mkDif Dot (Sym p) = mkSym (not . p)+mkDif (Sym _) Dot = mkZero "empty set of chars in difference expr" mkDif (Sym p1) (Sym p2) | null . chars $ (\ x -> p1 x && not (p2 x))- = mkZero "empty set of chars in difference expr"-mkDif e1 e2 = Dif e1 e2+ = mkZero "empty set of chars in difference expr"+mkDif e1 e2 = Dif e1 e2 -mkCompl :: Regex -> Regex-mkCompl = mkDif mkDot+mkCompl :: Regex -> Regex+mkCompl = mkDif mkDot -- ------------------------------------------------------------ instance Show Regex where- show (Zero s) = "{err:" ++ s ++ "}"- show Unit = "()"+ show (Zero s) = "{err:" ++ s ++ "}"+ show Unit = "()" show (Sym p)- | null (tail cs) &&- rng1 (head cs)- = escRng . head $ cs- | otherwise = "[" ++ concat cs' ++ "]"- where- rng1 (x,y) = x == y- cs = charRngs . chars $ p- cs' = map escRng cs- escRng (x, y)- | x == y = esc x- | succ x == y- = esc x ++ esc y- | otherwise- = esc x ++ "-" ++ esc y- esc x- | x `elem` "\\-[]{}()*+?.^"- = '\\':x:""- | x >= ' ' && x <= '~'- = x:""- | otherwise- = "&#" ++ show (fromEnum x) ++ ";"- show Dot = "."- show (Star e) = "(" ++ show e ++ ")*"- show (Alt e1 e2) = "(" ++ show e1 ++ "|" ++ show e2 ++ ")"- show (Seq e1 e2) = show e1 ++ show e2- show (Rep 1 e) = "(" ++ show e ++ ")+"- show (Rep i e) = "(" ++ show e ++ "){" ++ show i ++ ",}"- show (Rng 0 1 e) = "(" ++ show e ++ ")?"- show (Rng i j e) = "(" ++ show e ++ "){" ++ show i ++ "," ++ show j ++ "}"- show (Dif e1 e2) = "(" ++ show e1 ++ "-" ++ show e2 ++ ")"+ | null (tail cs) &&+ rng1 (head cs)+ = escRng . head $ cs+ | otherwise = "[" ++ concat cs' ++ "]"+ where+ rng1 (x,y) = x == y+ cs = charRngs . chars $ p+ cs' = map escRng cs+ escRng (x, y)+ | x == y = esc x+ | succ x == y+ = esc x ++ esc y+ | otherwise+ = esc x ++ "-" ++ esc y+ esc x+ | x `elem` "\\-[]{}()*+?.^"+ = '\\':x:""+ | x >= ' ' && x <= '~'+ = x:""+ | otherwise+ = "&#" ++ show (fromEnum x) ++ ";"+ show Dot = "."+ show (Star e) = "(" ++ show e ++ ")*"+ show (Alt e1 e2) = "(" ++ show e1 ++ "|" ++ show e2 ++ ")"+ show (Seq e1 e2) = show e1 ++ show e2+ show (Rep 1 e) = "(" ++ show e ++ ")+"+ show (Rep i e) = "(" ++ show e ++ "){" ++ show i ++ ",}"+ show (Rng 0 1 e) = "(" ++ show e ++ ")?"+ show (Rng i j e) = "(" ++ show e ++ "){" ++ show i ++ "," ++ show j ++ "}"+ show (Dif e1 e2) = "(" ++ show e1 ++ "-" ++ show e2 ++ ")" -- ------------------------------------------------------------ -isZero :: Regex -> Bool-isZero (Zero _) = True-isZero _ = False+isZero :: Regex -> Bool+isZero (Zero _) = True+isZero _ = False {-# INLINE isZero #-} -nullable :: Regex -> Bool-nullable (Zero _) = False-nullable Unit = True-nullable (Sym _p) = False -- assumption: p holds for at least one char-nullable Dot = False-nullable (Star _) = True-nullable (Alt e1 e2) = nullable e1 ||- nullable e2-nullable (Seq e1 e2) = nullable e1 &&- nullable e2-nullable (Rep _i e) = nullable e-nullable (Rng i _ e) = i == 0 ||- nullable e-nullable (Dif e1 e2) = nullable e1 &&- not (nullable e2)+nullable :: Regex -> Bool+nullable (Zero _) = False+nullable Unit = True+nullable (Sym _p) = False -- assumption: p holds for at least one char+nullable Dot = False+nullable (Star _) = True+nullable (Alt e1 e2) = nullable e1 ||+ nullable e2+nullable (Seq e1 e2) = nullable e1 &&+ nullable e2+nullable (Rep _i e) = nullable e+nullable (Rng i _ e) = i == 0 ||+ nullable e+nullable (Dif e1 e2) = nullable e1 &&+ not (nullable e2) -- ------------------------------------------------------------ -delta :: Regex -> Char -> Regex-delta e@(Zero _) _ = e-delta Unit c = mkZero $- "unexpected char " ++ show c+delta :: Regex -> Char -> Regex+delta e@(Zero _) _ = e+delta Unit c = mkZero $+ "unexpected char " ++ show c delta (Sym p) c- | p c = mkUnit- | otherwise = mkZero $- "unexpected char " ++ show c ++ ", expected: " ++ oneof ++ chars'+ | p c = mkUnit+ | otherwise = mkZero $+ "unexpected char " ++ show c ++ ", expected: " ++ oneof ++ chars' where- (cs, ds) = splitAt 40 (chars p)- oneof- | null (tail cs) = ""- | otherwise = "one of "- chars'- | null (tail cs) = "'" ++ cs ++ "'"- | null ds = "[" ++ cs ++ "]"- | otherwise = "[" ++ cs ++ "...]"+ (cs, ds) = splitAt 40 (chars p)+ oneof+ | null (tail cs) = ""+ | otherwise = "one of "+ chars'+ | null (tail cs) = "'" ++ cs ++ "'"+ | null ds = "[" ++ cs ++ "]"+ | otherwise = "[" ++ cs ++ "...]" -delta Dot _ = mkUnit-delta e@(Star e1) c = mkSeq (delta e1 c) e-delta (Alt e1 e2) c = mkAlt (delta e1 c) (delta e2 c)+delta Dot _ = mkUnit+delta e@(Star e1) c = mkSeq (delta e1 c) e+delta (Alt e1 e2) c = mkAlt (delta e1 c) (delta e2 c) delta (Seq e1 e2) c- | nullable e1 = mkAlt (mkSeq (delta e1 c) e2) (delta e2 c)- | otherwise = mkSeq (delta e1 c) e2-delta (Rep i e) c = mkSeq (delta e c) (mkRep (i-1) e)-delta (Rng i j e) c = mkSeq (delta e c) (mkRng ((i-1) `max` 0) (j-1) e)-delta (Dif e1 e2) c = mkDif (delta e1 c) (delta e2 c)+ | nullable e1 = mkAlt (mkSeq (delta e1 c) e2) (delta e2 c)+ | otherwise = mkSeq (delta e1 c) e2+delta (Rep i e) c = mkSeq (delta e c) (mkRep (i-1) e)+delta (Rng i j e) c = mkSeq (delta e c) (mkRng ((i-1) `max` 0) (j-1) e)+delta (Dif e1 e2) c = mkDif (delta e1 c) (delta e2 c) -- ------------------------------------------------------------ -delta' :: Regex -> String -> Regex-delta' = foldl' delta+delta' :: Regex -> String -> Regex+delta' = foldl' delta -matchWithRE :: Regex -> String -> Maybe String+matchWithRE :: Regex -> String -> Maybe String matchWithRE e = res . delta' e where- res (Zero err) = Just err+ res (Zero err) = Just err res re- | nullable re = Nothing -- o.k.- | otherwise = Just $ "input does not match " ++ show e+ | nullable re = Nothing -- o.k.+ | otherwise = Just $ "input does not match " ++ show e -- ------------------------------------------------------------ -(<&&>) :: (Char -> Bool) -> (Char -> Bool) -> (Char -> Bool)-f <&&> g = \ x -> f x && g x -- liftA2 (&&)+(<&&>) :: (Char -> Bool) -> (Char -> Bool) -> (Char -> Bool)+f <&&> g = \ x -> f x && g x -- liftA2 (&&) {-# INLINE (<&&>) #-} -(<||>) :: (Char -> Bool) -> (Char -> Bool) -> (Char -> Bool)-f <||> g = \ x -> f x || g x -- liftA2 (||)+(<||>) :: (Char -> Bool) -> (Char -> Bool) -> (Char -> Bool)+f <||> g = \ x -> f x || g x -- liftA2 (||) {-# INLINE (<||>) #-}
src/Text/XML/HXT/RelaxNG/XmlSchema/RegexMatch.hs view
@@ -24,11 +24,14 @@ , sedRE , tokenizeRE , tokenizeRE'+ , match , tokenize , tokenize' , sed , split++ , splitRegex ) where @@ -43,22 +46,22 @@ -- ------------------------------------------------------------ -splitRegex :: Regex -> String -> Maybe (String, String)+splitRegex :: Regex -> String -> Maybe (String, String) splitRegex re ""- | nullable re = Just ("", "")- | otherwise = Nothing+ | nullable re = Just ("", "")+ | otherwise = Nothing splitRegex re inp@(c : inp')- | isZero re = Nothing- | otherwise = evalRes . splitRegex {- (T.trace (show re') re') -} re' $ inp'+ | isZero re = Nothing+ | otherwise = evalRes . splitRegex {- (T.trace (show re') re') -} re' $ inp' where re' = delta re c evalRes Nothing- | nullable re = Just ("", inp)- | otherwise = Nothing+ | nullable re = Just ("", inp)+ | otherwise = Nothing evalRes (Just (tok, rest))- = Just (c : tok, rest)+ = Just (c : tok, rest) -- ------------------------------------------------------------ @@ -74,7 +77,7 @@ -- > splitRE "a+" "bc" = Nothing -- > splitRE "[" "abc" = Nothing -splitRE :: String -> String -> Maybe (String, String)+splitRE :: String -> String -> Maybe (String, String) splitRE re input = either (const Nothing) (flip splitRegex input) . parseRegex $ re @@ -82,7 +85,7 @@ -- -- syntax errors in R.E. are interpreted as no matching prefix found -split :: String -> String -> (String, String)+split :: String -> String -> (String, String) split re input = fromMaybe ("", input) . splitRE re $ input @@ -113,26 +116,26 @@ -- > -- > tokenizeRE "[^ \t\n\r]*" = words -tokenizeRE :: String -> String -> Maybe [String]+tokenizeRE :: String -> String -> Maybe [String] tokenizeRE regex input = either (const Nothing) (Just . flip token' input) $ parseRegex regex where- token' :: Regex -> String -> [String]+ token' :: Regex -> String -> [String] token' re inp- | null inp = []- | otherwise = evalRes . splitRegex re $ inp- where- token'' = token' re- evalRes Nothing = token'' (tail inp) -- re does not match any prefix- evalRes (Just (tok, rest))- | null tok = token'' (tail rest) -- re is nullable and only the empty prefix matches- | otherwise = tok : token'' rest -- token found, tokenize the rest+ | null inp = []+ | otherwise = evalRes . splitRegex re $ inp+ where+ token'' = token' re+ evalRes Nothing = token'' (tail inp) -- re does not match any prefix+ evalRes (Just (tok, rest))+ | null tok = token'' (tail rest) -- re is nullable and only the empty prefix matches+ | otherwise = tok : token'' rest -- token found, tokenize the rest -- | convenient function for tokenizeRE a string -- -- syntax errors in R.E. result in an empty list -tokenize :: String -> String -> [String]+tokenize :: String -> String -> [String] tokenize re = fromMaybe [] . tokenizeRE re @@ -150,33 +153,33 @@ -- -- > concat . map (either id id) . fromJust . tokenizeRE' re == id -tokenizeRE' :: String -> String -> Maybe [Either String String]+tokenizeRE' :: String -> String -> Maybe [Either String String] tokenizeRE' regex input = either (const Nothing) (Just . flip token' input) $ parseRegex regex where- token' :: Regex -> String -> [Either String String]+ token' :: Regex -> String -> [Either String String] token' re- = tok2 ""- where- tok2 :: String -> String -> [Either String String]- tok2 noMatchPrefix inp- | null inp = addNoMatch []- | otherwise = evalRes . splitRegex re $ inp- where- addNoMatch res- | null noMatchPrefix = res- | otherwise = (Left . reverse $ noMatchPrefix) : res+ = tok2 ""+ where+ tok2 :: String -> String -> [Either String String]+ tok2 noMatchPrefix inp+ | null inp = addNoMatch []+ | otherwise = evalRes . splitRegex re $ inp+ where+ addNoMatch res+ | null noMatchPrefix = res+ | otherwise = (Left . reverse $ noMatchPrefix) : res - evalRes Nothing = tok2 (head inp : noMatchPrefix) (tail inp) -- re does not match any prefix- evalRes (Just (tok, rest))- | null tok = tok2 (head rest : noMatchPrefix) (tail rest) -- re is nullable and only the empty prefix matches- | otherwise = addNoMatch . (Right tok :) . tok2 "" $ rest -- token found, tokenize the rest+ evalRes Nothing = tok2 (head inp : noMatchPrefix) (tail inp) -- re does not match any prefix+ evalRes (Just (tok, rest))+ | null tok = tok2 (head rest : noMatchPrefix) (tail rest) -- re is nullable and only the empty prefix matches+ | otherwise = addNoMatch . (Right tok :) . tok2 "" $ rest -- token found, tokenize the rest -- | convenient function for tokenizeRE' -- -- When the regular expression contains errors @[Left input]@ is returned, that means tokens are found -tokenize' :: String -> String -> [Either String String]+tokenize' :: String -> String -> [Either String String] tokenize' regex input = fromMaybe [Left input] . tokenizeRE' regex $ input @@ -193,7 +196,7 @@ -- > sedRE (\ x -> x ++ x) "a" "xax" = Just "xaax" -- > sedRE undefined "[" undefined = Nothing -sedRE :: (String -> String) -> String -> String -> Maybe String+sedRE :: (String -> String) -> String -> String -> Maybe String sedRE edit regex input = maybe Nothing (Just . concatMap (either id edit)) $ tokenizeRE' regex input @@ -204,7 +207,7 @@ -- -- > sed undefined "[" == id -sed :: (String -> String) -> String -> String -> String+sed :: (String -> String) -> String -> String -> String sed edit regex input = fromMaybe input . sedRE edit regex $ input @@ -222,7 +225,7 @@ -- > matchRE "x" "xxx" = Just False -- > matchRE "[" "xxx" = Nothing -matchRE :: String -> String -> Maybe Bool+matchRE :: String -> String -> Maybe Bool matchRE regex input = either (const Nothing) (Just . isNothing . flip matchWithRE input) $ parseRegex regex @@ -231,8 +234,8 @@ -- -- syntax errors in R.E. are interpreted as no match found -match :: String -> String -> Bool-match re = fromMaybe False . matchRE re+match :: String -> String -> Bool+match re = fromMaybe False . matchRE re -- ------------------------------------------------------------
src/Text/XML/HXT/RelaxNG/XmlSchema/RegexParser.hs view
@@ -39,14 +39,14 @@ = either (Left . show) Right . parse ( do- r <- regExp- eof- return r- ) ""+ r <- regExp+ eof+ return r+ ) "" -- ------------------------------------------------------------ -regExp :: Parser Regex+regExp :: Parser Regex regExp = do r1 <- branch@@ -54,65 +54,65 @@ return (foldr1 mkAlt $ r1:rs) where branch1- = do- _ <- char '|'- branch+ = do+ _ <- char '|'+ branch -branch :: Parser Regex+branch :: Parser Regex branch = do rs <- many piece return $ foldr mkSeq mkUnit rs -piece :: Parser Regex+piece :: Parser Regex piece = do r <- atom quantifier r -quantifier :: Regex -> Parser Regex+quantifier :: Regex -> Parser Regex quantifier r = ( do- _ <- char '?'- return $ mkOpt r )+ _ <- char '?'+ return $ mkOpt r ) <|> ( do- _ <- char '*'- return $ mkStar r )+ _ <- char '*'+ return $ mkStar r ) <|> ( do- _ <- char '+'- return $ mkRep 1 r )+ _ <- char '+'+ return $ mkRep 1 r ) <|> ( do- _ <- char '{'- res <- quantity r- _ <- char '}'- return res+ _ <- char '{'+ res <- quantity r+ _ <- char '}'+ return res ) <|> ( return r ) -quantity :: Regex -> Parser Regex+quantity :: Regex -> Parser Regex quantity r = do lb <- many1 digit quantityRest r (read lb) -quantityRest :: Regex -> Int -> Parser Regex+quantityRest :: Regex -> Int -> Parser Regex quantityRest r lb = ( do- _ <- char ','- ub <- many digit- return ( if null ub- then mkRep lb r- else mkRng lb (read ub) r- )+ _ <- char ','+ ub <- many digit+ return ( if null ub+ then mkRep lb r+ else mkRng lb (read ub) r+ ) ) <|> ( return $ mkRng lb lb r) -atom :: Parser Regex+atom :: Parser Regex atom = char1 <|>@@ -120,13 +120,13 @@ <|> between (char '(') (char ')') regExp -char1 :: Parser Regex+char1 :: Parser Regex char1 = do c <- satisfy $ (`notElem` ".\\?*+{}()|[]") return $ mkSym1 c -charClass :: Parser Regex+charClass :: Parser Regex charClass = charClassEsc <|>@@ -134,91 +134,91 @@ <|> wildCardEsc -charClassEsc :: Parser Regex+charClassEsc :: Parser Regex charClassEsc = do _ <- char '\\' ( singleCharEsc- <|>- multiCharEsc- <|>- catEsc- <|>- complEsc )+ <|>+ multiCharEsc+ <|>+ catEsc+ <|>+ complEsc ) -singleCharEsc :: Parser Regex+singleCharEsc :: Parser Regex singleCharEsc = do c <- singleCharEsc' return $ mkSym1 c -singleCharEsc' :: Parser Char+singleCharEsc' :: Parser Char singleCharEsc' = do c <- satisfy (`elem` "nrt\\|.?*+(){}-[]^") return $ maybe c id . lookup c . zip "ntr" $ "\n\r\t" -multiCharEsc :: Parser Regex+multiCharEsc :: Parser Regex multiCharEsc = do c <- satisfy (`elem` es) return $ mkSym . fromJust . lookup c $ pm where es = map fst pm- pm = [ ('s', isXmlSpaceChar )- , ('S', not . isXmlSpaceChar )- , ('i', isXmlNameStartChar )- , ('I', not . isXmlNameStartChar )- , ('c', isXmlNameChar )- , ('C', not . isXmlNameChar )- , ('d', isDigit )- , ('D', not . isDigit )- , ('w', not . isNotWord )- , ('W', isNotWord )- ]+ pm = [ ('s', isXmlSpaceChar )+ , ('S', not . isXmlSpaceChar )+ , ('i', isXmlNameStartChar )+ , ('I', not . isXmlNameStartChar )+ , ('c', isXmlNameChar )+ , ('C', not . isXmlNameChar )+ , ('d', isDigit )+ , ('D', not . isDigit )+ , ('w', not . isNotWord )+ , ('W', isNotWord )+ ] isDigit = ('0' <=) <&&> (<= '9') isNotWord = isUnicodeP <||>- isUnicodeZ <||>- isUnicodeC+ isUnicodeZ <||>+ isUnicodeC -catEsc :: Parser Regex+catEsc :: Parser Regex catEsc = do _ <- char 'p' s <- between (char '{') (char '}') charProp return $ mkSym s -charProp :: Parser (Char -> Bool)+charProp :: Parser (Char -> Bool) charProp = isCategory <|> isBlock -isBlock :: Parser (Char -> Bool)+isBlock :: Parser (Char -> Bool) isBlock = do _ <- string "Is" name <- many1 (satisfy legalChar) let b = lookup name codeBlocks if isJust b- then return $ let- (lb, ub) = fromJust b- in- (lb <=) <&&> (<= ub)- else fail $ "unknown Unicode code block " ++ show name+ then return $ let+ (lb, ub) = fromJust b+ in+ (lb <=) <&&> (<= ub)+ else fail $ "unknown Unicode code block " ++ show name where- legalChar c = 'A' <= c && c <= 'Z' ||- 'a' <= c && c <= 'z' ||- '0' <= c && c <= '9' ||- '-' == c+ legalChar c = 'A' <= c && c <= 'Z' ||+ 'a' <= c && c <= 'z' ||+ '0' <= c && c <= '9' ||+ '-' == c -isCategory :: Parser (Char -> Bool)+isCategory :: Parser (Char -> Bool) isCategory = do pr <- isCategory' return $ fromJust (lookup pr categories) -categories :: [(String, Char -> Bool)]+categories :: [(String, Char -> Bool)] categories = [ ("C", isUnicodeC ) , ("Cc", isUnicodeCc)@@ -258,66 +258,66 @@ , ("Zs", isUnicodeZs) ] -isCategory' :: Parser String+isCategory' :: Parser String isCategory' = ( foldr1 (<|>) . map (uncurry prop) $- [ ('L', "ultmo")- , ('M', "nce")- , ('N', "dlo")- , ('P', "cdseifo")- , ('Z', "slp")- , ('S', "mcko")- , ('C', "cfon")- ]+ [ ('L', "ultmo")+ , ('M', "nce")+ , ('N', "dlo")+ , ('P', "cdseifo")+ , ('Z', "slp")+ , ('S', "mcko")+ , ('C', "cfon")+ ] ) <?> "illegal Unicode character property" where prop c1 cs2- = do- _ <- char c1- s2 <- option ""- ( do- c2 <- satisfy (`elem` cs2)- return [c2] )- return $ c1:s2+ = do+ _ <- char c1+ s2 <- option ""+ ( do+ c2 <- satisfy (`elem` cs2)+ return [c2] )+ return $ c1:s2 -complEsc :: Parser Regex+complEsc :: Parser Regex complEsc = do _ <- char 'P' s <- between (char '{') (char '}') charProp return $ mkSym (not . s) -charClassExpr :: Parser Regex+charClassExpr :: Parser Regex charClassExpr = between (char '[') (char ']') charGroup -charGroup :: Parser Regex+charGroup :: Parser Regex charGroup = do- r <- ( negCharGroup -- a ^ at beginning denotes negation, not start of posCharGroup- <|>- posCharGroup- )- s <- option (mkZero "") -- charClassSub- ( do- _ <- char '-'- charClassExpr- )+ r <- ( negCharGroup -- a ^ at beginning denotes negation, not start of posCharGroup+ <|>+ posCharGroup+ )+ s <- option (mkZero "") -- charClassSub+ ( do+ _ <- char '-'+ charClassExpr+ ) return $ mkDif r s -posCharGroup :: Parser Regex+posCharGroup :: Parser Regex posCharGroup = do rs <- many1 (charRange <|> charClassEsc) return $ foldr1 mkAlt rs -charRange :: Parser Regex+charRange :: Parser Regex charRange = try seRange <|> xmlCharIncDash -seRange :: Parser Regex+seRange :: Parser Regex seRange = do c1 <- charOrEsc'@@ -325,26 +325,26 @@ c2 <- charOrEsc' return $ mkSymRng c1 c2 -charOrEsc' :: Parser Char+charOrEsc' :: Parser Char charOrEsc' = satisfy (`notElem` "\\-[]") <|> singleCharEsc' -xmlCharIncDash :: Parser Regex+xmlCharIncDash :: Parser Regex xmlCharIncDash = do c <- satisfy (`notElem` "\\[]") return $ mkSym1 c -negCharGroup :: Parser Regex+negCharGroup :: Parser Regex negCharGroup = do _ <- char '^' r <- posCharGroup return $ mkCompl r -wildCardEsc :: Parser Regex+wildCardEsc :: Parser Regex wildCardEsc = do _ <- char '.'