src/Pure/PIDE/markup.ML
author wenzelm
Tue Feb 25 17:03:55 2014 +0100 (2014-02-25)
changeset 55744 4a4e5686e091
parent 55694 a1184dfb8e00
child 55750 baa7a1e57f4a
permissions -rw-r--r--
clarified token markup: keyword1/keyword2 is for syntax, and "command" the entity kind;
tuned message;
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@52854
    22
  val instanceN: string
wenzelm@55615
    23
  val symbolsN: string
wenzelm@55666
    24
  val languageN: string
wenzelm@55666
    25
  val language: {name: string, symbols: bool, antiquotes: bool} -> T
wenzelm@55550
    26
  val language_sort: T
wenzelm@55550
    27
  val language_type: T
wenzelm@55550
    28
  val language_term: T
wenzelm@55550
    29
  val language_prop: T
wenzelm@55550
    30
  val language_ML: T
wenzelm@55550
    31
  val language_document: T
wenzelm@55653
    32
  val language_antiquotation: T
wenzelm@55561
    33
  val language_text: T
wenzelm@55613
    34
  val language_rail: T
wenzelm@50201
    35
  val bindingN: string val binding: T
wenzelm@50201
    36
  val entityN: string val entity: string -> string -> T
wenzelm@50201
    37
  val get_entity_kind: T -> string option
wenzelm@50201
    38
  val defN: string
wenzelm@50201
    39
  val refN: string
wenzelm@55694
    40
  val completionN: string val completion: T
wenzelm@50201
    41
  val lineN: string
wenzelm@50201
    42
  val offsetN: string
wenzelm@50201
    43
  val end_offsetN: string
wenzelm@50201
    44
  val fileN: string
wenzelm@50201
    45
  val idN: string
wenzelm@50201
    46
  val position_properties': string list
wenzelm@50201
    47
  val position_properties: string list
wenzelm@50201
    48
  val positionN: string val position: T
wenzelm@50201
    49
  val pathN: string val path: string -> T
wenzelm@54702
    50
  val urlN: string val url: string -> T
wenzelm@50201
    51
  val indentN: string
wenzelm@50201
    52
  val blockN: string val block: int -> T
wenzelm@50201
    53
  val widthN: string
wenzelm@50201
    54
  val breakN: string val break: int -> T
wenzelm@50201
    55
  val fbreakN: string val fbreak: T
wenzelm@51570
    56
  val itemN: string val item: T
wenzelm@50201
    57
  val hiddenN: string val hidden: T
wenzelm@50201
    58
  val theoryN: string
wenzelm@50201
    59
  val classN: string
wenzelm@50201
    60
  val type_nameN: string
wenzelm@50201
    61
  val constantN: string
wenzelm@50201
    62
  val fixedN: string val fixed: string -> T
wenzelm@53378
    63
  val caseN: string val case_: string -> T
wenzelm@50201
    64
  val dynamic_factN: string val dynamic_fact: string -> T
wenzelm@50201
    65
  val tfreeN: string val tfree: T
wenzelm@50201
    66
  val tvarN: string val tvar: T
wenzelm@50201
    67
  val freeN: string val free: T
wenzelm@50201
    68
  val skolemN: string val skolem: T
wenzelm@50201
    69
  val boundN: string val bound: T
wenzelm@50201
    70
  val varN: string val var: T
wenzelm@50201
    71
  val numeralN: string val numeral: T
wenzelm@50201
    72
  val literalN: string val literal: T
wenzelm@50201
    73
  val delimiterN: string val delimiter: T
wenzelm@50201
    74
  val inner_stringN: string val inner_string: T
wenzelm@55033
    75
  val inner_cartoucheN: string val inner_cartouche: T
wenzelm@50201
    76
  val inner_commentN: string val inner_comment: T
wenzelm@50201
    77
  val token_rangeN: string val token_range: T
wenzelm@50201
    78
  val sortingN: string val sorting: T
wenzelm@50201
    79
  val typingN: string val typing: T
wenzelm@55505
    80
  val ML_keyword1N: string val ML_keyword1: T
wenzelm@55505
    81
  val ML_keyword2N: string val ML_keyword2: T
wenzelm@55505
    82
  val ML_keyword3N: string val ML_keyword3: T
wenzelm@50201
    83
  val ML_delimiterN: string val ML_delimiter: T
wenzelm@50201
    84
  val ML_tvarN: string val ML_tvar: T
