X-Git-Url: https://git.rmz.io/my-scheme.git/blobdiff_plain/429ac1845f1b93f54bca8511a4efbf8cbcbb9bf3..081ba0cc6439a82a508100a59d6fa5dba80609d9:/app/Main.hs?ds=inline diff --git a/app/Main.hs b/app/Main.hs index 8520891..6fcf667 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -2,12 +2,36 @@ module Main where 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) + let atom = a:b + return $ case atom of + "#t" -> Bool True + "#f" -> Bool False + _ -> Atom atom + readExpr :: String -> String readExpr input = case parse (spaces >> symbol) "lisp" input of Left err -> "No match: " ++ show err