summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2016-04-16 22:16:41 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2016-04-16 22:16:41 +0200
commit03f321adafd3ef7a169555703ebc8e03903a1450 (patch)
treed37a3e5bdb608806915e9bd88113cea71d7d8e1a
parentbfbe2f67cc3fef07db4d0ef9423a2dbc2d002533 (diff)
downloadevents-03f321adafd3ef7a169555703ebc8e03903a1450.tar
events-03f321adafd3ef7a169555703ebc8e03903a1450.tar.gz
events-03f321adafd3ef7a169555703ebc8e03903a1450.tar.bz2
events-03f321adafd3ef7a169555703ebc8e03903a1450.tar.xz
events-03f321adafd3ef7a169555703ebc8e03903a1450.zip
Specifications to be evaluated
-rw-r--r--events/src/Events/Spec.hs36
-rw-r--r--events/src/Main.hs24
2 files changed, 59 insertions, 1 deletions
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 @@
1module Events.Spec
2 ( interpret
3 , Spec, Expr(..), BoolExpr(..)
4 ) where
5
6import Events.Types
7
8import Control.Monad.IO.Class
9import Control.Monad.State.Lazy
10
11import Data.Monoid
12import Data.Foldable
13import Control.Lens
14
15import Debug.Trace
16
17type Spec = [Expr] -- most significant last
18
19data Expr = Override Object
20 | Occurs BoolExpr
21 | Nop
22 deriving (Show)
23
24data BoolExpr = BoolLit Bool
25 deriving (Show)
26
27interpret :: MonadIO m => Spec -> Eval m ()
28interpret = mapM_ interpretExpr
29
30interpretExpr :: MonadIO m => Expr -> Eval m ()
31interpretExpr (Override obj) = ctxEvent ?= obj
32interpretExpr (Occurs expr) = ctxOccurs <~ interpretBoolExpr expr
33interpretExpr _ = return ()
34
35interpretBoolExpr :: Monad m => BoolExpr -> Eval m Bool
36interpretBoolExpr (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 @@
1{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedLists #-}
3
1import Events.Types 4import Events.Types
5import Events.Spec
6
7import qualified Data.Yaml as Yaml
8import qualified Data.ByteString.Char8 as CBS
9
10import Control.Lens
11import Control.Monad
12import Control.Monad.Trans
13import Data.Aeson.Lens
14import Data.Aeson
15
16import Debug.Trace
17
18import qualified ListT
2 19
3main :: IO () 20main :: IO ()
4main = undefined 21main = test $ [ -- Nop
22 -- , Override [("blub", String "Haha!")]
23 --, Occurs (BoolLit True)
24 ]
25 where
26 test = CBS.putStr . Yaml.encode <=< evaluate . interpret