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