summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--events/events.cabal4
-rw-r--r--events/events.nix12
-rw-r--r--events/src/Events/Spec/Parse.hs31
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
40 , list-t >=0.4.6 && <1 40 , list-t >=0.4.6 && <1
41 , data-default-class >=0.0.1 && <1 41 , data-default-class >=0.0.1 && <1
42 , text >=1.2.2.1 && <2 42 , text >=1.2.2.1 && <2
43 , conduit >=1.2.6.6 && <2 43 , parsec >=3.1.11 && <4
44 , conduit-extra >=1.1.13.2 && <2
45 , attoparsec >=0.13.0.2 && <1
46 , exceptions >=0.8.3 && <1 44 , exceptions >=0.8.3 && <1
47 hs-source-dirs: src 45 hs-source-dirs: src
48 default-language: Haskell2010 46 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 @@
1{ mkDerivation, aeson, aeson-lens, attoparsec, base, bytestring 1{ mkDerivation, aeson, aeson-lens, base, bytestring
2, conduit, conduit-extra, data-default-class, exceptions, lens 2, data-default-class, exceptions, lens, lens-time, list-t, mmorph
3, lens-time, list-t, mmorph, mtl, stdenv, text, time, transformers 3, mtl, parsec, stdenv, text, time, transformers, tz, yaml
4, tz, yaml
5}: 4}:
6mkDerivation { 5mkDerivation {
7 pname = "events"; 6 pname = "events";
@@ -10,9 +9,8 @@ mkDerivation {
10 isLibrary = false; 9 isLibrary = false;
11 isExecutable = true; 10 isExecutable = true;
12 executableHaskellDepends = [ 11 executableHaskellDepends = [
13 aeson aeson-lens attoparsec base bytestring conduit conduit-extra 12 aeson aeson-lens base bytestring data-default-class exceptions lens
14 data-default-class exceptions lens lens-time list-t mmorph mtl text 13 lens-time list-t mmorph mtl parsec text time transformers tz yaml
15 time transformers tz yaml
16 ]; 14 ];
17 homepage = "https://git.yggdrasil.li/gkleen/pub/events"; 15 homepage = "https://git.yggdrasil.li/gkleen/pub/events";
18 description = "An appointment book"; 16 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 @@
1{-# LANGUAGE GADTs, DataKinds, OverloadedStrings #-} 1{-# LANGUAGE GADTs, DataKinds, OverloadedStrings #-}
2{-# LANGUAGE StandaloneDeriving #-}
2 3
3module Events.Spec.Parse 4module Events.Spec.Parse
4 ( parse 5 ( parse
5 , Position(..), ParseError(..) 6 , ParseError(..)
6 ) where 7 ) where
7 8
8import Data.Conduit.Attoparsec 9import Events.Spec.Types
9import Data.Conduit
10 10
11import Data.Attoparsec.Text hiding (parse) 11import Text.Parsec hiding (parse, ParseError)
12import qualified Text.Parsec as Parsec (parse, ParseError)
12 13
13import Data.Text (Text) 14import Data.Text (Text)
14import qualified Data.Text as T 15import qualified Data.Text as Text
15 16
16import Events.Spec.Types 17import Data.Text.Lazy as Lazy (Text)
18import qualified Data.Text.Lazy as Lazy.Text
19
20import Data.Either (either)
21import Data.Typeable (Typeable)
22
23import Control.Monad.Catch (Exception(..), MonadThrow(..))
24
25
26newtype ParseError = ParseError Parsec.ParseError
27 deriving (Typeable, Show, Eq)
28instance Exception ParseError
17 29
18import Control.Monad.Catch (MonadThrow)
19 30
20parse :: MonadThrow m => Consumer Text m (Spec m) 31parse :: MonadThrow m => SourceName -> Lazy.Text -> Eval m (Spec m)
21parse = sinkParser $ pSpec <* endOfInput 32parse name = either (throwM . ParseError) return <=< runParserT pSpec () name
22 33
23pSpec :: Monad m => Parser (Spec m) 34pSpec :: ParsecT Lazy.Text () (Eval m) (Spec m)
24pSpec = mzero 35pSpec = mzero