@@ -8,13 +8,11 @@ module Text.XML.DOM.Parser.FromDom
8 , textFromDom
8 , textFromDom
9 , stringFromDom
9 , stringFromDom
10 , charFromDom
10 , charFromDom
12 , intFromDom
11 , intFromDom
13 , integerFromDom
12 , integerFromDom
14 , doubleFromDom
13 , doubleFromDom
15 , fixedFromDom
14 , fixedFromDom
16 , boolFromDom
15 , boolFromDom
18 , unitFromDom
16 , unitFromDom
19 , voidFromDom
17 , voidFromDom
20 , scientificFromDom
18 , scientificFromDom
@@ -47,36 +45,76 @@ class FromDom a where
47instance FromDom () where
45instance FromDom () where
48 fromDom = unitFromDom
46 fromDom = unitFromDom
48+-- | Always successfully parses any DOM to @()@
49+unitFromDom :: (Monad m) => DomParserT Identity m ()
50instance FromDom Void where
52instance FromDom Void where
51 fromDom = voidFromDom
53 fromDom = voidFromDom
55+-- | Never parses successfully. It is just 'empty'
56+voidFromDom :: (Monad m) => DomParserT Identity m Void
53instance FromDom Text where
59instance FromDom Text where
54 fromDom = textFromDom
60 fromDom = textFromDom
62+textFromDom :: (Monad m) => DomParserT Identity m Text
63+textFromDom = parseContent Right
56instance FromDom String where
65instance FromDom String where
57 fromDom = stringFromDom
66 fromDom = stringFromDom
68+stringFromDom :: (Monad m) => DomParserT Identity m String
69+stringFromDom = parseContent $ Right . T.unpack
59instance FromDom Char where
71instance FromDom Char where
60 fromDom = charFromDom
72 fromDom = charFromDom
74+charFromDom :: (Monad m) => DomParserT Identity m Char
75+charFromDom = parseContent readChar
62instance FromDom Int where
77instance FromDom Int where
63 fromDom = intFromDom
78 fromDom = intFromDom
80+intFromDom :: (Monad m) => DomParserT Identity m Int
81+intFromDom = parseContent readContent
65instance FromDom Integer where
83instance FromDom Integer where
66 fromDom = integerFromDom
84 fromDom = integerFromDom
86+integerFromDom :: (Monad m) => DomParserT Identity m Integer
87+integerFromDom = parseContent readContent
68instance FromDom Double where
89instance FromDom Double where
69 fromDom = doubleFromDom
90 fromDom = doubleFromDom
92+doubleFromDom :: (Monad m) => DomParserT Identity m Double
93+doubleFromDom = parseContent readContent
71instance (HasResolution a, Typeable a) => FromDom (Fixed a) where
95instance (HasResolution a, Typeable a) => FromDom (Fixed a) where
72 fromDom = fixedFromDom
96 fromDom = fixedFromDom
99+ :: (Monad m, Typeable a, HasResolution a)
100+ => DomParserT Identity m (Fixed a)
101+fixedFromDom = parseContent readContent
74instance FromDom Scientific where
103instance FromDom Scientific where
75 fromDom = scientificFromDom
104 fromDom = scientificFromDom
106+scientificFromDom :: Monad m => DomParserT Identity m Scientific
107+scientificFromDom = parseContent readContent
77instance FromDom Bool where
109instance FromDom Bool where
78 fromDom = boolFromDom
110 fromDom = boolFromDom
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
115+boolFromDom :: (Monad m) => DomParserT Identity m Bool
116+boolFromDom = parseContent readBool
80instance FromDom (Union '[]) where
118instance FromDom (Union '[]) where
81 fromDom = empty
119 fromDom = empty
@@ -88,54 +126,14 @@ instance
88 fromDom = (liftUnion <$> (proxyFromDom (Proxy :: Proxy a)))
126 fromDom = (liftUnion <$> (proxyFromDom (Proxy :: Proxy a)))
89 <|> (reUnion <$> (proxyFromDom (Proxy :: Proxy (Union as))))
127 <|> (reUnion <$> (proxyFromDom (Proxy :: Proxy (Union as))))
91−instance FromDom Element where
92− fromDom = elementFromDom
94−elementFromDom :: (Monad m) => DomParserT Identity m Element
95−elementFromDom = view $ pdElements . to runIdentity
97unionFromDom
129unionFromDom
98 :: (Monad m, FromDom (Union as))
130 :: (Monad m, FromDom (Union as))
99 => proxy as
131 => proxy as
100 -> DomParserT Identity m (Union as)
132 -> DomParserT Identity m (Union as)
101unionFromDom _ = fromDom
133unionFromDom _ = fromDom
103−textFromDom :: (Monad m) => DomParserT Identity m Text
135+instance FromDom Element where
104−textFromDom = parseContent Right
136+ fromDom = elementFromDom
106−stringFromDom :: (Monad m) => DomParserT Identity m String
107−stringFromDom = parseContent $ Right . T.unpack
109−charFromDom :: (Monad m) => DomParserT Identity m Char
110−charFromDom = parseContent readChar
112−intFromDom :: (Monad m) => DomParserT Identity m Int
113−intFromDom = parseContent readContent
115−integerFromDom :: (Monad m) => DomParserT Identity m Integer
116−integerFromDom = parseContent readContent
118−doubleFromDom :: (Monad m) => DomParserT Identity m Double
119−doubleFromDom = parseContent readContent
122− :: (Monad m, Typeable a, HasResolution a)
123− => DomParserT Identity m (Fixed a)
124−fixedFromDom = parseContent readContent
126−scientificFromDom :: Monad m => DomParserT Identity m Scientific
127−scientificFromDom = parseContent readContent
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
135−-- | Always successfully parses any DOM to @()@
136−unitFromDom :: (Monad m) => DomParserT Identity m ()
137−unitFromDom = pure ()
139−-- | Never parses successfully. It is just 'mzero'
140−voidFromDom :: (Monad m) => DomParserT Identity m Void
138+elementFromDom :: (Monad m) => DomParserT Identity m Element
141−voidFromDom = empty
139+elementFromDom = view $ pdElements . to runIdentity