doc-src/antiquote_setup.ML
author wenzelm
Mon, 09 Mar 2009 11:57:48 +0100
changeset 30382 910290f04692
parent 30369 937eaec692cb
child 30394 c11a1e65a2ed
permissions -rw-r--r--
adapted ThyOutput.antiquotation;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24584
01e83ffa6c54 fixed title
haftmann
parents: 24204
diff changeset
     1
(*  Title:      Doc/antiquote_setup.ML
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
     3
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
     4
Auxiliary antiquotations for the Isabelle manuals.
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
     5
*)
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
     6
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
     7
structure AntiquoteSetup: sig end =
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
     8
struct
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
     9
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    10
(* misc utils *)
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    11
29736
ec3fc818b82e clean_string/clean_name: proper treatment of \<dash>;
wenzelm
parents: 29726
diff changeset
    12
fun translate f = Symbol.explode #> map f #> implode;
ec3fc818b82e clean_string/clean_name: proper treatment of \<dash>;
wenzelm
parents: 29726
diff changeset
    13
ec3fc818b82e clean_string/clean_name: proper treatment of \<dash>;
wenzelm
parents: 29726
diff changeset
    14
val clean_string = translate
26853
52cb0e965041 clean_string: map "_" to "\\_" (best used with underscore.sty);
wenzelm
parents: 26843
diff changeset
    15
  (fn "_" => "\\_"
30120
aaa4667285c8 uniform treatment of ML indexing, using general \indexdef macro for formal Isabelle/Isar entities;
wenzelm
parents: 29736
diff changeset
    16
    | "#" => "\\#"
26897
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
    17
    | "<" => "$<$"
26768
844068d16ba0 clean_string: handle { };
wenzelm
parents: 26756
diff changeset
    18
    | ">" => "$>$"
844068d16ba0 clean_string: handle { };
wenzelm
parents: 26756
diff changeset
    19
    | "{" => "\\{"
30120
aaa4667285c8 uniform treatment of ML indexing, using general \indexdef macro for formal Isabelle/Isar entities;
wenzelm
parents: 29736
diff changeset
    20
    | "|" => "$\\mid$"
26768
844068d16ba0 clean_string: handle { };
wenzelm
parents: 26756
diff changeset
    21
    | "}" => "\\}"
29736
ec3fc818b82e clean_string/clean_name: proper treatment of \<dash>;
wenzelm
parents: 29726
diff changeset
    22
    | "\\<dash>" => "-"
26768
844068d16ba0 clean_string: handle { };
wenzelm
parents: 26756
diff changeset
    23
    | c => c);
26751
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
    24
26897
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
    25
fun clean_name "\\<dots>" = "dots"
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
    26
  | clean_name ".." = "ddot"
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
    27
  | clean_name "." = "dot"
26910
aa6357b39212 tuned clean_name (underscore);
wenzelm
parents: 26903
diff changeset
    28
  | clean_name "_" = "underscore"
26897
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
    29
  | clean_name "{" = "braceleft"
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
    30
  | clean_name "}" = "braceright"
29736
ec3fc818b82e clean_string/clean_name: proper treatment of \<dash>;
wenzelm
parents: 29726
diff changeset
    31
  | clean_name s = s |> translate (fn "_" => "-" | "\\<dash>" => "-" | c => c);
26897
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
    32
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    33
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    34
(* verbatim text *)
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    35
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    36
val verbatim = space_implode "\\verb,|," o map (enclose "\\verb|" "|") o space_explode "|";
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    37
30382
910290f04692 adapted ThyOutput.antiquotation;
wenzelm
parents: 30369
diff changeset
    38
