Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/ml-lex/export-lex.sml
ViewVC logotype

Annotation of /sml/trunk/src/ml-lex/export-lex.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 94 - (view) (download)

1 : monnier 2 (* export-lex.sml
2 :     *
3 :     * $Log$
4 : monnier 93 * Revision 1.1.1.3 1998/05/12 21:56:18 monnier
5 : monnier 8 * *** empty log message ***
6 : monnier 2 *
7 : monnier 93 * Revision 1.1.1.1 1998/04/08 18:40:10 george
8 :     * Version 110.5
9 :     *
10 : monnier 8 * Revision 1.2 1997/03/03 17:10:35 george
11 :     * moved callcc related functions to SMLofNJ.Cont
12 :     *
13 : monnier 2 # Revision 1.1.1.1 1997/01/14 01:38:01 george
14 :     # Version 109.24
15 :     #
16 :     * Revision 1.3 1996/02/26 16:55:18 jhr
17 :     * Moved exportFn/exportML to SMLofNJ structure.
18 :     *
19 :     * Revision 1.2 1996/02/26 15:02:26 george
20 :     * print no longer overloaded.
21 :     * use of makestring has been removed and replaced with Int.toString ..
22 :     * use of IO replaced with TextIO
23 :     *
24 :     * Revision 1.1.1.1 1996/01/31 16:01:15 george
25 :     * Version 109
26 :     *
27 :     *)
28 :    
29 :     structure ExportLexGen : sig
30 :    
31 :     val lexGen : (string * string list) -> OS.Process.status
32 :    
33 :     end = struct
34 :    
35 :     exception Interrupt
36 :    
37 :     (* This function applies operation to (). If it handles an interrupt
38 :     * signal (Control-C), it raises the exception Interrupt. Example:
39 :     * (handleInterrupt foo) handle Interrupt => print "Bang!\n"
40 :     *)
41 :     fun handleInterrupt (operation : unit -> unit) =
42 :     let exception Done
43 :     val old'handler = Signals.inqHandler(Signals.sigINT)
44 :     fun reset'handler () =
45 :     Signals.setHandler(Signals.sigINT, old'handler)
46 :     in (SMLofNJ.Cont.callcc (fn k =>
47 :     (Signals.setHandler(Signals.sigINT, Signals.HANDLER(fn _ => k));
48 :     operation ();
49 :     raise Done));
50 :     raise Interrupt)
51 :     handle Done => (reset'handler ())
52 :     | exn => (reset'handler (); raise exn)
53 :     end
54 :    
55 :     fun err msg = TextIO.output(TextIO.stdErr, String.concat msg)
56 :    
57 :     fun lexGen (name, args) = let
58 :     fun lex_gen () = (case args
59 :     of [] => (
60 :     err [name, ": missing filename\n"];
61 :     OS.Process.exit OS.Process.failure)
62 :     | files => List.app LexGen.lexGen files
63 :     (* end case *))
64 :     in
65 :     (handleInterrupt lex_gen; OS.Process.success)
66 :     handle Interrupt => (
67 :     err [name, ": Interrupt\n"];
68 :     OS.Process.failure)
69 :     | any => (
70 :     err [
71 :     name, ": uncaught exception ", exnMessage any, "\n"
72 :     ];
73 :     OS.Process.failure)
74 :     end
75 :    
76 :     end;
77 :    
78 :     fun export name = SMLofNJ.exportFn (name, ExportLexGen.lexGen);
79 :    

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0