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