summaryrefslogtreecommitdiff
path: root/events/src/Events
diff options
context:
space:
mode:
authorGregor Kleen <pngwjpgh@users.noreply.github.com>2016-08-07 15:56:46 +0200
committerGregor Kleen <pngwjpgh@users.noreply.github.com>2016-08-07 15:56:46 +0200
commit49c4de13e9f32a6c31c3dbb54c40e206fb50461c (patch)
treed69ab880728ce04763513a07f8b6f50b00df99bd /events/src/Events
parente2921b58336283597cba771d5dd54ede40f89ea5 (diff)
downloadevents-49c4de13e9f32a6c31c3dbb54c40e206fb50461c.tar
events-49c4de13e9f32a6c31c3dbb54c40e206fb50461c.tar.gz
events-49c4de13e9f32a6c31c3dbb54c40e206fb50461c.tar.bz2
events-49c4de13e9f32a6c31c3dbb54c40e206fb50461c.tar.xz
events-49c4de13e9f32a6c31c3dbb54c40e206fb50461c.zip
switch to parsec
Diffstat (limited to 'events/src/Events')
-rw-r--r--events/src/Events/Spec/Parse.hs31
1 files changed, 21 insertions, 10 deletions
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