src/Pure/PIDE/markup.ML
author wenzelm
Wed Dec 03 14:04:38 2014 +0100 (2014-12-03 ago)
changeset 59083 88b0b1f28adc
parent 59081 2ceb05ee0331
child 59112 e670969f34df
permissions -rw-r--r--
tuned signature;
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@58978
    50
  val end_lineN: string
wenzelm@50201
    51
  val offsetN: string
wenzelm@50201
    52
  val end_offsetN: string
wenzelm@50201
    53
  val fileN: string
wenzelm@50201
    54
  val idN: string
wenzelm@50201
    55
  val position_properties': string list
wenzelm@50201
    56
  val position_properties: string list
wenzelm@50201
    57
  val positionN: string val position: T
wenzelm@58464
    58
  val expressionN: string val expression: T
wenzelm@58545
    59
  val citationN: string val citation: string -> T
wenzelm@50201
    60
  val pathN: string val path: string -> T
wenzelm@54702
    61
  val urlN: string val url: string -> T
wenzelm@50201
    62
  val indentN: string
wenzelm@50201
    63
  val blockN: string val block: int -> T
wenzelm@50201
    64
  val widthN: string
wenzelm@50201
    65
  val breakN: string val break: int -> T
wenzelm@50201
    66
  val fbreakN: string val fbreak: T
wenzelm@51570
    67
  val itemN: string val item: T
wenzelm@56548
    68
  val wordsN: string val words: T
wenzelm@50201
    69
  val hiddenN: string val hidden: T
wenzelm@56465
    70
  val system_optionN: string
wenzelm@50201
    71
  val theoryN: string
wenzelm@50201
    72
  val classN: string
wenzelm@50201
    73
  val type_nameN: string
wenzelm@50201
    74
  val constantN: string
wenzelm@50201
    75
  val fixedN: string val fixed: string -> T
wenzelm@53378
    76
  val caseN: string val case_: string -> T
wenzelm@50201
    77
  val dynamic_factN: string val dynamic_fact: string -> T
wenzelm@58048
    78
  val method_modifierN: string
wenzelm@50201
    79
  val tfreeN: string val tfree: T
wenzelm@50201
    80
  val tvarN: string val tvar: T
wenzelm@50201
    81
  val freeN: string val free: T
wenzelm@50201
    82
  val skolemN: string val skolem: T
wenzelm@50201
    83
  val boundN: string val bound: T
wenzelm@50201
    84
  val varN: string val var: T
wenzelm@50201
    85
  val numeralN: string val numeral: T
wenzelm@50201
    86
  val literalN: string val literal: T
wenzelm@50201
    87
  val delimiterN: string val delimiter: T
wenzelm@50201
    88
  val inner_stringN: string val inner_string: T
wenzelm@55033
    89
  val inner_cartoucheN: string val inner_cartouche: T
wenzelm@50201
    90
  val inner_commentN: string val inner_comment: T
wenzelm@50201
    91
  val token_rangeN: string val token_range: T
wenzelm@50201
    92
  val sortingN: string val sorting: T
wenzelm@50201
    93
  val typingN: string val typing: T
wenzelm@55505
    94
  val ML_keyword1N: string val ML_keyword1: T
wenzelm@55505
    95
  val ML_keyword2N: string val ML_keyword2: T
wenzelm@55505
    96
  val ML_keyword3N: string val ML_keyword3: T
wenzelm@50201
    97
  val ML_delimiterN: string val ML_delimiter: T
wenzelm@50201
    98
  val ML_tvarN: string val ML_tvar: T
wenzelm@50201
    99
  val ML_numeralN: string val ML_numeral: T
wenzelm@50201
   100
  val ML_charN: string val ML_char: T
wenzelm@50201
   101
  val ML_stringN: string val ML_string: T
wenzelm@50201
   102
  val ML_commentN: string val ML_comment: T
wenzelm@56278
   103
  val SML_stringN: string val SML_string: T
wenzelm@56278
   104
  val SML_commentN: string val SML_comment: T
wenzelm@50201
   105
  val ML_defN: string
wenzelm@50201
   106
  val ML_openN: string
