diff options
-rw-r--r-- | events/events.cabal | 4 | ||||
-rw-r--r-- | events/events.nix | 12 | ||||
-rw-r--r-- | 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 | |||
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 | }: |
6 | mkDerivation { | 5 | mkDerivation { |
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 | ||
3 | module Events.Spec.Parse | 4 | module Events.Spec.Parse |
4 | ( parse | 5 | ( parse |
5 | , Position(..), ParseError(..) | 6 | , ParseError(..) |
6 | ) where | 7 | ) where |
7 | 8 | ||
8 | import Data.Conduit.Attoparsec | 9 | import Events.Spec.Types |
9 | import Data.Conduit | ||
10 | 10 | ||
11 | import Data.Attoparsec.Text hiding (parse) | 11 | import Text.Parsec hiding (parse, ParseError) |
12 | import qualified Text.Parsec as Parsec (parse, ParseError) | ||
12 | 13 | ||
13 | import Data.Text (Text) | 14 | import Data.Text (Text) |
14 | import qualified Data.Text as T | 15 | import qualified Data.Text as Text |
15 | 16 | ||
16 | import Events.Spec.Types | 17 | import Data.Text.Lazy as Lazy (Text) |
18 | import qualified Data.Text.Lazy as Lazy.Text | ||
19 | |||
20 | import Data.Either (either) | ||
21 | import Data.Typeable (Typeable) | ||
22 | |||
23 | import Control.Monad.Catch (Exception(..), MonadThrow(..)) | ||
24 | |||
25 | |||
26 | newtype ParseError = ParseError Parsec.ParseError | ||
27 | deriving (Typeable, Show, Eq) | ||
28 | instance Exception ParseError | ||
17 | 29 | ||
18 | import Control.Monad.Catch (MonadThrow) | ||
19 | 30 | ||
20 | parse :: MonadThrow m => Consumer Text m (Spec m) | 31 | parse :: MonadThrow m => SourceName -> Lazy.Text -> Eval m (Spec m) |
21 | parse = sinkParser $ pSpec <* endOfInput | 32 | parse name = either (throwM . ParseError) return <=< runParserT pSpec () name |
22 | 33 | ||
23 | pSpec :: Monad m => Parser (Spec m) | 34 | pSpec :: ParsecT Lazy.Text () (Eval m) (Spec m) |
24 | pSpec = mzero | 35 | pSpec = mzero |