diff options
author | Camil Staps | 2018-02-08 08:59:58 +0100 |
---|---|---|
committer | Camil Staps | 2018-02-08 08:59:58 +0100 |
commit | fcf33950c2632a9b65444586cd3ac415627fab12 (patch) | |
tree | c057daff8ed6e6a95cb9f271812141b607b70e7d | |
parent | Add example programs; Main.hs using stdin (diff) |
Return codes in Main.hs
-rw-r--r-- | src/Main.hs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/Main.hs b/src/Main.hs index 07733dd..72c577a 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -3,6 +3,7 @@ module Main where import Prelude hiding(lex) import System.Environment +import System.Exit import Text.Parsec.Error (ParseError) @@ -16,7 +17,9 @@ main = do args <- getArgs contents <- getContents case lex contents of - Nothing -> putStrLn "Failed to lex" + Nothing -> do + putStrLn "Failed to lex" + exit 1 Just tks -> if "--parse" `elem` args then doParse tks else return () @@ -26,4 +29,8 @@ main = do Left e -> do putStrLn $ "Failed to parse (" ++ show e ++ "). Tokens were:" putStrLn $ show tks + exit 1 Right pgm -> putStrLn $ prettyPrint pgm + + exit :: Int -> IO () + exit = exitWith . ExitFailure |