wenzelm@55837
   107
  val ML_structureN: string
wenzelm@50201
   108
  val ML_typingN: string val ML_typing: T
wenzelm@55526
   109
  val antiquotedN: string val antiquoted: T
wenzelm@55526
   110
  val antiquoteN: string val antiquote: T
wenzelm@50201
   111
  val ML_antiquotationN: string
wenzelm@50201
   112
  val document_antiquotationN: string
wenzelm@50201
   113
  val document_antiquotation_optionN: string
wenzelm@50201
   114
  val paragraphN: string val paragraph: T
wenzelm@50545
   115
  val text_foldN: string val text_fold: T
wenzelm@55750
   116
  val commandN: string val command: T
wenzelm@50201
   117
  val stringN: string val string: T
wenzelm@59081
   118
  val alt_stringN: string val alt_string: T
wenzelm@50201
   119
  val verbatimN: string val verbatim: T
wenzelm@55033
   120
  val cartoucheN: string val cartouche: T
wenzelm@50201
   121
  val commentN: string val comment: 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 reportN: string val report: T
wenzelm@50201
   166
  val no_reportN: string val no_report: T
wenzelm@50201
   167
  val badN: string val bad: T
wenzelm@50500
   168
  val intensifyN: string val intensify: T
wenzelm@52643
   169
  val informationN: string val information: T
wenzelm@50715
   170
  val browserN: string
wenzelm@50500
   171
  val graphviewN: string
wenzelm@50500
   172
  val sendbackN: string
wenzelm@50500
   173
  val paddingN: string
wenzelm@50842
   174
  val padding_line: Properties.entry
wenzelm@52697
   175
  val padding_command: Properties.entry
wenzelm@50500
   176
  val dialogN: string val dialog: serial -> string -> T
wenzelm@50201
   177
  val functionN: string
wenzelm@52563
   178
  val assign_update: Properties.T
wenzelm@50201
   179
  val removed_versions: Properties.T
wenzelm@52111
   180
  val protocol_handler: string -> Properties.T
wenzelm@50201
   181
  val invoke_scala: string -> string -> Properties.T
wenzelm@50201
   182
  val cancel_scala: string -> Properties.T
wenzelm@50842
   183
  val ML_statistics: Properties.entry
wenzelm@50975
   184
  val task_statistics: Properties.entry
wenzelm@51216
   185
  val command_timing: Properties.entry
wenzelm@50845
   186
  val loading_theory: string -> Properties.T
wenzelm@50845
   187
  val dest_loading_theory: Properties.T -> string option
wenzelm@56616
   188
  val use_theories_result: string -> bool -> Properties.T
wenzelm@56864
   189
  val print_operationsN: string
wenzelm@56864
   190
  val print_operations: Properties.T
wenzelm@57597
   191
  val simp_trace_panelN: string
wenzelm@55555
   192
  val simp_trace_logN: string
wenzelm@55555
   193
  val simp_trace_stepN: string
wenzelm@55555
   194
  val simp_trace_recurseN: string
wenzelm@55555
   195
  val simp_trace_hintN: string
wenzelm@55555
   196
  val simp_trace_ignoreN: string
wenzelm@55555
   197
  val simp_trace_cancel: serial -> Properties.T
wenzelm@40131
   198
  val no_output: Output.output * Output.output
wenzelm@40131
   199
  val default_output: T -> Output.output * Output.output
wenzelm@40131
   200
  val add_mode: string -> (T -> Output.output * Output.output) -> unit
wenzelm@40131
   201
  val output: T -> Output.output * Output.output
wenzelm@40131
   202
  val enclose: T -> Output.output -> Output.output
wenzelm@25552
   203
  val markup: T -> string -> string
wenzelm@43665
   204
  val markup_only: T -> string
wenzelm@55956
   205
  val markup_report: string -> string
wenzelm@23623
   206
end;
wenzelm@23623
   207
wenzelm@23623
   208
structure Markup: MARKUP =
wenzelm@23623
   209
struct
wenzelm@23623
   210
wenzelm@30221
   211
(** markup elements **)
wenzelm@30221
   212
wenzelm@51988
   213
