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