val _ = ThyOutput.antiquotation "verbatim" (Scan.lift Args.name)
910290f04692 adapted ThyOutput.antiquotation;
wenzelm
parents: 30369
diff changeset
    39
  (K (split_lines #> map verbatim #> space_implode "\\isasep\\isanewline%\n"));
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    40
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    41
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    42
(* ML text *)
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    43
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    44
local
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    45
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    46
fun ml_val (txt1, "") = "fn _ => (" ^ txt1 ^ ");"
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    47
  | ml_val (txt1, txt2) = "fn _ => (" ^ txt1 ^ ": " ^ txt2 ^ ");";
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    48
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    49
fun ml_type (txt1, "") = "val _ = NONE : (" ^ txt1 ^ ") option;"
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    50
  | ml_type (txt1, txt2) = "val _ = [NONE : (" ^ txt1 ^ ") option, NONE : (" ^ txt2 ^ ") option];";
22289
41ce4f5c97c9 added antiquotation for exceptions
haftmann
parents: 22094
diff changeset
    51
23651
6e0b8b6012c9 renamed ML_exc to ML_exn;
wenzelm
parents: 22289
diff changeset
    52
fun ml_exn (txt1, "") = "fn _ => (" ^ txt1 ^ ": exn);"
6e0b8b6012c9 renamed ML_exc to ML_exn;
wenzelm
parents: 22289
diff changeset
    53
  | ml_exn (txt1, txt2) = "fn _ => (" ^ txt1 ^ ": " ^ txt2 ^ " -> exn);";
22289
41ce4f5c97c9 added antiquotation for exceptions
haftmann
parents: 22094
diff changeset
    54
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    55
fun ml_structure (txt, _) = "functor DUMMY_FUNCTOR() = struct structure DUMMY = " ^ txt ^ " end;"
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    56
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    57
fun ml_functor _ = "val _ = ();";  (*no check!*)
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    58
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    59
fun index_ml kind ml src ctxt (txt1, txt2) =
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    60
  let
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    61
    val txt = if txt2 = "" then txt1 else
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    62
      if kind = "type" then txt1 ^ " = " ^ txt2
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    63
      else if kind = "exception" then txt1 ^ " of " ^ txt2
22289
41ce4f5c97c9 added antiquotation for exceptions
haftmann
parents: 22094
diff changeset
    64
      else txt1 ^ ": " ^ txt2;
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    65
    val txt' = if kind = "" then txt else kind ^ " " ^ txt;
28273
17f6aa02ded3 simplified ML_Context.eval_in -- expect immutable Proof.context value;
wenzelm
parents: 28237
diff changeset
    66
    val _ = ML_Context.eval_in (SOME ctxt) false Position.none (ml (txt1, txt2));
30120
aaa4667285c8 uniform treatment of ML indexing, using general \indexdef macro for formal Isabelle/Isar entities;
wenzelm
parents: 29736
diff changeset
    67
    val kind' = if kind = "" then "ML" else "ML " ^ kind;
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    68
  in
30120
aaa4667285c8 uniform treatment of ML indexing, using general \indexdef macro for formal Isabelle/Isar entities;
wenzelm
parents: 29736
diff changeset
    69
    "\\indexdef{}{" ^ kind' ^ "}{" ^ clean_string txt1 ^ "}" ^
28759
8358fabeea95 ignore ThyOutput.source flag;
wenzelm
parents: 28644
diff changeset
    70
    (txt'
30369
937eaec692cb use simplified ThyOutput.antiquotation;
wenzelm
parents: 30365
diff changeset
    71
    |> (if ! ThyOutput.quotes then quote else I)
937eaec692cb use simplified ThyOutput.antiquotation;
wenzelm
parents: 30365
diff changeset
    72
    |> (if ! ThyOutput.display then enclose "\\begin{verbatim}\n" "\n\\end{verbatim}"
26751
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
    73
        else split_lines #> map verbatim #> space_implode "\\isasep\\isanewline%\n"))
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    74
  end;
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    75
26461
da989545e59c some styling
haftmann
parents: 26455
diff changeset
    76
fun output_ml ctxt src =
30369
937eaec692cb use simplified ThyOutput.antiquotation;
wenzelm
parents: 30365
diff changeset
    77
  if ! ThyOutput.display then enclose "\\begin{verbatim}\n" "\n\\end{verbatim}"
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    78
  else
26461
da989545e59c some styling
haftmann
parents: 26455
diff changeset
    79
    split_lines
da989545e59c some styling
haftmann
parents: 26455
diff changeset
    80
    #> map (space_implode "\\verb,|," o map (enclose "\\verb|" "|") o space_explode "|")
da989545e59c some styling
haftmann
parents: 26455
diff changeset
    81
    #> space_implode "\\isasep\\isanewline%\n";
da989545e59c some styling
haftmann
parents: 26455
diff changeset
    82
30369
937eaec692cb use simplified ThyOutput.antiquotation;
wenzelm
parents: 30365
diff changeset
    83
fun ml_args x = ThyOutput.args (Scan.lift (Args.name -- Scan.optional (Args.colon |-- Args.name) "")) x;
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    84
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    85
in
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    86
30369
937eaec692cb use simplified ThyOutput.antiquotation;
wenzelm
parents: 30365
diff changeset
    87
val _ = ThyOutput.add_commands
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    88
 [("index_ML", ml_args (index_ml "" ml_val)),
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    89
  ("index_ML_type", ml_args (index_ml "type" ml_type)),
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    90
  ("index_ML_exn", ml_args (index_ml "exception" ml_exn)),
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    91
  ("index_ML_structure", ml_args (index_ml "structure" ml_structure)),
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    92
  ("index_ML_functor", ml_args (index_ml "functor" ml_functor)),
30369
937eaec692cb use simplified ThyOutput.antiquotation;
wenzelm
parents: 30365
diff changeset
    93
  ("ML_functor", ThyOutput.args (Scan.lift Args.name) output_ml),
937eaec692cb use simplified ThyOutput.antiquotation;
wenzelm
parents: 30365
diff changeset
    94
  ("ML_text", ThyOutput.args (Scan.lift Args.name) output_ml)];
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    95
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
    96
end;
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
    97
23846
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
    98
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
    99
(* theorems with names *)
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   100
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   101
local
23846
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   102
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   103
fun output_named_thms src ctxt xs =
28644
e2ae4a6cf166 ThyOutput: export some auxiliary operations;
wenzelm
parents: 28399
diff changeset
   104
  map (apfst (ThyOutput.pretty_thm ctxt)) xs        (*always pretty in order to exhibit errors!*)
30369
937eaec692cb use simplified ThyOutput.antiquotation;
wenzelm
parents: 30365
diff changeset
   105
  |> (if ! ThyOutput.quotes then map (apfst Pretty.quote) else I)
937eaec692cb use simplified ThyOutput.antiquotation;
wenzelm
parents: 30365
diff changeset
   106
  |> (if ! ThyOutput.display then
23846
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   107
    map (fn (p, name) =>
30369
937eaec692cb use simplified ThyOutput.antiquotation;
wenzelm
parents: 30365
diff changeset
   108
      Output.output (Pretty.string_of (Pretty.indent (! ThyOutput.indent) p)) ^
28644
e2ae4a6cf166 ThyOutput: export some auxiliary operations;
wenzelm
parents: 28399
diff changeset
   109
      "\\rulename{" ^ Output.output (Pretty.str_of (ThyOutput.pretty_text name)) ^ "}")
23846
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   110
    #> space_implode "\\par\\smallskip%\n"
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   111
    #> enclose "\\begin{isabelle}%\n" "%\n\\end{isabelle}"
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   112
  else
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   113
    map (fn (p, name) =>
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   114
      Output.output (Pretty.str_of p) ^
28644
e2ae4a6cf166 ThyOutput: export some auxiliary operations;
wenzelm
parents: 28399
diff changeset
   115
      "\\rulename{" ^ Output.output (Pretty.str_of (ThyOutput.pretty_text name)) ^ "}")
23846
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   116
    #> space_implode "\\par\\smallskip%\n"
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   117
    #> enclose "\\isa{" "}");
bfedd1a024fc Added named_thms antiquotation.
berghofe
parents: 23651
diff changeset
   118
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
   119
in
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
   120
30369
937eaec692cb use simplified ThyOutput.antiquotation;
wenzelm
parents: 30365
diff changeset
   121
val _ = ThyOutput.add_commands
937eaec692cb use simplified ThyOutput.antiquotation;
wenzelm
parents: 30365
diff changeset
   122
 [("named_thms", ThyOutput.args (Scan.repeat (Attrib.thm --
26751
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   123
      Scan.lift (Args.parens Args.name))) output_named_thms)];
21375
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
   124
ae8a112b62d7 Auxiliary antiquotations for Isabelle manuals.
wenzelm
parents:
diff changeset
   125
end;
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   126
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   127
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   128
(* theory files *)
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   129
30369
937eaec692cb use simplified ThyOutput.antiquotation;
wenzelm
parents: 30365
diff changeset
   130
val _ = ThyOutput.add_commands
937eaec692cb use simplified ThyOutput.antiquotation;
wenzelm
parents: 30365
diff changeset
   131
 [("thy_file", ThyOutput.args (Scan.lift Args.name) (ThyOutput.output (fn _ => fn name =>
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   132
      (ThyLoad.check_thy Path.current name; Pretty.str name))))];
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   133
26751
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   134
28218
1cb3bd5b664a tuned comment;
wenzelm
parents: 28217
diff changeset
   135
(* Isabelle entities (with index) *)
26751
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   136
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   137
local
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   138
26894
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   139
fun no_check _ _ = true;
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   140
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   141
fun thy_check intern defined ctxt =
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   142
  let val thy = ProofContext.theory_of ctxt
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   143
  in defined thy o intern thy end;
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   144
28237
f1fc11c73569 check setting and tool;
wenzelm
parents: 28218
diff changeset
   145
fun check_tool name =
f1fc11c73569 check setting and tool;
wenzelm
parents: 28218
diff changeset
   146
  File.exists (Path.append (Path.explode "~~/lib/Tools") (Path.basic name));
f1fc11c73569 check setting and tool;
wenzelm
parents: 28218
diff changeset
   147
26751
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   148
val arg = enclose "{" "}" o clean_string;
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   149
26894
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   150
fun output_entity check markup index kind ctxt (logic, name) =
26897
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   151
  let
30365
790129514c2d adapted to structure Long_Name;
wenzelm
parents: 30358
diff changeset
   152
    val hyper_name = "{" ^ Long_Name.append kind (Long_Name.append logic (clean_name name)) ^ "}";
26897
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   153
    val hyper =
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   154
      enclose ("\\hyperlink" ^ hyper_name ^ "{") "}" #>
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   155
      index = SOME true ? enclose ("\\hypertarget" ^ hyper_name ^ "{") "}";
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   156
    val idx =
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   157
      (case index of
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   158
        NONE => ""
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   159
      | SOME is_def =>
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   160
          "\\index" ^ (if is_def then "def" else "ref") ^ arg logic ^ arg kind ^ arg name);
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   161
  in
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   162
    if check ctxt name then
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   163
      idx ^
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   164
      (Output.output name
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   165
        |> (if markup = "" then I else enclose ("\\" ^ markup ^ "{") "}")
30369
937eaec692cb use simplified ThyOutput.antiquotation;
wenzelm
parents: 30365
diff changeset
   166
        |> (if ! ThyOutput.quotes then quote else I)
937eaec692cb use simplified ThyOutput.antiquotation;
wenzelm
parents: 30365
diff changeset
   167
        |> (if ! ThyOutput.display then enclose "\\begin{isabelle}%\n" "%\n\\end{isabelle}"
26897
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   168
            else hyper o enclose "\\mbox{\\isa{" "}}"))
28237
f1fc11c73569 check setting and tool;
wenzelm
parents: 28218
diff changeset
   169
    else error ("Bad " ^ kind ^ " " ^ quote name)
26897
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   170
  end;
26751
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   171
26894
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   172
fun entity check markup index kind =
30369
937eaec692cb use simplified ThyOutput.antiquotation;
wenzelm
parents: 30365
diff changeset
   173
  ThyOutput.args (Scan.lift (Scan.optional (Args.parens Args.name) "" -- Args.name))
26894
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   174
    (K (output_entity check markup index kind));
26897
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   175
26894
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   176
fun entity_antiqs check markup kind =
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   177
 [(kind, entity check markup NONE kind),
26897
044619358d3a clean_string: cover <;
wenzelm
parents: 26894
diff changeset
   178
  (kind ^ "_def", entity check markup (SOME true) kind),
26894
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   179
  (kind ^ "_ref", entity check markup (SOME false) kind)];
26751
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   180
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   181
in
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   182
30369
937eaec692cb use simplified ThyOutput.antiquotation;
wenzelm
parents: 30365
diff changeset
   183
val _ = ThyOutput.add_commands
26894
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   184
 (entity_antiqs no_check "" "syntax" @
27353
71c4dd53d4cb moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 26910
diff changeset
   185
  entity_antiqs (K (is_some o OuterKeyword.command_keyword)) "isacommand" "command" @
71c4dd53d4cb moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 26910
diff changeset
   186
  entity_antiqs (K OuterKeyword.is_keyword) "isakeyword" "keyword" @
71c4dd53d4cb moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 26910
diff changeset
   187
  entity_antiqs (K OuterKeyword.is_keyword) "isakeyword" "element" @
26894
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   188
  entity_antiqs (thy_check Method.intern Method.defined) "" "method" @
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   189
  entity_antiqs (thy_check Attrib.intern Attrib.defined) "" "attribute" @
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   190
  entity_antiqs no_check "" "fact" @
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   191
  entity_antiqs no_check "" "variable" @
1120f6cc10b0 proper checking of various Isar elements;
wenzelm
parents: 26853
diff changeset
   192
  entity_antiqs no_check "" "case" @
28217
21f0c2de0a38 added formal markup for setting, executable, tool;
wenzelm
parents: 27809
diff changeset
   193
  entity_antiqs (K ThyOutput.defined_command) "" "antiquotation" @
28237
f1fc11c73569 check setting and tool;
wenzelm
parents: 28218
diff changeset
   194
  entity_antiqs (fn _ => fn name => is_some (OS.Process.getEnv name)) "isatt" "setting" @
29726
5f91ff5c03a2 added "inference" entity;
wenzelm
parents: 28759
diff changeset
   195
  entity_antiqs no_check "" "inference" @
28217
21f0c2de0a38 added formal markup for setting, executable, tool;
wenzelm
parents: 27809
diff changeset
   196
  entity_antiqs no_check "isatt" "executable" @
28237
f1fc11c73569 check setting and tool;
wenzelm
parents: 28218
diff changeset
   197
  entity_antiqs (K check_tool) "isatt" "tool" @
28399
b11b1ca701e5 added theory antiquotation
haftmann
parents: 28273
diff changeset
   198
  entity_antiqs (K (File.exists o Path.explode)) "isatt" "file" @
b11b1ca701e5 added theory antiquotation
haftmann
parents: 28273
diff changeset
   199
  entity_antiqs (K ThyInfo.known_thy) "" "theory");
26751
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   200
26742
5a86bc79431c misc cleanup;
wenzelm
parents: 26710
diff changeset
   201
end;
26751
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   202
2b97ea3130c2 added setup for Isar entities;
wenzelm
parents: 26742
diff changeset
   203
end;