src/Pure/PIDE/markup.ML
author wenzelm
Sun Mar 24 17:53:46 2019 +0100 (3 months ago)
changeset 69968 1a400b14fd3a
parent 69965 da5e7278286b
child 70016 a8142ac5e4b6
permissions -rw-r--r--
clarified spell-checking (see also 30233285270a);
     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_licenseN: string val meta_license: T
    24   val meta_descriptionN: string val meta_description: 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 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 raw_textN: string val raw_text: T
   131   val plain_textN: string val plain_text: T
   132   val paragraphN: string val paragraph: T
   133   val text_foldN: string val text_fold: T
   134   val markdown_paragraphN: string val markdown_paragraph: T
   135   val markdown_itemN: string val markdown_item: T
   136   val markdown_bulletN: string val markdown_bullet: int -> T
   137   val markdown_listN: string val markdown_list: string -> T
   138   val itemizeN: string
   139   val enumerateN: string
   140   val descriptionN: string
   141   val inputN: string val input: bool -> Properties.T -> T
   142   val command_keywordN: string val command_keyword: T
   143   val commandN: string val command_properties: T -> T
   144   val keywordN: string val keyword_properties: T -> T
   145   val stringN: string val string: T
   146   val alt_stringN: string val alt_string: T
   147   val verbatimN: string val verbatim: T
   148   val cartoucheN: string val cartouche: T
   149   val commentN: string val comment: T
   150   val keyword1N: string val keyword1: T
   151   val keyword2N: string val keyword2: T
   152   val keyword3N: string val keyword3: T
   153   val quasi_keywordN: string val quasi_keyword: T
   154   val improperN: string val improper: T
   155   val operatorN: string val operator: T
   156   val comment1N: string val comment1: T
   157   val comment2N: string val comment2: T
   158   val comment3N: string val comment3: T
   159   val elapsedN: string
   160   val cpuN: string
   161   val gcN: string
   162   val timing_properties: {elapsed: Time.time, cpu: Time.time, gc: Time.time} -> Properties.T
   163   val parse_timing_properties: Properties.T -> {elapsed: Time.time, cpu: Time.time, gc: Time.time}
   164   val command_timingN: string
   165   val command_timing_properties:
   166     {file: string, offset: int, name: string} -> Time.time -> Properties.T
   167   val parse_command_timing_properties:
   168     Properties.T -> ({file: string, offset: int, name: string} * Time.time) option
   169   val timingN: string val timing: {elapsed: Time.time, cpu: Time.time, gc: Time.time} -> T
   170   val command_indentN: string val command_indent: int -> T
   171   val goalN: string val goal: T
   172   val subgoalN: string val subgoal: string -> T
   173   val taskN: string
   174   val acceptedN: string val accepted: T
   175   val forkedN: string val forked: T
   176   val joinedN: string val joined: T
   177   val runningN: string val running: T
   178   val finishedN: string val finished: T
   179   val failedN: string val failed: T
   180   val canceledN: string val canceled: T
   181   val initializedN: string val initialized: T
   182   val finalizedN: string val finalized: T
   183   val consolidatedN: string val consolidated: T
   184   val exec_idN: string
   185   val initN: string
   186   val statusN: string val status: T
   187   val resultN: string val result: T
   188   val writelnN: string val writeln: T
   189   val stateN: string val state: T
   190   val informationN: string val information: T
   191   val tracingN: string val tracing: T
   192   val warningN: string val warning: T
   193   val legacyN: string val legacy: T
   194   val errorN: string val error: T
   195   val systemN: string val system: T
   196   val protocolN: string
   197   val reportN: string val report: T
   198   val no_reportN: string val no_report: T
   199   val badN: string val bad: unit -> T
   200   val intensifyN: string val intensify: T
   201   val browserN: string
   202   val graphviewN: string
   203   val theory_exportsN: string
   204   val sendbackN: string
   205   val paddingN: string
   206   val padding_line: Properties.entry
   207   val padding_command: Properties.entry
   208   val dialogN: string val dialog: serial -> string -> T
   209   val jedit_actionN: string
   210   val functionN: string
   211   val assign_update: Properties.T
   212   val removed_versions: Properties.T
   213   val protocol_handler: string -> Properties.T
   214   val invoke_scala: string -> string -> Properties.T
   215   val cancel_scala: string -> Properties.T
   216   val ML_statistics: Properties.entry
   217   val task_statistics: Properties.entry
   218   val command_timing: Properties.entry
   219   val theory_timing: Properties.entry
   220   val loading_theory: string -> Properties.T
   221   val dest_loading_theory: Properties.T -> string option
   222   val build_session_finished: Properties.T
   223   val print_operationsN: string
   224   val print_operations: Properties.T
   225   val exportN: string
   226   type export_args =
   227    {id: string option,
   228     serial: serial,
   229     theory_name: string,
   230     name: string,
   231     executable: bool,
   232     compress: bool}
   233   val export: export_args -> Properties.T
   234   val debugger_state: string -> Properties.T
   235   val debugger_output: string -> Properties.T
   236   val simp_trace_panelN: string
   237   val simp_trace_logN: string
   238   val simp_trace_stepN: string
   239   val simp_trace_recurseN: string
   240   val simp_trace_hintN: string
   241   val simp_trace_ignoreN: string
   242   val simp_trace_cancel: serial -> Properties.T
   243   type output = Output.output * Output.output
   244   val no_output: output
   245   val add_mode: string -> (T -> output) -> unit
   246   val output: T -> output
   247   val enclose: T -> Output.output -> Output.output
   248   val markup: T -> string -> string
   249   val markups: T list -> string -> string
   250   val markup_only: T -> string
   251   val markup_report: string -> string
   252 end;
   253 
   254 structure Markup: MARKUP =
   255 struct
   256 
   257 (** markup elements **)
   258 
   259 (* basic markup *)
   260 
   261 type T = string * Properties.T;
   262 
   263 val empty = ("", []);
   264 
   265 fun is_empty ("", _) = true
   266   | is_empty _ = false;
   267 
   268 
   269 fun properties more_props ((elem, props): T) =
   270   (elem, fold_rev Properties.put more_props props);
   271 
   272 fun markup_elem name = (name, (name, []): T);
   273 fun markup_string name prop = (name, fn s => (name, [(prop, s)]): T);
   274 fun markup_int name prop = (name, fn i => (name, [(prop, Value.print_int i)]): T);
   275 
   276 
   277 (* misc properties *)
   278 
   279 val nameN = "name";
   280 fun name a = properties [(nameN, a)];
   281 
   282 val xnameN = "xname";
   283 fun xname a = properties [(xnameN, a)];
   284 
   285 val kindN = "kind";
   286 
   287 val serialN = "serial";
   288 fun serial_properties i = [(serialN, Value.print_int i)];
   289 
   290 val instanceN = "instance";
   291 
   292 
   293 (* meta data -- see https://www.dublincore.org/specifications/dublin-core/dcmi-terms *)
   294 
   295 val (meta_titleN, meta_title) = markup_elem "meta_title";
   296 val (meta_creatorN, meta_creator) = markup_elem "meta_creator";
   297 val (meta_contributorN, meta_contributor) = markup_elem "meta_contributor";
   298 val (meta_dateN, meta_date) = markup_elem "meta_date";
   299 val (meta_licenseN, meta_license) = markup_elem "meta_license";
   300 val (meta_descriptionN, meta_description) = markup_elem "meta_description";
   301 
   302 
   303 (* embedded languages *)
   304 
   305 val languageN = "language";
   306 val symbolsN = "symbols";
   307 val antiquotesN = "antiquotes";
   308 val delimitedN = "delimited"
   309 
   310 fun is_delimited props =
   311   Properties.get props delimitedN = SOME "true";
   312 
   313 fun language {name, symbols, antiquotes, delimited} =
   314   (languageN,
   315    [(nameN, name),
   316     (symbolsN, Value.print_bool symbols),
   317     (antiquotesN, Value.print_bool antiquotes),
   318     (delimitedN, Value.print_bool delimited)]);
   319 
   320 fun language' {name, symbols, antiquotes} delimited =
   321   language {name = name, symbols = symbols, antiquotes = antiquotes, delimited = delimited};
   322 
   323 val language_Isar = language' {name = "Isar", symbols = true, antiquotes = false};
   324 val language_method =
   325   language {name = "method", symbols = true, antiquotes = false, delimited = false};
   326 val language_attribute =
   327   language {name = "attribute", symbols = true, antiquotes = false, delimited = false};
   328 val language_sort = language' {name = "sort", symbols = true, antiquotes = false};
   329 val language_type = language' {name = "type", symbols = true, antiquotes = false};
   330 val language_term = language' {name = "term", symbols = true, antiquotes = false};
   331 val language_prop = language' {name = "prop", symbols = true, antiquotes = false};
   332 val language_ML = language' {name = "ML", symbols = false, antiquotes = true};
   333 val language_SML = language' {name = "SML", symbols = false, antiquotes = false};
   334 val language_document = language' {name = "document", symbols = false, antiquotes = true};
   335 val language_document_marker =
   336   language {name = "document_marker", symbols = true, antiquotes = true, delimited = true};
   337 val language_antiquotation =
   338   language {name = "antiquotation", symbols = true, antiquotes = false, delimited = true};
   339 val language_text = language' {name = "text", symbols = true, antiquotes = false};
   340 val language_verbatim = language' {name = "verbatim_text", symbols = true, antiquotes = false};
   341 val language_latex = language' {name = "latex", symbols = false, antiquotes = false};
   342 val language_rail = language {name = "rail", symbols = true, antiquotes = true, delimited = true};
   343 val language_path = language {name = "path", symbols = false, antiquotes = false, delimited = true};
   344 val language_mixfix =
   345   language {name = "mixfix_annotation", symbols = true, antiquotes = false, delimited = true};
   346 
   347 
   348 (* formal entities *)
   349 
   350 val (bindingN, binding) = markup_elem "binding";
   351 
   352 val entityN = "entity";
   353 fun entity kind name =
   354   (entityN,
   355     (if name = "" then [] else [(nameN, name)]) @ (if kind = "" then [] else [(kindN, kind)]));
   356 
   357 val defN = "def";
   358 val refN = "ref";
   359 
   360 
   361 (* completion *)
   362 
   363 val (completionN, completion) = markup_elem "completion";
   364 val (no_completionN, no_completion) = markup_elem "no_completion";
   365 
   366 val (updateN, update) = markup_elem "update";
   367 
   368 
   369 (* position *)
   370 
   371 val lineN = "line";
   372 val end_lineN = "end_line";
   373 
   374 val offsetN = "offset";
   375 val end_offsetN = "end_offset";
   376 
   377 val fileN = "file";
   378 val idN = "id";
   379 
   380 val position_properties' = [fileN, idN];
   381 val position_properties = [lineN, offsetN, end_offsetN] @ position_properties';
   382 
   383 val (positionN, position) = markup_elem "position";
   384 
   385 
   386 (* expression *)
   387 
   388 val expressionN = "expression";
   389 fun expression kind = (expressionN, if kind = "" then [] else [(kindN, kind)]);
   390 
   391 
   392 (* citation *)
   393 
   394 val (citationN, citation) = markup_string "citation" nameN;
   395 
   396 
   397 (* external resources *)
   398 
   399 val (pathN, path) = markup_string "path" nameN;
   400 val (urlN, url) = markup_string "url" nameN;
   401 val (docN, doc) = markup_string "doc" nameN;
   402 
   403 
   404 (* pretty printing *)
   405 
   406 val markupN = "markup";
   407 val consistentN = "consistent";
   408 val unbreakableN = "unbreakable";
   409 val indentN = "indent";
   410 
   411 val block_properties = [markupN, consistentN, unbreakableN, indentN];
   412 
   413 val widthN = "width";
   414 
   415 val blockN = "block";
   416 fun block c i =
   417   (blockN,
   418     (if c then [(consistentN, Value.print_bool c)] else []) @
   419     (if i <> 0 then [(indentN, Value.print_int i)] else []));
   420 
   421 val breakN = "break";
   422 fun break w i =
   423   (breakN,
   424     (if w <> 0 then [(widthN, Value.print_int w)] else []) @
   425     (if i <> 0 then [(indentN, Value.print_int i)] else []));
   426 
   427 val (fbreakN, fbreak) = markup_elem "fbreak";
   428 
   429 val (itemN, item) = markup_elem "item";
   430 
   431 
   432 (* text properties *)
   433 
   434 val (wordsN, words) = markup_elem "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 kind *)
   514 
   515 val (raw_textN, raw_text) = markup_elem "raw_text";
   516 val (plain_textN, plain_text) = markup_elem "plain_text";
   517 
   518 
   519 (* text structure *)
   520 
   521 val (paragraphN, paragraph) = markup_elem "paragraph";
   522 val (text_foldN, text_fold) = markup_elem "text_fold";
   523 
   524 
   525 (* Markdown document structure *)
   526 
   527 val (markdown_paragraphN, markdown_paragraph) = markup_elem "markdown_paragraph";
   528 val (markdown_itemN, markdown_item) = markup_elem "markdown_item";
   529 val (markdown_bulletN, markdown_bullet) = markup_int "markdown_bullet" "depth";
   530 val (markdown_listN, markdown_list) = markup_string "markdown_list" kindN;
   531 
   532 val itemizeN = "itemize";
   533 val enumerateN = "enumerate";
   534 val descriptionN = "description";
   535 
   536 
   537 (* formal input *)
   538 
   539 val inputN = "input";
   540 fun input delimited props = (inputN, (delimitedN, Value.print_bool delimited) :: props);
   541 
   542 
   543 (* outer syntax *)
   544 
   545 val (command_keywordN, command_keyword) = markup_elem "command_keyword";
   546 
   547 val commandN = "command"; val command_properties = properties [(kindN, commandN)];
   548 val keywordN = "keyword"; val keyword_properties = properties [(kindN, keywordN)];
   549 
   550 val (keyword1N, keyword1) = markup_elem "keyword1";
   551 val (keyword2N, keyword2) = markup_elem "keyword2";
   552 val (keyword3N, keyword3) = markup_elem "keyword3";
   553 val (quasi_keywordN, quasi_keyword) = markup_elem "quasi_keyword";
   554 val (improperN, improper) = markup_elem "improper";
   555 val (operatorN, operator) = markup_elem "operator";
   556 val (stringN, string) = markup_elem "string";
   557 val (alt_stringN, alt_string) = markup_elem "alt_string";
   558 val (verbatimN, verbatim) = markup_elem "verbatim";
   559 val (cartoucheN, cartouche) = markup_elem "cartouche";
   560 val (commentN, comment) = markup_elem "comment";
   561 
   562 
   563 (* comments *)
   564 
   565 val (comment1N, comment1) = markup_elem "comment1";
   566 val (comment2N, comment2) = markup_elem "comment2";
   567 val (comment3N, comment3) = markup_elem "comment3";
   568 
   569 
   570 (* timing *)
   571 
   572 val elapsedN = "elapsed";
   573 val cpuN = "cpu";
   574 val gcN = "gc";
   575 
   576 fun timing_properties {elapsed, cpu, gc} =
   577  [(elapsedN, Value.print_time elapsed),
   578   (cpuN, Value.print_time cpu),
   579   (gcN, Value.print_time gc)];
   580 
   581 fun parse_timing_properties props =
   582  {elapsed = Properties.seconds props elapsedN,
   583   cpu = Properties.seconds props cpuN,
   584   gc = Properties.seconds props gcN};
   585 
   586 val timingN = "timing";
   587 fun timing t = (timingN, timing_properties t);
   588 
   589 
   590 (* command timing *)
   591 
   592 val command_timingN = "command_timing";
   593 
   594 fun command_timing_properties {file, offset, name} elapsed =
   595  [(fileN, file), (offsetN, Value.print_int offset),
   596   (nameN, name), (elapsedN, Value.print_time elapsed)];
   597 
   598 fun parse_command_timing_properties props =
   599   (case (Properties.get props fileN, Properties.get props offsetN, Properties.get props nameN) of
   600     (SOME file, SOME offset, SOME name) =>
   601       SOME ({file = file, offset = Value.parse_int offset, name = name},
   602         Properties.seconds props elapsedN)
   603   | _ => NONE);
   604 
   605 
   606 (* indentation *)
   607 
   608 val (command_indentN, command_indent) = markup_int "command_indent" indentN;
   609 
   610 
   611 (* goals *)
   612 
   613 val (goalN, goal) = markup_elem "goal";
   614 val (subgoalN, subgoal) = markup_string "subgoal" nameN;
   615 
   616 
   617 (* command status *)
   618 
   619 val taskN = "task";
   620 
   621 val (acceptedN, accepted) = markup_elem "accepted";
   622 val (forkedN, forked) = markup_elem "forked";
   623 val (joinedN, joined) = markup_elem "joined";
   624 val (runningN, running) = markup_elem "running";
   625 val (finishedN, finished) = markup_elem "finished";
   626 val (failedN, failed) = markup_elem "failed";
   627 val (canceledN, canceled) = markup_elem "canceled";
   628 val (initializedN, initialized) = markup_elem "initialized";
   629 val (finalizedN, finalized) = markup_elem "finalized";
   630 val (consolidatedN, consolidated) = markup_elem "consolidated";
   631 
   632 
   633 (* messages *)
   634 
   635 val exec_idN = "exec_id";
   636 
   637 val initN = "init";
   638 val (statusN, status) = markup_elem "status";
   639 val (resultN, result) = markup_elem "result";
   640 val (writelnN, writeln) = markup_elem "writeln";
   641 val (stateN, state) = markup_elem "state"
   642 val (informationN, information) = markup_elem "information";
   643 val (tracingN, tracing) = markup_elem "tracing";
   644 val (warningN, warning) = markup_elem "warning";
   645 val (legacyN, legacy) = markup_elem "legacy";
   646 val (errorN, error) = markup_elem "error";
   647 val (systemN, system) = markup_elem "system";
   648 val protocolN = "protocol";
   649 
   650 val (reportN, report) = markup_elem "report";
   651 val (no_reportN, no_report) = markup_elem "no_report";
   652 
   653 val badN = "bad";
   654 fun bad () = (badN, serial_properties (serial ()));
   655 
   656 val (intensifyN, intensify) = markup_elem "intensify";
   657 
   658 
   659 (* active areas *)
   660 
   661 val browserN = "browser"
   662 val graphviewN = "graphview";
   663 val theory_exportsN = "theory_exports";
   664 
   665 val sendbackN = "sendback";
   666 val paddingN = "padding";
   667 val padding_line = (paddingN, "line");
   668 val padding_command = (paddingN, "command");
   669 
   670 val dialogN = "dialog";
   671 fun dialog i result = (dialogN, [(serialN, Value.print_int i), (resultN, result)]);
   672 
   673 val jedit_actionN = "jedit_action";
   674 
   675 
   676 (* protocol message functions *)
   677 
   678 val functionN = "function"
   679 
   680 val assign_update = [(functionN, "assign_update")];
   681 val removed_versions = [(functionN, "removed_versions")];
   682 
   683 fun protocol_handler name = [(functionN, "protocol_handler"), (nameN, name)];
   684 
   685 fun invoke_scala name id = [(functionN, "invoke_scala"), (nameN, name), (idN, id)];
   686 fun cancel_scala id = [(functionN, "cancel_scala"), (idN, id)];
   687 
   688 val ML_statistics = (functionN, "ML_statistics");
   689 
   690 val task_statistics = (functionN, "task_statistics");
   691 
   692 val command_timing = (functionN, "command_timing");
   693 
   694 val theory_timing = (functionN, "theory_timing");
   695 
   696 fun loading_theory name = [("function", "loading_theory"), ("name", name)];
   697 
   698 fun dest_loading_theory [("function", "loading_theory"), ("name", name)] = SOME name
   699   | dest_loading_theory _ = NONE;
   700 
   701 val build_session_finished = [("function", "build_session_finished")];
   702 
   703 val print_operationsN = "print_operations";
   704 val print_operations = [(functionN, print_operationsN)];
   705 
   706 
   707 (* export *)
   708 
   709 val exportN = "export";
   710 
   711 type export_args =
   712  {id: string option,
   713   serial: serial,
   714   theory_name: string,
   715   name: string,
   716   executable: bool,
   717   compress: bool};
   718 
   719 fun export ({id, serial, theory_name, name, executable, compress}: export_args) =
   720  [(functionN, exportN),
   721   (idN, the_default "" id),
   722   (serialN, Value.print_int serial),
   723   ("theory_name", theory_name),
   724   (nameN, name),
   725   ("executable", Value.print_bool executable),
   726   ("compress", Value.print_bool compress)];
   727 
   728 
   729 (* debugger *)
   730 
   731 fun debugger_state name = [(functionN, "debugger_state"), (nameN, name)];
   732 fun debugger_output name = [(functionN, "debugger_output"), (nameN, name)];
   733 
   734 
   735 (* simplifier trace *)
   736 
   737 val simp_trace_panelN = "simp_trace_panel";
   738 
   739 val simp_trace_logN = "simp_trace_log";
   740 val simp_trace_stepN = "simp_trace_step";
   741 val simp_trace_recurseN = "simp_trace_recurse";
   742 val simp_trace_hintN = "simp_trace_hint";
   743 val simp_trace_ignoreN = "simp_trace_ignore";
   744 
   745 fun simp_trace_cancel i = [(functionN, "simp_trace_cancel"), (serialN, Value.print_int i)];
   746 
   747 
   748 
   749 (** print mode operations **)
   750 
   751 type output = Output.output * Output.output;
   752 
   753 val no_output = ("", "");
   754 
   755 local
   756   val default = {output = Output_Primitives.markup_fn};
   757   val modes = Synchronized.var "Markup.modes" (Symtab.make [("", default)]);
   758 in
   759   fun add_mode name output =
   760     Synchronized.change modes (fn tab =>
   761       (if not (Symtab.defined tab name) then ()
   762        else Output.warning ("Redefining markup mode " ^ quote name);
   763        Symtab.update (name, {output = output}) tab));
   764   fun get_mode () =
   765     the_default default
   766       (Library.get_first (Symtab.lookup (Synchronized.value modes)) (print_mode_value ()));
   767 end;
   768 
   769 fun output m = if is_empty m then no_output else #output (get_mode ()) m;
   770 
   771 val enclose = output #-> Library.enclose;
   772 
   773 fun markup m =
   774   let val (bg, en) = output m
   775   in Library.enclose (Output.escape bg) (Output.escape en) end;
   776 
   777 val markups = fold_rev markup;
   778 
   779 fun markup_only m = markup m "";
   780 
   781 fun markup_report "" = ""
   782   | markup_report txt = markup report txt;
   783 
   784 end;