Created
November 13, 2013 21:00
-
-
Save 5outh/7456315 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
parseExpr :: String -> Either ParseError Expr | |
parseExpr = parse expr "" | |
where expr = buildExpressionParser operators term <?> "compound expression" | |
term = parens expr <|> variable <?> "full expression" | |
operators = [ [Prefix (string "NOT" *> spaces *> pure Not)] | |
, [binary "AND" And] | |
, [binary "OR" Or] ] | |
where binary n c = Infix (string n *> spaces *> pure c) AssocLeft | |
variable = Var <$> (letter <* spaces) <?> "variable" | |
parens p = SubExpr <$> (char '(' *> spaces *> p <* char ')' <* spaces) <?> "parens" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment