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