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