git.iko.soy/typeable/xml-lens
on master help sign in
.github/workflows/haskell.ymlnew file+37
since splitsnapshots
unifiedsplit
@@ -0,0 +1,37 @@
1+name: Haskell CI
2+
3+on: [push, pull_request]
4+
5+jobs:
6+ build:
7+
8+ runs-on: ubuntu-latest
9+ strategy:
10+ matrix:
11+ ghc: [ '8.8.4', '8.10.7', '9.0.1', '9.2.2' ]
12+ steps:
13+ - uses: actions/checkout@v3
14+ - uses: haskell/actions/setup@v1
15+ with:
16+ ghc-version: ${{ matrix.ghc }}
17+ cabal-version: '3.4'
18+
19+ - name: cabal Cache
20+ uses: actions/cache@v1
21+ env:
22+ cache-name: cache-cabal
23+ with:
24+ path: ~/.cabal
25+ key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/*.cabal') }}-${{ hashFiles('**/cabal.project') }}
26+ restore-keys: |
27+ ${{ runner.os }}-build-${{ env.cache-name }}-
28+ ${{ runner.os }}-build-
29+ ${{ runner.os }}-
30+ - name: Install dependencies
31+ run: |
32+ cabal update
33+ cabal build --only-dependencies --enable-tests --enable-benchmarks all
34+ - name: Build
35+ run: cabal build --enable-tests --enable-benchmarks all
36+ - name: Run tests
37+ run: cabal test --enable-tests --enable-benchmarks all
.gitignore+1
@@ -1,3 +1,4 @@
1+dist-newstyle
1#################
2#################
2## Eclipse
3## Eclipse
3#################
4#################
CHANGELOG.mdnew file+10
@@ -0,0 +1,10 @@
1+## 0.3.1
2+
3+* Supported GHC 9
4+
5+## 0.3 (2021/01)
6+
7+* Deprecated `el`
8+* Removed `./` and `entire`
9+
10+
README.md+8−4
@@ -9,16 +9,16 @@ Example
9```haskell
9```haskell
10> doc <- Text.XML.readFile def "examples/books.xml"
10> doc <- Text.XML.readFile def "examples/books.xml"
11
11
12−> doc ^.. root . el "books" ./ el "book" . attributeIs "category" "Textbooks" ./ el "title" . text
12+> doc ^.. root . named "books" ... named "book" . attributeIs "category" "Textbooks" ... named "title" . text
13["Learn You a Haskell for Great Good!","Programming in Haskell","Real World Haskell"]
13["Learn You a Haskell for Great Good!","Programming in Haskell","Real World Haskell"]
14
14
15−> lengthOf ?? doc $ root . el "books" ./ el "book"
15+> lengthOf ?? doc $ root . named "books" ... named "book"
167
167
17
17
18−> doc ^? root . el "books" ./ attributeIs "category" "Joke" ./ el "title" . text
18+> doc ^? root . named "books" ... attributeIs "category" "Joke" ... named "title" . text
19Just "Functional Ikamusume"
19Just "Functional Ikamusume"
20
20
21−> doc & root . el "books" ./ el "book" ./ el "pages" . text <>~ " pages" & renderLBS def & BL.putStrLn
21+> doc & root . named "books" ... named "book" ... named "pages" . text <>~ " pages" & renderLBS def & BL.putStrLn
22```
22```
23
23
24```xml
24```xml
@@ -43,4 +43,8 @@ Just "Functional Ikamusume"
43…
43…
44```
44```
45
45
46+Tips
47+----
46
48
49+* Use [cosmos](http://hackage.haskell.org/package/lens-4.19.2/docs/Control-Lens-Plated.html) to traverse over all children
50+* You can do or-composition of traversals with [failing](http://hackage.haskell.org/package/lens-4.19.2/docs/Control-Lens-Traversal.html#v:failing)
Text/XML/Lens.hs+30−23
@@ -14,7 +14,6 @@
14module Text.XML.Lens (
14module Text.XML.Lens (
15 -- * Lenses, traversals for 'Element'
15 -- * Lenses, traversals for 'Element'
16 Element(..)
16 Element(..)
17− , (./)
18 , (...)
17 , (...)
19 -- ** Names
18 -- ** Names
20 , name
19 , name
@@ -34,7 +33,6 @@ module Text.XML.Lens (
34 , text
33 , text
35 , comment
34 , comment
36 -- ** Children
35 -- ** Children
37− , entire
38 , nodes
36 , nodes
39 -- * Prisms for 'Node'
37 -- * Prisms for 'Node'
40 , Node(..)
38 , Node(..)
@@ -62,43 +60,48 @@ import Text.XML
62import Control.Lens
60import Control.Lens
63import Data.Text (Text)
61import Data.Text (Text)
64import Data.Map (Map)
62import Data.Map (Map)
65−import Control.Applicative
66import qualified Data.CaseInsensitive as CI
63import qualified Data.CaseInsensitive as CI
67import Data.Maybe (isNothing)
64import Data.Maybe (isNothing)
68
65
69−infixr 9 ./
70−
71prologue :: Lens' Document Prologue
66prologue :: Lens' Document Prologue
72prologue f doc = fmap (\p -> doc { documentPrologue = p} ) $ f $ documentPrologue doc
67prologue f doc = fmap (\p -> doc { documentPrologue = p} ) $ f $ documentPrologue doc
68+{-# INLINE prologue #-}
73
69
74-- | The root element of the document.
70-- | The root element of the document.
75root :: Lens' Document Element
71root :: Lens' Document Element
76root f doc = fmap (\p -> doc { documentRoot = p} ) $ f $ documentRoot doc
72root f doc = fmap (\p -> doc { documentRoot = p} ) $ f $ documentRoot doc
73+{-# INLINE root #-}
77
74
78epilogue :: Lens' Document [Miscellaneous]
75epilogue :: Lens' Document [Miscellaneous]
79epilogue f doc = fmap (\p -> doc { documentEpilogue = p} ) $ f $ documentEpilogue doc
76epilogue f doc = fmap (\p -> doc { documentEpilogue = p} ) $ f $ documentEpilogue doc
77+{-# INLINE epilogue #-}
80
78
81doctype :: Lens' Prologue (Maybe Doctype)
79doctype :: Lens' Prologue (Maybe Doctype)
82doctype f doc = fmap (\p -> doc { prologueDoctype = p} ) $ f $ prologueDoctype doc
80doctype f doc = fmap (\p -> doc { prologueDoctype = p} ) $ f $ prologueDoctype doc
81+{-# INLINE doctype #-}
83
82
84class AsInstruction t where
83class AsInstruction t where
85 _Instruction :: Prism' t Instruction
84 _Instruction :: Prism' t Instruction
86
85
87_instructionTarget :: Lens' Instruction Text
86_instructionTarget :: Lens' Instruction Text
88_instructionTarget f (Instruction t d) = f t <&> \t' -> Instruction t' d
87_instructionTarget f (Instruction t d) = f t <&> \t' -> Instruction t' d
88+{-# INLINE _instructionTarget #-}
89
89
90_instructionData :: Lens' Instruction Text
90_instructionData :: Lens' Instruction Text
91_instructionData f (Instruction t d) = f d <&> \d' -> Instruction t d'
91_instructionData f (Instruction t d) = f d <&> \d' -> Instruction t d'
92+{-# INLINE _instructionData #-}
92
93
93instance AsInstruction Node where
94instance AsInstruction Node where
94 _Instruction = prism' NodeInstruction $ \s -> case s of
95 _Instruction = prism' NodeInstruction $ \s -> case s of
95 NodeInstruction e -> Just e
96 NodeInstruction e -> Just e
96 _ -> Nothing
97 _ -> Nothing
98+ {-# INLINE _Instruction #-}
97
99
98instance AsInstruction Miscellaneous where
100instance AsInstruction Miscellaneous where
99 _Instruction = prism' MiscInstruction $ \s -> case s of
101 _Instruction = prism' MiscInstruction $ \s -> case s of
100 MiscInstruction e -> Just e
102 MiscInstruction e -> Just e
101 _ -> Nothing
103 _ -> Nothing
104+ {-# INLINE _Instruction #-}
102
105
103class AsComment t where
106class AsComment t where
104 _Comment :: Prism' t Text
107 _Comment :: Prism' t Text
@@ -107,33 +110,41 @@ instance AsComment Node where
107 _Comment = prism' NodeComment $ \s -> case s of
110 _Comment = prism' NodeComment $ \s -> case s of
108 NodeComment e -> Just e
111 NodeComment e -> Just e
109 _ -> Nothing
112 _ -> Nothing
113+ {-# INLINE _Comment #-}
110
114
111instance AsComment Miscellaneous where
115instance AsComment Miscellaneous where
112 _Comment = prism' MiscComment $ \s -> case s of
116 _Comment = prism' MiscComment $ \s -> case s of
113 MiscComment e -> Just e
117 MiscComment e -> Just e
114 _ -> Nothing
118 _ -> Nothing
119+ {-# INLINE _Comment #-}
115
120
116_nameLocalName :: Lens' Name Text
121_nameLocalName :: Lens' Name Text
117_nameLocalName f n = f (nameLocalName n) <&> \x -> n { nameLocalName = x }
122_nameLocalName f n = f (nameLocalName n) <&> \x -> n { nameLocalName = x }
123+{-# INLINE _nameLocalName #-}
118
124
119_nameNamespace :: Lens' Name (Maybe Text)
125_nameNamespace :: Lens' Name (Maybe Text)
120_nameNamespace f n = f (nameNamespace n) <&> \x -> n { nameNamespace = x }
126_nameNamespace f n = f (nameNamespace n) <&> \x -> n { nameNamespace = x }
127+{-# INLINE _nameNamespace #-}
121
128
122_namePrefix :: Lens' Name (Maybe Text)
129_namePrefix :: Lens' Name (Maybe Text)
123_namePrefix f n = f (namePrefix n) <&> \x -> n { namePrefix = x }
130_namePrefix f n = f (namePrefix n) <&> \x -> n { namePrefix = x }
131+{-# INLINE _namePrefix #-}
124
132
125_Element :: Prism' Node Element
133_Element :: Prism' Node Element
126_Element = prism' NodeElement $ \s -> case s of
134_Element = prism' NodeElement $ \s -> case s of
127 NodeElement e -> Just e
135 NodeElement e -> Just e
128 _ -> Nothing
136 _ -> Nothing
137+{-# INLINE _Element #-}
129
138
130_Content :: Prism' Node Text
139_Content :: Prism' Node Text
131_Content = prism' NodeContent $ \s -> case s of
140_Content = prism' NodeContent $ \s -> case s of
132 NodeContent e -> Just e
141 NodeContent e -> Just e
133 _ -> Nothing
142 _ -> Nothing
143+{-# INLINE _Content #-}
134
144
135name :: Lens' Element Name
145name :: Lens' Element Name
136name f e = f (elementName e) <&> \x -> e { elementName = x }
146name f e = f (elementName e) <&> \x -> e { elementName = x }
147+{-# INLINE name #-}
137
148
138localName :: Lens' Element Text
149localName :: Lens' Element Text
139localName = name . _nameLocalName
150localName = name . _nameLocalName
@@ -141,69 +152,65 @@ localName = name . _nameLocalName
141
152
142attrs :: Lens' Element (Map Name Text)
153attrs :: Lens' Element (Map Name Text)
143attrs f e = fmap (\x -> e { elementAttributes = x }) $ f $ elementAttributes e
154attrs f e = fmap (\x -> e { elementAttributes = x }) $ f $ elementAttributes e
155+{-# INLINE attrs #-}
144
156
145nodes :: Lens' Element [Node]
157nodes :: Lens' Element [Node]
146nodes f e = fmap (\x -> e { elementNodes = x }) $ f $ elementNodes e
158nodes f e = fmap (\x -> e { elementNodes = x }) $ f $ elementNodes e
159+{-# INLINE nodes #-}
147
160
148attr :: Name -> Traversal' Element Text
161attr :: Name -> Traversal' Element Text
149attr n = attrs . ix n
162attr n = attrs . ix n
163+{-# INLINE attr #-}
150
164
151attribute :: Name -> Lens' Element (Maybe Text)
165attribute :: Name -> Lens' Element (Maybe Text)
152attribute n = attrs . at n
166attribute n = attrs . at n
153−
167+{-# INLINE attribute #-}
154−-- | Traverse itself with its all children. Rewriting subnodes of each children will break a traversal law.
155−entire :: Traversal' Element Element
156−entire f e@(Element _ _ ns) = com <$> f e <*> traverse (_Element (entire f)) ns where
157− com (Element n a _) = Element n a
158−{-# DEPRECATED entire "Use cosmos or deep instead" #-}
159
168
160-- | Traverse elements which has the specified *local* name (case-insensitive).
169-- | Traverse elements which has the specified *local* name (case-insensitive).
161named :: CI.CI Text -> Traversal' Element Element
170named :: CI.CI Text -> Traversal' Element Element
162named n f s
171named n f s
163 | CI.mk (nameLocalName (elementName s)) == n = f s
172 | CI.mk (nameLocalName (elementName s)) == n = f s
164 | otherwise = pure s
173 | otherwise = pure s
174+{-# INLINE named #-}
165
175
166-- | Old name for 'named'
176-- | Old name for 'named'
167ell :: Text -> Traversal' Element Element
177ell :: Text -> Traversal' Element Element
168−ell = named . CI.mk
178+ell n = named $ CI.mk n
169
179
170-- | Traverse elements which has the specified name.
180-- | Traverse elements which has the specified name.
171el :: Name -> Traversal' Element Element
181el :: Name -> Traversal' Element Element
172el n f s
182el n f s
173 | elementName s == n = f s
183 | elementName s == n = f s
174 | otherwise = pure s
184 | otherwise = pure s
185+{-# DEPRECATED el "Use named instead" #-}
175
186
176attributeSatisfies :: Name -> (Text -> Bool) -> Traversal' Element Element
187attributeSatisfies :: Name -> (Text -> Bool) -> Traversal' Element Element
177attributeSatisfies n p = attributeSatisfies' n (maybe False p)
188attributeSatisfies n p = attributeSatisfies' n (maybe False p)
189+{-# INLINE attributeSatisfies #-}
178
190
179attributeSatisfies' :: Name -> (Maybe Text -> Bool) -> Traversal' Element Element
191attributeSatisfies' :: Name -> (Maybe Text -> Bool) -> Traversal' Element Element
180attributeSatisfies' n p = filtered (p . preview (attrs . ix n))
192attributeSatisfies' n p = filtered (p . preview (attrs . ix n))
193+{-# INLINE attributeSatisfies' #-}
181
194
182withoutAttribute :: Name -> Traversal' Element Element
195withoutAttribute :: Name -> Traversal' Element Element
183withoutAttribute n = attributeSatisfies' n isNothing
196withoutAttribute n = attributeSatisfies' n isNothing
197+{-# INLINE withoutAttribute #-}
184
198
185attributeIs :: Name -> Text -> Traversal' Element Element
199attributeIs :: Name -> Text -> Traversal' Element Element
186attributeIs n v = attributeSatisfies n (==v)
200attributeIs n v = attributeSatisfies n (==v)
201+{-# INLINE attributeIs #-}
187
202
188-- | Traverse all contents of the element.
203-- | Traverse all contents of the element.
189text :: Traversal' Element Text
204text :: Traversal' Element Text
190text = nodes . traverse . _Content
205text = nodes . traverse . _Content
206+{-# INLINE text #-}
191
207
192-- | Traverse all comments of the element.
208-- | Traverse all comments of the element.
193comment :: Traversal' Element Text
209comment :: Traversal' Element Text
194comment = nodes . traverse . _Comment
210comment = nodes . traverse . _Comment
211+{-# INLINE comment #-}
195
212
196-- | 'plate' traverses over its sub-elements.
213-- | 'plate' traverses over its sub-elements.
197instance Plated Element where
214instance Plated Element where
198 plate = nodes . traverse . _Element
215 plate = nodes . traverse . _Element
199−
200−-- | Combine two 'Traversal's just like XPath's slash. Identical to ('...').
201−--
202−-- @
203−-- l ./ m ≡ l . 'plate' . m
216+ {-# INLINE plate #-}
204−-- @
205−(./) :: (Applicative f, Plated c) => LensLike f s t c c -> Over p f c c a b -> Over p f s t a b
206−(./) = (...)
207−{-# INLINE (./) #-}
208−
209−{-# DEPRECATED (./) "Use (...) instead" #-}
cabal.projectnew file+1
@@ -0,0 +1 @@
1+packages: ./
stack.yamlnew file+4
@@ -0,0 +1,4 @@
1+resolver: lts-21.3
2+
3+packages:
4+- .
xml-lens.cabal+10−7
@@ -1,17 +1,20 @@
1+cabal-version: 2.4
1name: xml-lens
2name: xml-lens
2−version: 0.2
3+version: 0.3.1
3synopsis: Lenses, traversals, and prisms for xml-conduit
4synopsis: Lenses, traversals, and prisms for xml-conduit
4−description: Lens-based DOM selector
5+description: This package provides DOM selectors based on lenses and prisms. See README.md for examples
5homepage: https://github.com/fumieval/xml-lens
6homepage: https://github.com/fumieval/xml-lens
6bug-reports: https://github.com/fumieval/xml-lens/issues
7bug-reports: https://github.com/fumieval/xml-lens/issues
7−license: BSD3
8+license: BSD-3-Clause
8license-file: LICENSE
9license-file: LICENSE
9author: Fumiaki Kinoshita
10author: Fumiaki Kinoshita
10maintainer: Fumiaki Kinoshita <fumiexcel@gmail.com>
11maintainer: Fumiaki Kinoshita <fumiexcel@gmail.com>
11−copyright: Copyright (C) 2019 Fumiaki Kinoshita
12+copyright: Copyright (C) 2021 Fumiaki Kinoshita
12category: XML
13category: XML
13build-type: Simple
14build-type: Simple
14−cabal-version: >=1.10
15+extra-source-files:
16+ README.md
17+ CHANGELOG.md
15
18
16source-repository head
19source-repository head
17 type: git
20 type: git
@@ -22,8 +25,8 @@ library
22 ghc-options: -Wall
25 ghc-options: -Wall
23 exposed-modules: Text.XML.Lens
26 exposed-modules: Text.XML.Lens
24 build-depends: base ==4.*
27 build-depends: base ==4.*
25− , lens >= 4.0 && < 5
28+ , lens >= 4.0 && < 5.4
26 , containers >= 0.4.0 && < 0.7
29 , containers >= 0.4.0 && < 0.7
27− , text >= 0.7 && <2
30+ , text >= 0.7 && < 1.3 || >= 2 && < 2.2
28 , xml-conduit >= 1.1 && < 1.10
31 , xml-conduit >= 1.1 && < 1.10
29 , case-insensitive
32 , case-insensitive