(* misc values *)
wenzelm@51951
   214
wenzelm@51951
   215
fun parse_bool "true" = true
wenzelm@51951
   216
  | parse_bool "false" = false
wenzelm@51951
   217
  | parse_bool s = raise Fail ("Bad boolean: " ^ quote s);
wenzelm@51951
   218
wenzelm@51951
   219
val print_bool = Bool.toString;
wenzelm@51951
   220
wenzelm@38414
   221
fun parse_int s =
wenzelm@43797
   222
  let val i = Int.fromString s in
wenzelm@43797
   223
    if is_none i orelse String.isPrefix "~" s
wenzelm@43797
   224
    then raise Fail ("Bad integer: " ^ quote s)
wenzelm@43797
   225
    else the i
wenzelm@43797
   226
  end;
wenzelm@38414
   227
wenzelm@38414
   228
val print_int = signed_string_of_int;
wenzelm@38414
   229
wenzelm@51988
   230
fun parse_real s =
wenzelm@51988
   231
  (case Real.fromString s of
wenzelm@51988
   232
    SOME x => x
wenzelm@51988
   233
  | NONE => raise Fail ("Bad real: " ^ quote s));
wenzelm@51988
   234
wenzelm@51990
   235
fun print_real x =
wenzelm@51990
   236
  let val s = signed_string_of_real x in
wenzelm@51990
   237
    (case space_explode "." s of
wenzelm@51990
   238
      [a, b] => if forall_string (fn c => c = "0") b then a else s
wenzelm@51990
   239
    | _ => s)
wenzelm@51990
   240
  end;
wenzelm@51988
   241
wenzelm@38414
   242
wenzelm@23658
   243
(* basic markup *)
wenzelm@23623
   244
wenzelm@28017
   245
type T = string * Properties.T;
wenzelm@23637
   246
wenzelm@38474
   247
val empty = ("", []);
wenzelm@23637
   248
wenzelm@38474
   249
fun is_empty ("", _) = true
wenzelm@38474
   250
  | is_empty _ = false;
wenzelm@27883
   251
wenzelm@23794
   252
wenzelm@23671
   253
fun properties more_props ((elem, props): T) =
wenzelm@28017
   254
  (elem, fold_rev Properties.put more_props props);
wenzelm@23671
   255
wenzelm@55553
   256
fun markup_elem name = (name, (name, []): T);
wenzelm@55553
   257
fun markup_string name prop = (name, fn s => (name, [(prop, s)]): T);
wenzelm@55553
   258
fun markup_int name prop = (name, fn i => (name, [(prop, print_int i)]): T);
wenzelm@50201
   259
wenzelm@26977
   260
wenzelm@38721
   261
(* misc properties *)
wenzelm@26977
   262
wenzelm@23658
   263
val nameN = "name";
wenzelm@27818
   264
fun name a = properties [(nameN, a)];
wenzelm@27818
   265
wenzelm@23658
   266
val kindN = "kind";
wenzelm@23671
   267
wenzelm@52854
   268
val instanceN = "instance";
wenzelm@52854
   269
wenzelm@23658
   270
wenzelm@55552
   271
(* embedded languages *)
wenzelm@55552
   272
wenzelm@55828
   273
val languageN = "language";
wenzelm@55615
   274
val symbolsN = "symbols";
wenzelm@55666
   275
val antiquotesN = "antiquotes";
wenzelm@55828
   276
val delimitedN = "delimited"
wenzelm@55828
   277
wenzelm@55828
   278
fun is_delimited props =
wenzelm@55828
   279
  Properties.get props delimitedN = SOME "true";
wenzelm@55666
   280
wenzelm@55828
   281
fun language {name, symbols, antiquotes, delimited} =
wenzelm@55666
   282
  (languageN,
wenzelm@55828
   283
   [(nameN, name),
wenzelm@55828
   284
    (symbolsN, print_bool symbols),
wenzelm@55828
   285
    (antiquotesN, print_bool antiquotes),
wenzelm@55828
   286
    (delimitedN, print_bool delimited)]);
wenzelm@55552
   287
wenzelm@55828
   288
