Created
December 29, 2011 15:08
-
-
Save hughfdjackson/1534483 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help | |
| shell returned 1 | |
| :!ghc -o hello --make main.hs | |
| [1 of 1] Compiling Main ( main.hs, main.o ) | |
| main.hs:31:4: parse error on input `x' | |
| shell returned 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Main where | |
| import System.Environment | |
| import Text.ParserCombinators.Parsec hiding (spaces) | |
| main :: IO() | |
| main = do | |
| args <- getArgs | |
| putStrLn (readExpr (args !! 0)) | |
| symbol :: Parser Char | |
| symbol = oneOf "!#$%&|*+-/:<=>?@^_~" | |
| data LispVal = Atom String | |
| | List [LispVal] | |
| | DottedList [LispVal] LispVal | |
| | Number Integer | |
| | String String | |
| | Bool Bool | |
| readExpr :: String -> String | |
| readExpr input = case parse (space >> symbol) "lisp" input of | |
| Left err -> "no match: " ++ show err | |
| Right val -> "Found Val" | |
| spaces :: Parser () | |
| spaces = skipMany1 space | |
| parseString :: Parser LispVal | |
| parseString = do char '"' | |
| x <- many (noneOf "\"") | |
| char '"' | |
| return x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment