src/Pure/Isar/isar.ML
author wenzelm
Wed, 16 Jul 2008 11:20:24 +0200
changeset 27616 a811269b577c
parent 27606 82399f3a8ca8
child 27620 dfecac40e4be
permissions -rw-r--r--
export type id with no_id and create_command; basic support for editor model: insert_command, remove_command; refined command status; misc tuning;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26605
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Isar/isar.ML
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
     3
    Author:     Makarius
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
     4
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
     5
The global Isabelle/Isar state and main read-eval-print loop.
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
     6
*)
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
     7
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
     8
signature ISAR =
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
     9
sig
27616
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
    10
  type id = string
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
    11
  val no_id: id
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
    12
  val create_command: Toplevel.transition -> id
27530
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
    13
  val init_point: unit -> unit
26605
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
    14
  val state: unit -> Toplevel.state
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
    15
  val context: unit -> Proof.context
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
    16
  val goal: unit -> thm
27533
85bbd045ac3e added print;
wenzelm
parents: 27530
diff changeset
    17
  val print: unit -> unit
27616
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
    18
  val exn: unit -> (exn * string) option
26605
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
    19
  val >> : Toplevel.transition -> bool
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
    20
  val >>> : Toplevel.transition list -> unit
27529
6a5ccbb1bca0 added Isar.linear_undo;
wenzelm
parents: 27528
diff changeset
    21
  val linear_undo: int -> unit
27524
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
    22
  val undo: int -> unit
27530
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
    23
  val kill: unit -> unit
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
    24
  val kill_proof: unit -> unit
26605
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
    25
  val crashes: exn list ref
26643
99f5407c05ef Isar.toplevel_loop: separate init/welcome flag;
wenzelm
parents: 26606
diff changeset
    26
  val toplevel_loop: {init: bool, welcome: bool, sync: bool, secure: bool} -> unit
26605
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
    27
  val loop: unit -> unit
26606
379596d12f25 replaced Isar loop variants by generic toplevel_loop;
wenzelm
parents: 26605
diff changeset
    28
  val main: unit -> unit
27616
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
    29
  val insert_command: id -> id -> unit
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
    30
  val remove_command: id -> unit
26605
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
    31
end;
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
    32
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
    33
structure Isar: ISAR =
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
    34
struct
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
    35
27432
c5ec309c6de8 replaced datatype kind by OuterKeyword.category;
wenzelm
parents: 27428
diff changeset
    36
27428
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
    37
(** individual toplevel commands **)
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
    38
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
    39
(* unique identification *)
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
    40
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
    41
type id = string;
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
    42
val no_id : id = "";
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
    43
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
    44
fun identify tr =
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
    45
  (case Toplevel.get_id tr of
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
    46
    SOME id => (id, tr)
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
    47
  | NONE =>
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
    48
      let val id = "isabelle:" ^ serial_string ()
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
    49
      in (id, Toplevel.put_id id tr) end);
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
    50
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
    51
27438
9b2427cc234e command: always keep transition, not just as initial status;
wenzelm
parents: 27432
diff changeset
    52
(* command category *)
9b2427cc234e command: always keep transition, not just as initial status;
wenzelm
parents: 27432
diff changeset
    53
27524
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
    54
datatype category = Empty | Theory | Proof | Diag | Control;
27428
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
    55
27438
9b2427cc234e command: always keep transition, not just as initial status;
wenzelm
parents: 27432
diff changeset
    56
fun category_of tr =
9b2427cc234e command: always keep transition, not just as initial status;
wenzelm
parents: 27432
diff changeset
    57
  let val name = Toplevel.name_of tr in
9b2427cc234e command: always keep transition, not just as initial status;
wenzelm
parents: 27432
diff changeset
    58
    if name = "" then Empty
27524
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
    59
    else if OuterKeyword.is_theory name then Theory
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
    60
    else if OuterKeyword.is_proof name then Proof
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
    61
    else if OuterKeyword.is_diag name then Diag
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
    62
    else Control
27438
9b2427cc234e command: always keep transition, not just as initial status;
wenzelm
parents: 27432
diff changeset
    63
  end;
27428
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
    64
27524
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
    65
val is_theory = fn Theory => true | _ => false;
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
    66
val is_proper = fn Theory => true | Proof => true | _ => false;
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
    67
27428
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
    68
27616
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
    69
(* command status *)
27428
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
    70
27438
9b2427cc234e command: always keep transition, not just as initial status;
wenzelm
parents: 27432
diff changeset
    71