wenzelm@50201
    85
  val ML_numeralN: string val ML_numeral: T
wenzelm@50201
    86
  val ML_charN: string val ML_char: T
wenzelm@50201
    87
  val ML_stringN: string val ML_string: T
wenzelm@50201
    88
  val ML_commentN: string val ML_comment: T
wenzelm@50201
    89
  val ML_defN: string
wenzelm@50201
    90
  val ML_openN: string
wenzelm@50201
    91
  val ML_structN: string
wenzelm@50201
    92
  val ML_typingN: string val ML_typing: T
wenzelm@55526
    93
  val antiquotedN: string val antiquoted: T
wenzelm@55526
    94
  val antiquoteN: string val antiquote: T
wenzelm@50201
    95
  val ML_antiquotationN: string
wenzelm@50201
    96
  val document_antiquotationN: string
wenzelm@50201
    97
  val document_antiquotation_optionN: string
wenzelm@50201
    98
  val paragraphN: string val paragraph: T
wenzelm@50545
    99
  val text_foldN: string val text_fold: T
wenzelm@55744
   100
  val commandN: string
wenzelm@50201
   101
  val operatorN: string val operator: T
wenzelm@50201
   102
  val stringN: string val string: T
wenzelm@50201
   103
  val altstringN: string val altstring: T
wenzelm@50201
   104
  val verbatimN: string val verbatim: T
wenzelm@55033
   105
  val cartoucheN: string val cartouche: T
wenzelm@50201
   106
  val commentN: string val comment: T
wenzelm@50201
   107
  val controlN: string val control: T
wenzelm@50201
   108
  val tokenN: string val token: Properties.T -> T
wenzelm@50201
   109
  val keyword1N: string val keyword1: T
wenzelm@50201
   110
  val keyword2N: string val keyword2: T
wenzelm@50201
   111
  val elapsedN: string
wenzelm@50201
   112
  val cpuN: string
wenzelm@50201
   113
  val gcN: string
wenzelm@51606
   114
  val timing_properties: {elapsed: Time.time, cpu: Time.time, gc: Time.time} -> Properties.T
wenzelm@51606
   115
  val parse_timing_properties: Properties.T -> {elapsed: Time.time, cpu: Time.time, gc: Time.time}
wenzelm@51228
   116
  val command_timingN: string
wenzelm@51228
   117
  val command_timing_properties:
wenzelm@51228
   118
    {file: string, offset: int, name: string} -> Time.time -> Properties.T
wenzelm@51228
   119
  val parse_command_timing_properties:
wenzelm@51228
   120
    Properties.T -> ({file: string, offset: int, name: string} * Time.time) option
wenzelm@51606
   121
  val timingN: string val timing: {elapsed: Time.time, cpu: Time.time, gc: Time.time} -> T
wenzelm@50201
   122
  val subgoalsN: string
wenzelm@50201
   123
  val proof_stateN: string val proof_state: int -> T
wenzelm@50201
   124
  val stateN: string val state: T
wenzelm@50543
   125
  val goalN: string val goal: T
wenzelm@50537
   126
  val subgoalN: string val subgoal: string -> T
wenzelm@50201
   127
  val taskN: string
wenzelm@50201
   128
  val acceptedN: string val accepted: T
wenzelm@50201
   129
  val forkedN: string val forked: T
wenzelm@50201
   130
  val joinedN: string val joined: T
wenzelm@50201
   131
  val runningN: string val running: T
wenzelm@50201
   132
  val finishedN: string val finished: T
wenzelm@50201
   133
  val failedN: string val failed: T
wenzelm@50201
   134
  val serialN: string
wenzelm@52854
   135
  val serial_properties: int -> Properties.T
wenzelm@50914
   136
  val exec_idN: string
wenzelm@50201
   137
  val initN: string
wenzelm@50201
   138
  val statusN: string
wenzelm@50503
   139
  val resultN: string
wenzelm@50201
   140
  val writelnN: string
wenzelm@50201
   141
  val tracingN: string
wenzelm@50201
   142
  val warningN: string
wenzelm@50201
   143
  val errorN: string
wenzelm@50201
   144
  val protocolN: string
wenzelm@50201
   145
  val legacyN: string val legacy: T
wenzelm@50201
   146
  val promptN: string val prompt: T
wenzelm@50201
   147
  val reportN: string val report: T
wenzelm@50201
   148
  val no_reportN: string val no_report: T
