| author | ballarin | 
| Tue, 03 Sep 2013 22:12:48 +0200 | |
| changeset 53370 | 7a41ec2cc522 | 
| parent 52982 | 8e78bd316a53 | 
| child 56303 | 4cc3f4db3447 | 
| permissions | -rw-r--r-- | 
| 52865 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 1 | (* Title: Pure/PIDE/query_operation.ML | 
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 2 | Author: Makarius | 
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 3 | |
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 4 | One-shot query operations via asynchronous print functions and temporary | 
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 5 | document overlay. | 
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 6 | *) | 
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 7 | |
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 8 | signature QUERY_OPERATION = | 
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 9 | sig | 
| 52982 
8e78bd316a53
clarified Query_Operation.register: avoid hard-wired parallel policy;
 wenzelm parents: 
52953diff
changeset | 10 | val register: string -> | 
| 
8e78bd316a53
clarified Query_Operation.register: avoid hard-wired parallel policy;
 wenzelm parents: 
52953diff
changeset | 11 |     ({state: Toplevel.state, args: string list, output_result: string -> unit} -> unit) -> unit
 | 
| 52865 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 12 | end; | 
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 13 | |
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 14 | structure Query_Operation: QUERY_OPERATION = | 
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 15 | struct | 
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 16 | |
| 52982 
8e78bd316a53
clarified Query_Operation.register: avoid hard-wired parallel policy;
 wenzelm parents: 
52953diff
changeset | 17 | fun register name f = | 
| 52865 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 18 | Command.print_function name | 
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 19 |     (fn {args = instance :: args, ...} =>
 | 
| 52953 
2c927b7501c5
explicit "strict" flag for print functions (flipped internal meaning);
 wenzelm parents: 
52931diff
changeset | 20 |         SOME {delay = NONE, pri = 0, persistent = false, strict = false,
 | 
| 52931 
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
 wenzelm parents: 
52929diff
changeset | 21 | print_fn = fn _ => uninterruptible (fn restore_attributes => fn state => | 
| 52865 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 22 | let | 
| 52876 | 23 | fun result s = Output.result [(Markup.instanceN, instance)] s; | 
| 24 | fun status m = result (Markup.markup_only m); | |
| 52982 
8e78bd316a53
clarified Query_Operation.register: avoid hard-wired parallel policy;
 wenzelm parents: 
52953diff
changeset | 25 | fun output_result s = result (Markup.markup (Markup.writelnN, []) s); | 
| 52929 
52d21bddcb8a
clarified toplevel_error: absorb and print interrupts;
 wenzelm parents: 
52879diff
changeset | 26 | fun toplevel_error exn = | 
| 
52d21bddcb8a
clarified toplevel_error: absorb and print interrupts;
 wenzelm parents: 
52879diff
changeset | 27 | result (Markup.markup (Markup.errorN, []) (ML_Compiler.exn_message exn)); | 
| 52876 | 28 | |
| 29 | val _ = status Markup.running; | |
| 52982 
8e78bd316a53
clarified Query_Operation.register: avoid hard-wired parallel policy;
 wenzelm parents: 
52953diff
changeset | 30 |               fun run () = f {state = state, args = args, output_result = output_result};
 | 
| 
8e78bd316a53
clarified Query_Operation.register: avoid hard-wired parallel policy;
 wenzelm parents: 
52953diff
changeset | 31 | val _ = | 
| 
8e78bd316a53
clarified Query_Operation.register: avoid hard-wired parallel policy;
 wenzelm parents: 
52953diff
changeset | 32 | (case Exn.capture (*sic!*) (restore_attributes run) () of | 
| 
8e78bd316a53
clarified Query_Operation.register: avoid hard-wired parallel policy;
 wenzelm parents: 
52953diff
changeset | 33 | Exn.Res () => () | 
| 
8e78bd316a53
clarified Query_Operation.register: avoid hard-wired parallel policy;
 wenzelm parents: 
52953diff
changeset | 34 | | Exn.Exn exn => toplevel_error exn); | 
| 52876 | 35 | val _ = status Markup.finished; | 
| 52931 
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
 wenzelm parents: 
52929diff
changeset | 36 | in () end)} | 
| 52865 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 37 | | _ => NONE); | 
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 38 | |
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 39 | end; | 
| 
02a7e7180ee5
slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
 wenzelm parents: diff
changeset | 40 |