]> git.rmz.io Git - my-scheme.git/blobdiff - app/Main.hs
Parse Atoms which start with a letter or symbol
[my-scheme.git] / app / Main.hs
index a94dc2ce2355835c62533047f14994df94f28319..7c987cee50d96d97e445cc1b18756f845a47a24f 100644 (file)
@@ -1,12 +1,35 @@
 module Main where
-import Text.ParserCombinators.Parsec
+import Text.ParserCombinators.Parsec hiding (spaces)
 import System.Environment
 
+data LispVal = Atom String
+             | List [LispVal]
+             | DottedList [LispVal] LispVal
+             | Number Integer
+             | String String
+             | Bool Bool
+
 symbol :: Parser Char
 symbol = oneOf "!#$%&|*+-/:<=>?@^_~"
 
+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)
+    return $ Atom (a:b)
+
 readExpr :: String -> String
-readExpr input = case parse symbol "lisp" input of
+readExpr input = case parse (spaces >> symbol) "lisp" input of
     Left err -> "No match: " ++ show err
     Right val -> "Found value"