From 49c4de13e9f32a6c31c3dbb54c40e206fb50461c Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 7 Aug 2016 15:56:46 +0200 Subject: switch to parsec --- events/events.cabal | 4 +--- events/events.nix | 12 +++++------- events/src/Events/Spec/Parse.hs | 31 +++++++++++++++++++++---------- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/events/events.cabal b/events/events.cabal index 390f062..33909ff 100644 --- a/events/events.cabal +++ b/events/events.cabal @@ -40,9 +40,7 @@ executable events , list-t >=0.4.6 && <1 , data-default-class >=0.0.1 && <1 , text >=1.2.2.1 && <2 - , conduit >=1.2.6.6 && <2 - , conduit-extra >=1.1.13.2 && <2 - , attoparsec >=0.13.0.2 && <1 + , parsec >=3.1.11 && <4 , exceptions >=0.8.3 && <1 hs-source-dirs: src default-language: Haskell2010 diff --git a/events/events.nix b/events/events.nix index 3f5d798..72d5518 100644 --- a/events/events.nix +++ b/events/events.nix @@ -1,7 +1,6 @@ -{ mkDerivation, aeson, aeson-lens, attoparsec, base, bytestring -, conduit, conduit-extra, data-default-class, exceptions, lens -, lens-time, list-t, mmorph, mtl, stdenv, text, time, transformers -, tz, yaml +{ mkDerivation, aeson, aeson-lens, base, bytestring +, data-default-class, exceptions, lens, lens-time, list-t, mmorph +, mtl, parsec, stdenv, text, time, transformers, tz, yaml }: mkDerivation { pname = "events"; @@ -10,9 +9,8 @@ mkDerivation { isLibrary = false; isExecutable = true; executableHaskellDepends = [ - aeson aeson-lens attoparsec base bytestring conduit conduit-extra - data-default-class exceptions lens lens-time list-t mmorph mtl text - time transformers tz yaml + aeson aeson-lens base bytestring data-default-class exceptions lens + lens-time list-t mmorph mtl parsec text time transformers tz yaml ]; homepage = "https://git.yggdrasil.li/gkleen/pub/events"; description = "An appointment book"; diff --git a/events/src/Events/Spec/Parse.hs b/events/src/Events/Spec/Parse.hs index f3114f1..44aabd0 100644 --- a/events/src/Events/Spec/Parse.hs +++ b/events/src/Events/Spec/Parse.hs @@ -1,24 +1,35 @@ {-# LANGUAGE GADTs, DataKinds, OverloadedStrings #-} +{-# LANGUAGE StandaloneDeriving #-} module Events.Spec.Parse ( parse - , Position(..), ParseError(..) + , ParseError(..) ) where -import Data.Conduit.Attoparsec -import Data.Conduit +import Events.Spec.Types -import Data.Attoparsec.Text hiding (parse) +import Text.Parsec hiding (parse, ParseError) +import qualified Text.Parsec as Parsec (parse, ParseError) import Data.Text (Text) -import qualified Data.Text as T +import qualified Data.Text as Text -import Events.Spec.Types +import Data.Text.Lazy as Lazy (Text) +import qualified Data.Text.Lazy as Lazy.Text + +import Data.Either (either) +import Data.Typeable (Typeable) + +import Control.Monad.Catch (Exception(..), MonadThrow(..)) + + +newtype ParseError = ParseError Parsec.ParseError + deriving (Typeable, Show, Eq) +instance Exception ParseError -import Control.Monad.Catch (MonadThrow) -parse :: MonadThrow m => Consumer Text m (Spec m) -parse = sinkParser $ pSpec <* endOfInput +parse :: MonadThrow m => SourceName -> Lazy.Text -> Eval m (Spec m) +parse name = either (throwM . ParseError) return <=< runParserT pSpec () name -pSpec :: Monad m => Parser (Spec m) +pSpec :: ParsecT Lazy.Text () (Eval m) (Spec m) pSpec = mzero -- cgit v1.2.3