From 22129a2fcb660a29e1ed6935713282bc78c8d62f Mon Sep 17 00:00:00 2001 From: cyfraeviolae Date: Sun, 30 May 2021 16:47:16 -0400 Subject: associativity for -> and <-> --- src/Parser.hs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'src') 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 -- cgit v1.2.3