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