fun language' {name, symbols, antiquotes} delimited =
wenzelm@55828
   289
  language {name = name, symbols = symbols, antiquotes = antiquotes, delimited = delimited};
wenzelm@55828
   290
wenzelm@55828
   291
val language_method =
wenzelm@55828
   292
  language {name = "method", symbols = true, antiquotes = false, delimited = false};
wenzelm@56033
   293
val language_attribute =
wenzelm@56033
   294
  language {name = "attribute", symbols = true, antiquotes = false, delimited = false};
wenzelm@55828
   295
val language_sort = language' {name = "sort", symbols = true, antiquotes = false};
wenzelm@55828
   296
val language_type = language' {name = "type", symbols = true, antiquotes = false};
wenzelm@55828
   297
val language_term = language' {name = "term", symbols = true, antiquotes = false};
wenzelm@55828
   298
val language_prop = language' {name = "prop", symbols = true, antiquotes = false};
wenzelm@55828
   299
val language_ML = language' {name = "ML", symbols = false, antiquotes = true};
wenzelm@56278
   300
val language_SML = language' {name = "SML", symbols = false, antiquotes = false};
wenzelm@55828
   301
val language_document = language' {name = "document", symbols = false, antiquotes = true};
wenzelm@55828
   302
val language_antiquotation =
wenzelm@55828
   303
  language {name = "antiquotation", symbols = true, antiquotes = false, delimited = true};
wenzelm@55828
   304
val language_text = language' {name = "text", symbols = true, antiquotes = false};
wenzelm@55828
   305
val language_rail = language {name = "rail", symbols = true, antiquotes = true, delimited = true};
wenzelm@56034
   306
val language_path = language {name = "path", symbols = false, antiquotes = false, delimited = true};
wenzelm@55552
   307
wenzelm@55552
   308
wenzelm@50201
   309
(* formal entities *)
wenzelm@50201
   310
wenzelm@50201
   311
val (bindingN, binding) = markup_elem "binding";
wenzelm@50201
   312
wenzelm@50201
   313
val entityN = "entity";
wenzelm@50201
   314
fun entity kind name = (entityN, [(nameN, name), (kindN, kind)]);
wenzelm@50201
   315
wenzelm@50201
   316
fun get_entity_kind (name, props) =
wenzelm@50201
   317
  if name = entityN then AList.lookup (op =) props kindN
wenzelm@50201
   318
  else NONE;
wenzelm@50201
   319
wenzelm@50201
   320
val defN = "def";
wenzelm@50201
   321
val refN = "ref";
wenzelm@50201
   322
wenzelm@50201
   323
wenzelm@55672
   324
(* completion *)
wenzelm@55672
   325
wenzelm@55694
   326
val (completionN, completion) = markup_elem "completion";
wenzelm@55914
   327
val (no_completionN, no_completion) = markup_elem "no_completion";
wenzelm@55672
   328
wenzelm@55672
   329
wenzelm@50201
   330
(* position *)
wenzelm@50201
   331
wenzelm@50201
   332
val lineN = "line";
wenzelm@58978
   333
val end_lineN = "end_line";
wenzelm@58978
   334
wenzelm@50201
   335
val offsetN = "offset";
wenzelm@50201
   336
val end_offsetN = "end_offset";
wenzelm@58978
   337
wenzelm@50201
   338
val fileN = "file";
wenzelm@50201
   339
val idN = "id";
wenzelm@50201
   340
wenzelm@50201
   341
val position_properties' = [fileN, idN];
wenzelm@50201
   342
val position_properties = [lineN, offsetN, end_offsetN] @ position_properties';
wenzelm@50201
   343
wenzelm@50201
   344
val (positionN, position) = markup_elem "position";
wenzelm@50201
   345
wenzelm@50201
   346
wenzelm@58464
   347
(* expression *)
wenzelm@58464
   348
wenzelm@58464
   349
val (expressionN, expression) = markup_elem "expression";
wenzelm@58464
   350
wenzelm@58464
   351
wenzelm@58544
   352
(* citation *)
wenzelm@58544
   353
wenzelm@58545
   354
val (citationN, citation) = markup_string "citation" nameN;
wenzelm@58544
   355
