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/Expr.hs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/parser/Expr.hs') diff --git a/src/parser/Expr.hs b/src/parser/Expr.hs index 5334578..b462197 100644 --- a/src/parser/Expr.hs +++ b/src/parser/Expr.hs @@ -27,20 +27,23 @@ termP = operatorChoiceChain factorP factorP :: Parser Expr factorP = choice [ parenthesizedExprP - , imaginaryP , Rational <$> floatP , matrixP - , Function <$> labelP <*> parenthesizedExprP - , Variable <$> labelP + , Function <$> funLabelP <*> parenthesizedExprP + , imaginaryP + , Variable <$> varLabelP ] `chainl1` (infixOp "^" Exp) where parenthesizedExprP = parenthesis exprP - imaginaryP = Imaginary <$> (floatP <|> pure 1.0) <* char 'i' + imaginaryP = (Complex 0) <$> (floatP <|> pure 1.0) <* char 'i' -- Parse a matrix in the following format: -- [ [a, b]; [c, d] ] matrixP :: Parser Expr - matrixP = Matrix <$> brackets (matrixRowP `sepBy` (char ';')) + matrixP = Matrix <$> (brackets (matrixRowP `sepBy` (char ';')) >>= verify check) where matrixRowP = brackets (exprP `sepBy` (char ',')) brackets = between "[" "]" + check rows + | length rows == 0 = False + | otherwise = all ((length (head rows) ==) . length) $ tail rows -- cgit