X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=src%2Fmain.icl;h=f2b5c9383be05c655936f41854dda635c10f2b9e;hb=3d1c57710eb0b86f13df392f03131157aec22c21;hp=4739c359e5761d9930563fa6c421da93ed95ae07;hpb=9b257f4008624c0bdbb9821291f46e553e2f0f91;p=cc1516.git diff --git a/src/main.icl b/src/main.icl index 4739c35..f2b5c93 100644 --- a/src/main.icl +++ b/src/main.icl @@ -22,6 +22,32 @@ import lex :: *StartType :== (LexerOutput, ParserOutput, *World) +Start :: *World -> *StartType +Start w +# (args, w) = parseArgs w +| args.help + # (out, w) = stdio w + # out = out <<< "\nUsage: " <<< args.program <<< " [opts] [FILENAME]\n" + <<< "\t--help Show this help\n" + <<< "\t--lex Lex only, is mutually exclusive with --parse\n" + <<< "\t--parse Lex & Parse only\n\n" + <<< "\tFILENAME File to parse, when unspecified stdin is parsed\n" + # (_, w) = fclose out w + = (Left "", Left "", 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) + # lexout = lexer cs + # parsout = parser lexout + # stdin = stdin <<< (either (const "") toString parsout) + # (_, w) = fclose stdin w + = (lexout, parser lexout, w) + parseArgs :: *World -> (Opts, *World) parseArgs w # ([p:args], w) = getCommandLine w @@ -34,25 +60,6 @@ where pa ["--parse":r] = \o.pa r {o & lex=False, parse=True} pa [x:r] = \o.pa r {o & fp=Just x} -//Start :: *World -> (LexerOutput, ParserOutput, *World) -//Start w -//# (args, w) = getCommandLine w -//# (toparse, out) = readEntireFile out -//= (lexer toparse, parse (lexer toparse), w) - -Start :: *World -> *StartType -Start 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 @@ -61,7 +68,8 @@ 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 +# (b, w) = fclose fin w +| not b = (Left "Unable to close file", stdin, w) = (Right cs, stdin, w) readEntireFile :: *File -> *([Char], *File) @@ -70,15 +78,3 @@ readEntireFile f | not b = ([], f) # (cs, f) = readEntireFile f = ([c:cs], f) - -help :: String *World -> *StartType -help p w -# (out, w) = stdio w -# out = out <<< "\nUsage: " <<< p <<< " [opts] [FILENAME]\n" - <<< "\t--help Show this help\n" - <<< "\t--lex Lex only, is mutually exclusive with --parse\n" - <<< "\t--parse Lex & Parse only\n\n" - <<< "\tFILENAME File to parse, when unspecified stdin is parsed\n" -# (_, w) = fclose out w -= (Left "", Left "", w) -