git.iko.soy/typeable/dom-parser
on master help sign in
Upd: rename constructor and add @since decls
fca266cAleksey Uimanov
src/Text/XML/DOM/Parser/Content.hs+1−1
@@ -35,7 +35,7 @@ parseContent
35parseContent parse = getCurrentContent >>= \case
35parseContent parse = getCurrentContent >>= \case
36 Nothing -> throwParserError PEContentNotFound
36 Nothing -> throwParserError PEContentNotFound
37 Just c -> case parse c of
37 Just c -> case parse c of
38− Left e -> throwParserError $ PEWrongFormat e
38+ Left e -> throwParserError $ PEContentWrongFormat e
39 Right a -> return a
39 Right a -> return a
40
40
41
41
src/Text/XML/DOM/Parser/FromAttribute.hs+2
@@ -26,6 +26,8 @@ import Text.XML.DOM.Parser.Content
26-- | Class of types which can be get from attribute value. Method
26-- | Class of types which can be get from attribute value. Method
27-- 'fromAttribute' is a convenient default parameter for
27-- 'fromAttribute' is a convenient default parameter for
28-- 'parseAttribute'
28-- 'parseAttribute'
29+--
30+-- @since 2.0.0
29class FromAttribute a where
31class FromAttribute a where
30 fromAttribute
32 fromAttribute
31 :: Text
33 :: Text
src/Text/XML/DOM/Parser/FromDom.hs+2−1
@@ -38,7 +38,8 @@ proxyFromDom
38 -> DomParserT Identity m a
38 -> DomParserT Identity m a
39proxyFromDom _ = fromDom
39proxyFromDom _ = fromDom
40
40
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'
42class FromDom a where
43class FromDom a where
43 fromDom :: (Monad m) => DomParserT Identity m a
44 fromDom :: (Monad m) => DomParserT Identity m a
44
45
src/Text/XML/DOM/Parser/Types.hs+40−16
@@ -1,17 +1,17 @@
1module Text.XML.DOM.Parser.Types
1module Text.XML.DOM.Parser.Types
2+ (-- * Element matching
3+ ElemMatcher(..)
4+ , emMatch
5+ , emShow
6+ , matchElemName
7+ , elMatch
2− ( -- * Name matching
8+ -- * Name matching
3− NameMatcher(..)
9+ , NameMatcher(..)
4 , nmMatch
10 , nmMatch
5 , nmShow
11 , nmShow
6 , matchName
12 , matchName
7 , matchLocalName
13 , matchLocalName
8 , matchCILocalName
14 , matchCILocalName
9− -- * Element matching
10− , ElemMatcher(..)
11− , emMatch
12− , emShow
13− , matchElemName
14− , elMatch
15 -- * Parser internals
15 -- * Parser internals
16 , DomPath(..)
16 , DomPath(..)
17 , ParserError(..)
17 , ParserError(..)
@@ -43,6 +43,8 @@ import Text.XML
43import Text.XML.Lens
43import Text.XML.Lens
44
44
45-- | Arbitrary element matcher
45-- | Arbitrary element matcher
46+--
47+-- @since 2.0.0
46data ElemMatcher = ElemMatcher
48data ElemMatcher = ElemMatcher
47 { _emMatch :: Element -> Bool
49 { _emMatch :: Element -> Bool
48 , _emShow :: Text
50 , _emShow :: Text
@@ -51,6 +53,7 @@ data ElemMatcher = ElemMatcher
51
53
52makeLenses ''ElemMatcher
54makeLenses ''ElemMatcher
53
55
56+-- | Instance using instance of 'NameMatcher'
54instance IsString ElemMatcher where
57instance IsString ElemMatcher where
55 fromString = matchElemName . fromString
58 fromString = matchElemName . fromString
56
59
@@ -58,17 +61,24 @@ instance Show ElemMatcher where
58 show = T.unpack . _emShow
61 show = T.unpack . _emShow
59
62
60-- | Match element by name
63-- | Match element by name
64+--
65+-- @since 2.0.0
61matchElemName :: NameMatcher -> ElemMatcher
66matchElemName :: NameMatcher -> ElemMatcher
62matchElemName (NameMatcher matchName showName) = ElemMatcher
67matchElemName (NameMatcher matchName showName) = ElemMatcher
63 { _emMatch = views name matchName
68 { _emMatch = views name matchName
64 , _emShow = showName
69 , _emShow = showName
65 }
70 }
66
71
72+-- | Match over elements
73+--
74+-- @since 2.0.0
67elMatch :: ElemMatcher -> Traversal' Element Element
75elMatch :: ElemMatcher -> Traversal' Element Element
68elMatch (ElemMatcher match _) = filtered match
76elMatch (ElemMatcher match _) = filtered match
69
77
70-- | Arbitrary name matcher. Match name any way you want, but
78-- | Arbitrary name matcher. Match name any way you want, but
71-- considered to be used as comparator with some name with some rules
79-- considered to be used as comparator with some name with some rules
80+--
81+-- @since 2.0.0
72data NameMatcher = NameMatcher
82data NameMatcher = NameMatcher
73 { _nmMatch :: Name -> Bool
83 { _nmMatch :: Name -> Bool
74 -- ^ Name matching function, usually should be simple comparsion
84 -- ^ Name matching function, usually should be simple comparsion
@@ -80,6 +90,10 @@ data NameMatcher = NameMatcher
80
90
81makeLenses ''NameMatcher
91makeLenses ''NameMatcher
82
92
93+-- | Instance use 'matchCILocalName' as most general and liberal
94+-- matching strategy (while XML is often malformed).
95+--
96+-- @since 2.0.0
83instance IsString NameMatcher where
97instance IsString NameMatcher where
84 fromString = matchCILocalName . T.pack
98 fromString = matchCILocalName . T.pack
85
99
@@ -88,6 +102,8 @@ instance Show NameMatcher where
88
102
89-- | Makes matcher which matches only local part of name igoring
103-- | Makes matcher which matches only local part of name igoring
90-- namespace and prefix. Local name matching is case sensitive.
104-- namespace and prefix. Local name matching is case sensitive.
105+--
106+-- @since 2.0.0
91matchLocalName :: Text -> NameMatcher
107matchLocalName :: Text -> NameMatcher
92matchLocalName tname = NameMatcher
108matchLocalName tname = NameMatcher
93 { _nmMatch = \n -> nameLocalName n == tname
109 { _nmMatch = \n -> nameLocalName n == tname
@@ -97,6 +113,8 @@ matchLocalName tname = NameMatcher
97-- | Makes matcher which matches only local part of name igoring
113-- | Makes matcher which matches only local part of name igoring
98-- namespace and prefix. Local name matching is case insensitive. This
114-- namespace and prefix. Local name matching is case insensitive. This
99-- is the most common case.
115-- is the most common case.
116+--
117+-- @since 2.0.0
100matchCILocalName :: Text -> NameMatcher
118matchCILocalName :: Text -> NameMatcher
101matchCILocalName tname = NameMatcher
119matchCILocalName tname = NameMatcher
102 { _nmMatch = \n -> CI.mk (nameLocalName n) == CI.mk tname
120 { _nmMatch = \n -> CI.mk (nameLocalName n) == CI.mk tname
@@ -104,6 +122,8 @@ matchCILocalName tname = NameMatcher
104 }
122 }
105
123
106-- | Makes matcher which match name by 'Eq' with given
124-- | Makes matcher which match name by 'Eq' with given
125+--
126+-- @since 2.0.0
107matchName :: Name -> NameMatcher
127matchName :: Name -> NameMatcher
108matchName n = NameMatcher
128matchName n = NameMatcher
109 { _nmMatch = (== n)
129 { _nmMatch = (== n)
@@ -124,13 +144,17 @@ data ParserError
124 -- ^ Path of element error occured in
144 -- ^ Path of element error occured in
125 }
145 }
126
146
127− -- | Tag contents has wrong format, (could not read text to value)
147+ -- | Expected attribute but not found
128− | PEWrongFormat
148+ --
129− { _peDetails :: Text
149+ -- @since 1.0.0
150+ | PEAttributeNotFound
151+ { _peAttributeName :: NameMatcher
130− , _pePath :: DomPath
152+ , _pePath :: DomPath
131 }
153 }
132
154
133 -- | Could not parse attribute
155 -- | Could not parse attribute
156+ --
157+ -- @since 1.0.0
134 | PEAttributeWrongFormat
158 | PEAttributeWrongFormat
135 { _peAttributeName :: NameMatcher
159 { _peAttributeName :: NameMatcher
136 , _peDetails :: Text
160 , _peDetails :: Text
@@ -142,10 +166,10 @@ data ParserError
142 { _pePath :: DomPath
166 { _pePath :: DomPath
143 }
167 }
144
168
145− -- | Expected attribute but not found
169+ -- | Tag contents has wrong format, (could not read text to value)
146− | PEAttributeNotFound
170+ | PEContentWrongFormat
147− { _peAttributeName :: NameMatcher
171+ { _peDetails :: Text
148− , _pePath :: DomPath
172+ , _pePath :: DomPath
149 }
173 }
150
174
151 -- | Some other error
175 -- | Some other error