diff options
| -rw-r--r-- | src/Lib.hs | 12 | ||||
| -rw-r--r-- | src/Types.hs | 12 |
2 files changed, 16 insertions, 8 deletions
@@ -69,14 +69,18 @@ asPairs _ = throwError $ LException "Odd number of elements to pair up" parseToken :: String -> AST parseToken token - | isNumber token = ASTNumber (read token) + | isInteger token = ASTInteger (read token) + | isDouble token = ASTDouble (read token) | isString token = ASTString $ removeQuotes token | isBoolean token = ASTBoolean $ asBoolean token | otherwise = ASTSymbol token where - numberRegex = "^-?[[:digit:]]+(\\.[[:digit:]]+)?$" - isNumber :: String -> Bool - isNumber t = t =~ numberRegex + integerRegex = "^-?[[:digit:]]+$" + isInteger :: String -> Bool + isInteger t = t =~ integerRegex + doubleRegex = "^-?[[:digit:]]+(\\.[[:digit:]]+)?$" + isDouble :: String -> Bool + isDouble t = t =~ doubleRegex isString t = "\"" `L.isPrefixOf` t removeQuotes s = drop 1 s $> take (length s - 2) isBoolean t = t `elem` ["true", "false"] diff --git a/src/Types.hs b/src/Types.hs index 5779845..be9002a 100644 --- a/src/Types.hs +++ b/src/Types.hs @@ -17,7 +17,8 @@ data Config = Config { type LContext a = ReaderT Config (ExceptT LException IO) a data AST - = ASTNumber Double + = ASTInteger Int + | ASTDouble Double | ASTSymbol String | ASTBoolean Bool | ASTString String @@ -27,7 +28,8 @@ data AST | ASTFunction (AST -> AST) instance (Show AST) where - show (ASTNumber n) = show n + show (ASTInteger n) = show n + show (ASTDouble n) = show n show (ASTSymbol s) = s show (ASTBoolean b) = show b show (ASTString s) = show s @@ -39,7 +41,8 @@ instance (Show AST) where show (ASTFunction _) = "<fn>" instance (Eq AST) where - ASTNumber a == ASTNumber b = a == b + 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 @@ -48,7 +51,8 @@ instance (Eq AST) where _ == _ = False instance (Ord AST) where - ASTNumber a <= ASTNumber b = a <= b + 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 |