wenzelm@50201
   149
  val badN: string val bad: T
wenzelm@50500
   150
  val intensifyN: string val intensify: T
wenzelm@52643
   151
  val informationN: string val information: T
wenzelm@50715
   152
  val browserN: string
wenzelm@50500
   153
  val graphviewN: string
wenzelm@50500
   154
  val sendbackN: string
wenzelm@50500
   155
  val paddingN: string
wenzelm@50842
   156
  val padding_line: Properties.entry
wenzelm@52697
   157
  val padding_command: Properties.entry
wenzelm@50500
   158
  val dialogN: string val dialog: serial -> string -> T
wenzelm@50201
   159
  val functionN: string
wenzelm@52800
   160
  val flush: Properties.T
wenzelm@52563
   161
  val assign_update: Properties.T
wenzelm@50201
   162
  val removed_versions: Properties.T
wenzelm@52111
   163
  val protocol_handler: string -> Properties.T
wenzelm@50201
   164
  val invoke_scala: string -> string -> Properties.T
wenzelm@50201
   165
  val cancel_scala: string -> Properties.T
wenzelm@53055
   166
  val sledgehammer_provers: Properties.T
wenzelm@50842
   167
  val ML_statistics: Properties.entry
wenzelm@50975
   168
  val task_statistics: Properties.entry
wenzelm@51216
   169
  val command_timing: Properties.entry
wenzelm@50845
   170
  val loading_theory: string -> Properties.T
wenzelm@50845
   171
  val dest_loading_theory: Properties.T -> string option
wenzelm@55553
   172
  val simp_trace_logN: string
wenzelm@55553
   173
  val simp_trace_stepN: string
wenzelm@55553
   174
  val simp_trace_recurseN: string
wenzelm@55553
   175
  val simp_trace_hintN: string
wenzelm@55553
   176
  val simp_trace_ignoreN: string
wenzelm@55553
   177
  val simp_trace_cancel: serial -> Properties.T
wenzelm@40131
   178
  val no_output: Output.output * Output.output
wenzelm@40131
   179
  val default_output: T -> Output.output * Output.output
wenzelm@40131
   180
  val add_mode: string -> (T -> Output.output * Output.output) -> unit
wenzelm@40131
   181
  val output: T -> Output.output * Output.output
wenzelm@40131
   182
  val enclose: T -> Output.output -> Output.output
wenzelm@25552
   183
  val markup: T -> string -> string
wenzelm@43665
   184
  val markup_only: T -> string
wenzelm@23623
   185
end;
wenzelm@23623
   186
wenzelm@23623
   187
structure Markup: MARKUP =
wenzelm@23623
   188
struct
wenzelm@23623
   189
wenzelm@30221
   190
(** markup elements **)
wenzelm@30221
   191
wenzelm@51988
   192
(* misc values *)
wenzelm@51951
   193
wenzelm@51951
   194
fun parse_bool "true" = true
wenzelm@51951
   195
  | parse_bool "false" = false
wenzelm@51951
   196
  | parse_bool s = raise Fail ("Bad boolean: " ^ quote s);
wenzelm@51951
   197
wenzelm@51951
   198
val print_bool = Bool.toString;
wenzelm@51951
   199
wenzelm@38414
   200
fun parse_int s =
wenzelm@43797
   201
  let val i = Int.fromString s in
wenzelm@43797
   202
    if is_none i orelse String.isPrefix "~" s
wenzelm@43797
   203
    then raise Fail ("Bad integer: " ^ quote s)
wenzelm@43797
   204
    else the i
wenzelm@43797
   205
  end;
wenzelm@38414
   206
wenzelm@38414
   207
val print_int = signed_string_of_int;
wenzelm@38414
   208
wenzelm@51988
   209
fun parse_real s =
wenzelm@51988
   210
  (case Real.fromString s of
wenzelm@51988
   211
    SOME x => x
wenzelm@51988
   212
  | NONE => raise Fail ("Bad real: " ^ quote s));
wenzelm@51988
   213
wenzelm@51990
   214
fun print_real x =
wenzelm@51990
   215
  let val s = signed_string_of_real x in
wenzelm@51990
   216
    (case space_explode "." s of
wenzelm@51990
   217
      [a, b] => if forall_string (fn c => c = "0") b then a else s
wenzelm@51990
   218
    | _ => s)
wenzelm@51990
   219
  end;
wenzelm@51988
   220
