Last active
January 4, 2016 19:29
-
-
Save Heimdell/8667288 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
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