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 /ml-lex/trunk/export-lex.sml
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 498 - (view) (download)
Original Path: sml/branches/SMLNJ/src/ml-lex/export-lex.sml

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

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