Created
September 18, 2014 18:12
-
-
Save joshcough/d2e4ba1a2c93cdaedc81 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
sexprParser :: Parser SExpr | |
sexprParser = choice [intParser, symParser, listParser] | |
symParser :: Parser SExpr | |
symParser = AtomSym <$> ident variable | |
variable :: TokenParsing m => IdentifierStyle m | |
variable = IdentifierStyle | |
{ _styleName = "identifier" | |
, _styleStart = varInit | |
, _styleLetter = varSubsequent | |
, _styleReserved = HashSet.empty | |
, _styleHighlight = Highlight.Identifier | |
, _styleReservedHighlight = Highlight.ReservedConstructor | |
} where | |
varInit = letter <|> oneOf "!$%&*/:<=>?~_^" | |
varSubsequent = varInit <|> digit <|> oneOf ".+=" | |
intParser :: Parser SExpr | |
intParser = AtomNum . fromInteger <$> 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 -> 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