@@ -14,7 +14,6 @@
1414module Text.XML.Lens (
1515 -- * Lenses, traversals for 'Element'
1616 Element(..)
17− , (./)
1817 , (...)
1918 -- ** Names
2019 , name
@@ -34,7 +33,6 @@ module Text.XML.Lens (
3433 , text
3534 , comment
3635 -- ** Children
37− , entire
3836 , nodes
3937 -- * Prisms for 'Node'
4038 , Node(..)
@@ -62,43 +60,48 @@ import Text.XML
6260import Control.Lens
6361import Data.Text (Text)
6462import Data.Map (Map)
65−import Control.Applicative
6663import qualified Data.CaseInsensitive as CI
6764import Data.Maybe (isNothing)
6865
69−infixr 9 ./
70−
7166prologue :: Lens' Document Prologue
7267prologue f doc = fmap (\p -> doc { documentPrologue = p} ) $ f $ documentPrologue doc
68+{-# INLINE prologue #-}
7369
7470-- | The root element of the document.
7571root :: Lens' Document Element
7672root f doc = fmap (\p -> doc { documentRoot = p} ) $ f $ documentRoot doc
73+{-# INLINE root #-}
7774
7875epilogue :: Lens' Document [Miscellaneous]
7976epilogue f doc = fmap (\p -> doc { documentEpilogue = p} ) $ f $ documentEpilogue doc
77+{-# INLINE epilogue #-}
8078
8179doctype :: Lens' Prologue (Maybe Doctype)
8280doctype f doc = fmap (\p -> doc { prologueDoctype = p} ) $ f $ prologueDoctype doc
81+{-# INLINE doctype #-}
8382
8483class AsInstruction t where
8584 _Instruction :: Prism' t Instruction
8685
8786_instructionTarget :: Lens' Instruction Text
8887_instructionTarget f (Instruction t d) = f t <&> \t' -> Instruction t' d
88+{-# INLINE _instructionTarget #-}
8989
9090_instructionData :: Lens' Instruction Text
9191_instructionData f (Instruction t d) = f d <&> \d' -> Instruction t d'
92+{-# INLINE _instructionData #-}
9293
9394instance AsInstruction Node where
9495 _Instruction = prism' NodeInstruction $ \s -> case s of
9596 NodeInstruction e -> Just e
9697 _ -> Nothing
98+ {-# INLINE _Instruction #-}
9799
98100instance AsInstruction Miscellaneous where
99101 _Instruction = prism' MiscInstruction $ \s -> case s of
100102 MiscInstruction e -> Just e
101103 _ -> Nothing
104+ {-# INLINE _Instruction #-}
102105
103106class AsComment t where
104107 _Comment :: Prism' t Text
@@ -107,33 +110,41 @@ instance AsComment Node where
107110 _Comment = prism' NodeComment $ \s -> case s of
108111 NodeComment e -> Just e
109112 _ -> Nothing
113+ {-# INLINE _Comment #-}
110114
111115instance AsComment Miscellaneous where
112116 _Comment = prism' MiscComment $ \s -> case s of
113117 MiscComment e -> Just e
114118 _ -> Nothing
119+ {-# INLINE _Comment #-}
115120
116121_nameLocalName :: Lens' Name Text
117122_nameLocalName f n = f (nameLocalName n) <&> \x -> n { nameLocalName = x }
123+{-# INLINE _nameLocalName #-}
118124
119125_nameNamespace :: Lens' Name (Maybe Text)
120126_nameNamespace f n = f (nameNamespace n) <&> \x -> n { nameNamespace = x }
127+{-# INLINE _nameNamespace #-}
121128
122129_namePrefix :: Lens' Name (Maybe Text)
123130_namePrefix f n = f (namePrefix n) <&> \x -> n { namePrefix = x }
131+{-# INLINE _namePrefix #-}
124132
125133_Element :: Prism' Node Element
126134_Element = prism' NodeElement $ \s -> case s of
127135 NodeElement e -> Just e
128136 _ -> Nothing
137+{-# INLINE _Element #-}
129138
130139_Content :: Prism' Node Text
131140_Content = prism' NodeContent $ \s -> case s of
132141 NodeContent e -> Just e
133142 _ -> Nothing
143+{-# INLINE _Content #-}
134144
135145name :: Lens' Element Name
136146name f e = f (elementName e) <&> \x -> e { elementName = x }
147+{-# INLINE name #-}
137148
138149localName :: Lens' Element Text
139150localName = name . _nameLocalName
@@ -141,69 +152,65 @@ localName = name . _nameLocalName
141152
142153attrs :: Lens' Element (Map Name Text)
143154attrs f e = fmap (\x -> e { elementAttributes = x }) $ f $ elementAttributes e
155+{-# INLINE attrs #-}
144156
145157nodes :: Lens' Element [Node]
146158nodes f e = fmap (\x -> e { elementNodes = x }) $ f $ elementNodes e
159+{-# INLINE nodes #-}
147160
148161attr :: Name -> Traversal' Element Text
149162attr n = attrs . ix n
163+{-# INLINE attr #-}
150164
151165attribute :: Name -> Lens' Element (Maybe Text)
152166attribute n = attrs . at n
153−
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" #-}
167+{-# INLINE attribute #-}
159168
160169-- | Traverse elements which has the specified *local* name (case-insensitive).
161170named :: CI.CI Text -> Traversal' Element Element
162171named n f s
163172 | CI.mk (nameLocalName (elementName s)) == n = f s
164173 | otherwise = pure s
174+{-# INLINE named #-}
165175
166176-- | Old name for 'named'
167177ell :: Text -> Traversal' Element Element
168−ell = named . CI.mk
178+ell n = named $ CI.mk n
169179
170180-- | Traverse elements which has the specified name.
171181el :: Name -> Traversal' Element Element
172182el n f s
173183 | elementName s == n = f s
174184 | otherwise = pure s
185+{-# DEPRECATED el "Use named instead" #-}
175186
176187attributeSatisfies :: Name -> (Text -> Bool) -> Traversal' Element Element
177188attributeSatisfies n p = attributeSatisfies' n (maybe False p)
189+{-# INLINE attributeSatisfies #-}
178190
179191attributeSatisfies' :: Name -> (Maybe Text -> Bool) -> Traversal' Element Element
180192attributeSatisfies' n p = filtered (p . preview (attrs . ix n))
193+{-# INLINE attributeSatisfies' #-}
181194
182195withoutAttribute :: Name -> Traversal' Element Element
183196withoutAttribute n = attributeSatisfies' n isNothing
197+{-# INLINE withoutAttribute #-}
184198
185199attributeIs :: Name -> Text -> Traversal' Element Element
186200attributeIs n v = attributeSatisfies n (==v)
201+{-# INLINE attributeIs #-}
187202
188203-- | Traverse all contents of the element.
189204text :: Traversal' Element Text
190205text = nodes . traverse . _Content
206+{-# INLINE text #-}
191207
192208-- | Traverse all comments of the element.
193209comment :: Traversal' Element Text
194210comment = nodes . traverse . _Comment
211+{-# INLINE comment #-}
195212
196213-- | 'plate' traverses over its sub-elements.
197214instance Plated Element where
198215 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
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" #-}
216+ {-# INLINE plate #-}