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