summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcyfraeviolae <cyfraeviolae>2021-05-30 16:47:16 -0400
committercyfraeviolae <cyfraeviolae>2021-05-30 16:47:16 -0400
commit22129a2fcb660a29e1ed6935713282bc78c8d62f (patch)
tree6455bd707e2bfd77e562916a40f262871b0c2e8e /src
parentf33ee02f7a0b9836f6ea6321f4f8c015dfe1e850 (diff)
associativity for -> and <->
Diffstat (limited to 'src')
-rw-r--r--src/Parser.hs17
1 files changed, 5 insertions, 12 deletions
diff --git a/src/Parser.hs b/src/Parser.hs
index e328b6e..0891481 100644
--- a/src/Parser.hs
+++ b/src/Parser.hs
@@ -79,16 +79,9 @@ pMultiMatOp s op = do
Parsec.sepBy1
pFormulaInner
(Parsec.space *> Parsec.string s *> Parsec.space)
- return $ foldl1 op (term : terms)
-
-pBinMatOp :: String -> (Formula -> Formula -> Formula) -> Parser Formula
-pBinMatOp s op = do
- x <- pFormulaInner
- _ <- Parsec.space
- _ <- Parsec.string s
- _ <- Parsec.space
- y <- pFormulaInner
- return $ op x y
+ -- Imp is right-associative, whereas And/Or/Iff can be either, so
+ -- use right-associative for everything.
+ return $ foldr1 op (term : terms)
pNot :: Parser Formula
pNot = Not <$> (Parsec.char '~' *> pFormulaInner)
@@ -115,8 +108,8 @@ pFormulaInner =
(Parsec.char ')')
( Parsec.try (pMultiMatOp "&" And)
<|> Parsec.try (pMultiMatOp "|" Or)
- <|> Parsec.try (pBinMatOp "<->" Iff)
- <|> Parsec.try (pBinMatOp "->" Imp)
+ <|> Parsec.try (pMultiMatOp "<->" Iff)
+ <|> Parsec.try (pMultiMatOp "->" Imp)
)
<|> Parsec.try pQuantifier