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