pipes-attoparsec (empty) → 0.0.1
raw patch · 4 files changed
+101/−0 lines, 4 filesdep +attoparsecdep +basedep +pipes-coresetup-changed
Dependencies added: attoparsec, base, pipes-core
Files
- Control/Pipe/Attoparsec.hs +45/−0
- LICENSE +30/−0
- Setup.hs +2/−0
- pipes-attoparsec.cabal +24/−0
+ Control/Pipe/Attoparsec.hs view
@@ -0,0 +1,45 @@+{-# LANGUAGE DeriveDataTypeable #-}+module Control.Pipe.Attoparsec (+ ParseError(..),+ pipeParser,+ ) where++import qualified Control.Exception as E+import Control.Pipe+import Control.Pipe.Combinators+import Control.Pipe.Exception+import Data.Attoparsec.Types+import Data.Maybe+import Data.Monoid+import Data.Typeable++-- | A parse error as returned by Attoparsec.+data ParseError+ = ParseError {+ errorContexts :: [String], -- ^ Contexts where the error occurred.+ errorMessage :: String -- ^ Error message.+ }+ | DivergentParser -- ^ Returned if a parser does not terminate+ -- when its input is exhausted.+ deriving (Show, Typeable)++instance E.Exception ParseError++-- | Convert a parser continuation into a Pipe.+--+-- To get a parser continuation from a 'Parser', use the @parse@ function of the+-- appropriate Attoparsec module.+pipeParser :: (Monoid a, Monad m) => (a -> IResult a r) -> Pipe a x m (a, Either ParseError r)+pipeParser p = go p+ where+ go p = do+ chunk <- tryAwait+ case p (maybe mempty id chunk) of+ Fail leftover contexts msg ->+ return (leftover, Left $ ParseError contexts msg)+ Partial p' ->+ if isNothing chunk+ then return (mempty, Left DivergentParser)+ else go p'+ Done leftover result ->+ return (leftover, Right result)
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2012, Paolo Capriotti++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 Paolo Capriotti 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
+ pipes-attoparsec.cabal view
@@ -0,0 +1,24 @@+Name: pipes-attoparsec+Version: 0.0.1+License: BSD3+License-file: LICENSE+Author: Paolo Capriotti+Maintainer: p.capriotti@gmail.com+Stability: Experimental+Homepage: https://github.com/pcapriotti/pipes-extra+Category: Text+Build-type: Simple+Synopsis: Utilities to convert a parser into a pipe.+Description: Utilities to convert a parser into a pipe.+Cabal-version: >=1.8++Source-Repository head+ Type: git+ Location: https://github.com/pcapriotti/pipes-extra++Library+ Exposed-modules: Control.Pipe.Attoparsec+ Build-depends:+ base (== 4.*),+ pipes-core (== 0.0.*),+ attoparsec (== 0.10.*)