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