hexpat-conduit (empty) → 0.0.1
raw patch · 3 files changed
+96/−0 lines, 3 filesdep +Listdep +basedep +bytestring
Dependencies added: List, base, bytestring, conduit, hexpat, hexpat-streamparser, mtl, text, transformers
Files
- LICENSE +29/−0
- hexpat-conduit.cabal +31/−0
- src/Text/XML/Expat/StreamParser/Conduit.hs +36/−0
+ LICENSE view
@@ -0,0 +1,29 @@+BSD 3-Clause License++Copyright (c) 2020, Kristof Bastiaensen+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++1. Redistributions of source code must retain the above copyright notice, this+ list of conditions and the following disclaimer.++2. 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.++3. Neither the name of the copyright holder nor the names of its+ 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 HOLDER 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.
+ hexpat-conduit.cabal view
@@ -0,0 +1,31 @@+cabal-version: 1.12+name: hexpat-conduit+description: conduit streaming for hexpat-streamparser+version: 0.0.1+maintainer: kristof@resonata.be+copyright: Kristof Bastiaensen 2020+license: BSD3+license-file: LICENSE+build-type: Simple++source-repository head+ type: git+ location: https://github.com/kuribas/hexpat-conduit++library+ Ghc-options: -Wall+ default-language: Haskell2010+ exposed-modules:+ Text.XML.Expat.StreamParser.Conduit+ hs-source-dirs:+ src+ build-depends:+ base >= 4.9 && < 5,+ mtl >= 2.2 && < 2.3,+ List >= 0.6 && < 0.7,+ conduit >= 1.3.4,+ hexpat >= 0.20 && < 0.21,+ hexpat-streamparser == 0.1.3,+ bytestring >= 0.10.0,+ text > 1.2.0,+ transformers >= 0.5 && < 0.6
+ src/Text/XML/Expat/StreamParser/Conduit.hs view
@@ -0,0 +1,36 @@+{-# LANGUAGE RankNTypes #-}+module Text.XML.Expat.StreamParser.Conduit where+import Text.XML.Expat.StreamParser+import Text.XML.Expat.SAX+import Data.List.Class+import Control.Monad.ListT (ListT(..))+import Data.Conduit+import Data.Text+import Data.ByteString+import Data.Functor.Identity++-- | An EventParser in the ConduitT monad.+type ConduitEventParser e o m a =+ (forall i.EventParser (ListT (ConduitT i o m)) e (ConduitT i o m) a)++-- | Convert an EventParser in the ConduitT monad to a ConduitT that+-- takes bytestrings and produces the result of the parser. You can+-- use `lift . yield` to stream values as a side effect in the+-- ConduitT monad, or `lift effect` to run any effect in the ConduitT+-- monad.+streamParserToConduit :: Monad m+ => ParseOptions Text Text+ -> ConduitEventParser e o m a+ -> ConduitT ByteString o m (Either (EventParseError e,+ Maybe+ XMLParseLocation)+ a)+streamParserToConduit opts parser =+ runEventParser parser $ parseLocationsG opts bsStream+ where+ bsStream = ListT $ do+ next <- await+ case next of+ Nothing -> pure Nil+ Just el -> pure $ Cons el bsStream+