src/Pure/PIDE/markup.ML
author wenzelm
Sun Mar 10 00:21:34 2019 +0100 (3 months ago ago)
changeset 70068 b9985133805d
parent 69967 c175499a7537
child 70070 be04e9a053a7
permissions -rw-r--r--
added semantic document markers;
emulate old-style tags as "tag" markers, with subtle change of semantics for multiples tags (ever used?);
tuned;
     1 (*  Title:      Pure/PIDE/markup.ML
     2     Author:     Makarius
     3 
     4 Quasi-abstract markup elements.
     5 *)
     6 
     7 signature MARKUP =
     8 sig
     9   type T = string * Properties.T
    10   val empty: T
    11   val is_empty: T -> bool
    12   val properties: Properties.T -> T -> T
    13   val nameN: string val name: string -> T -> T
    14   val xnameN: string val xname: string -> T -> T
    15   val kindN: string
    16   val serialN: string
    17   val serial_properties: int -> Properties.T
    18   val instanceN: string
    19   val languageN: string
    20   val symbolsN: string
    21   val delimitedN: string
    22   val is_delimited: Properties.T -> bool
    23   val language: {name: string, symbols: bool, antiquotes: bool, delimited: bool} -> T
    24   val language': {name: string, symbols: bool, antiquotes: bool} -> bool -> T
    25   val language_Isar: bool -> T
    26   val language_method: T
    27   val language_attribute: T
    28   val language_sort: bool -> T
    29   val language_type: bool -> T
    30   val language_term: bool -> T
    31   val language_prop: bool -> T
    32   val language_ML: bool -> T
    33   val language_SML: bool -> T
    34   val language_document: bool -> T
    35   val language_document_marker: T
    36   val language_antiquotation: T
    37   val language_text: bool -> T
    38   val language_verbatim: bool -> T
    39   val language_latex: bool -> T
    40   val language_rail: T
    41   val language_path: T
    42   val language_mixfix: T
    43   val bindingN: string val binding: T
    44   val entityN: string val entity: string -> string -> T
    45   val defN: string
    46   val refN: string
    47   val completionN: string val completion: T
    48   val no_completionN: string val no_completion: T
    49   val updateN: string val update: T
    50   val lineN: string
    51   val end_lineN: string
    52   val offsetN: string
    53   val end_offsetN: string
    54   val fileN: string
    55   val idN: string
    56   val position_properties': string list
    57   val position_properties: string list
    58   val positionN: string val position: T
    59   val expressionN: string val expression: string -> T
    60   val citationN: string val citation: string -> T
    61   val pathN: string val path: string -> T
    62   val urlN: string val url: string -> T
    63   val docN: string val doc: string -> T
    64   val markupN: string
    65   val consistentN: string
    66   val unbreakableN: string
    67   val block_properties: string list
    68   val indentN: string
    69   val widthN: string
    70   val blockN: string val block: bool -> int -> T
    71   val breakN: string val break: int -> int -> T
    72   val fbreakN: string val fbreak: T
    73   val itemN: string val item: T
    74   val wordsN: string val words: T
    75   val no_wordsN: string val no_words: T
    76   val hiddenN: string val hidden: T
    77   val deleteN: string val delete: T
    78   val system_optionN: string
    79   val sessionN: string
    80   val theoryN: string
    81   val classN: string
    82   val type_nameN: string
    83   val constantN: string
    84   val fixedN: string val fixed: string -> T
    85   val caseN: string val case_: string -> T
    86   val dynamic_factN: string val dynamic_fact: string -> T
    87   val literal_factN: string val literal_fact: string -> T
    88   val method_modifierN: string
    89   val tfreeN: string val tfree: T
    90   val tvarN: string val tvar: T
    91   val freeN: string val free: T
    92   val skolemN: string val skolem: T
    93   val boundN: string val bound: T
    94   val varN: string val var: T
    95   val numeralN: string val numeral: T
    96   val literalN: string val literal: T
    97   val delimiterN: string val delimiter: T
    98   val inner_stringN: string val inner_string: T
    99   val inner_cartoucheN: string val inner_cartouche: T
   100   val token_rangeN: string val token_range: T
   101   val sortingN: string val sorting: T
   102   val typingN: string val typing: T
   103   val class_parameterN: string val class_parameter: T
   104   val ML_keyword1N: string val ML_keyword1: T
   105   val ML_keyword2N: string val ML_keyword2: T
   106   val ML_keyword3N: string val ML_keyword3: T
   107   val ML_delimiterN: string val ML_delimiter: T
   108   val ML_tvarN: string val ML_tvar: T
   109   val ML_numeralN: string val ML_numeral: T
   110   val ML_charN: string val ML_char: T
   111   val ML_stringN: string val ML_string: T
   112   val ML_commentN: string val ML_comment: T
   113   val ML_defN: string
   114   val ML_openN: string
   115   val ML_structureN: string
   116   val ML_typingN: string val ML_typing: T
   117   val ML_breakpointN: string val ML_breakpoint: int -> T
   118   val antiquotedN: string val antiquoted: T
   119   val antiquoteN: string val antiquote: T
   120   val file_typeN: string
   121   val antiquotationN: string
   122   val ML_antiquotationN: string
   123   val document_antiquotationN: string
   124   val document_antiquotation_optionN: string
   125   val paragraphN: string val paragraph: T
   126   val text_foldN: string val text_fold: T
   127   val markdown_paragraphN: string val markdown_paragraph: T
   128   val markdown_itemN: string val markdown_item: T
   129   val markdown_bulletN: string val markdown_bullet: int -> T
   130   val markdown_listN: string val markdown_list: string -> T
   131   val itemizeN: string
   132   val enumerateN: string
   133   val descriptionN: string
   134   val inputN: string val input: bool -> Properties.T -> T
   135   val command_keywordN: string val command_keyword: T
   136   val commandN: string val command_properties: T -> T
   137   val keywordN: string val keyword_properties: T -> T
   138   val stringN: string val string: T
   139   val alt_stringN: string val alt_string: T
   140   val verbatimN: string val verbatim: T
   141   val cartoucheN: string val cartouche: T
   142   val commentN: string val comment: T
   143   val keyword1N: string val keyword1: T
   144   val keyword2N: string val keyword2: T
   145   val keyword3N: string val keyword3: T
   146   val quasi_keywordN: string val quasi_keyword: T
   147   val improperN: string val improper: T
   148   val operatorN: string val operator: T
   149   val comment1N: string val comment1: T
   150   val comment2N: string val comment2: T
   151   val comment3N: string val comment3: T
   152   val elapsedN: string
   153   val cpuN: string
   154   val gcN: string
   155   val timing_properties: {elapsed: Time.time, cpu: Time.time, gc: Time.time} -> Properties.T
   156   val parse_timing_properties: Properties.T -> {elapsed: Time.time, cpu: Time.time, gc: Time.time}
   157   val command_timingN: string
   158   val command_timing_properties:
   159     {file: string, offset: int, name: string} -> Time.time -> Properties.T
   160   val parse_command_timing_properties:
   161     Properties.T -> ({file: string, offset: int, name: string} * Time.time) option
   162   val timingN: string val timing: {elapsed: Time.time, cpu: Time.time, gc: Time.time} -> T
   163   val command_indentN: string val command_indent: int -> T
   164   val goalN: string val goal: T
   165   val subgoalN: string val subgoal: string -> T
   166   val taskN: string
   167   val acceptedN: string val accepted: T
   168   val forkedN: string val forked: T
   169   val joinedN: string val joined: T
   170   val runningN: string val running: T
   171   val finishedN: string val finished: T
   172   val failedN: string val failed: T
   173   val canceledN: string val canceled: T
   174   val initializedN: string val initialized: T
   175   val finalizedN: string val finalized: T
   176   val consolidatedN: string val consolidated: T
   177   val exec_idN: string
   178   val initN: string
   179   val statusN: string val status: T
   180   val resultN: string val result: T
   181   val writelnN: string val writeln: T
   182   val stateN: string val state: T
   183   val informationN: string val information: T
   184   val tracingN: string val tracing: T
   185   val warningN: string val warning: T
   186   val legacyN: string val legacy: T
   187   val errorN: string val error: T
   188   val systemN: string val system: T
   189   val protocolN: string
   190   val reportN: string val report: T
   191   val no_reportN: string val no_report: T
   192   val badN: string val bad: unit -> T
   193   val intensifyN: string val intensify: T
   194   val browserN: string
   195   val graphviewN: string
   196   val theory_exportsN: string
   197   val sendbackN: string
   198   val paddingN: string
   199   val padding_line: Properties.entry
   200   val padding_command: Properties.entry
   201   val dialogN: string val dialog: serial -> string -> T
   202   val jedit_actionN: string
   203   val functionN: string
   204   val assign_update: Properties.T
   205   val removed_versions: Properties.T
   206   val protocol_handler: string -> Properties.T
   207   val invoke_scala: string -> string -> Properties.T
   208   val cancel_scala: string -> Properties.T
   209   val ML_statistics: Properties.entry
   210   val task_statistics: Properties.entry
   211   val command_timing: Properties.entry
   212   val theory_timing: Properties.entry
   213   val loading_theory: string -> Properties.T
   214   val dest_loading_theory: Properties.T -> string option
   215   val build_session_finished: Properties.T
   216   val print_operationsN: string
   217   val print_operations: Properties.T
   218   val exportN: string
   219   type export_args =
   220    {id: string option,
   221     serial: serial,
   222     theory_name: string,
   223     name: string,
   224     executable: bool,
   225     compress: bool}
   226   val export: export_args -> Properties.T
   227   val debugger_state: string -> Properties.T
   228   val debugger_output: string -> Properties.T
   229   val simp_trace_panelN: string
   230   val simp_trace_logN: string
   231   val simp_trace_stepN: string
   232   val simp_trace_recurseN: string
   233   val simp_trace_hintN: string
   234   val simp_trace_ignoreN: string
   235   val simp_trace_cancel: serial -> Properties.T
   236   type output = Output.output * Output.output
   237   val no_output: output
   238   val add_mode: string -> (T -> output) -> unit
   239   val output: T -> output
   240   val enclose: T -> Output.output -> Output.output
   241   val markup: T -> string -> string
   242   val markups: T list -> string -> string
   243   val markup_only: T -> string
   244   val markup_report: string -> string
   245 end;
   246 
   247 structure Markup: MARKUP =
   248 struct
   249 
   250 (** markup elements **)
   251 
   252 (* basic markup *)
   253 
   254 type T = string * Properties.T;
   255 
   256 val empty = ("", []);
   257 
   258 fun is_empty ("", _) = true
   259   | is_empty _ = false;
   260 
   261 
   262 fun properties more_props ((elem, props): T) =
   263   (elem, fold_rev Properties.put more_props props);
   264 
   265 fun markup_elem name = (name, (name, []): T);
   266 fun markup_string name prop = (name, fn s => (name, [(prop, s)]): T);
   267 fun markup_int name prop = (name, fn i => (name, [(prop, Value.print_int i)]): T);
   268 
   269 
   270 (* misc properties *)
   271 
   272 val nameN = "name";
   273 fun name a = properties [(nameN, a)];
   274 
   275 val xnameN = "xname";
   276 fun xname a = properties [(xnameN, a)];
   277 
   278 val kindN = "kind";
   279 
   280 val serialN = "serial";
   281 fun serial_properties i = [(serialN, Value.print_int i)];
   282 
   283 val instanceN = "instance";
   284 
   285 
   286 (* embedded languages *)
   287 
   288 val languageN = "language";
   289 val symbolsN = "symbols";
   290 val antiquotesN = "antiquotes";
   291 val delimitedN = "delimited"
   292 
   293 fun is_delimited props =
   294   Properties.get props delimitedN = SOME "true";
   295 
   296 fun language {name, symbols, antiquotes, delimited} =
   297   (languageN,
   298    [(nameN, name),
   299     (symbolsN, Value.print_bool symbols),
   300     (antiquotesN, Value.print_bool antiquotes),
   301     (delimitedN, Value.print_bool delimited)]);
   302 
   303 fun language' {name, symbols, antiquotes} delimited =
   304   language {name = name, symbols = symbols, antiquotes = antiquotes, delimited = delimited};
   305 
   306 val language_Isar = language' {name = "Isar", symbols = true, antiquotes = false};
   307 val language_method =
   308   language {name = "method", symbols = true, antiquotes = false, delimited = false};
   309 val language_attribute =
   310   language {name = "attribute", symbols = true, antiquotes = false, delimited = false};
   311 val language_sort = language' {name = "sort", symbols = true, antiquotes = false};
   312 val language_type = language' {name = "type", symbols = true, antiquotes = false};
   313 val language_term = language' {name = "term", symbols = true, antiquotes = false};
   314 val language_prop = language' {name = "prop", symbols = true, antiquotes = false};
   315 val language_ML = language' {name = "ML", symbols = false, antiquotes = true};
   316 val language_SML = language' {name = "SML", symbols = false, antiquotes = false};
   317 val language_document = language' {name = "document", symbols = false, antiquotes = true};
   318 val language_document_marker =
   319   language {name = "document_marker", symbols = true, antiquotes = true, delimited = true};
   320 val language_antiquotation =
   321   language {name = "antiquotation", symbols = true, antiquotes = false, delimited = true};
   322 val language_text = language' {name = "text", symbols = true, antiquotes = false};
   323 val language_verbatim = language' {name = "verbatim_text", symbols = true, antiquotes = false};
   324 val language_latex = language' {name = "latex", symbols = false, antiquotes = false};
   325 val language_rail = language {name = "rail", symbols = true, antiquotes = true, delimited = true};
   326 val language_path = language {name = "path", symbols = false, antiquotes = false, delimited = true};
   327 val language_mixfix =
   328   language {name = "mixfix_annotation", symbols = true, antiquotes = false, delimited = true};
   329 
   330 
   331 (* formal entities *)
   332 
   333 val (bindingN, binding) = markup_elem "binding";
   334 
   335 val entityN = "entity";
   336 fun entity kind name =
   337   (entityN,
   338     (if name = "" then [] else [(nameN, name)]) @ (if kind = "" then [] else [(kindN, kind)]));
   339 
   340 val defN = "def";
   341 val refN = "ref";
   342 
   343 
   344 (* completion *)
   345 
   346 val (completionN, completion) = markup_elem "completion";
   347 val (no_completionN, no_completion) = markup_elem "no_completion";
   348 
   349 val (updateN, update) = markup_elem "update";
   350 
   351 
   352 (* position *)
   353 
   354 val lineN = "line";
   355 val end_lineN = "end_line";
   356 
   357 val offsetN = "offset";
   358 val end_offsetN = "end_offset";
   359 
   360 val fileN = "file";
   361 val idN = "id";
   362 
   363 val position_properties' = [fileN, idN];
   364 val position_properties = [lineN, offsetN, end_offsetN] @ position_properties';
   365 
   366 val (positionN, position) = markup_elem "position";
   367 
   368 
   369 (* expression *)
   370 
   371 val expressionN = "expression";
   372 fun expression kind = (expressionN, if kind = "" then [] else [(kindN, kind)]);
   373 
   374 
   375 (* citation *)
   376 
   377 val (citationN, citation) = markup_string "citation" nameN;
   378 
   379 
   380 (* external resources *)
   381 
   382 val (pathN, path) = markup_string "path" nameN;
   383 val (urlN, url) = markup_string "url" nameN;
   384 val (docN, doc) = markup_string "doc" nameN;
   385 
   386 
   387 (* pretty printing *)
   388 
   389 val markupN = "markup";
   390 val consistentN = "consistent";
   391 val unbreakableN = "unbreakable";
   392 val indentN = "indent";
   393 
   394 val block_properties = [markupN, consistentN, unbreakableN, indentN];
   395 
   396 val widthN = "width";
   397 
   398 val blockN = "block";
   399 fun block c i =
   400   (blockN,
   401     (if c then [(consistentN, Value.print_bool c)] else []) @
   402     (if i <> 0 then [(indentN, Value.print_int i)] else []));
   403 
   404 val breakN = "break";
   405 fun break w i =
   406   (breakN,
   407     (if w <> 0 then [(widthN, Value.print_int w)] else []) @
   408     (if i <> 0 then [(indentN, Value.print_int i)] else []));
   409 
   410 val (fbreakN, fbreak) = markup_elem "fbreak";
   411 
   412 val (itemN, item) = markup_elem "item";
   413 
   414 
   415 (* text properties *)
   416 
   417 val (wordsN, words) = markup_elem "words";
   418 val (no_wordsN, no_words) = markup_elem "no_words";
   419 
   420 val (hiddenN, hidden) = markup_elem "hidden";
   421 
   422 val (deleteN, delete) = markup_elem "delete";
   423 
   424 
   425 (* misc entities *)
   426 
   427 val system_optionN = "system_option";
   428 
   429 val sessionN = "session";
   430 
   431 val theoryN = "theory";
   432 val classN = "class";
   433 val type_nameN = "type_name";
   434 val constantN = "constant";
   435 
   436 val (fixedN, fixed) = markup_string "fixed" nameN;
   437 val (caseN, case_) = markup_string "case" nameN;
   438 val (dynamic_factN, dynamic_fact) = markup_string "dynamic_fact" nameN;
   439 val (literal_factN, literal_fact) = markup_string "literal_fact" nameN;
   440 
   441 val method_modifierN = "method_modifier";
   442 
   443 
   444 (* inner syntax *)
   445 
   446 val (tfreeN, tfree) = markup_elem "tfree";
   447 val (tvarN, tvar) = markup_elem "tvar";
   448 val (freeN, free) = markup_elem "free";
   449 val (skolemN, skolem) = markup_elem "skolem";
   450 val (boundN, bound) = markup_elem "bound";
   451 val (varN, var) = markup_elem "var";
   452 val (numeralN, numeral) = markup_elem "numeral";
   453 val (literalN, literal) = markup_elem "literal";
   454 val (delimiterN, delimiter) = markup_elem "delimiter";
   455 val (inner_stringN, inner_string) = markup_elem "inner_string";
   456 val (inner_cartoucheN, inner_cartouche) = markup_elem "inner_cartouche";
   457 
   458 val (token_rangeN, token_range) = markup_elem "token_range";
   459 
   460 val (sortingN, sorting) = markup_elem "sorting";
   461 val (typingN, typing) = markup_elem "typing";
   462 val (class_parameterN, class_parameter) = markup_elem "class_parameter";
   463 
   464 
   465 (* ML *)
   466 
   467 val (ML_keyword1N, ML_keyword1) = markup_elem "ML_keyword1";
   468 val (ML_keyword2N, ML_keyword2) = markup_elem "ML_keyword2";
   469 val (ML_keyword3N, ML_keyword3) = markup_elem "ML_keyword3";
   470 val (ML_delimiterN, ML_delimiter) = markup_elem "ML_delimiter";
   471 val (ML_tvarN, ML_tvar) = markup_elem "ML_tvar";
   472 val (ML_numeralN, ML_numeral) = markup_elem "ML_numeral";
   473 val (ML_charN, ML_char) = markup_elem "ML_char";
   474 val (ML_stringN, ML_string) = markup_elem "ML_string";
   475 val (ML_commentN, ML_comment) = markup_elem "ML_comment";
   476 
   477 val ML_defN = "ML_def";
   478 val ML_openN = "ML_open";
   479 val ML_structureN = "ML_structure";
   480 val (ML_typingN, ML_typing) = markup_elem "ML_typing";
   481 
   482 val (ML_breakpointN, ML_breakpoint) = markup_int "ML_breakpoint" serialN;
   483 
   484 
   485 (* antiquotations *)
   486 
   487 val (antiquotedN, antiquoted) = markup_elem "antiquoted";
   488 val (antiquoteN, antiquote) = markup_elem "antiquote";
   489 
   490 val file_typeN = "file_type";
   491 val antiquotationN = "antiquotation";
   492 val ML_antiquotationN = "ML_antiquotation";
   493 val document_antiquotationN = "document_antiquotation";
   494 val document_antiquotation_optionN = "document_antiquotation_option";
   495 
   496 
   497 (* text structure *)
   498 
   499 val (paragraphN, paragraph) = markup_elem "paragraph";
   500 val (text_foldN, text_fold) = markup_elem "text_fold";
   501 
   502 
   503 (* Markdown document structure *)
   504 
   505 val (markdown_paragraphN, markdown_paragraph) = markup_elem "markdown_paragraph";
   506 val (markdown_itemN, markdown_item) = markup_elem "markdown_item";
   507 val (markdown_bulletN, markdown_bullet) = markup_int "markdown_bullet" "depth";
   508 val (markdown_listN, markdown_list) = markup_string "markdown_list" kindN;
   509 
   510 val itemizeN = "itemize";
   511 val enumerateN = "enumerate";
   512 val descriptionN = "description";
   513 
   514 
   515 (* formal input *)
   516 
   517 val inputN = "input";
   518 fun input delimited props = (inputN, (delimitedN, Value.print_bool delimited) :: props);
   519 
   520 
   521 (* outer syntax *)
   522 
   523 val (command_keywordN, command_keyword) = markup_elem "command_keyword";
   524 
   525 val commandN = "command"; val command_properties = properties [(kindN, commandN)];
   526 val keywordN = "keyword"; val keyword_properties = properties [(kindN, keywordN)];
   527 
   528 val (keyword1N, keyword1) = markup_elem "keyword1";
   529 val (keyword2N, keyword2) = markup_elem "keyword2";
   530 val (keyword3N, keyword3) = markup_elem "keyword3";
   531 val (quasi_keywordN, quasi_keyword) = markup_elem "quasi_keyword";
   532 val (improperN, improper) = markup_elem "improper";
   533 val (operatorN, operator) = markup_elem "operator";
   534 val (stringN, string) = markup_elem "string";
   535 val (alt_stringN, alt_string) = markup_elem "alt_string";
   536 val (verbatimN, verbatim) = markup_elem "verbatim";
   537 val (cartoucheN, cartouche) = markup_elem "cartouche";
   538 val (commentN, comment) = markup_elem "comment";
   539 
   540 
   541 (* comments *)
   542 
   543 val (comment1N, comment1) = markup_elem "comment1";
   544 val (comment2N, comment2) = markup_elem "comment2";
   545 val (comment3N, comment3) = markup_elem "comment3";
   546 
   547 
   548 (* timing *)
   549 
   550 val elapsedN = "elapsed";
   551 val cpuN = "cpu";
   552 val gcN = "gc";
   553 
   554 fun timing_properties {elapsed, cpu, gc} =
   555  [(elapsedN, Value.print_time elapsed),
   556   (cpuN, Value.print_time cpu),
   557   (gcN, Value.print_time gc)];
   558 
   559 fun parse_timing_properties props =
   560  {elapsed = Properties.seconds props elapsedN,
   561   cpu = Properties.seconds props cpuN,
   562   gc = Properties.seconds props gcN};
   563 
   564 val timingN = "timing";
   565 fun timing t = (timingN, timing_properties t);
   566 
   567 
   568 (* command timing *)
   569 
   570 val command_timingN = "command_timing";
   571 
   572 fun command_timing_properties {file, offset, name} elapsed =
   573  [(fileN, file), (offsetN, Value.print_int offset),
   574   (nameN, name), (elapsedN, Value.print_time elapsed)];
   575 
   576 fun parse_command_timing_properties props =
   577   (case (Properties.get props fileN, Properties.get props offsetN, Properties.get props nameN) of
   578     (SOME file, SOME offset, SOME name) =>
   579       SOME ({file = file, offset = Value.parse_int offset, name = name},
   580         Properties.seconds props elapsedN)
   581   | _ => NONE);
   582 
   583 
   584 (* indentation *)
   585 
   586 val (command_indentN, command_indent) = markup_int "command_indent" indentN;
   587 
   588 
   589 (* goals *)
   590 
   591 val (goalN, goal) = markup_elem "goal";
   592 val (subgoalN, subgoal) = markup_string "subgoal" nameN;
   593 
   594 
   595 (* command status *)
   596 
   597 val taskN = "task";
   598 
   599 val (acceptedN, accepted) = markup_elem "accepted";
   600 val (forkedN, forked) = markup_elem "forked";
   601 val (joinedN, joined) = markup_elem "joined";
   602 val (runningN, running) = markup_elem "running";
   603 val (finishedN, finished) = markup_elem "finished";
   604 val (failedN, failed) = markup_elem "failed";
   605 val (canceledN, canceled) = markup_elem "canceled";
   606 val (initializedN, initialized) = markup_elem "initialized";
   607 val (finalizedN, finalized) = markup_elem "finalized";
   608 val (consolidatedN, consolidated) = markup_elem "consolidated";
   609 
   610 
   611 (* messages *)
   612 
   613 val exec_idN = "exec_id";
   614 
   615 val initN = "init";
   616 val (statusN, status) = markup_elem "status";
   617 val (resultN, result) = markup_elem "result";
   618 val (writelnN, writeln) = markup_elem "writeln";
   619 val (stateN, state) = markup_elem "state"
   620 val (informationN, information) = markup_elem "information";
   621 val (tracingN, tracing) = markup_elem "tracing";
   622 val (warningN, warning) = markup_elem "warning";
   623 val (legacyN, legacy) = markup_elem "legacy";
   624 val (errorN, error) = markup_elem "error";
   625 val (systemN, system) = markup_elem "system";
   626 val protocolN = "protocol";
   627 
   628 val (reportN, report) = markup_elem "report";
   629 val (no_reportN, no_report) = markup_elem "no_report";
   630 
   631 val badN = "bad";
   632 fun bad () = (badN, serial_properties (serial ()));
   633 
   634 val (intensifyN, intensify) = markup_elem "intensify";
   635 
   636 
   637 (* active areas *)
   638 
   639 val browserN = "browser"
   640 val graphviewN = "graphview";
   641 val theory_exportsN = "theory_exports";
   642 
   643 val sendbackN = "sendback";
   644 val paddingN = "padding";
   645 val padding_line = (paddingN, "line");
   646 val padding_command = (paddingN, "command");
   647 
   648 val dialogN = "dialog";
   649 fun dialog i result = (dialogN, [(serialN, Value.print_int i), (resultN, result)]);
   650 
   651 val jedit_actionN = "jedit_action";
   652 
   653 
   654 (* protocol message functions *)
   655 
   656 val functionN = "function"
   657 
   658 val assign_update = [(functionN, "assign_update")];
   659 val removed_versions = [(functionN, "removed_versions")];
   660 
   661 fun protocol_handler name = [(functionN, "protocol_handler"), (nameN, name)];
   662 
   663 fun invoke_scala name id = [(functionN, "invoke_scala"), (nameN, name), (idN, id)];
   664 fun cancel_scala id = [(functionN, "cancel_scala"), (idN, id)];
   665 
   666 val ML_statistics = (functionN, "ML_statistics");
   667 
   668 val task_statistics = (functionN, "task_statistics");
   669 
   670 val command_timing = (functionN, "command_timing");
   671 
   672 val theory_timing = (functionN, "theory_timing");
   673 
   674 fun loading_theory name = [("function", "loading_theory"), ("name", name)];
   675 
   676 fun dest_loading_theory [("function", "loading_theory"), ("name", name)] = SOME name
   677   | dest_loading_theory _ = NONE;
   678 
   679 val build_session_finished = [("function", "build_session_finished")];
   680 
   681 val print_operationsN = "print_operations";
   682 val print_operations = [(functionN, print_operationsN)];
   683 
   684 
   685 (* export *)
   686 
   687 val exportN = "export";
   688 
   689 type export_args =
   690  {id: string option,
   691   serial: serial,
   692   theory_name: string,
   693   name: string,
   694   executable: bool,
   695   compress: bool};
   696 
   697 fun export ({id, serial, theory_name, name, executable, compress}: export_args) =
   698  [(functionN, exportN),
   699   (idN, the_default "" id),
   700   (serialN, Value.print_int serial),
   701   ("theory_name", theory_name),
   702   (nameN, name),
   703   ("executable", Value.print_bool executable),
   704   ("compress", Value.print_bool compress)];
   705 
   706 
   707 (* debugger *)
   708 
   709 fun debugger_state name = [(functionN, "debugger_state"), (nameN, name)];
   710 fun debugger_output name = [(functionN, "debugger_output"), (nameN, name)];
   711 
   712 
   713 (* simplifier trace *)
   714 
   715 val simp_trace_panelN = "simp_trace_panel";
   716 
   717 val simp_trace_logN = "simp_trace_log";
   718 val simp_trace_stepN = "simp_trace_step";
   719 val simp_trace_recurseN = "simp_trace_recurse";
   720 val simp_trace_hintN = "simp_trace_hint";
   721 val simp_trace_ignoreN = "simp_trace_ignore";
   722 
   723 fun simp_trace_cancel i = [(functionN, "simp_trace_cancel"), (serialN, Value.print_int i)];
   724 
   725 
   726 
   727 (** print mode operations **)
   728 
   729 type output = Output.output * Output.output;
   730 
   731 val no_output = ("", "");
   732 
   733 local
   734   val default = {output = Output_Primitives.markup_fn};
   735   val modes = Synchronized.var "Markup.modes" (Symtab.make [("", default)]);
   736 in
   737   fun add_mode name output =
   738     Synchronized.change modes (fn tab =>
   739       (if not (Symtab.defined tab name) then ()
   740        else Output.warning ("Redefining markup mode " ^ quote name);
   741        Symtab.update (name, {output = output}) tab));
   742   fun get_mode () =
   743     the_default default
   744       (Library.get_first (Symtab.lookup (Synchronized.value modes)) (print_mode_value ()));
   745 end;
   746 
   747 fun output m = if is_empty m then no_output else #output (get_mode ()) m;
   748 
   749 val enclose = output #-> Library.enclose;
   750 
   751 fun markup m =
   752   let val (bg, en) = output m
   753   in Library.enclose (Output.escape bg) (Output.escape en) end;
   754 
   755 val markups = fold_rev markup;
   756 
   757 fun markup_only m = markup m "";
   758 
   759 fun markup_report "" = ""
   760   | markup_report txt = markup report txt;
   761 
   762 end;