git.iko.soy/typeable/dom-parser
on master help sign in
Upd: rename constructor and add @since decls
commitfca266cbc7892611f59fcc09af7e22340582e10d authorAleksey Uimanov <s9gf4ult@gmail.com> dateSun 8 Jan 2017, 15:19 (10 years ago) parentbee2747
4 files changed+45−18
src/Text/XML/DOM/Parser/Content.hs+1−1 src/Text/XML/DOM/Parser/FromAttribute.hs+2 src/Text/XML/DOM/Parser/FromDom.hs+2−1 src/Text/XML/DOM/Parser/Types.hs+40−16
src/Text/XML/DOM/Parser/Content.hs+1−1
@@ -35,7 +35,7 @@ parseContent
3535parseContent parse = getCurrentContent >>= \case
3636 Nothing -> throwParserError PEContentNotFound
3737 Just c -> case parse c of
38− Left e -> throwParserError $ PEWrongFormat e
38+ Left e -> throwParserError $ PEContentWrongFormat e
3939 Right a -> return a
4040
4141
src/Text/XML/DOM/Parser/FromAttribute.hs+2
@@ -26,6 +26,8 @@ import Text.XML.DOM.Parser.Content
2626-- | Class of types which can be get from attribute value. Method
2727-- 'fromAttribute' is a convenient default parameter for
2828-- 'parseAttribute'
29+--
30+-- @since 2.0.0
2931class FromAttribute a where
3032 fromAttribute
3133 :: Text
src/Text/XML/DOM/Parser/FromDom.hs+2−1
@@ -38,7 +38,8 @@ proxyFromDom
3838 -> DomParserT Identity m a
3939proxyFromDom _ = fromDom
4040
41−-- | Class of types which can be parsed from single XML element.
41+-- | Class of types which can be parsed from single XML element. The
42+-- method 'fromDom' is convenient default to use with 'inElem'
4243class FromDom a where
4344 fromDom :: (Monad m) => DomParserT Identity m a
4445
src/Text/XML/DOM/Parser/Types.hs+40−16
@@ -1,17 +1,17 @@
11module Text.XML.DOM.Parser.Types
2− ( -- * Name matching
3− NameMatcher(..)
2+ (-- * Element matching
3+ ElemMatcher(..)
4+ , emMatch
5+ , emShow
6+ , matchElemName
7+ , elMatch
8+ -- * Name matching
9+ , NameMatcher(..)
410 , nmMatch
511 , nmShow
612 , matchName
713 , matchLocalName
814 , matchCILocalName
9− -- * Element matching
10− , ElemMatcher(..)
11− , emMatch
12− , emShow
13− , matchElemName
14− , elMatch
1515 -- * Parser internals
1616 , DomPath(..)
1717 , ParserError(..)
@@ -43,6 +43,8 @@ import Text.XML
4343import Text.XML.Lens
4444
4545-- | Arbitrary element matcher
46+--
47+-- @since 2.0.0
4648data ElemMatcher = ElemMatcher
4749 { _emMatch :: Element -> Bool
4850 , _emShow :: Text
@@ -51,6 +53,7 @@ data ElemMatcher = ElemMatcher
5153
5254makeLenses ''ElemMatcher
5355
56+-- | Instance using instance of 'NameMatcher'
5457instance IsString ElemMatcher where
5558 fromString = matchElemName . fromString
5659
@@ -58,17 +61,24 @@ instance Show ElemMatcher where
5861 show = T.unpack . _emShow
5962
6063-- | Match element by name
64+--
65+-- @since 2.0.0
6166matchElemName :: NameMatcher -> ElemMatcher
6267matchElemName (NameMatcher matchName showName) = ElemMatcher
6368 { _emMatch = views name matchName
6469 , _emShow = showName
6570 }
6671
72+-- | Match over elements
73+--
74+-- @since 2.0.0
6775elMatch :: ElemMatcher -> Traversal' Element Element
6876elMatch (ElemMatcher match _) = filtered match
6977
7078-- | Arbitrary name matcher. Match name any way you want, but
7179-- considered to be used as comparator with some name with some rules
80+--
81+-- @since 2.0.0
7282data NameMatcher = NameMatcher
7383 { _nmMatch :: Name -> Bool
7484 -- ^ Name matching function, usually should be simple comparsion
@@ -80,6 +90,10 @@ data NameMatcher = NameMatcher
8090
8191makeLenses ''NameMatcher
8292
93+-- | Instance use 'matchCILocalName' as most general and liberal
94+-- matching strategy (while XML is often malformed).
95+--
96+-- @since 2.0.0
8397instance IsString NameMatcher where
8498 fromString = matchCILocalName . T.pack
8599
@@ -88,6 +102,8 @@ instance Show NameMatcher where
88102
89103-- | Makes matcher which matches only local part of name igoring
90104-- namespace and prefix. Local name matching is case sensitive.
105+--
106+-- @since 2.0.0
91107matchLocalName :: Text -> NameMatcher
92108matchLocalName tname = NameMatcher
93109 { _nmMatch = \n -> nameLocalName n == tname
@@ -97,6 +113,8 @@ matchLocalName tname = NameMatcher
97113-- | Makes matcher which matches only local part of name igoring
98114-- namespace and prefix. Local name matching is case insensitive. This
99115-- is the most common case.
116+--
117+-- @since 2.0.0
100118matchCILocalName :: Text -> NameMatcher
101119matchCILocalName tname = NameMatcher
102120 { _nmMatch = \n -> CI.mk (nameLocalName n) == CI.mk tname
@@ -104,6 +122,8 @@ matchCILocalName tname = NameMatcher
104122 }
105123
106124-- | Makes matcher which match name by 'Eq' with given
125+--
126+-- @since 2.0.0
107127matchName :: Name -> NameMatcher
108128matchName n = NameMatcher
109129 { _nmMatch = (== n)
@@ -124,13 +144,17 @@ data ParserError
124144 -- ^ Path of element error occured in
125145 }
126146
127− -- | Tag contents has wrong format, (could not read text to value)
128− | PEWrongFormat
129− { _peDetails :: Text
130− , _pePath :: DomPath
147+ -- | Expected attribute but not found
148+ --
149+ -- @since 1.0.0
150+ | PEAttributeNotFound
151+ { _peAttributeName :: NameMatcher
152+ , _pePath :: DomPath
131153 }
132154
133155 -- | Could not parse attribute
156+ --
157+ -- @since 1.0.0
134158 | PEAttributeWrongFormat
135159 { _peAttributeName :: NameMatcher
136160 , _peDetails :: Text
@@ -142,10 +166,10 @@ data ParserError
142166 { _pePath :: DomPath
143167 }
144168
145− -- | Expected attribute but not found
146− | PEAttributeNotFound
147− { _peAttributeName :: NameMatcher
148− , _pePath :: DomPath
169+ -- | Tag contents has wrong format, (could not read text to value)
170+ | PEContentWrongFormat
171+ { _peDetails :: Text
172+ , _pePath :: DomPath
149173 }
150174
151175 -- | Some other error