datatype status =
27616
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
    72
  Unprocessed |
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
    73
  Running |
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
    74
  Failed of exn * string |
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
    75
  Finished of Toplevel.state;
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
    76
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
    77
fun status_markup Unprocessed = Markup.unprocessed
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
    78
  | status_markup Running = Markup.running
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
    79
  | status_markup (Failed _) = Markup.failed
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
    80
  | status_markup (Finished _) = Markup.finished;
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
    81
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
    82
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
    83
(* datatype command *)
27438
9b2427cc234e command: always keep transition, not just as initial status;
wenzelm
parents: 27432
diff changeset
    84
27428
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
    85
datatype command = Command of
27501
632ee56c2c0b global commands: explicit graph;
wenzelm
parents: 27438
diff changeset
    86
 {category: category,
27438
9b2427cc234e command: always keep transition, not just as initial status;
wenzelm
parents: 27432
diff changeset
    87
  transition: Toplevel.transition,
27428
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
    88
  status: status};
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
    89
27501
632ee56c2c0b global commands: explicit graph;
wenzelm
parents: 27438
diff changeset
    90
fun make_command (category, transition, status) =
632ee56c2c0b global commands: explicit graph;
wenzelm
parents: 27438
diff changeset
    91
  Command {category = category, transition = transition, status = status};
27438
9b2427cc234e command: always keep transition, not just as initial status;
wenzelm
parents: 27432
diff changeset
    92
9b2427cc234e command: always keep transition, not just as initial status;
wenzelm
parents: 27432
diff changeset
    93
val empty_command =
27616
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
    94
  make_command (Empty, Toplevel.empty, Finished Toplevel.toplevel);
27428
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
    95
27501
632ee56c2c0b global commands: explicit graph;
wenzelm
parents: 27438
diff changeset
    96
fun map_command f (Command {category, transition, status}) =
632ee56c2c0b global commands: explicit graph;
wenzelm
parents: 27438
diff changeset
    97
  make_command (f (category, transition, status));
27428
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
    98
27501
632ee56c2c0b global commands: explicit graph;
wenzelm
parents: 27438
diff changeset
    99
fun map_status f = map_command (fn (category, transition, status) =>
632ee56c2c0b global commands: explicit graph;
wenzelm
parents: 27438
diff changeset
   100
  (category, transition, f status));
27428
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
   101
26605
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   102
27501
632ee56c2c0b global commands: explicit graph;
wenzelm
parents: 27438
diff changeset
   103
(* global collection of identified commands *)
27428
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
   104
27518
1e5f48e01e5e misc tuning;
wenzelm
parents: 27501
diff changeset
   105
fun err_dup id = sys_error ("Duplicate command " ^ quote id);
1e5f48e01e5e misc tuning;
wenzelm
parents: 27501
diff changeset
   106
fun err_undef id = sys_error ("Unknown command " ^ quote id);
1e5f48e01e5e misc tuning;
wenzelm
parents: 27501
diff changeset
   107
27616
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   108
local val global_commands = ref (Graph.empty: command Graph.T) in
27428
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
   109
27501
632ee56c2c0b global commands: explicit graph;
wenzelm
parents: 27438
diff changeset
   110
fun change_commands f = NAMED_CRITICAL "Isar" (fn () => change global_commands f)
27616
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   111
  handle Graph.DUP bad => err_dup bad | Graph.UNDEF bad => err_undef bad;
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   112
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   113
fun get_commands () = NAMED_CRITICAL "Isar" (fn () => ! global_commands);
27501
632ee56c2c0b global commands: explicit graph;
wenzelm
parents: 27438
diff changeset
   114
27616
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   115
end;
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   116
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   117
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   118
fun init_commands () = change_commands (K Graph.empty);
27428
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
   119
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
   120
fun the_command id =
27524
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   121
  let val Command cmd =
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   122
    if id = no_id then empty_command
27616
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   123
    else (Graph.get_node (get_commands ()) id handle Graph.UNDEF bad => err_undef bad)
27524
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   124
  in cmd end;
27518
1e5f48e01e5e misc tuning;
wenzelm
parents: 27501
diff changeset
   125
1e5f48e01e5e misc tuning;
wenzelm
parents: 27501
diff changeset
   126
fun prev_command id =
1e5f48e01e5e misc tuning;
wenzelm
parents: 27501
diff changeset
   127
  if id = no_id then NONE
