11 import System.CommandLine
23 :: *StartType :== (LexerOutput, ParserOutput, *World)
25 parseArgs :: *World -> (Opts, *World)
27 # ([p:args], w) = getCommandLine w
28 = (pa args {program=p, lex=False, parse=False, fp=Nothing, help=False}, w)
30 pa :: [String] -> (Opts -> Opts)
32 pa ["--help":r] = \o.pa r {o & help=True}
33 pa ["--lex":r] = \o.pa r {o & lex=True, parse=False}
34 pa ["--parse":r] = \o.pa r {o & lex=False, parse=True}
35 pa [x:r] = \o.pa r {o & fp=Just x}
37 //Start :: *World -> (LexerOutput, ParserOutput, *World)
39 //# (args, w) = getCommandLine w
40 //# (toparse, out) = readEntireFile out
41 //= (lexer toparse, parse (lexer toparse), w)
43 Start :: *World -> *StartType
45 # (args, w) = parseArgs w
46 | args.help = help args.program w
47 # (stdin, w) = stdio w
48 # (contents, stdin, w) = readFileOrStdin stdin args.fp w
49 | args.lex = case contents of
50 (Right cs) = (lexer cs, Left "Parsing Disabled", w)
51 (Left e) = (Left e, Left "Parsing disabled", w)
53 (Left e) = (Left e, Left "", w)
54 (Right cs) = let lexOut = lexer cs in (lexOut, parser lexOut, w)
56 readFileOrStdin :: *File (Maybe String) *World -> *(Either String [Char], *File, *World)
57 readFileOrStdin stdin Nothing w
58 # (cs, stdin) = readEntireFile stdin
59 = (Right cs, stdin, w)
60 readFileOrStdin stdin (Just fp) w
61 # (b, fin, w) = fopen fp FReadText w
62 | not b = (Left "Unable to open file", stdin, w)
63 # (cs, fin) = readEntireFile fin
64 # (_, w) = fclose fin w
65 = (Right cs, stdin, w)
67 readEntireFile :: *File -> *([Char], *File)
69 # (b, c, f) = freadc f
71 # (cs, f) = readEntireFile f
74 help :: String *World -> *StartType
77 # out = out <<< "\nUsage: " <<< p <<< " [opts] [FILENAME]\n"
78 <<< "\t--help Show this help\n"
79 <<< "\t--lex Lex only, is mutually exclusive with --parse\n"
80 <<< "\t--parse Lex & Parse only\n\n"
81 <<< "\tFILENAME File to parse, when unspecified stdin is parsed\n"
82 # (_, w) = fclose out w
83 = (Left "", Left "", w)