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