X-Git-Url: https://git.rmz.io/my-scheme.git/blobdiff_plain/b388d53e751db6d925a39c06dc871c125799b8e5..7495ece1a44cd1a8cccae2bdbc61fa6873f106d2:/app/Main.hs diff --git a/app/Main.hs b/app/Main.hs index c64fd18..6daf522 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,4 +1,5 @@ module Main where +import Control.Monad import Text.ParserCombinators.Parsec hiding (spaces) import System.Environment @@ -15,6 +16,26 @@ 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) + 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