wenzelm@58544
   356
wenzelm@54702
   357
(* external resources *)
wenzelm@50201
   358
wenzelm@50201
   359
val (pathN, path) = markup_string "path" nameN;
wenzelm@54702
   360
val (urlN, url) = markup_string "url" nameN;
wenzelm@50201
   361
wenzelm@50201
   362
wenzelm@50201
   363
(* pretty printing *)
wenzelm@50201
   364
wenzelm@50201
   365
val indentN = "indent";
wenzelm@50201
   366
val (blockN, block) = markup_int "block" indentN;
wenzelm@50201
   367
wenzelm@50201
   368
val widthN = "width";
wenzelm@50201
   369
val (breakN, break) = markup_int "break" widthN;
wenzelm@50201
   370
wenzelm@50201
   371
val (fbreakN, fbreak) = markup_elem "fbreak";
wenzelm@50201
   372
wenzelm@51570
   373
val (itemN, item) = markup_elem "item";
wenzelm@51570
   374
wenzelm@50201
   375
wenzelm@56548
   376
(* text properties *)
wenzelm@56548
   377
wenzelm@56548
   378
val (wordsN, words) = markup_elem "words";
wenzelm@50201
   379
wenzelm@50201
   380
val (hiddenN, hidden) = markup_elem "hidden";
wenzelm@50201
   381
wenzelm@50201
   382
wenzelm@58048
   383
(* misc entities *)
wenzelm@56465
   384
wenzelm@56465
   385
val system_optionN = "system_option";
wenzelm@50201
   386
wenzelm@50201
   387
val theoryN = "theory";
wenzelm@50201
   388
val classN = "class";
wenzelm@50201
   389
val type_nameN = "type_name";
wenzelm@50201
   390
val constantN = "constant";
wenzelm@50201
   391
wenzelm@50201
   392
val (fixedN, fixed) = markup_string "fixed" nameN;
wenzelm@53378
   393
val (caseN, case_) = markup_string "case" nameN;
wenzelm@50201
   394
val (dynamic_factN, dynamic_fact) = markup_string "dynamic_fact" nameN;
wenzelm@50201
   395
wenzelm@58048
   396
val method_modifierN = "method_modifier";
wenzelm@58048
   397
wenzelm@50201
   398
wenzelm@50201
   399
(* inner syntax *)
wenzelm@50201
   400
wenzelm@50201
   401
val (tfreeN, tfree) = markup_elem "tfree";
wenzelm@50201
   402
val (tvarN, tvar) = markup_elem "tvar";
wenzelm@50201
   403
val (freeN, free) = markup_elem "free";
wenzelm@50201
   404
val (skolemN, skolem) = markup_elem "skolem";
wenzelm@50201
   405
val (boundN, bound) = markup_elem "bound";
wenzelm@50201
   406
val (varN, var) = markup_elem "var";
wenzelm@50201
   407
val (numeralN, numeral) = markup_elem "numeral";
wenzelm@50201
   408
val (literalN, literal) = markup_elem "literal";
wenzelm@50201
   409
val (delimiterN, delimiter) = markup_elem "delimiter";
wenzelm@50201
   410
val (inner_stringN, inner_string) = markup_elem "inner_string";
wenzelm@55033
   411
val (inner_cartoucheN, inner_cartouche) = markup_elem "inner_cartouche";
wenzelm@50201
   412
val (inner_commentN, inner_comment) = markup_elem "inner_comment";
wenzelm@50201
   413
wenzelm@50201
   414
val (token_rangeN, token_range) = markup_elem "token_range";
wenzelm@50201
   415
wenzelm@50201
   416
val (sortingN, sorting) = markup_elem "sorting";
wenzelm@50201
   417
val (typingN, typing) = markup_elem "typing";
wenzelm@50201
   418
wenzelm@50201
   419
wenzelm@50201
   420
(* ML syntax *)
wenzelm@50201
   421
wenzelm@55505
   422
val (ML_keyword1N, ML_keyword1) = markup_elem "ML_keyword1";
wenzelm@55505
   423
val (ML_keyword2N, ML_keyword2) = markup_elem "ML_keyword2";
wenzelm@55505
   424
