src/Pure/PIDE/markup.ML
author wenzelm
Wed May 22 14:10:45 2013 +0200 (2013-05-22 ago)
changeset 52111 1fd184eaa310
parent 51990 cc66addbba6d
child 52563 f9a20c2c3b70
permissions -rw-r--r--
explicit management of Session.Protocol_Handlers, with protocol state and functions;
more self-contained ML/Scala module Invoke_Scala;
wenzelm@45670
     1
(*  Title:      Pure/PIDE/markup.ML
wenzelm@23623
     2
    Author:     Makarius
wenzelm@23623
     3
wenzelm@50201
     4
Isabelle-specific implementation of quasi-abstract markup elements.
wenzelm@23623
     5
*)
wenzelm@23623
     6
wenzelm@23623
     7
signature MARKUP =
wenzelm@23623
     8
sig
wenzelm@51951
     9
  val parse_bool: string -> bool
wenzelm@51951
    10
  val print_bool: bool -> string
wenzelm@38414
    11
  val parse_int: string -> int
wenzelm@38414
    12
  val print_int: int -> string
wenzelm@51988
    13
  val parse_real: string -> real
wenzelm@51988
    14
  val print_real: real -> string
wenzelm@28017
    15
  type T = string * Properties.T
wenzelm@38474
    16
  val empty: T
wenzelm@38474
    17
  val is_empty: T -> bool
wenzelm@38229
    18
  val properties: Properties.T -> T -> T
wenzelm@23623
    19
  val nameN: string
wenzelm@27818
    20
  val name: string -> T -> T
wenzelm@38887
    21
  val kindN: string
wenzelm@50201
    22
  val bindingN: string val binding: T
wenzelm@50201
    23
  val entityN: string val entity: string -> string -> T
wenzelm@50201
    24
  val get_entity_kind: T -> string option
wenzelm@50201
    25
  val defN: string
wenzelm@50201
    26
  val refN: string
wenzelm@50201
    27
  val lineN: string
wenzelm@50201
    28
  val offsetN: string
wenzelm@50201
    29
  val end_offsetN: string
wenzelm@50201
    30
  val fileN: string
wenzelm@50201
    31
  val idN: string
wenzelm@50201
    32
  val position_properties': string list
wenzelm@50201
    33
  val position_properties: string list
wenzelm@50201
    34
  val positionN: string val position: T
wenzelm@50201
    35
  val pathN: string val path: string -> T
wenzelm@50201
    36
  val indentN: string
wenzelm@50201
    37
  val blockN: string val block: int -> T
wenzelm@50201
    38
  val widthN: string
wenzelm@50201
    39
  val breakN: string val break: int -> T
wenzelm@50201
    40
  val fbreakN: string val fbreak: T
wenzelm@51570
    41
  val itemN: string val item: T
wenzelm@50201
    42
  val hiddenN: string val hidden: T
wenzelm@50201
    43
  val theoryN: string
wenzelm@50201
    44
  val classN: string
wenzelm@50201
    45
  val type_nameN: string
wenzelm@50201
    46
  val constantN: string
wenzelm@50201
    47
  val fixedN: string val fixed: string -> T
wenzelm@50201
    48
  val dynamic_factN: string val dynamic_fact: string -> T
wenzelm@50201
    49
  val tfreeN: string val tfree: T
wenzelm@50201
    50
  val tvarN: string val tvar: T
wenzelm@50201
    51
  val freeN: string val free: T
wenzelm@50201
    52
  val skolemN: string val skolem: T
wenzelm@50201
    53
  val boundN: string val bound: T
wenzelm@50201
    54
  val varN: string val var: T
wenzelm@50201
    55
  val numeralN: string val numeral: T
wenzelm@50201
    56
  val literalN: string val literal: T
wenzelm@50201
    57
  val delimiterN: string val delimiter: T
wenzelm@50201
    58
  val inner_stringN: string val inner_string: T
wenzelm@50201
    59
  val inner_commentN: string val inner_comment: T
