diff options
-rw-r--r-- | events/events.cabal | 5 | ||||
-rw-r--r-- | events/events.nix | 4 | ||||
-rw-r--r-- | events/src/Events/Spec/Parse.hs | 26 | ||||
-rw-r--r-- | events/src/Events/Spec/Parse/AST.hs | 19 | ||||
-rw-r--r-- | events/src/Events/Spec/Parse/Token.hs | 43 |
5 files changed, 84 insertions, 13 deletions
diff --git a/events/events.cabal b/events/events.cabal index 33909ff..f8d23dd 100644 --- a/events/events.cabal +++ b/events/events.cabal | |||
@@ -24,6 +24,9 @@ executable events | |||
24 | , Events.Spec | 24 | , Events.Spec |
25 | , Events.Spec.Types | 25 | , Events.Spec.Types |
26 | , Events.Spec.Eval | 26 | , Events.Spec.Eval |
27 | , Events.Spec.Parse | ||
28 | , Events.Spec.Parse.Token | ||
29 | , Events.Spec.Parse.AST | ||
27 | -- other-extensions: | 30 | -- other-extensions: |
28 | build-depends: base >=4.8 && <5 | 31 | build-depends: base >=4.8 && <5 |
29 | , lens >=4.13 && <5 | 32 | , lens >=4.13 && <5 |
@@ -40,7 +43,7 @@ executable events | |||
40 | , list-t >=0.4.6 && <1 | 43 | , list-t >=0.4.6 && <1 |
41 | , data-default-class >=0.0.1 && <1 | 44 | , data-default-class >=0.0.1 && <1 |
42 | , text >=1.2.2.1 && <2 | 45 | , text >=1.2.2.1 && <2 |
43 | , parsec >=3.1.11 && <4 | 46 | , megaparsec >=5.0.1 && <6 |
44 | , exceptions >=0.8.3 && <1 | 47 | , exceptions >=0.8.3 && <1 |
45 | hs-source-dirs: src | 48 | hs-source-dirs: src |
46 | default-language: Haskell2010 | 49 | default-language: Haskell2010 |
diff --git a/events/events.nix b/events/events.nix index 72d5518..f124baa 100644 --- a/events/events.nix +++ b/events/events.nix | |||
@@ -1,6 +1,6 @@ | |||
1 | { mkDerivation, aeson, aeson-lens, base, bytestring | 1 | { mkDerivation, aeson, aeson-lens, base, bytestring |
2 | , data-default-class, exceptions, lens, lens-time, list-t, mmorph | 2 | , data-default-class, exceptions, lens, lens-time, list-t, mmorph |
3 | , mtl, parsec, stdenv, text, time, transformers, tz, yaml | 3 | , mtl, megaparsec, stdenv, text, time, transformers, tz, yaml |
4 | }: | 4 | }: |
5 | mkDerivation { | 5 | mkDerivation { |
6 | pname = "events"; | 6 | pname = "events"; |
@@ -10,7 +10,7 @@ mkDerivation { | |||
10 | isExecutable = true; | 10 | isExecutable = true; |
11 | executableHaskellDepends = [ | 11 | executableHaskellDepends = [ |
12 | aeson aeson-lens base bytestring data-default-class exceptions lens | 12 | aeson aeson-lens base bytestring data-default-class exceptions lens |
13 | lens-time list-t mmorph mtl parsec text time transformers tz yaml | 13 | lens-time list-t mmorph mtl megaparsec text time transformers tz yaml |
14 | ]; | 14 | ]; |
15 | homepage = "https://git.yggdrasil.li/gkleen/pub/events"; | 15 | homepage = "https://git.yggdrasil.li/gkleen/pub/events"; |
16 | 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 44aabd0..2847372 100644 --- a/events/src/Events/Spec/Parse.hs +++ b/events/src/Events/Spec/Parse.hs | |||
@@ -1,15 +1,18 @@ | |||
1 | {-# LANGUAGE GADTs, DataKinds, OverloadedStrings #-} | 1 | {-# LANGUAGE GADTs, DataKinds, OverloadedStrings #-} |
2 | {-# LANGUAGE StandaloneDeriving #-} | 2 | {-# LANGUAGE StandaloneDeriving, FlexibleContexts #-} |
3 | 3 | ||
4 | module Events.Spec.Parse | 4 | module Events.Spec.Parse |
5 | ( parse | 5 | ( parse |
6 | , ParseError(..) | 6 | , ParseError(..) |
7 | , TypeError(..) | ||
7 | ) where | 8 | ) where |
8 | 9 | ||
9 | import Events.Spec.Types | 10 | import Events.Spec.Types |
11 | import Events.Spec.Parse.Token | ||
12 | import Events.Spec.Parse.AST | ||
10 | 13 | ||
11 | import Text.Parsec hiding (parse, ParseError) | 14 | import Text.Megaparsec hiding (parse) |
12 | import qualified Text.Parsec as Parsec (parse, ParseError) | 15 | import qualified Text.Megaparsec.Lexer as L |
13 | 16 | ||
14 | import Data.Text (Text) | 17 | import Data.Text (Text) |
15 | import qualified Data.Text as Text | 18 | import qualified Data.Text as Text |
@@ -23,13 +26,16 @@ import Data.Typeable (Typeable) | |||
23 | import Control.Monad.Catch (Exception(..), MonadThrow(..)) | 26 | import Control.Monad.Catch (Exception(..), MonadThrow(..)) |
24 | 27 | ||
25 | 28 | ||
26 | newtype ParseError = ParseError Parsec.ParseError | 29 | data TypeError = TypeError |
27 | deriving (Typeable, Show, Eq) | 30 | deriving (Typeable, Show) |
28 | instance Exception ParseError | ||
29 | 31 | ||
32 | instance Exception TypeError | ||
30 | 33 | ||
31 | parse :: MonadThrow m => SourceName -> Lazy.Text -> Eval m (Spec m) | ||
32 | parse name = either (throwM . ParseError) return <=< runParserT pSpec () name | ||
33 | 34 | ||
34 | pSpec :: ParsecT Lazy.Text () (Eval m) (Spec m) | 35 | parse :: (MonadIO m, MonadThrow m) => String -> Lazy.Text -> m (Spec m) |
35 | pSpec = mzero | 36 | parse name = typecheck <=< runParserT' pAST name <=< runParserT' pTokens name |
37 | where | ||
38 | runParserT' parser name = either throwM return <=< runParserT parser name | ||
39 | |||
40 | typecheck :: MonadThrow m => AST -> m (Spec m) | ||
41 | typecheck = undefined | ||
diff --git a/events/src/Events/Spec/Parse/AST.hs b/events/src/Events/Spec/Parse/AST.hs new file mode 100644 index 0000000..38c2c84 --- /dev/null +++ b/events/src/Events/Spec/Parse/AST.hs | |||
@@ -0,0 +1,19 @@ | |||
1 | {-# LANGUAGE GADTs, DataKinds, OverloadedStrings #-} | ||
2 | |||
3 | module Events.Spec.Parse.AST | ||
4 | ( AST(..) | ||
5 | , pAST | ||
6 | ) where | ||
7 | |||
8 | import Events.Spec.Types | ||
9 | import Events.Spec.Parse.Token | ||
10 | |||
11 | import Text.Megaparsec hiding (parse) | ||
12 | |||
13 | import Data.Typeable (Typeable) | ||
14 | |||
15 | data AST = AST | ||
16 | deriving (Typeable) | ||
17 | |||
18 | pAST :: ParsecT Dec [SpecToken] m AST | ||
19 | pAST = mzero {- TODO -} | ||
diff --git a/events/src/Events/Spec/Parse/Token.hs b/events/src/Events/Spec/Parse/Token.hs new file mode 100644 index 0000000..df6f09e --- /dev/null +++ b/events/src/Events/Spec/Parse/Token.hs | |||
@@ -0,0 +1,43 @@ | |||
1 | {-# LANGUAGE GADTs, DataKinds, OverloadedStrings #-} | ||
2 | {-# LANGUAGE StandaloneDeriving #-} | ||
3 | {-# LANGUAGE FlexibleInstances, TypeFamilies #-} | ||
4 | |||
5 | module Events.Spec.Parse.Token | ||
6 | ( SpecToken(..) | ||
7 | , pToken, pTokens | ||
8 | ) where | ||
9 | |||
10 | import Events.Spec.Types | ||
11 | |||
12 | import Text.Megaparsec hiding (parse) | ||
13 | import Text.Megaparsec.Pos | ||
14 | import qualified Text.Megaparsec.Lexer as L | ||
15 | |||
16 | import Data.Typeable (Typeable) | ||
17 | |||
18 | import Data.Text (Text) | ||
19 | import qualified Data.Text as Text | ||
20 | |||
21 | import Data.Text.Lazy as Lazy (Text) | ||
22 | import qualified Data.Text.Lazy as Lazy.Text | ||
23 | |||
24 | data SpecToken = Token | ||
25 | deriving (Typeable, Show, Eq, Ord) | ||
26 | |||
27 | instance Stream [SpecToken] where | ||
28 | type Token [SpecToken] = SpecToken | ||
29 | |||
30 | uncons [] = Nothing | ||
31 | uncons (s:ss) = Just (s, ss) | ||
32 | |||
33 | updatePos = undefined | ||
34 | |||
35 | |||
36 | tSpace :: ParsecT Dec Lazy.Text m () | ||
37 | tSpace = L.space (() <$ spaceChar) (L.skipLineComment "--") (L.skipBlockComment "{-" "-}") | ||
38 | |||
39 | pToken :: ParsecT Dec Lazy.Text m SpecToken | ||
40 | pToken = mzero {- TODO -} | ||
41 | |||
42 | pTokens :: ParsecT Dec Lazy.Text m [SpecToken] | ||
43 | pTokens = manyTill (tSpace *> pToken <* tSpace) eof | ||