diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-12-09 10:48:58 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-12-09 10:48:58 +0100 |
commit | 897fb17dd6a045a7056e6d6babbbb24748f698f6 (patch) | |
tree | 65f0659483ba2239d07e30b3547379625f5b5cae /ast.hs |
Initial
Diffstat (limited to 'ast.hs')
-rw-r--r-- | ast.hs | 46 |
1 files changed, 46 insertions, 0 deletions
@@ -0,0 +1,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 |