Skip to content

Instantly share code, notes, and snippets.

@Heimdell
Last active January 4, 2016 19:29
Show Gist options
  • Save Heimdell/8667288 to your computer and use it in GitHub Desktop.
Save Heimdell/8667288 to your computer and use it in GitHub Desktop.
module SchemeParser where
import Control.Applicative
import Text.ParserCombinators.Parsec hiding ((<|>))
data Ast = Term String | List [Ast]
deriving Show
program :: Parser Ast
program = do
spaces
List <$> node `sepEndBy` spaces
node :: Parser Ast
node = term <|> list
term :: Parser Ast
term = Term <$> many1 nameSymbols
nameSymbols :: Parser Char
nameSymbols = noneOf "\t\r\n ()"
list :: Parser Ast
list = do
char '('
result <- program
char ')'
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment