Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

New parser for Hatt with support for associativity and operator precedence

View hatt-parser2.hs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
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.