From f5ddd91d290a0c508e04cce2cb19c4c8bae32835 Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 5 Jun 2020 14:48:14 +0200 Subject: Removed Imaginary type, Added variable name check (/= i), Added Matrix check if rectangular --- src/parser/Core.hs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/parser/Core.hs') diff --git a/src/parser/Core.hs b/src/parser/Core.hs index 5928fe4..64e0b84 100644 --- a/src/parser/Core.hs +++ b/src/parser/Core.hs @@ -100,13 +100,16 @@ choice :: [Parser a] -> Parser a choice [] = empty choice (p:ps) = p <|> choice ps --- verify :: (a -> Bool) -> Parser a -> Parser a --- verify predicate p = do a <- p --- if predicate a then p else Parser (\_ -> Left "Bonjour") +verify :: (a -> Bool) -> a -> Parser a +verify predicate x = if predicate x then pure x else empty --- Parse a string of alpha character, converted to lower case -labelP :: Parser String -labelP = (map toLower) <$> some (satisfyChar isAlpha) +-- Parse a string of alpha character +-- Convert to lower case and check that the label isn't `i` +varLabelP :: Parser String +varLabelP = (map toLower <$> some (satisfyChar isAlpha)) >>= verify (/= "i") + +funLabelP :: Parser String +funLabelP = map toLower <$> some (satisfyChar isAlpha) floatP :: Parser Float -- cgit