wenzelm@50201
    60
  val token_rangeN: string val token_range: T
wenzelm@50201
    61
  val sortN: string val sort: T
wenzelm@50201
    62
  val typN: string val typ: T
wenzelm@50201
    63
  val termN: string val term: T
wenzelm@50201
    64
  val propN: string val prop: T
wenzelm@50201
    65
  val sortingN: string val sorting: T
wenzelm@50201
    66
  val typingN: string val typing: T
wenzelm@50201
    67
  val ML_keywordN: string val ML_keyword: T
wenzelm@50201
    68
  val ML_delimiterN: string val ML_delimiter: T
wenzelm@50201
    69
  val ML_tvarN: string val ML_tvar: T
wenzelm@50201
    70
  val ML_numeralN: string val ML_numeral: T
wenzelm@50201
    71
  val ML_charN: string val ML_char: T
wenzelm@50201
    72
  val ML_stringN: string val ML_string: T
wenzelm@50201
    73
  val ML_commentN: string val ML_comment: T
wenzelm@50201
    74
  val ML_defN: string
wenzelm@50201
    75
  val ML_openN: string
wenzelm@50201
    76
  val ML_structN: string
wenzelm@50201
    77
  val ML_typingN: string val ML_typing: T
wenzelm@50201
    78
  val ML_sourceN: string val ML_source: T
wenzelm@51626
    79
  val document_sourceN: string val document_source: T
wenzelm@50201
    80
  val antiqN: string val antiq: T
wenzelm@50201
    81
  val ML_antiquotationN: string
wenzelm@50201
    82
  val document_antiquotationN: string
wenzelm@50201
    83
  val document_antiquotation_optionN: string
wenzelm@50201
    84
  val paragraphN: string val paragraph: T
wenzelm@50545
    85
  val text_foldN: string val text_fold: T
wenzelm@50201
    86
  val keywordN: string val keyword: T
wenzelm@50201
    87
  val operatorN: string val operator: T
wenzelm@50201
    88
  val commandN: string val command: T
wenzelm@50201
    89
  val stringN: string val string: T
wenzelm@50201
    90
  val altstringN: string val altstring: T
wenzelm@50201
    91
  val verbatimN: string val verbatim: T
wenzelm@50201
    92
  val commentN: string val comment: T
wenzelm@50201
    93
  val controlN: string val control: T
wenzelm@50201
    94
  val tokenN: string val token: Properties.T -> T
wenzelm@50201
    95
  val keyword1N: string val keyword1: T
wenzelm@50201
    96
  val keyword2N: string val keyword2: T
wenzelm@50201
    97
  val elapsedN: string
wenzelm@50201
    98
  val cpuN: string
wenzelm@50201
    99
  val gcN: string
wenzelm@51606
   100
  val timing_properties: {elapsed: Time.time, cpu: Time.time, gc: Time.time} -> Properties.T
wenzelm@51606
   101
  val parse_timing_properties: Properties.T -> {elapsed: Time.time, cpu: Time.time, gc: Time.time}
wenzelm@51228
   102
  val command_timingN: string
wenzelm@51228
   103
  val command_timing_properties:
wenzelm@51228
   104
    {file: string, offset: int, name: string} -> Time.time -> Properties.T
wenzelm@51228
   105
  val parse_command_timing_properties:
wenzelm@51228
   106
    Properties.T -> ({file: string, offset: int, name: string} * Time.time) option
wenzelm@51606
   107
  val timingN: string val timing: {elapsed: Time.time, cpu: Time.time, gc: Time.time} -> T
wenzelm@50201
   108
  val subgoalsN: string
wenzelm@50201
   109
  val proof_stateN: string val proof_state: int -> T
wenzelm@50201
   110
  val stateN: string val state: T
wenzelm@50543
   111
  val goalN: string val goal: T
wenzelm@50537
   112
  val subgoalN: string val subgoal: string -> T
wenzelm@50201
   113
  val taskN: string
