From ee09f262f9b8c7c6a4042071cdfff3e22adbef86 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 15 Feb 2017 15:10:51 +0100 Subject: Establish framework --- lib/Postdelay/TimeSpec/Utils.hs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 lib/Postdelay/TimeSpec/Utils.hs (limited to 'lib/Postdelay/TimeSpec/Utils.hs') 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 @@ +{-# LANGUAGE RankNTypes, ConstraintKinds, TypeFamilies, FlexibleContexts, ScopedTypeVariables, ViewPatterns #-} + +module Postdelay.TimeSpec.Utils where + +import Control.Applicative +import Control.Monad +import Control.Lens + +import Data.Time +import Data.Time.Zones + +import Data.AdditiveGroup + +import Text.Megaparsec +import Text.Megaparsec.Prim (MonadParsec) +import qualified Text.Megaparsec.Lexer as L + + +type StringParser s m = (MonadParsec Dec s m, Token s ~ Char) + + +spaceConsumer :: StringParser s m => m () +spaceConsumer = L.space (void spaceChar) empty empty + +lexeme :: StringParser s m => m a -> m a +lexeme = L.lexeme spaceConsumer + +signed, optSigned :: (StringParser s m, AdditiveGroup n) => m n -> m n +signed = (<*>) (lexeme sign) +optSigned = (<*>) (option id $ lexeme sign) + +sign :: (StringParser s m, AdditiveGroup n) => m (n -> n) +sign = choice [ id <$ char '+' + , negateV <$ char '-' + ] -- cgit v1.2.3