From: Samir Benmendil Date: Sun, 14 Jan 2018 00:19:18 +0000 (+0000) Subject: Parse Atoms which start with a letter or symbol X-Git-Url: https://git.rmz.io/my-scheme.git/commitdiff_plain/d06e8ae01efc00ea0eb6f0bed346032b004aca57?ds=sidebyside Parse Atoms which start with a letter or symbol `<|>` is a Parser combinator, the choice operator. It will try the first parser, if it doesn't match anything, try the second parser, and so on. `a:b` creates a list from `a` and `b`. Another possibility would be to use `[a] ++ b`, where a new list with a single element is created `[a]` and concatenated with `++` --- diff --git a/app/Main.hs b/app/Main.hs index 22de748..7c987ce 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -22,6 +22,12 @@ parseString = do 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 (spaces >> symbol) "lisp" input of Left err -> "No match: " ++ show err