wenzelm@50201
   114
  val acceptedN: string val accepted: T
wenzelm@50201
   115
  val forkedN: string val forked: T
wenzelm@50201
   116
  val joinedN: string val joined: T
wenzelm@50201
   117
  val runningN: string val running: T
wenzelm@50201
   118
  val finishedN: string val finished: T
wenzelm@50201
   119
  val failedN: string val failed: T
wenzelm@50201
   120
  val serialN: string
wenzelm@50914
   121
  val exec_idN: string
wenzelm@50201
   122
  val initN: string
wenzelm@50201
   123
  val statusN: string
wenzelm@50503
   124
  val resultN: string
wenzelm@50201
   125
  val writelnN: string
wenzelm@50201
   126
  val tracingN: string
wenzelm@50201
   127
  val warningN: string
wenzelm@50201
   128
  val errorN: string
wenzelm@50201
   129
  val protocolN: string
wenzelm@50201
   130
  val legacyN: string val legacy: T
wenzelm@50201
   131
  val promptN: string val prompt: T
wenzelm@50201
   132
  val reportN: string val report: T
wenzelm@50201
   133
  val no_reportN: string val no_report: T
wenzelm@50201
   134
  val badN: string val bad: T
wenzelm@50500
   135
  val intensifyN: string val intensify: T
wenzelm@50715
   136
  val browserN: string
wenzelm@50500
   137
  val graphviewN: string
wenzelm@50500
   138
  val sendbackN: string
wenzelm@50500
   139
  val paddingN: string
wenzelm@50842
   140
  val padding_line: Properties.entry
wenzelm@50500
   141
  val dialogN: string val dialog: serial -> string -> T
wenzelm@50201
   142
  val functionN: string
wenzelm@50201
   143
  val assign_execs: Properties.T
wenzelm@50201
   144
  val removed_versions: Properties.T
wenzelm@52111
   145
  val protocol_handler: string -> Properties.T
wenzelm@50201
   146
  val invoke_scala: string -> string -> Properties.T
wenzelm@50201
   147
  val cancel_scala: string -> Properties.T
wenzelm@50842
   148
  val ML_statistics: Properties.entry
wenzelm@50975
   149
  val task_statistics: Properties.entry
wenzelm@51216
   150
  val command_timing: Properties.entry
wenzelm@50845
   151
  val loading_theory: string -> Properties.T
wenzelm@50845
   152
  val dest_loading_theory: Properties.T -> string option
wenzelm@40131
   153
  val no_output: Output.output * Output.output
wenzelm@40131
   154
  val default_output: T -> Output.output * Output.output
wenzelm@40131
   155
  val add_mode: string -> (T -> Output.output * Output.output) -> unit
wenzelm@40131
   156
  val output: T -> Output.output * Output.output
wenzelm@40131
   157
  val enclose: T -> Output.output -> Output.output
wenzelm@25552
   158
  val markup: T -> string -> string
wenzelm@43665
   159
  val markup_only: T -> string
wenzelm@23623
   160
end;
wenzelm@23623
   161
wenzelm@23623
   162
structure Markup: MARKUP =
wenzelm@23623
   163
struct
wenzelm@23623
   164
wenzelm@30221
   165
(** markup elements **)
wenzelm@30221
   166
wenzelm@51988
   167
(* misc values *)
wenzelm@51951
   168
wenzelm@51951
   169
fun parse_bool "true" = true
wenzelm@51951
   170
  | parse_bool "false" = false
wenzelm@51951
   171
  | parse_bool s = raise Fail ("Bad boolean: " ^ quote s);
wenzelm@51951
   172
wenzelm@51951
   173
val print_bool = Bool.toString;
wenzelm@51951
   174
wenzelm@38414
   175
fun parse_int s =
wenzelm@43797
   176
  let val i = Int.fromString s in
wenzelm@43797
   177
    if is_none i orelse String.isPrefix "~" s
wenzelm@43797
   178
    then raise Fail ("Bad integer: " ^ quote s)
