Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
New parser for Hatt with support for associativity and operator precedence
module Data.Logic.Propositional.Parser2 where
import Data.Logic.Propositional
import Text.Parsec.Prim ((<|>), (<?>), runPT)
import Text.Parsec.Char (char, letter, spaces, string)
import Text.Parsec.Expr
parseExpr' = runPT expr ()
expr = buildExpressionParser operators term
<?> "compound expression"
term = parens expr
<|> variable
<?> "expression"
variable = do c <- letter
return $ Variable (Var c)
<?> "variable"
parens p = do char '('
spaces
x <- p
spaces
char ')'
return x
<?> "parens"
operators = [ [Prefix (string "~" >> return Negation)]
, [binary "&" Conjunction]
, [binary "|" Disjunction]
, [binary "->" Conditional]
, [binary "<->" Biconditional]
]
binary n c = Infix (spaces >> string n >> spaces >> return c) AssocRight
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.