diff options
Diffstat (limited to 'events/src/Events/Spec')
-rw-r--r-- | events/src/Events/Spec/Parse.hs | 31 |
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 | ||
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 |