diff options
Diffstat (limited to 'lib/Postdelay/TimeSpec/Utils.hs')
-rw-r--r-- | lib/Postdelay/TimeSpec/Utils.hs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/Postdelay/TimeSpec/Utils.hs b/lib/Postdelay/TimeSpec/Utils.hs new file mode 100644 index 0000000..e4ba732 --- /dev/null +++ b/lib/Postdelay/TimeSpec/Utils.hs | |||
@@ -0,0 +1,35 @@ | |||
1 | {-# LANGUAGE RankNTypes, ConstraintKinds, TypeFamilies, FlexibleContexts, ScopedTypeVariables, ViewPatterns #-} | ||
2 | |||
3 | module Postdelay.TimeSpec.Utils where | ||
4 | |||
5 | import Control.Applicative | ||
6 | import Control.Monad | ||
7 | import Control.Lens | ||
8 | |||
9 | import Data.Time | ||
10 | import Data.Time.Zones | ||
11 | |||
12 | import Data.AdditiveGroup | ||
13 | |||
14 | import Text.Megaparsec | ||
15 | import Text.Megaparsec.Prim (MonadParsec) | ||
16 | import qualified Text.Megaparsec.Lexer as L | ||
17 | |||
18 | |||
19 | type StringParser s m = (MonadParsec Dec s m, Token s ~ Char) | ||
20 | |||
21 | |||
22 | spaceConsumer :: StringParser s m => m () | ||
23 | spaceConsumer = L.space (void spaceChar) empty empty | ||
24 | |||
25 | lexeme :: StringParser s m => m a -> m a | ||
26 | lexeme = L.lexeme spaceConsumer | ||
27 | |||
28 | signed, optSigned :: (StringParser s m, AdditiveGroup n) => m n -> m n | ||
29 | signed = (<*>) (lexeme sign) | ||
30 | optSigned = (<*>) (option id $ lexeme sign) | ||
31 | |||
32 | sign :: (StringParser s m, AdditiveGroup n) => m (n -> n) | ||
33 | sign = choice [ id <$ char '+' | ||
34 | , negateV <$ char '-' | ||
35 | ] | ||