@@ -1,17 +1,17 @@
11module Text.XML.DOM.Parser.Types
2− (-- * Element matching
3− ElemMatcher(..)
4− , emMatch
5− , emShow
6− , matchElemName
7− , elMatch
8− -- * Name matching
9− , NameMatcher(..)
2+ ( -- * Name matching
3+ NameMatcher(..)
104 , nmMatch
115 , nmShow
126 , matchName
137 , matchLocalName
148 , matchCILocalName
9+ -- * Element matching
10+ , ElemMatcher(..)
11+ , emMatch
12+ , emShow
13+ , matchElemName
14+ , elMatch
1515 -- * Parser internals
1616 , DomPath(..)
1717 , ParserError(..)
@@ -43,8 +43,6 @@ import Text.XML
4343import Text.XML.Lens
4444
4545-- | Arbitrary element matcher
46−--
47−-- @since 2.0.0
4846data ElemMatcher = ElemMatcher
4947 { _emMatch :: Element -> Bool
5048 , _emShow :: Text
@@ -53,7 +51,6 @@ data ElemMatcher = ElemMatcher
5351
5452makeLenses ''ElemMatcher
5553
56−-- | Instance using instance of 'NameMatcher'
5754instance IsString ElemMatcher where
5855 fromString = matchElemName . fromString
5956
@@ -61,24 +58,17 @@ instance Show ElemMatcher where
6158 show = T.unpack . _emShow
6259
6360-- | Match element by name
64−--
65−-- @since 2.0.0
6661matchElemName :: NameMatcher -> ElemMatcher
6762matchElemName (NameMatcher matchName showName) = ElemMatcher
6863 { _emMatch = views name matchName
6964 , _emShow = showName
7065 }
7166
72−-- | Match over elements
73−--
74−-- @since 2.0.0
7567elMatch :: ElemMatcher -> Traversal' Element Element
7668elMatch (ElemMatcher match _) = filtered match
7769
7870-- | Arbitrary name matcher. Match name any way you want, but
7971-- considered to be used as comparator with some name with some rules
80−--
81−-- @since 2.0.0
8272data NameMatcher = NameMatcher
8373 { _nmMatch :: Name -> Bool
8474 -- ^ Name matching function, usually should be simple comparsion
@@ -88,10 +78,8 @@ data NameMatcher = NameMatcher
8878 -- ^ Field for 'Show' instance and bulding usefull errors
8979 }
9080
91−-- | Instance use 'matchCILocalName' as most general and liberal
92−-- matching strategy (while XML is often malformed).
93−--
94−-- @since 2.0.0
81+makeLenses ''NameMatcher
82+
9583instance IsString NameMatcher where
9684 fromString = matchCILocalName . T.pack
9785
@@ -100,8 +88,6 @@ instance Show NameMatcher where
10088
10189-- | Makes matcher which matches only local part of name igoring
10290-- namespace and prefix. Local name matching is case sensitive.
103−--
104−-- @since 2.0.0
10591matchLocalName :: Text -> NameMatcher
10692matchLocalName tname = NameMatcher
10793 { _nmMatch = \n -> nameLocalName n == tname
@@ -111,19 +97,13 @@ matchLocalName tname = NameMatcher
11197-- | Makes matcher which matches only local part of name igoring
11298-- namespace and prefix. Local name matching is case insensitive. This
11399-- is the most common case.
114−--
115−-- @since 2.0.0
116100matchCILocalName :: Text -> NameMatcher
117101matchCILocalName tname = NameMatcher
118102 { _nmMatch = \n -> CI.mk (nameLocalName n) == CI.mk tname
119103 , _nmShow = tname
120104 }
121105
122−makeLenses ''NameMatcher
123−
124106-- | Makes matcher which match name by 'Eq' with given
125−--
126−-- @since 2.0.0
127107matchName :: Name -> NameMatcher
128108matchName n = NameMatcher
129109 { _nmMatch = (== n)
@@ -134,7 +114,7 @@ matchName n = NameMatcher
134114-- element of the document. Errors are much more usefull with path.
135115newtype DomPath = DomPath
136116 { unDomPath :: [Text]
137− } deriving (Eq, Ord, Show, Semigroup, Monoid)
117+ } deriving (Eq, Ord, Show, Monoid)
138118
139119-- | DOM parser error description.
140120data ParserError
@@ -144,17 +124,13 @@ data ParserError
144124 -- ^ Path of element error occured in
145125 }
146126
147− -- | Expected attribute but not found
148− --
149− -- @since 1.0.0
150− | PEAttributeNotFound
151− { _peAttributeName :: NameMatcher
152− , _pePath :: DomPath
127+ -- | Tag contents has wrong format, (could not read text to value)
128+ | PEWrongFormat
129+ { _peDetails :: Text
130+ , _pePath :: DomPath
153131 }
154132
155133 -- | Could not parse attribute
156− --
157− -- @since 1.0.0
158134 | PEAttributeWrongFormat
159135 { _peAttributeName :: NameMatcher
160136 , _peDetails :: Text
@@ -166,10 +142,10 @@ data ParserError
166142 { _pePath :: DomPath
167143 }
168144
169− -- | Tag contents has wrong format, (could not read text to value)
170− | PEContentWrongFormat
171− { _peDetails :: Text
172− , _pePath :: DomPath
145+ -- | Expected attribute but not found
146+ | PEAttributeNotFound
147+ { _peAttributeName :: NameMatcher
148+ , _pePath :: DomPath
173149 }
174150
175151 -- | Some other error
@@ -184,7 +160,7 @@ instance Exception ParserError
184160
185161newtype ParserErrors = ParserErrors
186162 { unParserErrors :: [ParserError]
187− } deriving (Show, Semigroup, Monoid, Generic)
163+ } deriving (Show, Monoid, Generic)
188164
189165makePrisms ''ParserErrors
190166