Created
March 23, 2012 09:45
-
-
Save osa1/2169083 to your computer and use it in GitHub Desktop.
sexp parser
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 Parser where | |
import Text.ParserCombinators.Parsec hiding (token) | |
data Sexp = List [Sexp] | Atom String deriving (Show) | |
sexps :: Parser [Sexp] | |
sexps = sexp `sepBy` listSeparator | |
sexp :: Parser Sexp | |
sexp = atom <|> list | |
atom :: Parser Sexp | |
atom = do | |
s <- many1 (letter <|> digit) | |
return $ Atom s | |
list :: Parser Sexp | |
list = do | |
char '(' | |
sexps <- (list <|> atom) `sepBy` listSeparator | |
char ')' | |
return $ List sexps | |
listSeparator :: Parser () | |
listSeparator = skipMany space |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment