@@ -24,27 +24,25 @@ module Text.XML.DOM.Parser.Combinators
24 , checkCurrentName
24 , checkCurrentName
25 -- * Parsing element's content
25 -- * Parsing element's content
26 , parseContent
26 , parseContent
29 -- * Parsing attributes
27 -- * Parsing attributes
30 , parseAttribute
28 , parseAttribute
31 , parseAttributeMaybe
29 , parseAttributeMaybe
34−import Control.Lens
32+import Control.Lens
35−import Control.Monad.Except
33+import Control.Monad.Except
36−import Control.Monad.Reader
34+import Control.Monad.Reader
35+import Data.Foldable as F
37−import Data.List.NonEmpty (NonEmpty(..))
37+import Data.List.NonEmpty (NonEmpty(..))
38−import qualified Data.Map.Strict as M
38+import Data.Map.Strict as M
39−import Data.Monoid
39+import Data.Monoid
40−import Data.Text (Text)
41−import qualified Data.Text as T
40+import Data.Text as T
42−import Data.Traversable
41+import Data.Traversable
43−import Data.Typeable
42+import Text.XML
45−import Text.XML
43+import Text.XML.DOM.Parser.Common
46−import Text.XML.DOM.Parser.Types
44+import Text.XML.DOM.Parser.Types
47−import Text.XML.Lens
45+import Text.XML.Lens
50-- | Generic function to traverse arbitrary inner cursors.
48-- | Generic function to traverse arbitrary inner cursors.
@@ -156,9 +154,9 @@ divePath path = magnify $ to modElems
158 = over pdElements (toListOf $ folded . diver)
156 = over pdElements (toListOf $ folded . diver)
159− . over pdPath (<> DomPath (map _nmShow path))
157+ . over pdPath (<> DomPath (L.map _nmShow path))
160 diver :: Fold Element Element
158 diver :: Fold Element Element
161− diver = foldr (.) id $ map toDive path
159+ diver = F.foldr (.) id $ L.map toDive path
162 toDive n = nodes . folded . _Element . elMatchName n
160 toDive n = nodes . folded . _Element . elMatchName n
@@ -190,7 +188,7 @@ ignoreEmpty
190 -> DomParserT Identity m (Maybe a)
188 -> DomParserT Identity m (Maybe a)
191ignoreEmpty = ignoreElem test
189ignoreEmpty = ignoreElem test
193− test e = null $ e ^. nodes
191+ test e = L.null $ e ^. nodes
195-- | If all current elements contains blank content, or contains nothing at all
193-- | If all current elements contains blank content, or contains nothing at all
196-- , then returns Nothing, else runs parser.
194-- , then returns Nothing, else runs parser.
@@ -204,7 +202,7 @@ ignoreBlank = ignoreElem test
205 elems = e ^.. nodes . folded . _Element
203 elems = e ^.. nodes . folded . _Element
206 cont = mconcat $ e ^.. nodes . folded . _Content
204 cont = mconcat $ e ^.. nodes . folded . _Content
207− in if | not $ null elems -> False
205+ in if | not $ L.null elems -> False
208 | T.null $ T.strip cont -> True
206 | T.null $ T.strip cont -> True
209 | otherwise -> False
207 | otherwise -> False
@@ -225,7 +223,7 @@ checkCurrentName n = do
225 cn <- getCurrentName
223 cn <- getCurrentName
226 unless ((n ^. nmMatch) cn) $ do
224 unless ((n ^. nmMatch) cn) $ do
227 p <- view pdPath
225 p <- view pdPath
228− let pinit = if null (unDomPath p) then [] else init $ unDomPath p
226+ let pinit = if L.null (unDomPath p) then [] else L.init $ unDomPath p
229 throwError $ ParserErrors [PENotFound $ DomPath $ pinit ++ [_nmShow n]]
227 throwError $ ParserErrors [PENotFound $ DomPath $ pinit ++ [_nmShow n]]
230 return ()
228 return ()
@@ -242,8 +240,8 @@ getCurrentContent = do
242 conts :: [Text]
240 conts :: [Text]
243 conts = nds ^.. folded . _Content
241 conts = nds ^.. folded . _Content
244 return $ if
242 return $ if
245− | not $ null els -> Nothing
243+ | not $ L.null els -> Nothing
246− | null conts -> Nothing
244+ | L.null conts -> Nothing
247 | otherwise -> Just $ mconcat conts
245 | otherwise -> Just $ mconcat conts
249-- | Parses content inside current tag. It expects current element set
247-- | Parses content inside current tag. It expects current element set
@@ -260,31 +258,6 @@ parseContent parse = getCurrentContent >>= \case
260 Left e -> throwParserError $ PEWrongFormat e
258 Left e -> throwParserError $ PEWrongFormat e
261 Right a -> return a
259 Right a -> return a
263−-- | If reader returns 'Nothing' then resulting function returns 'Left
270− => (Text -> Maybe a)
271− -- ^ Content or attribute reader
273− -- ^ Content or attribute value
275−maybeReadContent f t = maybe (Left msg) Right $ f t
277− msg = "Not readable " <> n <> ": " <> t
278− n = T.pack $ show $ typeRep (Proxy :: Proxy a)
280−-- | Tries to read given text to value using 'Read'. Useful to use
281−-- with 'parseContent' and 'parseAttribute'
283− :: (Read a, Typeable a)
286−readContent = maybeReadContent $ readMaybe . T.unpack . T.strip
288-- | Retuns map of attributes of current element
261-- | Retuns map of attributes of current element
290-- @since 1.0.0
263-- @since 1.0.0