wenzelm@43797
   179
    else the i
wenzelm@43797
   180
  end;
wenzelm@38414
   181
wenzelm@38414
   182
val print_int = signed_string_of_int;
wenzelm@38414
   183
wenzelm@51988
   184
fun parse_real s =
wenzelm@51988
   185
  (case Real.fromString s of
wenzelm@51988
   186
    SOME x => x
wenzelm@51988
   187
  | NONE => raise Fail ("Bad real: " ^ quote s));
wenzelm@51988
   188
wenzelm@51990
   189
fun print_real x =
wenzelm@51990
   190
  let val s = signed_string_of_real x in
wenzelm@51990
   191
    (case space_explode "." s of
wenzelm@51990
   192
      [a, b] => if forall_string (fn c => c = "0") b then a else s
wenzelm@51990
   193
    | _ => s)
wenzelm@51990
   194
  end;
wenzelm@51988
   195
wenzelm@38414
   196
wenzelm@23658
   197
(* basic markup *)
wenzelm@23623
   198
wenzelm@28017
   199
type T = string * Properties.T;
wenzelm@23637
   200
wenzelm@38474
   201
val empty = ("", []);
wenzelm@23637
   202
wenzelm@38474
   203
fun is_empty ("", _) = true
wenzelm@38474
   204
  | is_empty _ = false;
wenzelm@27883
   205
wenzelm@23794
   206
wenzelm@23671
   207
fun properties more_props ((elem, props): T) =
wenzelm@28017
   208
  (elem, fold_rev Properties.put more_props props);
wenzelm@23671
   209
wenzelm@50201
   210
fun markup_elem elem = (elem, (elem, []): T);
wenzelm@50201
   211
fun markup_string elem prop = (elem, fn s => (elem, [(prop, s)]): T);
wenzelm@50201
   212
fun markup_int elem prop = (elem, fn i => (elem, [(prop, print_int i)]): T);
wenzelm@50201
   213
wenzelm@26977
   214
wenzelm@38721
   215
(* misc properties *)
wenzelm@26977
   216
wenzelm@23658
   217
val nameN = "name";
wenzelm@27818
   218
fun name a = properties [(nameN, a)];
wenzelm@27818
   219
wenzelm@23658
   220
val kindN = "kind";
wenzelm@23671
   221
wenzelm@23658
   222
wenzelm@50201
   223
(* formal entities *)
wenzelm@50201
   224
wenzelm@50201
   225
val (bindingN, binding) = markup_elem "binding";
wenzelm@50201
   226
wenzelm@50201
   227
val entityN = "entity";
wenzelm@50201
   228
fun entity kind name = (entityN, [(nameN, name), (kindN, kind)]);
wenzelm@50201
   229
wenzelm@50201
   230
fun get_entity_kind (name, props) =
wenzelm@50201
   231
  if name = entityN then AList.lookup (op =) props kindN
wenzelm@50201
   232
  else NONE;
wenzelm@50201
   233
wenzelm@50201
   234
val defN = "def";
wenzelm@50201
   235
val refN = "ref";
wenzelm@50201
   236
wenzelm@50201
   237
wenzelm@50201
   238
(* position *)
wenzelm@50201
   239
wenzelm@50201
   240
val lineN = "line";
wenzelm@50201
   241
val offsetN = "offset";
wenzelm@50201
   242
val end_offsetN = "end_offset";
wenzelm@50201
   243
val fileN = "file";
wenzelm@50201
   244
val idN = "id";
wenzelm@50201
   245
wenzelm@50201
   246
val position_properties' = [fileN, idN];
wenzelm@50201
   247
val position_properties = [lineN, offsetN, end_offsetN] @ position_properties';
wenzelm@50201
   248
wenzelm@50201
   249
val (positionN, position) = markup_elem "position";
wenzelm@50201
   250
wenzelm@50201
   251
wenzelm@50201
   252
(* path *)
wenzelm@50201
   253
