From 03f321adafd3ef7a169555703ebc8e03903a1450 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 16 Apr 2016 22:16:41 +0200 Subject: Specifications to be evaluated --- events/src/Events/Spec.hs | 36 ++++++++++++++++++++++++++++++++++++ events/src/Main.hs | 24 +++++++++++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 events/src/Events/Spec.hs diff --git a/events/src/Events/Spec.hs b/events/src/Events/Spec.hs new file mode 100644 index 0000000..deabcc3 --- /dev/null +++ b/events/src/Events/Spec.hs @@ -0,0 +1,36 @@ +module Events.Spec + ( interpret + , Spec, Expr(..), BoolExpr(..) + ) where + +import Events.Types + +import Control.Monad.IO.Class +import Control.Monad.State.Lazy + +import Data.Monoid +import Data.Foldable +import Control.Lens + +import Debug.Trace + +type Spec = [Expr] -- most significant last + +data Expr = Override Object + | Occurs BoolExpr + | Nop + deriving (Show) + +data BoolExpr = BoolLit Bool + deriving (Show) + +interpret :: MonadIO m => Spec -> Eval m () +interpret = mapM_ interpretExpr + +interpretExpr :: MonadIO m => Expr -> Eval m () +interpretExpr (Override obj) = ctxEvent ?= obj +interpretExpr (Occurs expr) = ctxOccurs <~ interpretBoolExpr expr +interpretExpr _ = return () + +interpretBoolExpr :: Monad m => BoolExpr -> Eval m Bool +interpretBoolExpr (BoolLit v) = return v diff --git a/events/src/Main.hs b/events/src/Main.hs index 1c56140..7f65b19 100644 --- a/events/src/Main.hs +++ b/events/src/Main.hs @@ -1,4 +1,26 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE OverloadedLists #-} + import Events.Types +import Events.Spec + +import qualified Data.Yaml as Yaml +import qualified Data.ByteString.Char8 as CBS + +import Control.Lens +import Control.Monad +import Control.Monad.Trans +import Data.Aeson.Lens +import Data.Aeson + +import Debug.Trace + +import qualified ListT main :: IO () -main = undefined +main = test $ [ -- Nop + -- , Override [("blub", String "Haha!")] + --, Occurs (BoolLit True) + ] + where + test = CBS.putStr . Yaml.encode <=< evaluate . interpret -- cgit v1.2.3