summaryrefslogtreecommitdiff
path: root/lib/Postdelay/TimeSpec/Utils.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Postdelay/TimeSpec/Utils.hs')
-rw-r--r--lib/Postdelay/TimeSpec/Utils.hs35
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
3module Postdelay.TimeSpec.Utils where
4
5import Control.Applicative
6import Control.Monad
7import Control.Lens
8
9import Data.Time
10import Data.Time.Zones
11
12import Data.AdditiveGroup
13
14import Text.Megaparsec
15import Text.Megaparsec.Prim (MonadParsec)
16import qualified Text.Megaparsec.Lexer as L
17
18
19type StringParser s m = (MonadParsec Dec s m, Token s ~ Char)
20
21
22spaceConsumer :: StringParser s m => m ()
23spaceConsumer = L.space (void spaceChar) empty empty
24
25lexeme :: StringParser s m => m a -> m a
26lexeme = L.lexeme spaceConsumer
27
28signed, optSigned :: (StringParser s m, AdditiveGroup n) => m n -> m n
29signed = (<*>) (lexeme sign)
30optSigned = (<*>) (option id $ lexeme sign)
31
32sign :: (StringParser s m, AdditiveGroup n) => m (n -> n)
33sign = choice [ id <$ char '+'
34 , negateV <$ char '-'
35 ]