wenzelm@50201
   254
val (pathN, path) = markup_string "path" nameN;
wenzelm@50201
   255
wenzelm@50201
   256
wenzelm@50201
   257
(* pretty printing *)
wenzelm@50201
   258
wenzelm@50201
   259
val indentN = "indent";
wenzelm@50201
   260
val (blockN, block) = markup_int "block" indentN;
wenzelm@50201
   261
wenzelm@50201
   262
val widthN = "width";
wenzelm@50201
   263
val (breakN, break) = markup_int "break" widthN;
wenzelm@50201
   264
wenzelm@50201
   265
val (fbreakN, fbreak) = markup_elem "fbreak";
wenzelm@50201
   266
wenzelm@51570
   267
val (itemN, item) = markup_elem "item";
wenzelm@51570
   268
wenzelm@50201
   269
wenzelm@50201
   270
(* hidden text *)
wenzelm@50201
   271
wenzelm@50201
   272
val (hiddenN, hidden) = markup_elem "hidden";
wenzelm@50201
   273
wenzelm@50201
   274
wenzelm@50201
   275
(* logical entities *)
wenzelm@50201
   276
wenzelm@50201
   277
val theoryN = "theory";
wenzelm@50201
   278
val classN = "class";
wenzelm@50201
   279
val type_nameN = "type_name";
wenzelm@50201
   280
val constantN = "constant";
wenzelm@50201
   281
wenzelm@50201
   282
val (fixedN, fixed) = markup_string "fixed" nameN;
wenzelm@50201
   283
val (dynamic_factN, dynamic_fact) = markup_string "dynamic_fact" nameN;
wenzelm@50201
   284
wenzelm@50201
   285
wenzelm@50201
   286
(* inner syntax *)
wenzelm@50201
   287
wenzelm@50201
   288
val (tfreeN, tfree) = markup_elem "tfree";
wenzelm@50201
   289
val (tvarN, tvar) = markup_elem "tvar";
wenzelm@50201
   290
val (freeN, free) = markup_elem "free";
wenzelm@50201
   291
val (skolemN, skolem) = markup_elem "skolem";
wenzelm@50201
   292
val (boundN, bound) = markup_elem "bound";
wenzelm@50201
   293
val (varN, var) = markup_elem "var";
wenzelm@50201
   294
val (numeralN, numeral) = markup_elem "numeral";
wenzelm@50201
   295
val (literalN, literal) = markup_elem "literal";
wenzelm@50201
   296
val (delimiterN, delimiter) = markup_elem "delimiter";
wenzelm@50201
   297
val (inner_stringN, inner_string) = markup_elem "inner_string";
wenzelm@50201
   298
val (inner_commentN, inner_comment) = markup_elem "inner_comment";
wenzelm@50201
   299
wenzelm@50201
   300
val (token_rangeN, token_range) = markup_elem "token_range";
wenzelm@50201
   301
wenzelm@50201
   302
val (sortN, sort) = markup_elem "sort";
wenzelm@50201
   303
val (typN, typ) = markup_elem "typ";
wenzelm@50201
   304
val (termN, term) = markup_elem "term";
wenzelm@50201
   305
val (propN, prop) = markup_elem "prop";
wenzelm@50201
   306
wenzelm@50201
   307
val (sortingN, sorting) = markup_elem "sorting";
wenzelm@50201
   308
val (typingN, typing) = markup_elem "typing";
wenzelm@50201
   309
wenzelm@50201
   310
wenzelm@50201
   311
(* ML syntax *)
wenzelm@50201
   312
wenzelm@50201
   313
val (ML_keywordN, ML_keyword) = markup_elem "ML_keyword";
wenzelm@50201
   314
val (ML_delimiterN, ML_delimiter) = markup_elem "ML_delimiter";
wenzelm@50201
   315
val (ML_tvarN, ML_tvar) = markup_elem "ML_tvar";
wenzelm@50201
   316
