Skip to content

Instantly share code, notes, and snippets.

@osa1
Created March 23, 2012 09:45
Show Gist options
  • Save osa1/2169083 to your computer and use it in GitHub Desktop.
Save osa1/2169083 to your computer and use it in GitHub Desktop.
sexp parser
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