Created
September 19, 2014 01:15
-
-
Save joshcough/258f9a9048142e67ee2f to your computer and use it in GitHub Desktop.
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
myToken :: Parser a -> Parser a | |
myToken p = p <* (lookAhead $ eof <|> someSpace <|> (symbolic ')' >> return ())) | |
sexprParser :: Parser SExpr | |
sexprParser = choice [intParser, symParser, listParser] | |
symParser :: Parser SExpr | |
symParser = AtomSym <$> myToken (ident variable) | |
variable :: TokenParsing m => IdentifierStyle m | |
variable = IdentifierStyle | |
{ _styleName = "identifier" | |
, _styleStart = varInit | |
, _styleLetter = varSubsequent | |
, _styleReserved = HashSet.empty | |
, _styleHighlight = Highlight.Identifier | |
, _styleReservedHighlight = Highlight.ReservedIdentifier | |
} where | |
varInit = letter <|> oneOf "!$%&*/:<=>?~_^" | |
varSubsequent = varInit <|> digit <|> oneOf ".+=" | |
intParser :: Parser SExpr | |
intParser = AtomNum . fromInteger <$> myToken integer | |
listParser :: Parser SExpr | |
listParser = List <$> (parens $ some sexprParser) | |
runParser :: Parser a -> String -> ParseResult a | |
runParser p s = case parseByteString p mempty (UTF8.fromString s) of | |
Failure xs -> error (show xs) -- Left $ show xs | |
Success a -> Right a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment