blob: e4ba732b7ba39abd6442bff02d20008b2d555f17 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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 '-'
]
|