@@ -8,13 +8,11 @@ module Text.XML.DOM.Parser.FromDom
88 , textFromDom
99 , stringFromDom
1010 , charFromDom
11− , readChar
1211 , intFromDom
1312 , integerFromDom
1413 , doubleFromDom
1514 , fixedFromDom
1615 , boolFromDom
17− , readBool
1816 , unitFromDom
1917 , voidFromDom
2018 , scientificFromDom
@@ -47,36 +45,76 @@ class FromDom a where
4745instance FromDom () where
4846 fromDom = unitFromDom
4947
48+-- | Always successfully parses any DOM to @()@
49+unitFromDom :: (Monad m) => DomParserT Identity m ()
50+unitFromDom = pure ()
51+
5052instance FromDom Void where
5153 fromDom = voidFromDom
5254
55+-- | Never parses successfully. It is just 'empty'
56+voidFromDom :: (Monad m) => DomParserT Identity m Void
57+voidFromDom = empty
58+
5359instance FromDom Text where
5460 fromDom = textFromDom
5561
62+textFromDom :: (Monad m) => DomParserT Identity m Text
63+textFromDom = parseContent Right
64+
5665instance FromDom String where
5766 fromDom = stringFromDom
5867
68+stringFromDom :: (Monad m) => DomParserT Identity m String
69+stringFromDom = parseContent $ Right . T.unpack
70+
5971instance FromDom Char where
6072 fromDom = charFromDom
6173
74+charFromDom :: (Monad m) => DomParserT Identity m Char
75+charFromDom = parseContent readChar
76+
6277instance FromDom Int where
6378 fromDom = intFromDom
6479
80+intFromDom :: (Monad m) => DomParserT Identity m Int
81+intFromDom = parseContent readContent
82+
6583instance FromDom Integer where
6684 fromDom = integerFromDom
6785
86+integerFromDom :: (Monad m) => DomParserT Identity m Integer
87+integerFromDom = parseContent readContent
88+
6889instance FromDom Double where
6990 fromDom = doubleFromDom
7091
92+doubleFromDom :: (Monad m) => DomParserT Identity m Double
93+doubleFromDom = parseContent readContent
94+
7195instance (HasResolution a, Typeable a) => FromDom (Fixed a) where
7296 fromDom = fixedFromDom
7397
98+fixedFromDom
99+ :: (Monad m, Typeable a, HasResolution a)
100+ => DomParserT Identity m (Fixed a)
101+fixedFromDom = parseContent readContent
102+
74103instance FromDom Scientific where
75104 fromDom = scientificFromDom
76105
106+scientificFromDom :: Monad m => DomParserT Identity m Scientific
107+scientificFromDom = parseContent readContent
108+
77109instance FromDom Bool where
78110 fromDom = boolFromDom
79111
112+-- | Expects content to be y, yes, t, true or 1 for True Values n, no,
113+-- f, false or 0 for False. Case is not significant, blank characters
114+-- are striped.
115+boolFromDom :: (Monad m) => DomParserT Identity m Bool
116+boolFromDom = parseContent readBool
117+
80118instance FromDom (Union '[]) where
81119 fromDom = empty
82120
@@ -88,54 +126,14 @@ instance
88126 fromDom = (liftUnion <$> (proxyFromDom (Proxy :: Proxy a)))
89127 <|> (reUnion <$> (proxyFromDom (Proxy :: Proxy (Union as))))
90128
91−instance FromDom Element where
92− fromDom = elementFromDom
93−
94−elementFromDom :: (Monad m) => DomParserT Identity m Element
95−elementFromDom = view $ pdElements . to runIdentity
96−
97129unionFromDom
98130 :: (Monad m, FromDom (Union as))
99131 => proxy as
100132 -> DomParserT Identity m (Union as)
101133unionFromDom _ = fromDom
102134
103−textFromDom :: (Monad m) => DomParserT Identity m Text
104−textFromDom = parseContent Right
105−
106−stringFromDom :: (Monad m) => DomParserT Identity m String
107−stringFromDom = parseContent $ Right . T.unpack
108−
109−charFromDom :: (Monad m) => DomParserT Identity m Char
110−charFromDom = parseContent readChar
111−
112−intFromDom :: (Monad m) => DomParserT Identity m Int
113−intFromDom = parseContent readContent
114−
115−integerFromDom :: (Monad m) => DomParserT Identity m Integer
116−integerFromDom = parseContent readContent
117−
118−doubleFromDom :: (Monad m) => DomParserT Identity m Double
119−doubleFromDom = parseContent readContent
120−
121−fixedFromDom
122− :: (Monad m, Typeable a, HasResolution a)
123− => DomParserT Identity m (Fixed a)
124−fixedFromDom = parseContent readContent
125−
126−scientificFromDom :: Monad m => DomParserT Identity m Scientific
127−scientificFromDom = parseContent readContent
128−
129−-- | Expects content to be y, yes, t, true or 1 for True value. n, no,
130−-- f, false or 0 for False value. Case is not significant, blank
131−-- characters are striped.
132−boolFromDom :: (Monad m) => DomParserT Identity m Bool
133−boolFromDom = parseContent readBool
134−
135−-- | Always successfully parses any DOM to @()@
136−unitFromDom :: (Monad m) => DomParserT Identity m ()
137−unitFromDom = pure ()
135+instance FromDom Element where
136+ fromDom = elementFromDom
138137
139−-- | Never parses successfully. It is just 'mzero'
140−voidFromDom :: (Monad m) => DomParserT Identity m Void
141−voidFromDom = empty
138+elementFromDom :: (Monad m) => DomParserT Identity m Element
139+elementFromDom = view $ pdElements . to runIdentity