val (ML_numeralN, ML_numeral) = markup_elem "ML_numeral";
wenzelm@50201
   317
val (ML_charN, ML_char) = markup_elem "ML_char";
wenzelm@50201
   318
val (ML_stringN, ML_string) = markup_elem "ML_string";
wenzelm@50201
   319
val (ML_commentN, ML_comment) = markup_elem "ML_comment";
wenzelm@50201
   320
wenzelm@50201
   321
val ML_defN = "ML_def";
wenzelm@50201
   322
val ML_openN = "ML_open";
wenzelm@50201
   323
val ML_structN = "ML_struct";
wenzelm@50201
   324
val (ML_typingN, ML_typing) = markup_elem "ML_typing";
wenzelm@50201
   325
wenzelm@50201
   326
wenzelm@50201
   327
(* embedded source text *)
wenzelm@50201
   328
wenzelm@50201
   329
val (ML_sourceN, ML_source) = markup_elem "ML_source";
wenzelm@51626
   330
val (document_sourceN, document_source) = markup_elem "document_source";
wenzelm@50201
   331
wenzelm@50201
   332
val (antiqN, antiq) = markup_elem "antiq";
wenzelm@50201
   333
val ML_antiquotationN = "ML_antiquotation";
wenzelm@50201
   334
val document_antiquotationN = "document_antiquotation";
wenzelm@50201
   335
val document_antiquotation_optionN = "document_antiquotation_option";
wenzelm@50201
   336
wenzelm@50201
   337
wenzelm@50201
   338
(* text structure *)
wenzelm@50201
   339
wenzelm@50201
   340
val (paragraphN, paragraph) = markup_elem "paragraph";
wenzelm@50545
   341
val (text_foldN, text_fold) = markup_elem "text_fold";
wenzelm@50201
   342
wenzelm@50201
   343
wenzelm@50201
   344
(* outer syntax *)
wenzelm@50201
   345
wenzelm@50201
   346
val (keywordN, keyword) = markup_elem "keyword";
wenzelm@50201
   347
val (operatorN, operator) = markup_elem "operator";
wenzelm@50201
   348
val (commandN, command) = markup_elem "command";
wenzelm@50201
   349
val (stringN, string) = markup_elem "string";
wenzelm@50201
   350
val (altstringN, altstring) = markup_elem "altstring";
wenzelm@50201
   351
val (verbatimN, verbatim) = markup_elem "verbatim";
wenzelm@50201
   352
val (commentN, comment) = markup_elem "comment";
wenzelm@50201
   353
val (controlN, control) = markup_elem "control";
wenzelm@50201
   354
wenzelm@50201
   355
val tokenN = "token";
wenzelm@50201
   356
fun token props = (tokenN, props);
wenzelm@50201
   357
wenzelm@50201
   358
val (keyword1N, keyword1) = markup_elem "keyword1";
wenzelm@50201
   359
val (keyword2N, keyword2) = markup_elem "keyword2";
wenzelm@50201
   360
wenzelm@50201
   361
wenzelm@50201
   362
(* timing *)
wenzelm@50201
   363
wenzelm@50201
   364
val elapsedN = "elapsed";
wenzelm@50201
   365
val cpuN = "cpu";
wenzelm@50201
   366
val gcN = "gc";
wenzelm@50201
   367
wenzelm@50781
   368
fun timing_properties {elapsed, cpu, gc} =
wenzelm@50781
   369
 [(elapsedN, Time.toString elapsed),
wenzelm@50781
   370
  (cpuN, Time.toString cpu),
wenzelm@50781
   371
  (gcN, Time.toString gc)];
wenzelm@50781
   372
wenzelm@51665
   373
fun parse_timing_properties props =
wenzelm@51665
   374
 {elapsed = Properties.seconds props elapsedN,
wenzelm@51665
   375
  cpu = Properties.seconds props cpuN,
wenzelm@51665
   376
  gc = Properties.seconds props gcN};
wenzelm@51218
   377
wenzelm@51665
   378
