Debian Codegraph @

lib/mllpt-lib/ml-lpt/ml-antlr/examples/dragon/main.sml

raw
1 structure Main =
2 struct
3
4 structure L = Mlex
5 structure P = ParseFn(L)
6
7 fun errMsg l =
8 TextIO.output(TextIO.stdErr, String.concat l)
9
10 fun parse strm = let
11 val s = Mlex.streamifyInstream strm
12 val sm = AntlrStreamPos.mkSourcemap()
13 val (SOME p, s', errors) = P.parse (L.lex sm) s before TextIO.closeIn strm
14 fun doErr err = print ("Syntax error " ^
15 AntlrRepair.repairToString Tokens.toString sm err ^ "\n")
16 in
17 app doErr errors;
18 p
19 end
20
21 fun main (_, [file]) = (
22 print ("\n -- ECHO -- \n\n" ^ (parse (TextIO.openIn file)));
23 print "\n\n";
24 OS.Process.success)
25 handle ex => (
26 errMsg [
27 "uncaught exception ", General.exnName ex,
28 " [", exnMessage ex, "]\n"
29 ];
30 List.app (fn s => errMsg [" raised at ", s, "\n"]) (SMLofNJ.exnHistory ex);
31 OS.Process.failure)
32
33 end