@@ -17,6 +17,7 @@ module Text.XML.DOM.Parser.Class
17 , readBool
17 , readBool
18 , unitFromDom
18 , unitFromDom
19 , voidFromDom
19 , voidFromDom
22import Control.Applicative
23import Control.Applicative
@@ -24,6 +25,7 @@ import Control.Lens
24import Data.Fixed
25import Data.Fixed
25import Data.Monoid
26import Data.Monoid
26import Data.OpenUnion
27import Data.OpenUnion
28+import Data.Scientific
27import Data.Text (Text)
29import Data.Text (Text)
28import qualified Data.Text as T
30import qualified Data.Text as T
29import Data.Typeable
31import Data.Typeable
@@ -77,12 +79,13 @@ instance FromDom Bool where
77instance FromDom (Union '[]) where
79instance FromDom (Union '[]) where
78 fromDom = empty
80 fromDom = empty
80−instance ( Typeable a, FromDom a, FromDom (Union as)
83+ ( Typeable a, FromDom a, FromDom (Union as)
81− , SubList as (a ': as) )
84+ , SubList as (a ': as) )
82− => FromDom (Union (a ': as)) where
85+ => FromDom (Union (a ': as)) where
83 -- fromDom :: forall m. (DomParserMonad m) => m a
86 -- fromDom :: forall m. (DomParserMonad m) => m a
84 fromDom = (liftUnion <$> (proxyFromDom (Proxy :: Proxy a)))
87 fromDom = (liftUnion <$> (proxyFromDom (Proxy :: Proxy a)))
85− <|> (reUnion <$> (proxyFromDom (Proxy :: Proxy (Union as))))
88+ <|> (reUnion <$> (proxyFromDom (Proxy :: Proxy (Union as))))
87instance FromDom Element where
90instance FromDom Element where
88 fromDom = elementFromDom
91 fromDom = elementFromDom
@@ -127,6 +130,9 @@ fixedFromDom
127 => DomParserT Identity m (Fixed a)
130 => DomParserT Identity m (Fixed a)
128fixedFromDom = parseContent readContent
131fixedFromDom = parseContent readContent
133+scientificFromDom :: Monad m => DomParserT Identity m Scientific
134+scientificFromDom = parseContent readContent
130-- | Expects content to be y, yes, t, true or 1 for True value. n, no,
136-- | Expects content to be y, yes, t, true or 1 for True value. n, no,
131-- f, false or 0 for False value. Case is not significant, blank
137-- f, false or 0 for False value. Case is not significant, blank
132-- characters are striped.
138-- characters are striped.
@@ -140,10 +146,11 @@ readBool t =
140 lowt = T.toLower $ T.strip t
146 lowt = T.toLower $ T.strip t
141 tvals = ["y", "yes", "t", "true", "1"]
147 tvals = ["y", "yes", "t", "true", "1"]
142 fvals = ["n", "no", "f", "false", "0"]
148 fvals = ["n", "no", "f", "false", "0"]
143− in if | lowt `elem` tvals -> Right True
150+ | lowt `elem` tvals -> Right True
144− | lowt `elem` fvals -> Right False
151+ | lowt `elem` fvals -> Right False
145− | otherwise ->
152+ | otherwise ->
146− Left $ "Could not read " <> t <> " as Bool"
153+ Left $ "Could not read " <> t <> " as Bool"
148-- | Always successfully parses any DOM to @()@
155-- | Always successfully parses any DOM to @()@
149unitFromDom :: (Monad m) => DomParserT Identity m ()
156unitFromDom :: (Monad m) => DomParserT Identity m ()