val timingN = "timing";
wenzelm@51665
   379
fun timing t = (timingN, timing_properties t);
wenzelm@51218
   380
wenzelm@51228
   381
wenzelm@51228
   382
(* command timing *)
wenzelm@51228
   383
wenzelm@51228
   384
val command_timingN = "command_timing";
wenzelm@51228
   385
wenzelm@51228
   386
fun command_timing_properties {file, offset, name} elapsed =
wenzelm@51228
   387
 [(fileN, file), (offsetN, print_int offset),
wenzelm@51228
   388
  (nameN, name), (elapsedN, Time.toString elapsed)];
wenzelm@51228
   389
wenzelm@51228
   390
fun parse_command_timing_properties props =
wenzelm@51228
   391
  (case (Properties.get props fileN, Properties.get props offsetN, Properties.get props nameN) of
wenzelm@51228
   392
    (SOME file, SOME offset, SOME name) =>
wenzelm@51665
   393
      SOME ({file = file, offset = parse_int offset, name = name},
wenzelm@51665
   394
        Properties.seconds props elapsedN)
wenzelm@51228
   395
  | _ => NONE);
wenzelm@51228
   396
wenzelm@51228
   397
wenzelm@50201
   398
(* toplevel *)
wenzelm@50201
   399
wenzelm@50201
   400
val subgoalsN = "subgoals";
wenzelm@50201
   401
val (proof_stateN, proof_state) = markup_int "proof_state" subgoalsN;
wenzelm@50201
   402
wenzelm@50201
   403
val (stateN, state) = markup_elem "state";
wenzelm@50543
   404
val (goalN, goal) = markup_elem "goal";
wenzelm@50537
   405
val (subgoalN, subgoal) = markup_string "subgoal" nameN;
wenzelm@50215
   406
wenzelm@50450
   407
wenzelm@50201
   408
(* command status *)
wenzelm@50201
   409
wenzelm@50201
   410
val taskN = "task";
wenzelm@50201
   411
wenzelm@50201
   412
val (acceptedN, accepted) = markup_elem "accepted";
wenzelm@50201
   413
val (forkedN, forked) = markup_elem "forked";
wenzelm@50201
   414
val (joinedN, joined) = markup_elem "joined";
wenzelm@50201
   415
val (runningN, running) = markup_elem "running";
wenzelm@50201
   416
val (finishedN, finished) = markup_elem "finished";
wenzelm@50201
   417
val (failedN, failed) = markup_elem "failed";
wenzelm@50201
   418
wenzelm@50201
   419
wenzelm@50201
   420
(* messages *)
wenzelm@50201
   421
wenzelm@50201
   422
val serialN = "serial";
wenzelm@50914
   423
val exec_idN = "exec_id";
wenzelm@50201
   424
wenzelm@50201
   425
val initN = "init";
wenzelm@50201
   426
val statusN = "status";
wenzelm@50503
   427
val resultN = "result";
wenzelm@50201
   428
val writelnN = "writeln";
wenzelm@50201
   429
val tracingN = "tracing";
wenzelm@50201
   430
val warningN = "warning";
wenzelm@50201
   431
val errorN = "error";
wenzelm@50201
   432
val protocolN = "protocol";
wenzelm@50201
   433
wenzelm@50201
   434
val (legacyN, legacy) = markup_elem "legacy";
wenzelm@50201
   435
val (promptN, prompt) = markup_elem "prompt";
wenzelm@50201
   436
wenzelm@50201
   437
val (reportN, report) = markup_elem "report";
wenzelm@50201
   438
val (no_reportN, no_report) = markup_elem "no_report";
wenzelm@50201
   439
wenzelm@50201
   440
val (badN, bad) = markup_elem "bad";
wenzelm@50201
   441
wenzelm@50500
   442
val (intensifyN, intensify) = markup_elem "intensify";
wenzelm@50500
   443
wenzelm@50500
   444
wenzelm@50500
   445
(* active areas *)
wenzelm@50500
   446
