doc-src/antiquote_setup.ML
author aspinall
Sun Dec 31 15:34:21 2006 +0100 (2006-12-31)
changeset 21973 e7c9b0d3ce82
parent 21375 ae8a112b62d7
child 22090 bc8aee017f8a
permissions -rw-r--r--
Quote arguments in PGIP exceptions. Tune comment.
wenzelm@21375
     1
(*  Title:      antiquote_setup.ML
wenzelm@21375
     2
    ID:         $Id$
wenzelm@21375
     3
    Author:     Makarius
wenzelm@21375
     4
wenzelm@21375
     5
Auxiliary antiquotations for Isabelle manuals.
wenzelm@21375
     6
*)
wenzelm@21375
     7
wenzelm@21375
     8
local
wenzelm@21375
     9
wenzelm@21375
    10
structure O = IsarOutput;
wenzelm@21375
    11
wenzelm@21375
    12
val str_of_source = space_implode " " o map Args.string_of o #2 o #1 o Args.dest_src;
wenzelm@21375
    13
wenzelm@21375
    14
fun ml_val (txt1, "") = "fn _ => (" ^ txt1 ^ ");"
wenzelm@21375
    15
  | ml_val (txt1, txt2) = "fn _ => (" ^ txt1 ^ ": " ^ txt2 ^ ");";
wenzelm@21375
    16
wenzelm@21375
    17
fun ml_type (txt1, "") = "val _ = NONE : (" ^ txt1 ^ ") option;"
wenzelm@21375
    18
  | ml_type (txt1, txt2) = "val _ = [NONE : (" ^ txt1 ^ ") option, NONE : (" ^ txt2 ^ ") option];";
wenzelm@21375
    19
  
wenzelm@21375
    20
fun ml_structure (txt, _) = "functor DUMMY_FUNCTOR() = struct structure DUMMY = " ^ txt ^ " end;"
wenzelm@21375
    21
wenzelm@21375
    22
fun ml_functor _ = "val _ = ();";  (*no check!*)
wenzelm@21375
    23
wenzelm@21375
    24
val verbatim = space_implode "\\verb,|," o map (enclose "\\verb|" "|") o space_explode "|";
wenzelm@21375
    25
wenzelm@21375
    26
fun index_ml kind ml src ctxt (txt1, txt2) =
wenzelm@21375
    27
  let
wenzelm@21375
    28
    val txt = if txt2 = "" then txt1 else
wenzelm@21375
    29
      if kind = "type"
wenzelm@21375
    30
        then txt1 ^ " = " ^ txt2
wenzelm@21375
    31
        else txt1 ^ ": " ^ txt2;
wenzelm@21375
    32
    val txt' = if kind = "" then txt else kind ^ " " ^ txt;
wenzelm@21375
    33
    val _ = Context.use_mltext (ml (txt1, txt2)) false (SOME (ProofContext.theory_of ctxt));
wenzelm@21375
    34
  in
wenzelm@21375
    35
    "\\indexml" ^ kind ^ enclose "{" "}"
wenzelm@21375
    36
      (translate_string (fn "_" => "-" | ">" => "$>$" | c => c) txt1) ^
wenzelm@21375
    37
    ((if ! O.source then str_of_source src else txt')
wenzelm@21375
    38
    |> (if ! O.quotes then quote else I)
wenzelm@21375
    39
    |> (if ! O.display then enclose "\\begin{verbatim}\n" "\n\\end{verbatim}"
wenzelm@21375
    40
    else split_lines #> map verbatim #> space_implode "\\isasep\\isanewline%\n"))
wenzelm@21375
    41
  end;
wenzelm@21375
    42
wenzelm@21375
    43
fun output_verbatim _ _ = split_lines #> map verbatim #> space_implode "\\isasep\\isanewline%\n";
wenzelm@21375
    44
wenzelm@21375
    45
fun arguments x = O.args (Scan.lift (Args.name -- Scan.optional (Args.colon |-- Args.name) "")) x;
wenzelm@21375
    46
wenzelm@21375
    47
fun pretty_thy_file name = (ThyLoad.check_thy Path.current name false; Pretty.str name);
wenzelm@21375
    48
wenzelm@21375
    49
in
wenzelm@21375
    50
wenzelm@21375
    51
val _ = O.add_commands
wenzelm@21375
    52
 [("index_ML", arguments (index_ml "" ml_val)),
wenzelm@21375
    53
  ("index_ML_type", arguments (index_ml "type" ml_type)),
wenzelm@21375
    54
  ("index_ML_structure", arguments (index_ml "structure" ml_structure)),
wenzelm@21375
    55
  ("index_ML_functor", arguments (index_ml "functor" ml_functor)),
wenzelm@21375
    56
  ("ML_functor", O.args (Scan.lift Args.name) output_verbatim),
wenzelm@21375
    57
  ("verbatim", O.args (Scan.lift Args.name) output_verbatim),
wenzelm@21375
    58
  ("thy_file", O.args (Scan.lift Args.name) (O.output (K pretty_thy_file)))];
wenzelm@21375
    59
wenzelm@21375
    60
end;