wenzelm@38414
   221
wenzelm@23658
   222
(* basic markup *)
wenzelm@23623
   223
wenzelm@28017
   224
type T = string * Properties.T;
wenzelm@23637
   225
wenzelm@38474
   226
val empty = ("", []);
wenzelm@23637
   227
wenzelm@38474
   228
fun is_empty ("", _) = true
wenzelm@38474
   229
  | is_empty _ = false;
wenzelm@27883
   230
wenzelm@23794
   231
wenzelm@23671
   232
fun properties more_props ((elem, props): T) =
wenzelm@28017
   233
  (elem, fold_rev Properties.put more_props props);
wenzelm@23671
   234
wenzelm@55551
   235
fun markup_elem name = (name, (name, []): T);
wenzelm@55551
   236
fun markup_string name prop = (name, fn s => (name, [(prop, s)]): T);
wenzelm@55551
   237
fun markup_int name prop = (name, fn i => (name, [(prop, print_int i)]): T);
wenzelm@50201
   238
wenzelm@26977
   239
wenzelm@38721
   240
(* misc properties *)
wenzelm@26977
   241
wenzelm@23658
   242
val nameN = "name";
wenzelm@27818
   243
fun name a = properties [(nameN, a)];
wenzelm@27818
   244
wenzelm@23658
   245
val kindN = "kind";
wenzelm@23671
   246
wenzelm@52854
   247
val instanceN = "instance";
wenzelm@52854
   248
wenzelm@23658
   249
wenzelm@55550
   250
(* embedded languages *)
wenzelm@55550
   251
wenzelm@55615
   252
val symbolsN = "symbols";
wenzelm@55666
   253
val antiquotesN = "antiquotes";
wenzelm@55615
   254
val languageN = "language";
wenzelm@55666
   255
wenzelm@55666
   256
fun language {name, symbols, antiquotes} =
wenzelm@55666
   257
  (languageN,
wenzelm@55666
   258
    [(nameN, name), (symbolsN, print_bool symbols), (antiquotesN, print_bool antiquotes)]);
wenzelm@55550
   259
wenzelm@55666
   260
val language_sort = language {name = "sort", symbols = true, antiquotes = false};
wenzelm@55666
   261
val language_type = language {name = "type", symbols = true, antiquotes = false};
wenzelm@55666
   262
val language_term = language {name = "term", symbols = true, antiquotes = false};
wenzelm@55666
   263
val language_prop = language {name = "prop", symbols = true, antiquotes = false};
wenzelm@55666
   264
val language_ML = language {name = "ML", symbols = false, antiquotes = true};
wenzelm@55666
   265
val language_document = language {name = "document", symbols = false, antiquotes = true};
wenzelm@55666
   266
val language_antiquotation = language {name = "antiquotation", symbols = true, antiquotes = false};
wenzelm@55666
   267
val language_text = language {name = "text", symbols = true, antiquotes = false};
wenzelm@55666
   268
val language_rail = language {name = "rail", symbols = true, antiquotes = true};
wenzelm@55550
   269
wenzelm@55550
   270
wenzelm@50201
   271
(* formal entities *)
wenzelm@50201
   272
wenzelm@50201
   273
val (bindingN, binding) = markup_elem "binding";
wenzelm@50201
   274
wenzelm@50201
   275
val entityN = "entity";
wenzelm@50201
   276
fun entity kind name = (entityN, [(nameN, name), (kindN, kind)]);
wenzelm@50201
   277
wenzelm@50201
   278
fun get_entity_kind (name, props) =
wenzelm@50201
   279
  if name = entityN then AList.lookup (op =) props kindN
wenzelm@50201
   280
  else NONE;
wenzelm@50201
   281
wenzelm@50201
   282
val defN = "def";
wenzelm@50201
   283
val refN = "ref";
wenzelm@50201
   284
wenzelm@50201
   285
wenzelm@55672
   286
(* completion *)
wenzelm@55672
   287
wenzelm@55694
   288
val (completionN, completion) = markup_elem "completion";
wenzelm@55672
   289
wenzelm@55672
   290
wenzelm@50201
   291
(* position *)
wenzelm@50201
   292
wenzelm@50201
   293
val lineN = "line";
wenzelm@50201
   294
val offsetN = "offset";
wenzelm@50201
   295
val end_offsetN = "end_offset";
wenzelm@50201
   296
val fileN = "file";
wenzelm@50201
   297