wenzelm@50715
   447
val browserN = "browser"
wenzelm@50500
   448
val graphviewN = "graphview";
wenzelm@50500
   449
wenzelm@50500
   450
val sendbackN = "sendback";
wenzelm@50500
   451
val paddingN = "padding";
wenzelm@50500
   452
val padding_line = (paddingN, lineN);
wenzelm@50500
   453
wenzelm@50500
   454
val dialogN = "dialog";
wenzelm@50503
   455
fun dialog i result = (dialogN, [(serialN, print_int i), (resultN, result)]);
wenzelm@50500
   456
wenzelm@50201
   457
wenzelm@50201
   458
(* protocol message functions *)
wenzelm@50201
   459
wenzelm@50201
   460
val functionN = "function"
wenzelm@50201
   461
wenzelm@50201
   462
val assign_execs = [(functionN, "assign_execs")];
wenzelm@50201
   463
val removed_versions = [(functionN, "removed_versions")];
wenzelm@50201
   464
wenzelm@52111
   465
fun protocol_handler name = [(functionN, "protocol_handler"), (nameN, name)];
wenzelm@52111
   466
wenzelm@50201
   467
fun invoke_scala name id = [(functionN, "invoke_scala"), (nameN, name), (idN, id)];
wenzelm@50201
   468
fun cancel_scala id = [(functionN, "cancel_scala"), (idN, id)];
wenzelm@50201
   469
wenzelm@50683
   470
val ML_statistics = (functionN, "ML_statistics");
wenzelm@50255
   471
wenzelm@50975
   472
val task_statistics = (functionN, "task_statistics");
wenzelm@50975
   473
wenzelm@51216
   474
val command_timing = (functionN, "command_timing");
wenzelm@51216
   475
wenzelm@50845
   476
fun loading_theory name = [("function", "loading_theory"), ("name", name)];
wenzelm@50845
   477
wenzelm@50845
   478
fun dest_loading_theory [("function", "loading_theory"), ("name", name)] = SOME name
wenzelm@50845
   479
  | dest_loading_theory _ = NONE;
wenzelm@50845
   480
wenzelm@50201
   481
wenzelm@27969
   482
wenzelm@30221
   483
(** print mode operations **)
wenzelm@23704
   484
wenzelm@29325
   485
val no_output = ("", "");
wenzelm@29325
   486
fun default_output (_: T) = no_output;
wenzelm@23704
   487
wenzelm@23704
   488
local
wenzelm@23704
   489
  val default = {output = default_output};
wenzelm@43684
   490
  val modes = Synchronized.var "Markup.modes" (Symtab.make [("", default)]);
wenzelm@23704
   491
in
wenzelm@43684
   492
  fun add_mode name output =
wenzelm@46894
   493
    Synchronized.change modes (fn tab =>
wenzelm@46894
   494
      (if not (Symtab.defined tab name) then ()
wenzelm@46894
   495
       else warning ("Redefining markup mode " ^ quote name);
wenzelm@46894
   496
       Symtab.update (name, {output = output}) tab));
wenzelm@23704
   497
  fun get_mode () =
wenzelm@43684
   498
    the_default default
wenzelm@43684
   499
      (Library.get_first (Symtab.lookup (Synchronized.value modes)) (print_mode_value ()));
wenzelm@23623
   500
end;
wenzelm@23704
   501
wenzelm@38474
   502
fun output m = if is_empty m then no_output else #output (get_mode ()) m;
wenzelm@23704
   503
wenzelm@23719
   504
val enclose = output #-> Library.enclose;
wenzelm@23719
   505
wenzelm@25552
   506
fun markup m =
wenzelm@25552
   507
  let val (bg, en) = output m
wenzelm@25552
   508
  in Library.enclose (Output.escape bg) (Output.escape en) end;
wenzelm@25552
   509
wenzelm@43665
   510
fun markup_only m = markup m "";
wenzelm@43665
   511
wenzelm@23704
   512
end;