doc-src/antiquote_setup.ML
author haftmann
Sat, 10 Feb 2007 09:26:07 +0100
changeset 22289 41ce4f5c97c9
parent 22094 008794185f4d
child 23651 6e0b8b6012c9
permissions -rw-r--r--
added antiquotation for exceptions
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
     1
(*  Title:      antiquote_setup.ML
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
     3
    Author:     Makarius
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
     4
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
     5
Auxiliary antiquotations for Isabelle manuals.
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
     6
*)
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
     7
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
     8
local
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
     9
22094
008794185f4d renamed IsarOutput to ThyOutput;
wenzelm
parents: 22090
diff changeset
    10
structure O = ThyOutput;
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    11
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    12
val str_of_source = space_implode " " o map Args.string_of o #2 o #1 o Args.dest_src;
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    13
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    14
fun ml_val (txt1, "") = "fn _ => (" ^ txt1 ^ ");"
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    15
  | ml_val (txt1, txt2) = "fn _ => (" ^ txt1 ^ ": " ^ txt2 ^ ");";
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    16
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    17
fun ml_type (txt1, "") = "val _ = NONE : (" ^ txt1 ^ ") option;"
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    18
  | ml_type (txt1, txt2) = "val _ = [NONE : (" ^ txt1 ^ ") option, NONE : (" ^ txt2 ^ ") option];";
22289
41ce4f5c97c9 added antiquotation for exceptions
haftmann
parents: 22094
diff changeset
    19
41ce4f5c97c9 added antiquotation for exceptions
haftmann
parents: 22094
diff changeset
    20
fun ml_exc (txt1, "") = "fn _ => (" ^ txt1 ^ ": exn);"
41ce4f5c97c9 added antiquotation for exceptions
haftmann
parents: 22094
diff changeset
    21
  | ml_exc (txt1, txt2) = "fn _ => (" ^ txt1 ^ ": " ^ txt2 ^ " -> exn);";
41ce4f5c97c9 added antiquotation for exceptions
haftmann
parents: 22094
diff changeset
    22
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    23
fun ml_structure (txt, _) = "functor DUMMY_FUNCTOR() = struct structure DUMMY = " ^ txt ^ " end;"
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    24
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    25
fun ml_functor _ = "val _ = ();";  (*no check!*)
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    26
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    27
val verbatim = space_implode "\\verb,|," o map (enclose "\\verb|" "|") o space_explode "|";
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    28
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    29
fun index_ml kind ml src ctxt (txt1, txt2) =
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    30
  let
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    31
    val txt = if txt2 = "" then txt1 else
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    32
      if kind = "type"
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    33
        then txt1 ^ " = " ^ txt2
22289
41ce4f5c97c9 added antiquotation for exceptions
haftmann
parents: 22094
diff changeset
    34
      else if kind = "exception"
41ce4f5c97c9 added antiquotation for exceptions
haftmann
parents: 22094
diff changeset
    35
        then txt1 ^ " of " ^ txt2
41ce4f5c97c9 added antiquotation for exceptions
haftmann
parents: 22094
diff changeset
    36
      else txt1 ^ ": " ^ txt2;
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    37
    val txt' = if kind = "" then txt else kind ^ " " ^ txt;
22289
41ce4f5c97c9 added antiquotation for exceptions
haftmann
parents: 22094
diff changeset
    38
    val _ = writeln (ml (txt1, txt2));
22094
008794185f4d renamed IsarOutput to ThyOutput;
wenzelm
parents: 22090
diff changeset
    39
    val _ = ML_Context.use_mltext (ml (txt1, txt2)) false (SOME (Context.Proof ctxt));
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    40
  in
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    41
    "\\indexml" ^ kind ^ enclose "{" "}"
22289
41ce4f5c97c9 added antiquotation for exceptions
haftmann
parents: 22094
diff changeset
    42
      (translate_string (fn "_" => "-" | ">" => "$>$" | "#" => "\\#" | c => c) txt1) ^
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    43
    ((if ! O.source then str_of_source src else txt')
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    44
    |> (if ! O.quotes then quote else I)
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    45
    |> (if ! O.display then enclose "\\begin{verbatim}\n" "\n\\end{verbatim}"
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    46
    else split_lines #> map verbatim #> space_implode "\\isasep\\isanewline%\n"))
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    47
  end;
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    48
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    49
fun output_verbatim _ _ = split_lines #> map verbatim #> space_implode "\\isasep\\isanewline%\n";
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    50
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    51
fun arguments x = O.args (Scan.lift (Args.name -- Scan.optional (Args.colon |-- Args.name) "")) x;
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    52
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    53
fun pretty_thy_file name = (ThyLoad.check_thy Path.current name false; Pretty.str name);
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    54
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    55
in
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    56
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    57
val _ = O.add_commands
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    58
 [("index_ML", arguments (index_ml "" ml_val)),
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    59
  ("index_ML_type", arguments (index_ml "type" ml_type)),
22289
41ce4f5c97c9 added antiquotation for exceptions
haftmann
parents: 22094
diff changeset
    60
  ("index_ML_exc", arguments (index_ml "exception" ml_exc)),
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    61
  ("index_ML_structure", arguments (index_ml "structure" ml_structure)),
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    62
  ("index_ML_functor", arguments (index_ml "functor" ml_functor)),
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    63
  ("ML_functor", O.args (Scan.lift Args.name) output_verbatim),
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    64
  ("verbatim", O.args (Scan.lift Args.name) output_verbatim),
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    65
  ("thy_file", O.args (Scan.lift Args.name) (O.output (K pretty_thy_file)))];
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    66
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    67
end;