val idN = "id";
wenzelm@50201
   298
wenzelm@50201
   299
val position_properties' = [fileN, idN];
wenzelm@50201
   300
val position_properties = [lineN, offsetN, end_offsetN] @ position_properties';
wenzelm@50201
   301
wenzelm@50201
   302
val (positionN, position) = markup_elem "position";
wenzelm@50201
   303
wenzelm@50201
   304
wenzelm@54702
   305
(* external resources *)
wenzelm@50201
   306
wenzelm@50201
   307
val (pathN, path) = markup_string "path" nameN;
wenzelm@54702
   308
val (urlN, url) = markup_string "url" nameN;
wenzelm@50201
   309
wenzelm@50201
   310
wenzelm@50201
   311
(* pretty printing *)
wenzelm@50201
   312
wenzelm@50201
   313
val indentN = "indent";
wenzelm@50201
   314
val (blockN, block) = markup_int "block" indentN;
wenzelm@50201
   315
wenzelm@50201
   316
val widthN = "width";
wenzelm@50201
   317
val (breakN, break) = markup_int "break" widthN;
wenzelm@50201
   318
wenzelm@50201
   319
val (fbreakN, fbreak) = markup_elem "fbreak";
wenzelm@50201
   320
wenzelm@51570
   321
val (itemN, item) = markup_elem "item";
wenzelm@51570
   322
wenzelm@50201
   323
wenzelm@50201
   324
(* hidden text *)
wenzelm@50201
   325
wenzelm@50201
   326
val (hiddenN, hidden) = markup_elem "hidden";
wenzelm@50201
   327
wenzelm@50201
   328
wenzelm@50201
   329
(* logical entities *)
wenzelm@50201
   330
wenzelm@50201
   331
val theoryN = "theory";
wenzelm@50201
   332
val classN = "class";
wenzelm@50201
   333
val type_nameN = "type_name";
wenzelm@50201
   334
val constantN = "constant";
wenzelm@50201
   335
wenzelm@50201
   336
val (fixedN, fixed) = markup_string "fixed" nameN;
wenzelm@53378
   337
val (caseN, case_) = markup_string "case" nameN;
wenzelm@50201
   338
val (dynamic_factN, dynamic_fact) = markup_string "dynamic_fact" nameN;
wenzelm@50201
   339
wenzelm@50201
   340
wenzelm@50201
   341
(* inner syntax *)
wenzelm@50201
   342
wenzelm@50201
   343
val (tfreeN, tfree) = markup_elem "tfree";
wenzelm@50201
   344
val (tvarN, tvar) = markup_elem "tvar";
wenzelm@50201
   345
val (freeN, free) = markup_elem "free";
wenzelm@50201
   346
val (skolemN, skolem) = markup_elem "skolem";
wenzelm@50201
   347
val (boundN, bound) = markup_elem "bound";
wenzelm@50201
   348
val (varN, var) = markup_elem "var";
wenzelm@50201
   349
val (numeralN, numeral) = markup_elem "numeral";
wenzelm@50201
   350
val (literalN, literal) = markup_elem "literal";
wenzelm@50201
   351
val (delimiterN, delimiter) = markup_elem "delimiter";
wenzelm@50201
   352
val (inner_stringN, inner_string) = markup_elem "inner_string";
wenzelm@55033
   353
val (inner_cartoucheN, inner_cartouche) = markup_elem "inner_cartouche";
wenzelm@50201
   354
val (inner_commentN, inner_comment) = markup_elem "inner_comment";
wenzelm@50201
   355
wenzelm@50201
   356
val (token_rangeN, token_range) = markup_elem "token_range";
wenzelm@50201
   357
wenzelm@50201
   358
val (sortingN, sorting) = markup_elem "sorting";
wenzelm@50201
   359
val (typingN, typing) = markup_elem "typing";
wenzelm@50201
   360
wenzelm@50201
   361
wenzelm@50201
   362
(* ML syntax *)
wenzelm@50201
   363
wenzelm@55505
   364
val (ML_keyword1N, ML_keyword1) = markup_elem "ML_keyword1";
wenzelm@55505
   365
val (ML_keyword2N, ML_keyword2) = markup_elem "ML_keyword2";
wenzelm@55505
   366
val (ML_keyword3N, ML_keyword3) = markup_elem "ML_keyword3";
wenzelm@50201
   367
val (ML_delimiterN, ML_delimiter) = markup_elem "ML_delimiter";
wenzelm@50201
   368
