]> git.rmz.io Git - my-scheme.git/blobdiff - app/Main.hs
Parse Numbers
[my-scheme.git] / app / Main.hs
index 22de7480421b03aaa552b541b8266a4a9bd41135..6daf522b2c86598881760fa72c242009d8516092 100644 (file)
@@ -1,4 +1,5 @@
 module Main where
 module Main where
+import Control.Monad
 import Text.ParserCombinators.Parsec hiding (spaces)
 import System.Environment
 
 import Text.ParserCombinators.Parsec hiding (spaces)
 import System.Environment
 
@@ -22,6 +23,19 @@ parseString = do
     char '"'
     return $ String x
 
     char '"'
     return $ String x
 
+parseAtom :: Parser LispVal
+parseAtom = do
+    a <- letter <|> symbol
+    b <- many (letter <|> digit <|> symbol)
+    let atom = a:b
+    return $ case atom of
+                "#t" -> Bool True
+                "#f" -> Bool False
+                _    -> Atom atom
+
+parseNumber :: Parser LispVal
+parseNumber = liftM (Number . read) $ many1 digit
+
 readExpr :: String -> String
 readExpr input = case parse (spaces >> symbol) "lisp" input of
     Left err -> "No match: " ++ show err
 readExpr :: String -> String
 readExpr input = case parse (spaces >> symbol) "lisp" input of
     Left err -> "No match: " ++ show err