Created
July 2, 2010 15:46
-
-
Save danlei/461535 to your computer and use it in GitHub Desktop.
ConstituentParser
This file contains 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 ConstituentParser | |
where | |
import Text.ParserCombinators.Parsec | |
import Control.Monad | |
import Control.Applicative ((<$>)) | |
symbol = oneOf "!#$%&|*+-/:<=>?@^_~" | |
parseSymbol = Symbol <$> many1 (letter <|> digit <|> symbol) | |
parseList = List <$> sepBy parseConstituent spaces | |
parseConstituent = try (skipMany space >> parseSymbol) | |
<|> try (do skipMany space | |
char '(' | |
x <- parseList | |
char ')' | |
return x) | |
data Constituent = Symbol String | |
| List [Constituent] | |
instance Show Constituent where | |
show (Symbol x) = x | |
show (List x) = "(" ++ unwords (map show x) ++ ")" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment