]> git.rmz.io Git - my-scheme.git/blobdiff - app/Main.hs
Parse Numbers
[my-scheme.git] / app / Main.hs
index c64fd18d83b0cdf0575889388df8cfa6344619c8..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
 
@@ -15,6 +16,26 @@ symbol = oneOf "!#$%&|*+-/:<=>?@^_~"
 spaces :: Parser ()
 spaces = skipMany space
 
 spaces :: Parser ()
 spaces = skipMany space
 
+parseString :: Parser LispVal
+parseString = do
+    char '"'
+    x <- many (noneOf "\"")
+    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