val (ML_tvarN, ML_tvar) = markup_elem "ML_tvar";
wenzelm@50201
   369
val (ML_numeralN, ML_numeral) = markup_elem "ML_numeral";
wenzelm@50201
   370
val (ML_charN, ML_char) = markup_elem "ML_char";
wenzelm@50201
   371
val (ML_stringN, ML_string) = markup_elem "ML_string";
wenzelm@50201
   372
val (ML_commentN, ML_comment) = markup_elem "ML_comment";
wenzelm@50201
   373
wenzelm@50201
   374
val ML_defN = "ML_def";
wenzelm@50201
   375
val ML_openN = "ML_open";
wenzelm@50201
   376
val ML_structN = "ML_struct";
wenzelm@50201
   377
val (ML_typingN, ML_typing) = markup_elem "ML_typing";
wenzelm@50201
   378
wenzelm@50201
   379
wenzelm@55550
   380
(* antiquotations *)
wenzelm@50201
   381
wenzelm@55526
   382
val (antiquotedN, antiquoted) = markup_elem "antiquoted";
wenzelm@55526
   383
val (antiquoteN, antiquote) = markup_elem "antiquote";
wenzelm@55526
   384
wenzelm@50201
   385
val ML_antiquotationN = "ML_antiquotation";
wenzelm@50201
   386
val document_antiquotationN = "document_antiquotation";
wenzelm@50201
   387
val document_antiquotation_optionN = "document_antiquotation_option";
wenzelm@50201
   388
wenzelm@50201
   389
wenzelm@50201
   390
(* text structure *)
wenzelm@50201
   391
wenzelm@50201
   392
val (paragraphN, paragraph) = markup_elem "paragraph";
wenzelm@50545
   393
val (text_foldN, text_fold) = markup_elem "text_fold";
wenzelm@50201
   394
wenzelm@50201
   395
wenzelm@50201
   396
(* outer syntax *)
wenzelm@50201
   397
wenzelm@55744
   398
val commandN = "command";
wenzelm@55744
   399
wenzelm@55744
   400
val (keyword1N, keyword1) = markup_elem "keyword1";
wenzelm@55744
   401
val (keyword2N, keyword2) = markup_elem "keyword2";
wenzelm@50201
   402
val (operatorN, operator) = markup_elem "operator";
wenzelm@50201
   403
val (stringN, string) = markup_elem "string";
wenzelm@50201
   404
val (altstringN, altstring) = markup_elem "altstring";
wenzelm@50201
   405
val (verbatimN, verbatim) = markup_elem "verbatim";
wenzelm@55033
   406
val (cartoucheN, cartouche) = markup_elem "cartouche";
wenzelm@50201
   407
val (commentN, comment) = markup_elem "comment";
wenzelm@50201
   408
val (controlN, control) = markup_elem "control";
wenzelm@50201
   409
wenzelm@50201
   410
val tokenN = "token";
wenzelm@50201
   411
fun token props = (tokenN, props);
wenzelm@50201
   412
wenzelm@50201
   413
wenzelm@50201
   414
(* timing *)
wenzelm@50201
   415
wenzelm@50201
   416
val elapsedN = "elapsed";
wenzelm@50201
   417
val cpuN = "cpu";
wenzelm@50201
   418
val gcN = "gc";
wenzelm@50201
   419
wenzelm@50781
   420
fun timing_properties {elapsed, cpu, gc} =
wenzelm@50781
   421
 [(elapsedN, Time.toString elapsed),
wenzelm@50781
   422
  (cpuN, Time.toString cpu),
wenzelm@50781
   423
  (gcN, Time.toString gc)];
wenzelm@50781
   424
wenzelm@51665
   425
fun parse_timing_properties props =
wenzelm@51665
   426
 {elapsed = Properties.seconds props elapsedN,
wenzelm@51665
   427
  cpu = Properties.seconds props cpuN,
wenzelm@51665
   428
  gc = Properties.seconds props gcN};
wenzelm@51218
   429
wenzelm@51665
   430
val timingN = "timing";
wenzelm@51665
   431
fun timing t = (timingN, timing_properties t);
wenzelm@51218
   432
wenzelm@51228
   433
wenzelm@51228
   434
(* command timing *)
wenzelm@51228
   435
wenzelm@51228
   436
val command_timingN = "command_timing";
wenzelm@51228
   437
