packages feed

lens-xml (empty) → 0.1.0.0

raw patch · 5 files changed

+199/−0 lines, 5 filesdep +basedep +lensdep +lens-xmlsetup-changed

Dependencies added: base, lens, lens-xml, xml

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Nick Partridge (c) 2016++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Nick Partridge nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ lens-xml.cabal view
@@ -0,0 +1,36 @@+name:                lens-xml+version:             0.1.0.0+synopsis:            Lenses for the xml package.+description:         Please see README.md+homepage:            https://github.com/nkpart/lens-xml#readme+license:             BSD3+license-file:        LICENSE+author:              Nick Partridge+maintainer:          nkpart@gmail.com+copyright:           2016 Nick Partridge+category:            Web+build-type:          Simple+cabal-version:       >=1.10++library+  hs-source-dirs:      src+  exposed-modules:     Text.XML.Light.Lens+  build-depends:       base >= 4.7 && < 5+                     , lens >= 4.13 && < 5+                     , xml >= 1.3 && < 1.4+  default-language:    Haskell2010++test-suite lens-xml-test+  type:                exitcode-stdio-1.0+  hs-source-dirs:      test+  main-is:             Spec.hs+  build-depends:       base+                     , lens-xml+                     , xml+                     , lens+  ghc-options:         -threaded -rtsopts -with-rtsopts=-N+  default-language:    Haskell2010++source-repository head+  type:     git+  location: https://github.com/nkpart/lens-xml
+ src/Text/XML/Light/Lens.hs view
@@ -0,0 +1,119 @@+{-|+Module      : Text.XML.Light.Lens+Description : Lenses for xml+Copyright   : (c) Nick Partridge, 2016+License     : BSD-3+Maintainer  : nkpart@gmail.com++This module defines lenses and prisms for @Text.XML.Light@. The naming should be consistent:++* Prisms: an underscore followed by the name of the constructor they wrap.+* Lenses: To avoid clashes with Text.XML.Light, lenses are named as for the record field, with a suffix of `L`.+-}++module Text.XML.Light.Lens (+  -- * Cursor+  currentL, leftsL, rightsL, parentsL,+  -- * Content+  _Elem, _Text, _CRef,+  -- * Elem+  elNameL, elAttribsL, elContentL, elLineL,+  -- * Attr+  attrKeyL, attrValL,+  -- * CData+  cdVerbatimL, cdDataL, cdLineL,+  -- * CDataKind+  _CDataText, _CDataVerbatim, _CDataRaw,+  -- * QName+  qNameL, qURIL, qPrefixL,+                           ) where++import Control.Lens+import Text.XML.Light+import Text.XML.Light.Cursor++-- |+currentL :: Lens' Cursor Content+currentL = lens current (\v x -> v { current = x})++-- |+leftsL :: Lens' Cursor [Content]+leftsL = lens lefts (\v x -> v { lefts = x})++-- |+rightsL :: Lens' Cursor [Content]+rightsL = lens rights (\v x -> v { rights = x})++-- |+parentsL :: Lens' Cursor Path+parentsL = lens parents (\v x -> v { parents = x})++-- |+_Elem :: Prism' Content Element+_Elem = prism Elem g+  where g (Elem e) = Right e+        g v = Left v++-- |+_Text :: Prism' Content CData+_Text = prism Text g+  where g (Text e) = Right e+        g v = Left v++-- |+_CRef :: Prism' Content String+_CRef = prism CRef g+  where g (CRef e) = Right e+        g v = Left v++-- | +elNameL :: Lens' Element QName+elNameL = lens elName (\v a -> v { elName = a })++elAttribsL :: Lens' Element [Attr]+elAttribsL = lens elAttribs (\v a -> v { elAttribs = a })++elContentL :: Lens' Element [Content]+elContentL = lens elContent (\v a -> v { elContent = a })++elLineL :: Lens' Element (Maybe Line)+elLineL = lens elLine (\v a -> v { elLine = a })++attrKeyL :: Lens' Attr QName+attrKeyL = lens attrKey (\v a -> v { attrKey = a })++attrValL :: Lens' Attr String+attrValL = lens attrVal (\v a -> v { attrVal = a })++cdVerbatimL :: Lens' CData CDataKind+cdVerbatimL = lens cdVerbatim (\v a -> v { cdVerbatim = a })++cdDataL :: Lens' CData String+cdDataL = lens cdData (\v a -> v { cdData = a })++cdLineL :: Lens' CData (Maybe Line)+cdLineL = lens cdLine (\v a -> v { cdLine = a })++_CDataText :: Prism' CDataKind ()+_CDataText = prism' (const CDataText) g+  where g CDataText = Just ()+        g _ = Nothing++_CDataVerbatim :: Prism' CDataKind ()+_CDataVerbatim = prism' (const CDataVerbatim) g+  where g CDataVerbatim = Just ()+        g _ = Nothing++_CDataRaw :: Prism' CDataKind ()+_CDataRaw = prism' (const CDataRaw) g+  where g CDataRaw = Just ()+        g _ = Nothing++qNameL :: Lens' QName String+qNameL = lens qName (\v a -> v { qName = a })++qURIL :: Lens' QName (Maybe String)+qURIL = lens qURI (\v a -> v { qURI = a })++qPrefixL :: Lens' QName (Maybe String)+qPrefixL = lens qPrefix (\v a -> v { qPrefix = a })
+ test/Spec.hs view
@@ -0,0 +1,12 @@++import Text.XML.Light+import Text.XML.Light.Lens+import Control.Lens++main :: IO ()+main =+  let v = parseXML sample+   in print $ v ^.. traverse . _Elem . elNameL . qNameL++sample =+  "<a>5</a>"