val (ML_keyword3N, ML_keyword3) = markup_elem "ML_keyword3";
wenzelm@50201
   425
val (ML_delimiterN, ML_delimiter) = markup_elem "ML_delimiter";
wenzelm@50201
   426
val (ML_tvarN, ML_tvar) = markup_elem "ML_tvar";
wenzelm@50201
   427
val (ML_numeralN, ML_numeral) = markup_elem "ML_numeral";
wenzelm@50201
   428
val (ML_charN, ML_char) = markup_elem "ML_char";
wenzelm@50201
   429
val (ML_stringN, ML_string) = markup_elem "ML_string";
wenzelm@50201
   430
val (ML_commentN, ML_comment) = markup_elem "ML_comment";
wenzelm@56278
   431
val (SML_stringN, SML_string) = markup_elem "SML_string";
wenzelm@56278
   432
val (SML_commentN, SML_comment) = markup_elem "SML_comment";
wenzelm@50201
   433
wenzelm@50201
   434
val ML_defN = "ML_def";
wenzelm@50201
   435
val ML_openN = "ML_open";
wenzelm@55837
   436
val ML_structureN = "ML_structure";
wenzelm@50201
   437
val (ML_typingN, ML_typing) = markup_elem "ML_typing";
wenzelm@50201
   438
wenzelm@50201
   439
wenzelm@55552
   440
(* antiquotations *)
wenzelm@50201
   441
wenzelm@55526
   442
val (antiquotedN, antiquoted) = markup_elem "antiquoted";
wenzelm@55526
   443
val (antiquoteN, antiquote) = markup_elem "antiquote";
wenzelm@55526
   444
wenzelm@50201
   445
val ML_antiquotationN = "ML_antiquotation";
wenzelm@50201
   446
val document_antiquotationN = "document_antiquotation";
wenzelm@50201
   447
val document_antiquotation_optionN = "document_antiquotation_option";
wenzelm@50201
   448
wenzelm@50201
   449
wenzelm@50201
   450
(* text structure *)
wenzelm@50201
   451
wenzelm@50201
   452
val (paragraphN, paragraph) = markup_elem "paragraph";
wenzelm@50545
   453
val (text_foldN, text_fold) = markup_elem "text_fold";
wenzelm@50201
   454
wenzelm@50201
   455
wenzelm@50201
   456
(* outer syntax *)
wenzelm@50201
   457
wenzelm@55750
   458
val (commandN, command) = markup_elem "command";
wenzelm@55744
   459
val (keyword1N, keyword1) = markup_elem "keyword1";
wenzelm@55744
   460
val (keyword2N, keyword2) = markup_elem "keyword2";
wenzelm@55763
   461
val (keyword3N, keyword3) = markup_elem "keyword3";
wenzelm@55919
   462
val (quasi_keywordN, quasi_keyword) = markup_elem "quasi_keyword";
wenzelm@56202
   463
val (improperN, improper) = markup_elem "improper";
wenzelm@50201
   464
val (operatorN, operator) = markup_elem "operator";
wenzelm@50201
   465
val (stringN, string) = markup_elem "string";
wenzelm@59081
   466
val (alt_stringN, alt_string) = markup_elem "alt_string";
wenzelm@50201
   467
val (verbatimN, verbatim) = markup_elem "verbatim";
wenzelm@55033
   468
val (cartoucheN, cartouche) = markup_elem "cartouche";
wenzelm@50201
   469
val (commentN, comment) = markup_elem "comment";
wenzelm@50201
   470
wenzelm@50201
   471
val tokenN = "token";
wenzelm@55828
   472
fun token delimited props = (tokenN, (delimitedN, print_bool delimited) :: props);
wenzelm@50201
   473
wenzelm@50201
   474
wenzelm@50201
   475
(* timing *)
wenzelm@50201
   476
wenzelm@50201
   477
val elapsedN = "elapsed";
wenzelm@50201
   478
val cpuN = "cpu";
wenzelm@50201
   479
val gcN = "gc";
wenzelm@50201
   480
wenzelm@50781
   481