wenzelm@51228
   438
fun command_timing_properties {file, offset, name} elapsed =
wenzelm@51228
   439
 [(fileN, file), (offsetN, print_int offset),
wenzelm@51228
   440
  (nameN, name), (elapsedN, Time.toString elapsed)];
wenzelm@51228
   441
wenzelm@51228
   442
fun parse_command_timing_properties props =
wenzelm@51228
   443
  (case (Properties.get props fileN, Properties.get props offsetN, Properties.get props nameN) of
wenzelm@51228
   444
    (SOME file, SOME offset, SOME name) =>
wenzelm@51665
   445
      SOME ({file = file, offset = parse_int offset, name = name},
wenzelm@51665
   446
        Properties.seconds props elapsedN)
wenzelm@51228
   447
  | _ => NONE);
wenzelm@51228
   448
wenzelm@51228
   449
wenzelm@50201
   450
(* toplevel *)
wenzelm@50201
   451
wenzelm@50201
   452
val subgoalsN = "subgoals";
wenzelm@50201
   453
val (proof_stateN, proof_state) = markup_int "proof_state" subgoalsN;
wenzelm@50201
   454
wenzelm@50201
   455
val (stateN, state) = markup_elem "state";
wenzelm@50543
   456
val (goalN, goal) = markup_elem "goal";
wenzelm@50537
   457
val (subgoalN, subgoal) = markup_string "subgoal" nameN;
wenzelm@50215
   458
wenzelm@50450
   459
wenzelm@50201
   460
(* command status *)
wenzelm@50201
   461
wenzelm@50201
   462
val taskN = "task";
wenzelm@50201
   463
wenzelm@50201
   464
val (acceptedN, accepted) = markup_elem "accepted";
wenzelm@50201
   465
val (forkedN, forked) = markup_elem "forked";
wenzelm@50201
   466
val (joinedN, joined) = markup_elem "joined";
wenzelm@50201
   467
val (runningN, running) = markup_elem "running";
wenzelm@50201
   468
val (finishedN, finished) = markup_elem "finished";
wenzelm@50201
   469
val (failedN, failed) = markup_elem "failed";
wenzelm@50201
   470
wenzelm@50201
   471
wenzelm@50201
   472
(* messages *)
wenzelm@50201
   473
wenzelm@50201
   474
val serialN = "serial";
wenzelm@52854
   475
fun serial_properties i = [(serialN, print_int i)];
wenzelm@52854
   476
wenzelm@50914
   477
val exec_idN = "exec_id";
wenzelm@50201
   478
wenzelm@50201
   479
val initN = "init";
wenzelm@50201
   480
val statusN = "status";
wenzelm@50503
   481
val resultN = "result";
wenzelm@50201
   482
val writelnN = "writeln";
wenzelm@50201
   483
val tracingN = "tracing";
wenzelm@50201
   484
val warningN = "warning";
wenzelm@50201
   485
val errorN = "error";
wenzelm@50201
   486
val protocolN = "protocol";
wenzelm@50201
   487
wenzelm@50201
   488
val (legacyN, legacy) = markup_elem "legacy";
wenzelm@50201
   489
val (promptN, prompt) = markup_elem "prompt";
wenzelm@50201
   490
wenzelm@50201
   491
val (reportN, report) = markup_elem "report";
wenzelm@50201
   492
val (no_reportN, no_report) = markup_elem "no_report";
wenzelm@50201
   493
wenzelm@50201
   494
val (badN, bad) = markup_elem "bad";
wenzelm@50201
   495
wenzelm@50500
   496
val (intensifyN, intensify) = markup_elem "intensify";
wenzelm@52643
   497
val (informationN, information) = markup_elem "information";
wenzelm@50500
   498
wenzelm@50500
   499
wenzelm@50500
   500
(* active areas *)
wenzelm@50500
   501
wenzelm@50715
   502
val browserN = "browser"
wenzelm@50500
   503
val graphviewN = "graphview";
wenzelm@50500
   504
wenzelm@50500
   505
val sendbackN = "sendback";
wenzelm@50500
   506
val paddingN = "padding";
wenzelm@52697
   507
val padding_line = (paddingN, "line");
wenzelm@52697
   508
val padding_command = (paddingN, "command");
wenzelm@50500
   509
wenzelm@50500
   510
val dialogN = "dialog";
wenzelm@50503
   511
