blob: eae5af80add2ff031c15d140c26f83d2dad9d4ce (
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
36
37
38
39
40
41
42
43
44
45
46
|
module AST where
import Data.List
data Program = Program [Value]
type Name = String
data Value
= VList [Value]
| VNum Int
| VString String
| VName Name
| VQuoted Value
| VLambda [Name] Value
| VBuiltin String
| VEllipsis
deriving (Eq)
instance Show Program where
show (Program l) = intercalate "\n" $ map show l
instance Show Value where
show (VList es) = '(' : intercalate " " (map show es) ++ ")"
show (VNum i) = show i
show (VString s) = show s
show (VName n) = n
show (VQuoted e) = '\'' : show e
show (VLambda as v) = "(lambda (" ++ intercalate " " as ++ ") " ++ show v ++ ")"
show (VBuiltin str) = "[[builtin " ++ str ++ "]]"
show VEllipsis = "..."
fromVName :: Value -> Maybe Name
fromVName (VName s) = Just s
fromVName _ = Nothing
fromVNum :: Value -> Maybe Int
fromVNum (VNum i) = Just i
fromVNum _ = Nothing
fromVString :: Value -> Maybe String
fromVString (VString s) = Just s
fromVString _ = Nothing
|