diff options
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 |