fun dialog i result = (dialogN, [(serialN, print_int i), (resultN, result)]);
wenzelm@50500
   512
wenzelm@50201
   513
wenzelm@50201
   514
(* protocol message functions *)
wenzelm@50201
   515
wenzelm@50201
   516
val functionN = "function"
wenzelm@50201
   517
wenzelm@52800
   518
val flush = [(functionN, "flush")];
wenzelm@52800
   519
wenzelm@52563
   520
val assign_update = [(functionN, "assign_update")];
wenzelm@50201
   521
val removed_versions = [(functionN, "removed_versions")];
wenzelm@50201
   522
wenzelm@52111
   523
fun protocol_handler name = [(functionN, "protocol_handler"), (nameN, name)];
wenzelm@52111
   524
wenzelm@50201
   525
fun invoke_scala name id = [(functionN, "invoke_scala"), (nameN, name), (idN, id)];
wenzelm@50201
   526
fun cancel_scala id = [(functionN, "cancel_scala"), (idN, id)];
wenzelm@50201
   527
wenzelm@53055
   528
val sledgehammer_provers = [(functionN, "sledgehammer_provers")];
wenzelm@53055
   529
wenzelm@50683
   530
val ML_statistics = (functionN, "ML_statistics");
wenzelm@50255
   531
wenzelm@50975
   532
val task_statistics = (functionN, "task_statistics");
wenzelm@50975
   533
wenzelm@51216
   534
val command_timing = (functionN, "command_timing");
wenzelm@51216
   535
wenzelm@50845
   536
fun loading_theory name = [("function", "loading_theory"), ("name", name)];
wenzelm@50845
   537
wenzelm@50845
   538
fun dest_loading_theory [("function", "loading_theory"), ("name", name)] = SOME name
wenzelm@50845
   539
  | dest_loading_theory _ = NONE;
wenzelm@50845
   540
wenzelm@50201
   541
wenzelm@55553
   542
(* simplifier trace *)
wenzelm@55553
   543
wenzelm@55553
   544
val simp_trace_logN = "simp_trace_log";
wenzelm@55553
   545
val simp_trace_stepN = "simp_trace_step";
wenzelm@55553
   546
val simp_trace_recurseN = "simp_trace_recurse";
wenzelm@55553
   547
val simp_trace_hintN = "simp_trace_hint";
wenzelm@55553
   548
val simp_trace_ignoreN = "simp_trace_ignore";
wenzelm@55553
   549
wenzelm@55553
   550
fun simp_trace_cancel i = [(functionN, "simp_trace_cancel"), (serialN, print_int i)];
wenzelm@55553
   551
wenzelm@27969
   552
wenzelm@55672
   553
wenzelm@30221
   554
(** print mode operations **)
wenzelm@23704
   555
wenzelm@29325
   556
val no_output = ("", "");
wenzelm@29325
   557
fun default_output (_: T) = no_output;
wenzelm@23704
   558
wenzelm@23704
   559
local
wenzelm@23704
   560
  val default = {output = default_output};
wenzelm@43684
   561
  val modes = Synchronized.var "Markup.modes" (Symtab.make [("", default)]);
wenzelm@23704
   562
in
wenzelm@43684
   563
  fun add_mode name output =
wenzelm@46894
   564
    Synchronized.change modes (fn tab =>
wenzelm@46894
   565
      (if not (Symtab.defined tab name) then ()
wenzelm@46894
   566
       else warning ("Redefining markup mode " ^ quote name);
wenzelm@46894
   567
       Symtab.update (name, {output = output}) tab));
wenzelm@23704
   568
  fun get_mode () =
wenzelm@43684
   569
    the_default default
wenzelm@43684
   570
      (Library.get_first (Symtab.lookup (Synchronized.value modes)) (print_mode_value ()));
wenzelm@23623
   571
end;
wenzelm@23704
   572
wenzelm@38474
   573
fun output m = if is_empty m then no_output else #output (get_mode ()) m;
wenzelm@23704
   574
wenzelm@23719
   575
val enclose = output #-> Library.enclose;
wenzelm@23719
   576
wenzelm@25552
   577
fun markup m =
wenzelm@25552
   578
  let val (bg, en) = output m
wenzelm@25552
   579
  in Library.enclose (Output.escape bg) (Output.escape en) end;
wenzelm@25552
   580
wenzelm@43665
   581
fun markup_only m = markup m "";
wenzelm@43665
   582
wenzelm@23704
   583
end;