-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpressions.hs
More file actions
53 lines (49 loc) · 1.79 KB
/
Expressions.hs
File metadata and controls
53 lines (49 loc) · 1.79 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
module Expressions where
-- A command which performs something - can be a command that takes arguments
-- or an assignment.
data Cmd = Cmd { name :: Expr -- The command name (can be a variable)
, args :: [Expr] -- The command arguments
, inDir :: Maybe Expr -- A redirected input fp
, outDir :: Maybe Expr -- A redirected output fp
, append :: Bool -- If redirected, is it appending?
}
| Assign { var :: Expr -- Assignment target
, val :: Expr -- A value to assign to a variable
}
deriving Show
-- A bottom-level expression
data Expr = Var String -- A named variable
| Str String -- A mere string, the peasant of expressions
deriving (Eq, Show)
-- A comparison operation
data Comp = CEQ Expr Expr -- ==
| CNE Expr Expr -- /=
| CGE Expr Expr -- >=
| CGT Expr Expr -- >
| CLE Expr Expr -- <=
| CLT Expr Expr -- <
| CLI Expr -- A wrapped expression literal - True if nonempty
deriving (Eq, Show)
-- Something that evaluates to a truth value
data Pred = Pred Comp -- A wrapped comparison
| Not Pred -- Negation
| And Pred Pred -- A binary logical and
| Or Pred Pred -- A binary logical or
| Parens Pred -- An expression in parentheses
deriving (Eq, Show)
-- A conditional branching expression - if-then or if-then-else
-- If-then with a condition and a list of actions
data Conditional = If {cond :: Pred -- Predicate to satisfy
, cthen :: [Cmd] -- Actions if satisfied
}
-- An if-then-else with a condition and two possible paths
| IfElse { cond :: Pred -- Predicate to satisfy
, cthen :: [Cmd] -- Actions if satisfied
, celse :: [Cmd] -- Actions otherwise
}
deriving Show
-- A top-level expression, wrapping either a conditional expression or a
-- command
data TLExpr = TLCmd Cmd
| TLCnd Conditional
deriving Show