aboutsummaryrefslogtreecommitdiffstats
path: root/src/Lib.hs
diff options
context:
space:
mode:
authorJan Tuomi <jan.tuomi@valuemotive.com>2022-09-23 15:14:37 +0300
committerJan Tuomi <jans.tuomi@gmail.com>2022-12-05 14:21:53 +0200
commitc02d29e8e119d12748c90b3965f6b98633efbec2 (patch)
tree8b72350fa9ad7454c70f1fe3626f27a478b04eee /src/Lib.hs
parent51c3993f0a84b3de57bae480ce7bb14a1408f25e (diff)
Add integer type
Diffstat (limited to 'src/Lib.hs')
-rw-r--r--src/Lib.hs12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/Lib.hs b/src/Lib.hs
index 13e4234..8c2fc06 100644
--- a/src/Lib.hs
+++ b/src/Lib.hs
@@ -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"]