diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-06-05 14:48:14 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-06-05 14:48:14 +0200 |
| commit | f5ddd91d290a0c508e04cce2cb19c4c8bae32835 (patch) | |
| tree | 3d3082c3d6fa977b12290f4cd2ed6c7ada4e9606 /src/parser/Expr.hs | |
| parent | 45cada8eade7242eb7f29af7b92858e9a1a7f68b (diff) | |
| download | computorv2-f5ddd91d290a0c508e04cce2cb19c4c8bae32835.tar.gz computorv2-f5ddd91d290a0c508e04cce2cb19c4c8bae32835.tar.bz2 computorv2-f5ddd91d290a0c508e04cce2cb19c4c8bae32835.zip | |
Removed Imaginary type, Added variable name check (/= i), Added Matrix check if rectangular
Diffstat (limited to 'src/parser/Expr.hs')
| -rw-r--r-- | src/parser/Expr.hs | 13 |
1 files changed, 8 insertions, 5 deletions
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 |
