aboutsummaryrefslogtreecommitdiff
path: root/src/main.hs
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-03-10 12:35:27 +0100
committerCharles <sircharlesaze@gmail.com>2020-03-10 12:35:27 +0100
commite5ba91f99722d047f90f94a710d77344db36e110 (patch)
tree4c9b2c0e474eb1279d23a88623f0ee8b53391f50 /src/main.hs
parent101739991c2ca919e3bb150b6df0041b27cf75a1 (diff)
downloadcomputorv1-e5ba91f99722d047f90f94a710d77344db36e110.tar.gz
computorv1-e5ba91f99722d047f90f94a710d77344db36e110.tar.bz2
computorv1-e5ba91f99722d047f90f94a710d77344db36e110.zip
Edge case handling in parsing and equation solving
Diffstat (limited to 'src/main.hs')
-rw-r--r--src/main.hs21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/main.hs b/src/main.hs
index 20815f4..a11f7fc 100644
--- a/src/main.hs
+++ b/src/main.hs
@@ -1,20 +1,31 @@
import System.Environment
+import System.IO
+import System.IO.Error
+import Control.Exception
import Data.List
import Parser
import Equation
-
main :: IO ()
-main = do
+main = catchIOError tryMain handler
+ where handler e
+ | isUserError e = putStrLn $ trimUserError (show e)
+ | otherwise = putStrLn "Error"
+ where trimUserError s = init $ tail $ dropWhile (/='(') s
+
+tryMain :: IO ()
+tryMain = do
args <- getArgs
checkArgs args
equ <- checkParsing (head args)
let reduced = reduce equ
+ l = filterNull $ left reduced
putStrLn $ "Reduced From: " ++ show reduced
- putStrLn $ "Polynomial degree: " ++ (show $ degree $ left reduced)
- putSolutions (left reduced)
-
+ putStrLn $ "Polynomial degree: " ++ (show $ degree l)
+ case l of [] -> putStrLn "Infinite solutions"
+ [_] -> putStrLn "No solution"
+ _ -> putSolutions l
checkArgs :: [String] -> IO ()
checkArgs args