1e5f48e01e5e misc tuning;
wenzelm
parents: 27501
diff changeset
   128
  else
27616
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   129
    (case Graph.imm_preds (get_commands ()) id handle Graph.UNDEF bad => err_undef bad of
27518
1e5f48e01e5e misc tuning;
wenzelm
parents: 27501
diff changeset
   130
      [] => NONE
1e5f48e01e5e misc tuning;
wenzelm
parents: 27501
diff changeset
   131
    | [prev] => SOME prev
1e5f48e01e5e misc tuning;
wenzelm
parents: 27501
diff changeset
   132
    | _ => sys_error ("Non-linear command dependency " ^ quote id));
27501
632ee56c2c0b global commands: explicit graph;
wenzelm
parents: 27438
diff changeset
   133
27616
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   134
fun next_commands id =
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   135
  if id = no_id then []
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   136
  else Graph.imm_succs (get_commands ()) id handle Graph.UNDEF bad => err_undef bad;
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   137
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   138
fun descendant_commands ids =
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   139
  Graph.all_succs (get_commands ()) (filter_out (fn id => id = no_id) ids)
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   140
    handle Graph.UNDEF bad => err_undef bad;
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   141
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   142
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   143
(* maintain status *)
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   144
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   145
fun report_status markup id = Toplevel.status (#transition (the_command id)) markup;
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   146
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   147
fun update_status status id = change_commands (Graph.map_node id (map_status (fn old_status =>
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   148
  let
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   149
    val markup = status_markup status;
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   150
    val _ = if markup <> status_markup old_status then report_status markup id else ();
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   151
  in status end)));
27501
632ee56c2c0b global commands: explicit graph;
wenzelm
parents: 27438
diff changeset
   152
26605
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   153
27616
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   154
(* create and dispose commands *)
27524
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   155
27616
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   156
fun create_command raw_tr =
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   157
  let
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   158
    val (id, tr) = identify raw_tr;
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   159
    val cmd = make_command (category_of tr, tr, Unprocessed);
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   160
    val _ = change_commands (Graph.new_node (id, cmd));
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   161
  in id end;
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   162
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   163
fun dispose_command id =
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   164
  let
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   165
    val desc = descendant_commands [id];
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   166
    val _ = List.app (report_status Markup.disposed) desc;
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   167
    val _ = change_commands (Graph.del_nodes desc);
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   168
  in () end;
27606
82399f3a8ca8 support for command status;
wenzelm
parents: 27600
diff changeset
   169
27428
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
   170
27616
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   171
(* final state *)
27501
632ee56c2c0b global commands: explicit graph;
wenzelm
parents: 27438
diff changeset
   172
27616
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   173
fun the_state id =
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   174
  (case the_command id of
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   175
    {status = Finished state, ...} => state
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   176
  | {transition, ...} => error ("Unfinished command " ^ Toplevel.str_of transition));
27501
632ee56c2c0b global commands: explicit graph;
wenzelm
parents: 27438
diff changeset
   177
27428
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
   178
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
   179
27616
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   180
(** TTY model -- single-threaded **)
27428
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
   181
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
   182
(* global point *)
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
   183
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
   184
local val global_point = ref no_id in
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
   185
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
   186
fun change_point f = NAMED_CRITICAL "Isar" (fn () => change global_point f);
27524
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   187
fun point () = NAMED_CRITICAL "Isar" (fn () => ! global_point);
27428
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
   188
27501
632ee56c2c0b global commands: explicit graph;
wenzelm
parents: 27438
diff changeset
   189
end;
632ee56c2c0b global commands: explicit graph;
wenzelm
parents: 27438
diff changeset
   190
27616
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   191
27524
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   192
fun set_point id = change_point (K id);
27530
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
   193
fun init_point () = set_point no_id;
27524
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   194
27616
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   195
fun point_state () = NAMED_CRITICAL "Isar" (fn () =>
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   196
  let val id = point () in (id, the_state id) end);
27501
632ee56c2c0b global commands: explicit graph;
wenzelm
parents: 27438
diff changeset
   197
27616
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   198
fun state () = #2 (point_state ());
26605
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   199
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   200
fun context () =
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   201
  Toplevel.context_of (state ())
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   202
    handle Toplevel.UNDEF => error "Unknown context";
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   203
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   204
fun goal () =
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   205
  #2 (#2 (Proof.get_goal (Toplevel.proof_of (state ()))))
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   206
    handle Toplevel.UNDEF => error "No goal present";
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   207
27533
85bbd045ac3e added print;
wenzelm
parents: 27530
diff changeset
   208
fun print () = Toplevel.print_state false (state ());
85bbd045ac3e added print;
wenzelm
parents: 27530
diff changeset
   209
26605
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   210
27616
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   211
(* global failure status *)
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   212
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   213
local val global_exn = ref (NONE: (exn * string) option) in
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   214
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   215
fun set_exn err = global_exn := err;
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   216
fun exn () = ! global_exn;
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   217
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   218
end;
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   219
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   220
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   221
(* interactive state transformations *)
26605
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   222
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   223
nonfix >> >>>;
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   224
27428
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
   225
fun >> raw_tr =
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
   226
  let
27616
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   227
    val id = create_command raw_tr;
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   228
    val {category, transition = tr, ...} = the_command id;
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   229
    val (prev, prev_state) = point_state ();
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   230
    val _ = if prev <> no_id then change_commands (Graph.add_edge (prev, id)) else ();
27428
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
   231
  in
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
   232
    (case Toplevel.transition true tr prev_state of
27501
632ee56c2c0b global commands: explicit graph;
wenzelm
parents: 27438
diff changeset
   233
      NONE => (dispose_command id; false)
27616
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   234
    | SOME (_, SOME err) =>
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   235
       (Toplevel.error_msg tr err; set_exn (SOME err); dispose_command id; true)
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   236
    | SOME (state, NONE) =>
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   237
       (set_exn NONE;
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   238
        if category = Control then dispose_command id
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   239
        else (update_status (Finished state) id; set_point id);
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   240
        true))
27428
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
   241
  end;
26605
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   242
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   243
fun >>> [] = ()
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   244
  | >>> (tr :: trs) = if >> tr then >>> trs else ();
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   245
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   246
27530
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
   247
(* implicit navigation wrt. proper commands *)
27524
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   248
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   249
local
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   250
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   251
fun err_undo () = error "Undo history exhausted";
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   252
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   253
fun get_prev id = the_default no_id (prev_command id);
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   254
27530
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
   255
fun find_category which id =
27524
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   256
  (case #category (the_command id) of
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   257
    Empty => err_undo ()
27530
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
   258
  | category => if which category then id else find_category which (get_prev id));
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
   259
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
   260
fun find_begin_theory id =
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
   261
  if id = no_id then err_undo ()
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
   262
  else if is_some (Toplevel.init_of (#transition (the_command id))) then id
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
   263
  else find_begin_theory (get_prev id);
27524
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   264
27529
6a5ccbb1bca0 added Isar.linear_undo;
wenzelm
parents: 27528
diff changeset
   265
fun undo_command id =
27530
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
   266
  (case Toplevel.init_of (#transition (the_command id)) of
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
   267
    SOME name => get_prev id before ThyInfo.kill_thy name
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
   268
  | NONE => get_prev id);
27529
6a5ccbb1bca0 added Isar.linear_undo;
wenzelm
parents: 27528
diff changeset
   269
27524
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   270
in
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   271
27530
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
   272
fun linear_undo n = change_point (funpow n (fn id => undo_command (find_category is_proper id)));
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
   273
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
   274
fun undo n = change_point (funpow n (fn id => undo_command
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
   275
  (find_category (if Toplevel.is_proof (the_state id) then is_proper else is_theory) id)));
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
   276
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
   277
fun kill () = change_point (fn id => undo_command
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
   278
  (if Toplevel.is_proof (the_state id) then find_category is_theory id else find_begin_theory id));
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
   279
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
   280
fun kill_proof () = change_point (fn id =>
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
   281
  if Toplevel.is_proof (the_state id) then undo_command (find_category is_theory id)
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
   282
  else raise Toplevel.UNDEF);
27524
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   283
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   284
end;
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   285
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   286
26606
379596d12f25 replaced Isar loop variants by generic toplevel_loop;
wenzelm
parents: 26605
diff changeset
   287
(* toplevel loop *)
26605
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   288
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   289
val crashes = ref ([]: exn list);
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   290
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   291
local
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   292
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   293
fun raw_loop secure src =
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   294
  let
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   295
    fun check_secure () =
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   296
      (if secure then warning "Secure loop -- cannot exit to ML" else (); secure);
27524
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   297
    val prev = point ();
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   298
    val prev_name = Toplevel.name_of (#transition (the_command prev));
27428
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
   299
    val prompt_markup =
27524
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   300
      prev <> no_id ? Markup.markup
cd95da386e9a provide old-style undo operation (still unused);
wenzelm
parents: 27518
diff changeset
   301
        (Markup.properties [(Markup.idN, prev), (Markup.nameN, prev_name)] Markup.prompt);
26605
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   302
  in
27428
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
   303
    (case Source.get_single (Source.set_prompt (prompt_markup Source.default_prompt) src) of
26606
379596d12f25 replaced Isar loop variants by generic toplevel_loop;
wenzelm
parents: 26605
diff changeset
   304
      NONE => if secure then quit () else ()
379596d12f25 replaced Isar loop variants by generic toplevel_loop;
wenzelm
parents: 26605
diff changeset
   305
    | SOME (tr, src') => if >> tr orelse check_secure () then raw_loop secure src' else ())
26605
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   306
    handle exn => (Output.error_msg (Toplevel.exn_message exn) handle crash =>
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   307
      (CRITICAL (fn () => change crashes (cons crash));
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   308
        warning "Recovering after Isar toplevel crash -- see also Isar.crashes");
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   309
      raw_loop secure src)
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   310
  end;
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   311
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   312
in
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   313
27428
f92d47cdc0de explicit identification of toplevel commands, with status etc.;
wenzelm
parents: 26643
diff changeset
   314
fun toplevel_loop {init, welcome, sync, secure} =
26605
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   315
 (Context.set_thread_data NONE;
27530
df14c9cbd21d export init_point;
wenzelm
parents: 27529
diff changeset
   316
  if init then (init_point (); init_commands ()) else ();
26643
99f5407c05ef Isar.toplevel_loop: separate init/welcome flag;
wenzelm
parents: 26606
diff changeset
   317
  if welcome then writeln (Session.welcome ()) else ();
26606
379596d12f25 replaced Isar loop variants by generic toplevel_loop;
wenzelm
parents: 26605
diff changeset
   318
  uninterruptible (fn _ => fn () => raw_loop secure (OuterSyntax.isar sync)) ());
26605
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   319
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   320
end;
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   321
26643
99f5407c05ef Isar.toplevel_loop: separate init/welcome flag;
wenzelm
parents: 26606
diff changeset
   322
fun loop () =
99f5407c05ef Isar.toplevel_loop: separate init/welcome flag;
wenzelm
parents: 26606
diff changeset
   323
  toplevel_loop {init = false, welcome = false, sync = false, secure = Secure.is_secure ()};
27528
wenzelm
parents: 27527
diff changeset
   324
26643
99f5407c05ef Isar.toplevel_loop: separate init/welcome flag;
wenzelm
parents: 26606
diff changeset
   325
fun main () =
99f5407c05ef Isar.toplevel_loop: separate init/welcome flag;
wenzelm
parents: 26606
diff changeset
   326
  toplevel_loop {init = true, welcome = true, sync = false, secure = Secure.is_secure ()};
26605
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   327
27616
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   328
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   329
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   330
(** editor model **)
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   331
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   332
(* run commands *)  (* FIXME *)
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   333
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   334
fun run_commands ids =
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   335
  let
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   336
    val _ = List.app (update_status Unprocessed) ids;
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   337
  in () end;
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   338
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   339
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   340
(* modify document *)
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   341
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   342
fun insert_command prev id = NAMED_CRITICAL "Isar" (fn () =>
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   343
  let
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   344
    val nexts = next_commands prev;
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   345
    val _ = change_commands
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   346
      (fold (fn next => Graph.del_edge (prev, next) #> Graph.add_edge (id, next)) nexts #>
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   347
        Graph.add_edge (prev, id));
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   348
  in descendant_commands [id] end) |> run_commands;
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   349
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   350
fun remove_command id = NAMED_CRITICAL "Isar" (fn () =>
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   351
  let
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   352
    val prev_edge =
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   353
      (case prev_command id of NONE => K I
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   354
      | SOME prev => fn next => Graph.add_edge (prev, next));
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   355
    val nexts = next_commands id;
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   356
    val _ = change_commands (fold (fn next => Graph.del_edge (id, next) #> prev_edge next) nexts);
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   357
  in descendant_commands nexts end) |> run_commands;
a811269b577c export type id with no_id and create_command;
wenzelm
parents: 27606
diff changeset
   358
26605
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   359
end;
24e60e823d22 The global Isabelle/Isar state and main read-eval-print loop.
wenzelm
parents:
diff changeset
   360