diff options
Diffstat (limited to 'src/Cron/Expr.hs')
-rw-r--r-- | src/Cron/Expr.hs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/Cron/Expr.hs b/src/Cron/Expr.hs new file mode 100644 index 0000000..a6cb4ca --- /dev/null +++ b/src/Cron/Expr.hs @@ -0,0 +1,21 @@ +module Cron.Expr (Expr (..), StepLExpr (..), showExpr) where + +import Data.List.NonEmpty (NonEmpty, intersperse) +import Data.Semigroup (sconcat) +import Intro + +data Expr = Every | Multi (NonEmpty Int) | Range Int Int | Step StepLExpr Int deriving (Show) + +data StepLExpr = StepLEvery | StepLRange Int Int deriving (Show) + +showExpr :: Expr -> String +showExpr = \case + Every -> "*" + Multi ns -> sconcat $ intersperse "," (fmap show ns) + Range n m -> mconcat [show n, "-", show m] + Step n m -> mconcat [showStepLExpr n, "/", show m] + +showStepLExpr :: StepLExpr -> String +showStepLExpr = \case + StepLEvery -> "*" + StepLRange n m -> mconcat [show n, "-", show m] |