packages feed

hexpat-lens 0.0.1 → 0.0.2

raw patch · 4 files changed

+78/−11 lines, 4 filesdep +bytestringdep +hexpat-tagsoupPVP ok

version bump matches the API change (PVP)

Dependencies added: bytestring, hexpat-tagsoup

API changes (from Hackage documentation)

+ Text.XML.Expat.Lens.Parse: _HTML :: GenericXMLString text => Iso' ByteString (UNode text)
+ Text.XML.Expat.Lens.Parse: _HTML' :: GenericXMLString text => Iso' ByteString (UNode text)
+ Text.XML.Expat.Lens.Parse: _HTMLWithOptions :: GenericXMLString text => ParseOptions ByteString -> Iso' ByteString (UNode text)
+ Text.XML.Expat.Lens.Parse: _XML :: (GenericXMLString tag, GenericXMLString text) => Prism' ByteString (NodeG [] tag text)
+ Text.XML.Expat.Lens.Parse: _XMLWithOptions :: (GenericXMLString tag, GenericXMLString text) => ParseOptions tag text -> Prism' ByteString (NodeG [] tag text)

Files

hexpat-lens.cabal view
@@ -1,5 +1,5 @@ name:                hexpat-lens-version:             0.0.1+version:             0.0.2 synopsis:            Lenses for Hexpat. license:             MIT license-file:        LICENSE@@ -13,12 +13,15 @@ library   exposed-modules:          Text.XML.Expat.Lens.Unqualified+    Text.XML.Expat.Lens.Parse     Text.XML.Expat.Lens.Names   build-depends:       -      base >=4.6 && <4.7-    , deepseq >=1.3 && <1.4-    , hexpat >=0.20 && <0.21-    , lens >=3.9 && <3.10+      base            >= 4.6      && < 4.7+    , bytestring      >= 0.10.0.2 && < 0.10.1+    , deepseq         >= 1.3      && < 1.4+    , hexpat          >= 0.20     && < 0.21+    , lens            >= 3.9      && < 3.10+    , hexpat-tagsoup  == 0.1.*   ghc-options: -Wall   hs-source-dirs:      src   default-language:    Haskell2010
src/Text/XML/Expat/Lens/Names.hs view
@@ -31,7 +31,6 @@  import Text.XML.Expat.Tree -import Data.Data import Control.DeepSeq import System.IO.Unsafe @@ -39,11 +38,11 @@   localPart :: Lens' (a t) t  prefix :: Lens' (QName text) (Maybe text)-prefix inj (QName pre part) = (\pre' -> QName pre' part) <$> inj pre+prefix inj (QName pref part) = (\pref' -> QName pref' part) <$> inj pref {-# INLINE prefix #-}  instance HasLocalPart QName where-  localPart inj (QName pre part) = (\part' -> QName pre part') <$> inj part+  localPart inj (QName pref part) = (\part' -> QName pref part') <$> inj part   {-# INLINE localPart #-}  namespace :: Lens' (NName text) (Maybe text)
+ src/Text/XML/Expat/Lens/Parse.hs view
@@ -0,0 +1,64 @@+{-# LANGUAGE RankNTypes #-}++-- |+-- Module      : Text.XML.Expat.Lens.Parse+-- Copyright   : (c) 2013, Joseph Abrahamson+-- License     : MIT+-- +-- Maintainer  : me@jspha.com+-- Stability   : experimental+-- Portability : non-portable+-- +-- XML parsing 'Prism's from Hexpat. HTML parsing 'Iso's from TagSoup.+-- +-- While @Hexpat@ offers lazy, incremental parsing and this can+-- improve performance, we must force the parse to completion in order+-- to provide a 'Prism', so the lazy parsing is not offered here.++module Text.XML.Expat.Lens.Parse (+  _XML, _XMLWithOptions, _HTML, _HTML', _HTMLWithOptions+  ) where++import Control.Lens+import Text.XML.Expat.Format+import Text.XML.Expat.Tree       as T+import Text.XML.Expat.TagSoup    as TS+import qualified Data.ByteString as S++-- | Strict parsing and formatting of XML via 'format'' and 'parse''.+_XML ::+  (GenericXMLString tag, GenericXMLString text) =>+  Prism' S.ByteString (NodeG [] tag text)+_XML = _XMLWithOptions defaultParseOptions+{-# INLINE _XML #-}++-- | Provides an '_XMLWithOptions parsing 'Prism' with access to the+-- 'ParsingOptions'.+_XMLWithOptions ::+  (GenericXMLString tag, GenericXMLString text) =>+  T.ParseOptions tag text -> Prism' S.ByteString (NodeG [] tag text)+_XMLWithOptions opts = prism format' (\s -> bimap (const s) id $ parse' opts s)+{-# INLINE _XMLWithOptions #-}++-- | Uses "tag soup" parsing to build a 'UNode' tree. Technically a+-- retract, since @_HTML@ tries very hard to return *something*, we+-- get an 'Iso' instead of a 'Prism'.+_HTML+  :: (GenericXMLString text) => Iso' S.ByteString (UNode text)+_HTML = _HTMLWithOptions TS.parseOptions+{-# INLINE _HTML #-}++-- | Uses "tag soup" parsing to build a 'UNode' tree. Technically a+-- retract, since @_HTML@ tries very hard to return *something*, we+-- get an 'Iso' instead of a 'Prism'. Uses the *fast* tag soup parsing+-- options.+_HTML'+  :: (GenericXMLString text) => Iso' S.ByteString (UNode text)+_HTML' = _HTMLWithOptions TS.parseOptions+{-# INLINE _HTML' #-}++-- | Like '_HTML but allows choice of 'TS.ParseOptions'.+_HTMLWithOptions+  :: (GenericXMLString text) => TS.ParseOptions S.ByteString -> Iso' S.ByteString (UNode text)+_HTMLWithOptions opts = iso (parseTagsOptions opts) format'+{-# INLINE _HTMLWithOptions #-}
src/Text/XML/Expat/Lens/Unqualified.hs view
@@ -14,6 +14,7 @@ -- module provides a less general interface to the Hexpat datatypes -- via lenses. +{-# OPTIONS -fno-warn-orphans #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE TypeSynonymInstances #-}@@ -32,7 +33,7 @@  name :: Traversal' (UNode t) t name inj (Element n a c) = (\n' -> Element n' a c) <$> inj n-name inj t               = pure t+name _   t               = pure t {-# INLINE name #-}  -- | Traverses to the list of attributes of an 'Element'. This is as@@ -41,7 +42,7 @@  attributes :: Traversal' (UNode t) (UAttributes t) attributes inj (Element n a c) = (\a' -> Element n a' c) <$> inj a-attributes inj t               = pure t+attributes _   t               = pure t {-# INLINE attributes #-}  -- The @attributes@ form, effectively, a lookup table allowing us to@@ -75,7 +76,7 @@  children :: Traversal' (UNode t) [UNode t] children inj (Element n a c) = (\c' -> Element n a c') <$> inj c-children inj t               = pure t+children _   t               = pure t {-# INLINE children #-}  -- | Prismatic access to the text of a 'Text' node. This is more