summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-12-17 18:45:45 +1100
committerJed Barber <jjbarber@y7mail.com>2014-12-17 18:45:45 +1100
commit1f0a57c5890ec539d5f17255fe413004c94abe44 (patch)
tree060deea741c0d180e67541f9ddcf87c6ee08dfde /src
parenta3844616b62aae43e7aa12da6df852628acab504 (diff)
Grasp command line program now has a testing/debug mode
Diffstat (limited to 'src')
-rw-r--r--src/grasp.hs44
1 files changed, 37 insertions, 7 deletions
diff --git a/src/grasp.hs b/src/grasp.hs
index 4b12abd..fb8f866 100644
--- a/src/grasp.hs
+++ b/src/grasp.hs
@@ -1,27 +1,57 @@
-import System.Environment( getArgs )
+
+import qualified System.Environment as Env
+
+import System.Console.GetOpt( OptDescr )
+import qualified System.Console.GetOpt as GetOpt
+
import Control.Exception( ErrorCall(..), Handler(..), catches )
+
+import qualified Control.Monad as Monad
+
import Grasp.Parser
import Grasp.Interpreter
+data Flag = Testing
+ deriving (Eq, Show)
+
+
+
+
usageString :: String
-usageString = "Usage: grasp <program file>"
+usageString = "Usage: grasp [--testing] <program file>"
+
+
+
+options :: [OptDescr Flag]
+options =
+ [ GetOpt.Option ['t'] ["testing"] (GetOpt.NoArg Testing) "Enables before and after showing of program graph" ]
program :: IO ()
program = do
- args <- getArgs
- fileContents <- if (length args /= 1)
- then error usageString
- else readFile (head args)
+ (options, arguments, errors) <- Env.getArgs >>= return . GetOpt.getOpt GetOpt.Permute options
+ Monad.when (length options > 1) (error usageString)
+ Monad.when (length arguments /= 1) (error usageString)
+ Monad.when (length errors /= 0) (error usageString)
+
+ fileContents <- readFile (head arguments)
+
case (parseGrasp fileContents) of
Left x -> putStrLn (show x)
- Right x -> grasp x >> return ()
+ Right x -> if (Testing `elem` options)
+ then do
+ putStrLn "Input:"
+ putStrLn (show x)
+ y <- grasp x
+ putStrLn "\nOutput:"
+ putStrLn (show y)
+ else grasp x >> return ()