fun timing_properties {elapsed, cpu, gc} =
wenzelm@50781
   482
 [(elapsedN, Time.toString elapsed),
wenzelm@50781
   483
  (cpuN, Time.toString cpu),
wenzelm@50781
   484
  (gcN, Time.toString gc)];
wenzelm@50781
   485
wenzelm@51665
   486
fun parse_timing_properties props =
wenzelm@51665
   487
 {elapsed = Properties.seconds props elapsedN,
wenzelm@51665
   488
  cpu = Properties.seconds props cpuN,
wenzelm@51665
   489
  gc = Properties.seconds props gcN};
wenzelm@51218
   490
wenzelm@51665
   491
val timingN = "timing";
wenzelm@51665
   492
fun timing t = (timingN, timing_properties t);
wenzelm@51218
   493
wenzelm@51228
   494
wenzelm@51228
   495
(* command timing *)
wenzelm@51228
   496
wenzelm@51228
   497
val command_timingN = "command_timing";
wenzelm@51228
   498
wenzelm@51228
   499
fun command_timing_properties {file, offset, name} elapsed =
wenzelm@51228
   500
 [(fileN, file), (offsetN, print_int offset),
wenzelm@51228
   501
  (nameN, name), (elapsedN, Time.toString elapsed)];
wenzelm@51228
   502
wenzelm@51228
   503
fun parse_command_timing_properties props =
wenzelm@51228
   504
  (case (Properties.get props fileN, Properties.get props offsetN, Properties.get props nameN) of
wenzelm@51228
   505
    (SOME file, SOME offset, SOME name) =>
wenzelm@51665
   506
      SOME ({file = file, offset = parse_int offset, name = name},
wenzelm@51665
   507
        Properties.seconds props elapsedN)
wenzelm@51228
   508
  | _ => NONE);
wenzelm@51228
   509
wenzelm@51228
   510
wenzelm@50201
   511
(* toplevel *)
wenzelm@50201
   512
wenzelm@50201
   513
val subgoalsN = "subgoals";
wenzelm@50201
   514
val (proof_stateN, proof_state) = markup_int "proof_state" subgoalsN;
wenzelm@50201
   515
wenzelm@50201
   516
val (stateN, state) = markup_elem "state";
wenzelm@50543
   517
val (goalN, goal) = markup_elem "goal";
wenzelm@50537
   518
val (subgoalN, subgoal) = markup_string "subgoal" nameN;
wenzelm@50215
   519
wenzelm@50450
   520
wenzelm@50201
   521
(* command status *)
wenzelm@50201
   522
wenzelm@50201
   523
val taskN = "task";
wenzelm@50201
   524
wenzelm@50201
   525
val (acceptedN, accepted) = markup_elem "accepted";
wenzelm@50201
   526
val (forkedN, forked) = markup_elem "forked";
wenzelm@50201
   527
val (joinedN, joined) = markup_elem "joined";
wenzelm@50201
   528
val (runningN, running) = markup_elem "running";
wenzelm@50201
   529
val (finishedN, finished) = markup_elem "finished";
wenzelm@50201
   530
val (failedN, failed) = markup_elem "failed";
wenzelm@50201
   531
wenzelm@50201
   532
wenzelm@50201
   533
(* messages *)
wenzelm@50201
   534
wenzelm@50201
   535
val serialN = "serial";
wenzelm@52854
   536
fun serial_properties i = [(serialN, print_int i)];
wenzelm@52854
   537
wenzelm@50914
   538
val exec_idN = "exec_id";
wenzelm@50201
   539
wenzelm@50201
   540
val initN = "init";
wenzelm@50201
   541
val statusN = "status";
wenzelm@50503
   542
val resultN = "result";
wenzelm@50201
   543
val writelnN = "writeln";
wenzelm@50201
   544
val tracingN = "tracing";
wenzelm@50201
   545
val warningN = "warning";
wenzelm@50201
   546
val errorN = "error";
wenzelm@57975
   547
val systemN = "system";
wenzelm@50201
   548
val protocolN = "protocol";
wenzelm@50201
   549
wenzelm@50201
   550
val (legacyN, legacy) = markup_elem "legacy";
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;