@@ -1,8 +1,6 @@
1−module Text.XML.DOM.Parser.Common
2− ( -- * Buildable
3− Buildable(..)
4− -- * Content readers
5− , readBool
1+module Text.XML.DOM.Parser.Content
2+ ( -- * Content readers
3+ readBool
64 , readChar
75 -- ** Reader constructors
86 , maybeReadContent
@@ -24,9 +22,7 @@ import Control.Lens
2422import Control.Monad
2523import Control.Monad.Except
2624import Data.List as L
27−import Data.List.NonEmpty as NE
2825import Data.Map.Strict as M
29−import Data.Maybe
3026import Data.Monoid
3127import Data.Text as T
3228import Data.Typeable
@@ -34,25 +30,6 @@ import Text.Read
3430import Text.XML.DOM.Parser.Types
3531import Text.XML.Lens
3632
37−-- | Class of traversable functors which may be constructed from list. Or may
38−-- not.
39−class Traversable f => Buildable f where
40− -- | If method return Nothing this means we can not build
41− -- traversable from given list. In this case 'inFilteredTrav' should
42− -- fail traversing.
43− build :: [a] -> Maybe (f a)
44−
45−instance Buildable Identity where
46− build = fmap Identity . listToMaybe
47−
48−instance Buildable [] where
49− build = Just
50−
51−instance Buildable Maybe where
52− build = Just . listToMaybe
53−
54−instance Buildable NonEmpty where
55− build = NE.nonEmpty
5633
5734-- | @since 1.0.0
5835readBool :: Text -> Either Text Bool
@@ -76,7 +53,8 @@ readChar t = case T.unpack $ T.strip t of
7653 _ -> Left "Should have exactly one non-blank character"
7754
7855-- | If reader returns 'Nothing' then resulting function returns 'Left
79−-- "error message"'
56+-- "error message"'. 'Typeable' is used for generating usefull error
57+-- message.
8058--
8159-- @since 1.0.0
8260maybeReadContent
@@ -94,7 +72,8 @@ maybeReadContent f t = maybe (Left msg) Right $ f t
9472
9573
9674-- | Tries to read given text to value using 'Read'. Useful to use
97−-- with 'parseContent' and 'parseAttribute'
75+-- with 'parseContent' and 'parseAttribute'. Content is stripped
76+-- before reading.
9877readContent
9978 :: (Read a, Typeable a)
10079 => Text
@@ -186,7 +165,8 @@ parseAttribute attrName parser =
186165 Nothing -> throwParserError $ PEAttributeNotFound attrName
187166 Just a -> return a
188167
189−-- | Parses attribute with given name.
168+-- | Parses attribute with given name. Returns Nothing if attribute is
169+-- not found.
190170--
191171-- @since 1.0.0
192172parseAttributeMaybe