packages feed

attoparsec-text-enumerator (empty) → 0.2.0.0

raw patch · 4 files changed

+118/−0 lines, 4 filesdep +attoparsec-textdep +basedep +enumeratorsetup-changed

Dependencies added: attoparsec-text, base, enumerator, text

Files

+ Data/Attoparsec/Text/Enumerator.hs view
@@ -0,0 +1,56 @@+-----------------------------------------------------------------------------+-- |+-- Module: Data.Attoparsec.Text.Enumerator+-- Copyright: Felipe Lessa 2010, John Millikin 2010+-- License: MIT+--+-- Maintainer: felipe.lessa@gmail.com+-- Portability: portable+--+-- Convert an attoparsec-text parser into an iteratee.  This+-- package is heavily based on attoparsec-enumerator for the+-- original attoparsec on @ByteString@.+--+-----------------------------------------------------------------------------+{-# LANGUAGE DeriveDataTypeable #-}+module Data.Attoparsec.Text.Enumerator+	( ParseError (..)+	, iterParser+	) where+import Control.Exception (Exception)+import Data.Typeable (Typeable)+import qualified Data.Attoparsec.Text as A+import qualified Data.Text as T+import qualified Data.Enumerator as E++-- | The context and message from a 'A.Fail' value.+data ParseError = ParseError+	{ errorContexts :: [String]+	, errorMessage :: String+	}+	deriving (Show, Typeable)++instance Exception ParseError++-- | Convert an Attoparsec 'A.Parser' into an 'E.Iteratee'. The parser will+-- be streamed characters until it returns 'A.Done' or 'A.Fail'.+--+-- If parsing fails, the iteratee's error value will contain a 'ParseError'.+iterParser :: Monad m => A.Parser a -> E.Iteratee T.Text m a+iterParser p = E.continue (step (A.parse p)) where+	step parse (E.Chunks xs) = parseLoop parse (notEmpty xs)+	step parse E.EOF = case A.feed (parse T.empty) T.empty of+		A.Done _ a -> E.yield a E.EOF+		A.Partial _ -> err [] "iterParser: divergent parser"+		A.Fail _ ctx msg -> err ctx msg++	parseLoop parse [] = E.continue (step parse)+	parseLoop parse (x:xs) = case parse x of+		A.Done extra a -> E.yield a $ if T.null extra+			then E.Chunks xs+			else E.Chunks (extra:xs)+		A.Partial parse' -> parseLoop parse' xs+		A.Fail _ ctx msg -> err ctx msg++	err ctx msg = E.throwError (ParseError ctx msg)+	notEmpty = filter (not . T.null)
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ attoparsec-text-enumerator.cabal view
@@ -0,0 +1,38 @@+name: attoparsec-text-enumerator+version: 0.2.0.0+synopsis: Convert an attoparsec-text parser into an iteratee+license: MIT+license-file: license.txt+author: Felipe Lessa <felipe.lessa@gmail.com>, John Millikin <jmillikin@gmail.com>+maintainer: Felipe Lessa <felipe.lessa@gmail.com>+copyright: Copyright (c) Felipe Lessa 2010, John Millikin 2010+build-type: Simple+cabal-version: >=1.6+category: Text, Parsing, Enumerator+stability: experimental+-- bug-reports: mailto:jmillikin@gmail.com+-- homepage: http://john-millikin.com/software/attoparsec-enumerator/+tested-with: GHC==6.12.1+description:+  Convert an attoparsec-text parser into an iteratee.+  .+  This library is basically a translation of the original+  attoparsec-enumerator library to use text instead of+  bytestrings.+++library+  if true+    ghc-options: -Wall++  if impl(ghc >= 6.11)+    ghc-options: -fno-warn-unused-do-bind++  build-depends:+      base            >= 3    && < 5+    , attoparsec-text >= 0.8  && < 0.9+    , text            >= 0.10 && < 0.12+    , enumerator      >= 0.4  && < 0.5++  exposed-modules:+    Data.Attoparsec.Text.Enumerator
+ license.txt view
@@ -0,0 +1,22 @@+Copyright (c) 2010 John Millikin++Permission is hereby granted, free of charge, to any person+obtaining a copy of this software and associated documentation+files (the "Software"), to deal in the Software without+restriction, including without limitation the rights to use,+copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the+Software is furnished to do so, subject to the following+conditions:++The above copyright notice and this permission notice shall be+included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR+OTHER DEALINGS IN THE SOFTWARE.