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