From 6314bf6584f98c735f606155a76c809fd6de5d0b Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Sun, 25 Sep 2022 17:52:12 +0300 Subject: Add throwL --- src/Types.hs | 94 ------------------------------------------------------------ 1 file changed, 94 deletions(-) delete mode 100644 src/Types.hs (limited to 'src/Types.hs') diff --git a/src/Types.hs b/src/Types.hs deleted file mode 100644 index 21a1ceb..0000000 --- a/src/Types.hs +++ /dev/null @@ -1,94 +0,0 @@ -{-# OPTIONS_GHC -Wno-missing-export-lists #-} -module Types where - -import Control.Monad.Except -import Control.Monad.Reader -import qualified Data.Map as M -import qualified Data.List as L -import qualified Data.Char as C -import Utils - -newtype LException = LException String -data Config = Config { - configScriptFileName :: Maybe String, - configVerboseMode :: Bool, - configShowHelp :: Bool -} - -type LContext a = ReaderT Config (ExceptT LException IO) a - -type Env = M.Map String AST - -type LFunction = (Env -> AST -> LContext AST) - -data AST - = ASTInteger Int - | ASTDouble Double - | ASTSymbol String - | ASTBoolean Bool - | ASTString String - | ASTVector [AST] - | ASTFunctionCall [AST] - | ASTHashMap (M.Map AST AST) - | ASTFunction LFunction - | ASTUnit - -instance (Show AST) where - show (ASTInteger n) = show n - show (ASTDouble n) = show n - show (ASTSymbol s) = s - show (ASTBoolean b) = show b $> map C.toLower - show (ASTString s) = show s - show (ASTVector v) = "[" ++ L.intercalate " " (map show v) ++ "]" - show (ASTFunctionCall v) = "(" ++ L.intercalate " " (map show v) ++ ")" - show (ASTHashMap m) = - let flattenMap = M.assocs .> L.concatMap (\(k, v) -> [k, v]) - in "{" ++ L.intercalate " " (map show $ flattenMap m) ++ "}" - show (ASTFunction _) = "" - show ASTUnit = "" - -instance (Eq AST) where - ASTInteger a == ASTInteger b = a == b - ASTDouble a == ASTDouble b = a == b - ASTSymbol a == ASTSymbol b = a == b - ASTBoolean a == ASTBoolean b = a == b - ASTString a == ASTString b = a == b - ASTVector a == ASTVector b = a == b - ASTHashMap a == ASTHashMap b = a == b - ASTUnit == ASTUnit = True - _ == _ = False - -instance (Ord AST) where - ASTInteger a <= ASTInteger b = a <= b - ASTDouble a <= ASTDouble b = a <= b - ASTSymbol a <= ASTSymbol b = a <= b - ASTBoolean a <= ASTBoolean b = a <= b - ASTString a <= ASTString b = a <= b - ASTVector a <= ASTVector b = a <= b - ASTHashMap a <= ASTHashMap b = a <= b - _ <= _ = False - -assertIsASTFunction :: AST -> LContext AST -assertIsASTFunction ast = case ast of - (ASTFunction _) -> return ast - _ -> throwError $ LException $ show ast ++ " is not a function" - -assertIsASTInteger :: AST -> LContext AST -assertIsASTInteger ast = case ast of - (ASTInteger _) -> return ast - _ -> throwError $ LException $ show ast ++ " is not an integer" - -assertIsASTSymbol :: AST -> LContext AST -assertIsASTSymbol ast = case ast of - (ASTSymbol _) -> return ast - _ -> throwError $ LException $ show ast ++ " is not a symbol" - -assertIsASTVector :: AST -> LContext AST -assertIsASTVector ast = case ast of - (ASTVector _) -> return ast - _ -> throwError $ LException $ show ast ++ " is not a vector" - -assertIsASTFunctionCall :: AST -> LContext AST -assertIsASTFunctionCall ast = case ast of - (ASTFunctionCall _) -> return ast - _ -> throwError $ LException $ show ast ++ " is not a function call or body" -- cgit v1.3