git.iko.soy/typeable/dom-parser
on bee2747 help sign in
12 files changed+67−173
since splitsnapshots
unifiedsplit
.travis.yml+5−7 CHANGELOG.md−44 README.md−5 dom-parser.cabal+10−10 ghc-963.yaml−7 src/Text/XML/DOM/Parser/Combinators.hs+1 src/Text/XML/DOM/Parser/Content.hs+4−5 src/Text/XML/DOM/Parser/FromAttribute.hs−2 src/Text/XML/DOM/Parser/FromDom.hs+21−2 src/Text/XML/DOM/Parser/Types.hs+20−44 src/Text/XML/Soap.hs−46 stack.yaml+6−1
.travis.yml+5−7
@@ -4,12 +4,6 @@ sudo: false
44# Do not choose a language; we provide our own build tools.
55language: generic
66
7−env:
8− - STACK_YAML=stack.yaml
9− - STACK_YAML=ghc-802.yaml
10− - STACK_YAML=ghc-822.yaml
11− - STACK_YAML=ghc-841.yaml
12−
137# Caching so the next build will be fast too.
148cache:
159 directories:
@@ -27,6 +21,10 @@ before_install:
2721- export PATH=$HOME/.local/bin:$PATH
2822- travis_retry curl -L https://www.stackage.org/stack/linux-x86_64 | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'
2923
24+install:
25+# Build dependencies
26+- stack --no-terminal --install-ghc build --only-dependencies
27+
3028script:
3129# Build the package, its tests, and its docs and run the tests
32−- stack --no-terminal --install-ghc test --haddock --no-haddock-deps
30+- stack --no-terminal test --haddock --no-haddock-deps
CHANGELOG.md−44
@@ -1,54 +1,10 @@
11# CHANGELOG
22
3−## HEAD
4−
5−## 3.2.0
6−
7−### Added
8−
9−* Text.XML.Soap module with XmlEnvelope stuff in it.
10−* GHC 9 compatibility.
11−
12−### Removed
13−
14−* Old stackage files.
15−
16−## 3.1.0
17−
18−### Added
19−
20−* Additional builds with GHC 8.0.2 and 8.2.1
21−* Compatibility with GHC 8.4.1
22−
23−## 3.0.0
24−
25−* GHC 8 compatible release
26−
27−### Removed
28−
29−* `open-union` dependency
30−
31−## 2.0.0
32−
33−### Added
34−
35−* `NameMatcher` and `ElemMatcher` as more flexible mechanisms for
36− matching names and elements instead of just matching by name.
37−* Class `FromAttribute` and some default instances
38−
39−### Changed
40−
41−* `DomTraversable` renamed to `Buildable`
42−* Combinators use `NameMatcher` and `ElemMatcher`
43−* Documentation improved
44−
453## 1.0.0
46−
474* Added support for parsing attributes
485* Changed public interface for 'parseContent'
496* Added useful functions
507* Dropped unnecessary dependency from shakespeare
518
529## 0.1.0
53−
5410* Public release
README.mddeleted−5
@@ -1,5 +0,0 @@
1−# dom-parser
2−
3−[![Build Status](https://travis-ci.org/typeable/dom-parser.svg?branch=master)](https://travis-ci.org/typeable/dom-parser)
4−
5−Simple monadic DOM parser
dom-parser.cabal+10−10
@@ -1,5 +1,5 @@
11name: dom-parser
2−version: 3.2.0
2+version: 1.0.0
33synopsis: Simple monadic DOM parser
44license: MIT
55license-file: LICENSE
@@ -7,13 +7,12 @@ author: Typeable.io contributors
77maintainer: makeit@typeable.io
88category: XML
99build-type: Simple
10+extra-source-files: CHANGELOG.md
1011cabal-version: >=1.10
12+
13+extra-source-files: CHANGELOG.md
14+
1115homepage: https://github.com/typeable/dom-parser
12−tested-with: GHC == 9.2.7
13− , GHC == 9.4.8
14− , GHC == 9.6.3
15−extra-source-files: CHANGELOG.md
16− , README.md
1716
1817source-repository head
1918 type: git
@@ -44,16 +43,18 @@ library
4443 , TypeFamilies
4544 , TypeOperators
4645 , UndecidableInstances
47− build-depends: base >= 4.11 && < 5
46+ build-depends: base >= 4.7 && < 5
4847 , case-insensitive
4948 , containers
5049 , lens
51− , mtl < 2.3 || > 2.3
50+ , mtl
51+ , open-union >= 0.2
5252 , scientific
53+ , semigroups
5354 , text
5455 , transformers
56+ , type-fun
5557 , xml-conduit
56− , xml-conduit-writer
5758 , xml-lens
5859 exposed-modules: Text.XML.DOM.Parser
5960 , Text.XML.DOM.Parser.Attributes
@@ -63,7 +64,6 @@ library
6364 , Text.XML.DOM.Parser.FromAttribute
6465 , Text.XML.DOM.Parser.FromDom
6566 , Text.XML.DOM.Parser.Types
66− , Text.XML.Soap
6767
6868test-suite test
6969 type: exitcode-stdio-1.0
ghc-963.yamldeleted−7
@@ -1,7 +0,0 @@
1−resolver: lts-22.6
2−
3−extra-deps:
4− - xml-conduit-writer-0.1.1.5
5−
6−nix:
7− packages: [zlib]
src/Text/XML/DOM/Parser/Combinators.hs+1
@@ -22,6 +22,7 @@ import Control.Monad.Reader
2222import Data.Foldable as F
2323import Data.List as L
2424import Data.List.NonEmpty (NonEmpty(..))
25+import Data.Monoid
2526import Data.Text as T
2627import Data.Traversable
2728import Text.XML
src/Text/XML/DOM/Parser/Content.hs+4−5
@@ -20,7 +20,6 @@ import Data.List as L
2020import Data.Monoid
2121import Data.Text as T
2222import Data.Typeable
23−import Prelude as P
2423import Text.Read
2524import Text.XML.DOM.Parser.Types
2625import Text.XML.Lens
@@ -36,7 +35,7 @@ parseContent
3635parseContent parse = getCurrentContent >>= \case
3736 Nothing -> throwParserError PEContentNotFound
3837 Just c -> case parse c of
39− Left e -> throwParserError $ PEContentWrongFormat e
38+ Left e -> throwParserError $ PEWrongFormat e
4039 Right a -> return a
4140
4241
@@ -94,7 +93,7 @@ maybeReadContent
9493maybeReadContent f t = maybe (Left msg) Right $ f t
9594 where
9695 msg = "Not readable " <> n <> ": " <> t
97− n = T.pack $ P.show $ typeRep (Proxy :: Proxy a)
96+ n = T.pack $ show $ typeRep (Proxy :: Proxy a)
9897
9998
10099-- | Tries to read given text to value using 'Read'. Useful to use
@@ -115,8 +114,8 @@ readBool t =
115114 tvals = ["y", "yes", "t", "true", "1"]
116115 fvals = ["n", "no", "f", "false", "0"]
117116 in if
118− | lowt `L.elem` tvals -> Right True
119− | lowt `L.elem` fvals -> Right False
117+ | lowt `elem` tvals -> Right True
118+ | lowt `elem` fvals -> Right False
120119 | otherwise ->
121120 Left $ "Could not read " <> t <> " as Bool"
122121
src/Text/XML/DOM/Parser/FromAttribute.hs−2
@@ -26,8 +26,6 @@ import Text.XML.DOM.Parser.Content
2626-- | Class of types which can be get from attribute value. Method
2727-- 'fromAttribute' is a convenient default parameter for
2828-- 'parseAttribute'
29−--
30−-- @since 2.0.0
3129class FromAttribute a where
3230 fromAttribute
3331 :: Text
src/Text/XML/DOM/Parser/FromDom.hs+21−2
@@ -4,6 +4,7 @@ module Text.XML.DOM.Parser.FromDom
44 , proxyFromDom
55 -- * Explicit methods for convenience
66 , elementFromDom
7+ , unionFromDom
78 , textFromDom
89 , stringFromDom
910 , charFromDom
@@ -20,6 +21,7 @@ module Text.XML.DOM.Parser.FromDom
2021import Control.Applicative
2122import Control.Lens
2223import Data.Fixed
24+import Data.OpenUnion
2325import Data.Scientific
2426import Data.Text as T hiding (empty)
2527import Data.Typeable
@@ -27,6 +29,7 @@ import Data.Void
2729import Text.XML
2830import Text.XML.DOM.Parser.Content
2931import Text.XML.DOM.Parser.Types
32+import TypeFun.Data.List hiding (Union)
3033
3134proxyFromDom
3235 :: forall proxy m a
@@ -35,8 +38,7 @@ proxyFromDom
3538 -> DomParserT Identity m a
3639proxyFromDom _ = fromDom
3740
38−-- | Class of types which can be parsed from single XML element. The
39−-- method 'fromDom' is convenient default to use with 'inElem'
41+-- | Class of types which can be parsed from single XML element.
4042class FromDom a where
4143 fromDom :: (Monad m) => DomParserT Identity m a
4244
@@ -113,6 +115,23 @@ instance FromDom Bool where
113115boolFromDom :: (Monad m) => DomParserT Identity m Bool
114116boolFromDom = parseContent readBool
115117
118+instance FromDom (Union '[]) where
119+ fromDom = empty
120+
121+instance
122+ ( Typeable a, FromDom a, FromDom (Union as)
123+ , SubList as (a ': as) )
124+ => FromDom (Union (a ': as)) where
125+ -- fromDom :: forall m. (DomParserMonad m) => m a
126+ fromDom = (liftUnion <$> (proxyFromDom (Proxy :: Proxy a)))
127+ <|> (reUnion <$> (proxyFromDom (Proxy :: Proxy (Union as))))
128+
129+unionFromDom
130+ :: (Monad m, FromDom (Union as))
131+ => proxy as
132+ -> DomParserT Identity m (Union as)
133+unionFromDom _ = fromDom
134+
116135instance FromDom Element where
117136 fromDom = elementFromDom
118137
src/Text/XML/DOM/Parser/Types.hs+20−44
@@ -1,17 +1,17 @@
11module Text.XML.DOM.Parser.Types
2− (-- * Element matching
3− ElemMatcher(..)
4− , emMatch
5− , emShow
6− , matchElemName
7− , elMatch
8− -- * Name matching
9− , NameMatcher(..)
2+ ( -- * Name matching
3+ NameMatcher(..)
104 , nmMatch
115 , nmShow
126 , matchName
137 , matchLocalName
148 , matchCILocalName
9+ -- * Element matching
10+ , ElemMatcher(..)
11+ , emMatch
12+ , emShow
13+ , matchElemName
14+ , elMatch
1515 -- * Parser internals
1616 , DomPath(..)
1717 , ParserError(..)
@@ -43,8 +43,6 @@ import Text.XML
4343import Text.XML.Lens
4444
4545-- | Arbitrary element matcher
46−--
47−-- @since 2.0.0
4846data ElemMatcher = ElemMatcher
4947 { _emMatch :: Element -> Bool
5048 , _emShow :: Text
@@ -53,7 +51,6 @@ data ElemMatcher = ElemMatcher
5351
5452makeLenses ''ElemMatcher
5553
56−-- | Instance using instance of 'NameMatcher'
5754instance IsString ElemMatcher where
5855 fromString = matchElemName . fromString
5956
@@ -61,24 +58,17 @@ instance Show ElemMatcher where
6158 show = T.unpack . _emShow
6259
6360-- | Match element by name
64−--
65−-- @since 2.0.0
6661matchElemName :: NameMatcher -> ElemMatcher
6762matchElemName (NameMatcher matchName showName) = ElemMatcher
6863 { _emMatch = views name matchName
6964 , _emShow = showName
7065 }
7166
72−-- | Match over elements
73−--
74−-- @since 2.0.0
7567elMatch :: ElemMatcher -> Traversal' Element Element
7668elMatch (ElemMatcher match _) = filtered match
7769
7870-- | Arbitrary name matcher. Match name any way you want, but
7971-- considered to be used as comparator with some name with some rules
80−--
81−-- @since 2.0.0
8272data NameMatcher = NameMatcher
8373 { _nmMatch :: Name -> Bool
8474 -- ^ Name matching function, usually should be simple comparsion
@@ -88,10 +78,8 @@ data NameMatcher = NameMatcher
8878 -- ^ Field for 'Show' instance and bulding usefull errors
8979 }
9080
91−-- | Instance use 'matchCILocalName' as most general and liberal
92−-- matching strategy (while XML is often malformed).
93−--
94−-- @since 2.0.0
81+makeLenses ''NameMatcher
82+
9583instance IsString NameMatcher where
9684 fromString = matchCILocalName . T.pack
9785
@@ -100,8 +88,6 @@ instance Show NameMatcher where
10088
10189-- | Makes matcher which matches only local part of name igoring
10290-- namespace and prefix. Local name matching is case sensitive.
103−--
104−-- @since 2.0.0
10591matchLocalName :: Text -> NameMatcher
10692matchLocalName tname = NameMatcher
10793 { _nmMatch = \n -> nameLocalName n == tname
@@ -111,19 +97,13 @@ matchLocalName tname = NameMatcher
11197-- | Makes matcher which matches only local part of name igoring
11298-- namespace and prefix. Local name matching is case insensitive. This
11399-- is the most common case.
114−--
115−-- @since 2.0.0
116100matchCILocalName :: Text -> NameMatcher
117101matchCILocalName tname = NameMatcher
118102 { _nmMatch = \n -> CI.mk (nameLocalName n) == CI.mk tname
119103 , _nmShow = tname
120104 }
121105
122−makeLenses ''NameMatcher
123−
124106-- | Makes matcher which match name by 'Eq' with given
125−--
126−-- @since 2.0.0
127107matchName :: Name -> NameMatcher
128108matchName n = NameMatcher
129109 { _nmMatch = (== n)
@@ -134,7 +114,7 @@ matchName n = NameMatcher
134114-- element of the document. Errors are much more usefull with path.
135115newtype DomPath = DomPath
136116 { unDomPath :: [Text]
137− } deriving (Eq, Ord, Show, Semigroup, Monoid)
117+ } deriving (Eq, Ord, Show, Monoid)
138118
139119-- | DOM parser error description.
140120data ParserError
@@ -144,17 +124,13 @@ data ParserError
144124 -- ^ Path of element error occured in
145125 }
146126
147− -- | Expected attribute but not found
148− --
149− -- @since 1.0.0
150− | PEAttributeNotFound
151− { _peAttributeName :: NameMatcher
152− , _pePath :: DomPath
127+ -- | Tag contents has wrong format, (could not read text to value)
128+ | PEWrongFormat
129+ { _peDetails :: Text
130+ , _pePath :: DomPath
153131 }
154132
155133 -- | Could not parse attribute
156− --
157− -- @since 1.0.0
158134 | PEAttributeWrongFormat
159135 { _peAttributeName :: NameMatcher
160136 , _peDetails :: Text
@@ -166,10 +142,10 @@ data ParserError
166142 { _pePath :: DomPath
167143 }
168144
169− -- | Tag contents has wrong format, (could not read text to value)
170− | PEContentWrongFormat
171− { _peDetails :: Text
172− , _pePath :: DomPath
145+ -- | Expected attribute but not found
146+ | PEAttributeNotFound
147+ { _peAttributeName :: NameMatcher
148+ , _pePath :: DomPath
173149 }
174150
175151 -- | Some other error
@@ -184,7 +160,7 @@ instance Exception ParserError
184160
185161newtype ParserErrors = ParserErrors
186162 { unParserErrors :: [ParserError]
187− } deriving (Show, Semigroup, Monoid, Generic)
163+ } deriving (Show, Monoid, Generic)
188164
189165makePrisms ''ParserErrors
190166
src/Text/XML/Soap.hsdeleted−46
@@ -1,46 +0,0 @@
1−module Text.XML.Soap where
2−
3−import Control.Lens
4−import Data.String
5−import Text.XML
6−import Text.XML.DOM.Parser
7−import Text.XML.Writer
8−
9−data XmlEnvelope h b = XmlEnvelope
10− { _xeHeader :: !(Maybe h)
11− , _xeBody :: !(Maybe b)
12− } deriving (Eq, Show)
13−
14−makeLenses ''XmlEnvelope
15−
16−xmlEnvelopeToDocument :: (ToXML h, ToXML b) => XmlEnvelope h b -> Document
17−xmlEnvelopeToDocument xe = doc
18− where
19− sname n = fromString $ "{http://schemas.xmlsoap.org/soap/envelope/}" <> n
20− doc =
21− Document
22− { documentPrologue = Prologue [] Nothing []
23− , documentRoot =
24− Element
25− { elementName = sname "Envelope"
26− , elementAttributes = mempty
27− , elementNodes = [NodeElement header, NodeElement body]
28− }
29− , documentEpilogue = []
30− }
31− header =
32− Element
33− { elementName = sname "Header"
34− , elementAttributes = mempty
35− , elementNodes = render . toXML $ xe ^. xeHeader
36− }
37− body =
38− Element
39− { elementName = sname "Body"
40− , elementAttributes = mempty
41− , elementNodes = render . toXML $ xe ^. xeBody
42− }
43−
44−instance (FromDom h, FromDom b) => FromDom (XmlEnvelope h b) where
45− fromDom = XmlEnvelope <$> inElemMay "Header" fromDom
46− <*> inElemMay "Body" fromDom
stack.yamlmode 120000 → 100644+6−1
@@ -1 +0,0 @@
1−ghc-963.yaml
@@ -0,0 +1,6 @@
1+packages:
2+ - .
3+extra-deps:
4+ - open-union-0.2.0.0
5+ - type-fun-0.1.1
6+resolver: lts-6.25