diff options
author | Gregor Kleen <aethoago@141.li> | 2017-02-15 15:10:51 +0100 |
---|---|---|
committer | Gregor Kleen <aethoago@141.li> | 2017-02-15 15:10:51 +0100 |
commit | ee09f262f9b8c7c6a4042071cdfff3e22adbef86 (patch) | |
tree | baeb1d9ee726881d25e0762c21f750850efb37f2 /lib/Postdelay/TimeSpec/Utils.hs | |
parent | 8a24b41b333bce25e698d2e4b87f4b4f6548772c (diff) | |
download | postdelay-ee09f262f9b8c7c6a4042071cdfff3e22adbef86.tar postdelay-ee09f262f9b8c7c6a4042071cdfff3e22adbef86.tar.gz postdelay-ee09f262f9b8c7c6a4042071cdfff3e22adbef86.tar.bz2 postdelay-ee09f262f9b8c7c6a4042071cdfff3e22adbef86.tar.xz postdelay-ee09f262f9b8c7c6a4042071cdfff3e22adbef86.zip |
Establish framework
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 | ] | ||