-# (out, w) = stdio w
-# (toparse, out) = readEntireFile out
-# (_, w) = fclose out w
-= (lexer toparse, parse (lexer toparse), w)
+# (args, w) = parseArgs w
+| args.help = help args.program w
+# (stdin, w) = stdio w
+# (contents, stdin, w) = readFileOrStdin stdin args.fp w
+| args.lex = case contents of
+ (Right cs) = (lexer cs, Left "Parsing Disabled", w)
+ (Left e) = (Left e, Left "Parsing disabled", w)
+= case contents of
+ (Left e) = (Left e, Left "", w)
+ (Right cs) = let lexOut = lexer cs in (lexOut, parser lexOut, w)
+
+readFileOrStdin :: *File (Maybe String) *World -> *(Either String [Char], *File, *World)
+readFileOrStdin stdin Nothing w
+# (cs, stdin) = readEntireFile stdin
+= (Right cs, stdin, w)
+readFileOrStdin stdin (Just fp) w
+# (b, fin, w) = fopen fp FReadText w
+| not b = (Left "Unable to open file", stdin, w)
+# (cs, fin) = readEntireFile fin
+# (_, w) = fclose fin w
+= (Right cs, stdin, w)