src/Pure/Isar/isar_output.ML
author wenzelm
Thu, 09 Jun 2005 12:03:32 +0200
changeset 16345 b035482bed02
parent 16194 3d192ab9907b
child 16894 40f80823b451
permissions -rw-r--r--
Args.local_typ_abbrev;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Isar/isar_output.ML
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
16002
wenzelm
parents: 15988
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
     4
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
     5
Isar theory output.
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
     6
*)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
     7
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
     8
signature ISAR_OUTPUT =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
     9
sig
14899
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
    10
  val display: bool ref
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
    11
  val quotes: bool ref
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
    12
  val indent: int ref
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
    13
  val source: bool ref
10321
bbaad3045e37 let commands access Toplevel.state;
wenzelm
parents: 9863
diff changeset
    14
  val add_commands: (string * (Args.src -> Toplevel.state -> string)) list -> unit
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    15
  val add_options: (string * (string -> (unit -> string) -> unit -> string)) list -> unit
9220
d0506ced27c8 added options "eta_contract", "long_names";
wenzelm
parents: 9213
diff changeset
    16
  val print_antiquotations: unit -> unit
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    17
  val boolean: string -> bool
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    18
  val integer: string -> int
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    19
  val args: (Proof.context * Args.T list -> 'a * (Proof.context * Args.T list)) ->
10321
bbaad3045e37 let commands access Toplevel.state;
wenzelm
parents: 9863
diff changeset
    20
    (Args.src -> Proof.context -> 'a -> string) -> Args.src -> Toplevel.state -> string
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    21
  datatype markup = Markup | MarkupEnv | Verbatim
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    22
  val interest_level: int ref
15430
1e1aeaf1dec3 Implemented hiding of proofs and other commands.
berghofe
parents: 15349
diff changeset
    23
  val hide_commands: bool ref
1e1aeaf1dec3 Implemented hiding of proofs and other commands.
berghofe
parents: 15349
diff changeset
    24
  val add_hidden_commands: string list -> unit
11714
bc0a84063a9c added global modes ref;
wenzelm
parents: 11524
diff changeset
    25
  val modes: string list ref
12939
279a3cf23a98 export eval_antiquote;
wenzelm
parents: 12881
diff changeset
    26
  val eval_antiquote: Scan.lexicon -> Toplevel.state -> string * Position.T -> string
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    27
  val parse_thy: (markup -> OuterLex.token list -> OuterLex.token * OuterLex.token list) ->
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    28
    Scan.lexicon -> Toplevel.transition list -> (OuterLex.token, 'a) Source.source ->
15430
1e1aeaf1dec3 Implemented hiding of proofs and other commands.
berghofe
parents: 15349
diff changeset
    29
      (Toplevel.transition * (Toplevel.state -> Toplevel.state -> Buffer.T -> Buffer.T)) list * Buffer.T
11716
064833efb479 Exported output_with.
berghofe
parents: 11714
diff changeset
    30
  val output_with: (Proof.context -> 'a -> Pretty.T) -> Args.src ->
064833efb479 Exported output_with.
berghofe
parents: 11714
diff changeset
    31
    Proof.context -> 'a -> string
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    32
end;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    33
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    34
structure IsarOutput: ISAR_OUTPUT =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    35
struct
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    36
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    37
structure T = OuterLex;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    38
structure P = OuterParse;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    39
14899
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
    40
(** global references -- defaults for options **)
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
    41
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
    42
val locale = ref "";
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
    43
val display = ref false;
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
    44
val quotes = ref false;
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
    45
val indent = ref 0;
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
    46
val source = ref false;
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
    47
val break = ref false;
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
    48
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
    49
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
    50
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    51
(** maintain global commands **)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    52
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    53
local
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    54
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    55
val global_commands =
10321
bbaad3045e37 let commands access Toplevel.state;
wenzelm
parents: 9863
diff changeset
    56
  ref (Symtab.empty: (Args.src -> Toplevel.state -> string) Symtab.table);
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    57
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    58
val global_options =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    59
  ref (Symtab.empty: (string -> (unit -> string) -> unit -> string) Symtab.table);
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    60
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    61
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    62
fun add_item kind (tab, (name, x)) =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    63
 (if is_none (Symtab.lookup (tab, name)) then ()
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    64
  else warning ("Redefined antiquotation output " ^ kind ^ ": " ^ quote name);
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    65
  Symtab.update ((name, x), tab));
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    66
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
    67
fun add_items kind xs tab = Library.foldl (add_item kind) (tab, xs);
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    68
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    69
in
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    70
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    71
val add_commands = Library.change global_commands o (add_items "command");
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    72
val add_options = Library.change global_options o (add_items "option");
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    73
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    74
fun command src =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    75
  let val ((name, _), pos) = Args.dest_src src in
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    76
    (case Symtab.lookup (! global_commands, name) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15529
diff changeset
    77
      NONE => error ("Unknown antiquotation command: " ^ quote name ^ Position.str_of pos)
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15529
diff changeset
    78
    | SOME f => transform_failure (curry Antiquote.ANTIQUOTE_FAIL (name, pos)) (f src))
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    79
  end;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    80
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    81
fun option (name, s) f () =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    82
  (case Symtab.lookup (! global_options, name) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15529
diff changeset
    83
    NONE => error ("Unknown antiquotation option: " ^ quote name)
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15529
diff changeset
    84
  | SOME opt => opt s f ());
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    85
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    86
fun options [] f = f
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    87
  | options (opt :: opts) f = option opt (options opts f);
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    88
9213
2651a4db8883 help_antiquotations;
wenzelm
parents: 9140
diff changeset
    89
9220
d0506ced27c8 added options "eta_contract", "long_names";
wenzelm
parents: 9213
diff changeset
    90
fun print_antiquotations () =
d0506ced27c8 added options "eta_contract", "long_names";
wenzelm
parents: 9213
diff changeset
    91
 [Pretty.big_list "antiquotation commands:" (map Pretty.str (Symtab.keys (! global_commands))),
d0506ced27c8 added options "eta_contract", "long_names";
wenzelm
parents: 9213
diff changeset
    92
  Pretty.big_list "antiquotation options:" (map Pretty.str (Symtab.keys (! global_options)))]
d0506ced27c8 added options "eta_contract", "long_names";
wenzelm
parents: 9213
diff changeset
    93
 |> Pretty.chunks |> Pretty.writeln;
9213
2651a4db8883 help_antiquotations;
wenzelm
parents: 9140
diff changeset
    94
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    95
end;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    96
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    97
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    98
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    99
(** syntax of antiquotations **)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   100
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   101
(* option values *)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   102
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   103
fun boolean "" = true
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   104
  | boolean "true" = true
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   105
  | boolean "false" = false
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   106
  | boolean s = error ("Bad boolean value: " ^ quote s);
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   107
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   108
fun integer s =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   109
  let
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   110
    fun int ss =
14899
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
   111
      (case Library.read_int ss of (i, []) => i
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
   112
      | _ => error ("Bad integer value: " ^ quote s));
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   113
  in (case Symbol.explode s of "-" :: ss => ~ (int ss) | ss => int ss) end;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   114
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   115
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   116
(* args syntax *)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   117
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   118
fun syntax (scan: (Proof.context * Args.T list -> 'a * (Proof.context * Args.T list))) =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   119
  Args.syntax "antiquotation" scan;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   120
10321
bbaad3045e37 let commands access Toplevel.state;
wenzelm
parents: 9863
diff changeset
   121
fun args scan f src state : string =
14899
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
   122
  let
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
   123
    val ctxt0 =
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
   124
      if ! locale = "" then Toplevel.context_of state
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15529
diff changeset
   125
      else #3 (Locale.read_context_statement (SOME (! locale)) [] []
14899
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
   126
        (ProofContext.init (Toplevel.theory_of state)));
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
   127
    val (ctxt, x) = syntax scan src ctxt0;
10321
bbaad3045e37 let commands access Toplevel.state;
wenzelm
parents: 9863
diff changeset
   128
  in f src ctxt x end;
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   129
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   130
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   131
(* outer syntax *)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   132
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   133
local
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   134
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   135
val property = P.xname -- Scan.optional (P.$$$ "=" |-- P.!!! P.xname) "";
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   136
val properties = Scan.optional (P.$$$ "[" |-- P.!!! (P.enum "," property --| P.$$$ "]")) [];
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   137
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   138
val antiq = P.position P.xname -- properties -- P.arguments --| Scan.ahead P.eof
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   139
  >> (fn (((x, pos), y), z) => (y, Args.src ((x, z), pos)));
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   141
fun antiq_args_aux keyword_lexicon (str, pos) =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   142
  Source.of_string str
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   143
  |> Symbol.source false
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   144
  |> T.source false (K (keyword_lexicon, Scan.empty_lexicon)) pos
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   145
  |> T.source_proper
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15529
diff changeset
   146
  |> Source.source T.stopper (Scan.error (Scan.bulk (P.!!! antiq))) NONE
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   147
  |> Source.exhaust;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   148
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   149
in
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   150
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   151
fun antiq_args lex (s, pos) =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   152
  (case antiq_args_aux lex (s, pos) of [x] => x | _ => raise ERROR) handle ERROR =>
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   153
    error ("Malformed antiquotation: " ^ quote ("@{" ^ s ^ "}") ^ Position.str_of pos);
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   154
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   155
end;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   156
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   157
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   158
(* eval_antiquote *)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   159
11714
bc0a84063a9c added global modes ref;
wenzelm
parents: 11524
diff changeset
   160
val modes = ref ([]: string list);
bc0a84063a9c added global modes ref;
wenzelm
parents: 11524
diff changeset
   161
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   162
fun eval_antiquote lex state (str, pos) =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   163
  let
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   164
    fun expand (Antiquote.Text s) = s
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   165
      | expand (Antiquote.Antiq x) =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   166
          let val (opts, src) = antiq_args lex x in
10739
ec19f5902ef5 antiq: preview errors;
wenzelm
parents: 10570
diff changeset
   167
            options opts (fn () => command src state) ();  (*preview errors!*)
11714
bc0a84063a9c added global modes ref;
wenzelm
parents: 11524
diff changeset
   168
            Library.setmp print_mode (! modes @ Latex.modes @ ! print_mode)
16194
3d192ab9907b Output.no_warnings;
wenzelm
parents: 16165
diff changeset
   169
              (Output.no_warnings (options opts (fn () => command src state))) ()
10321
bbaad3045e37 let commands access Toplevel.state;
wenzelm
parents: 9863
diff changeset
   170
          end;
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   171
    val ants = Antiquote.antiquotes_of (str, pos);
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   172
  in
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   173
    if Toplevel.is_toplevel state andalso exists Antiquote.is_antiq ants then
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   174
      error ("Cannot expand antiquotations at top-level" ^ Position.str_of pos)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   175
    else implode (map expand ants)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   176
  end;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   177
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   178
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   179
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   180
(** present theory source **)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   181
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   182
(* present_tokens *)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   183
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   184
val interest_level = ref 0;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   185
15473
24132e496561 - Proofs are now hidden by default
berghofe
parents: 15437
diff changeset
   186
val hide_commands = ref true;
15430
1e1aeaf1dec3 Implemented hiding of proofs and other commands.
berghofe
parents: 15349
diff changeset
   187
val hidden_commands = ref ([] : string list);
1e1aeaf1dec3 Implemented hiding of proofs and other commands.
berghofe
parents: 15349
diff changeset
   188
1e1aeaf1dec3 Implemented hiding of proofs and other commands.
berghofe
parents: 15349
diff changeset
   189
fun add_hidden_commands cmds = (hidden_commands := !hidden_commands @ cmds);
1e1aeaf1dec3 Implemented hiding of proofs and other commands.
berghofe
parents: 15349
diff changeset
   190
1e1aeaf1dec3 Implemented hiding of proofs and other commands.
berghofe
parents: 15349
diff changeset
   191
fun is_proof state = (case Toplevel.node_of state of
1e1aeaf1dec3 Implemented hiding of proofs and other commands.
berghofe
parents: 15349
diff changeset
   192
  Toplevel.Theory _ => false | _ => true) handle Toplevel.UNDEF => false;
1e1aeaf1dec3 Implemented hiding of proofs and other commands.
berghofe
parents: 15349
diff changeset
   193
1e1aeaf1dec3 Implemented hiding of proofs and other commands.
berghofe
parents: 15349
diff changeset
   194
fun is_newline (Latex.Basic tk, _) = T.is_newline tk
1e1aeaf1dec3 Implemented hiding of proofs and other commands.
berghofe
parents: 15349
diff changeset
   195
  | is_newline _ = false;
1e1aeaf1dec3 Implemented hiding of proofs and other commands.
berghofe
parents: 15349
diff changeset
   196
1e1aeaf1dec3 Implemented hiding of proofs and other commands.
berghofe
parents: 15349
diff changeset
   197
fun is_hidden (Latex.Basic tk, _) =
1e1aeaf1dec3 Implemented hiding of proofs and other commands.
berghofe
parents: 15349
diff changeset
   198
      T.is_kind T.Command tk andalso T.val_of tk mem !hidden_commands
1e1aeaf1dec3 Implemented hiding of proofs and other commands.
berghofe
parents: 15349
diff changeset
   199
  | is_hidden _ = false;
1e1aeaf1dec3 Implemented hiding of proofs and other commands.
berghofe
parents: 15349
diff changeset
   200
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
   201
fun filter_newlines toks = (case List.mapPartial
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15529
diff changeset
   202
    (fn (tk, i) => if is_newline tk then SOME tk else NONE) toks of
15529
b86d5c84a9a7 Optimized present_tokens to produce fewer newlines when hiding proofs.
berghofe
parents: 15473
diff changeset
   203
  [] => [] | [tk] => [tk] | _ :: toks' => toks');
b86d5c84a9a7 Optimized present_tokens to produce fewer newlines when hiding proofs.
berghofe
parents: 15473
diff changeset
   204
15437
berghofe
parents: 15430
diff changeset
   205
fun present_tokens lex (flag, toks) state state' =
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15529
diff changeset
   206
  Buffer.add (case flag of NONE => "" | SOME b => Latex.flag_markup b) o
15437
berghofe
parents: 15430
diff changeset
   207
   ((if !hide_commands andalso exists (is_hidden o fst) toks then []
15529
b86d5c84a9a7 Optimized present_tokens to produce fewer newlines when hiding proofs.
berghofe
parents: 15473
diff changeset
   208
     else if !hide_commands andalso is_proof state then
b86d5c84a9a7 Optimized present_tokens to produce fewer newlines when hiding proofs.
berghofe
parents: 15473
diff changeset
   209
       if is_proof state' then [] else filter_newlines toks
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
   210
     else List.mapPartial (fn (tk, i) =>
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15529
diff changeset
   211
       if i > ! interest_level then NONE else SOME tk) toks)
15437
berghofe
parents: 15430
diff changeset
   212
    |> map (apsnd (eval_antiquote lex state'))
11861
38d8075ebff6 maintain Latex.flag_markup;
wenzelm
parents: 11716
diff changeset
   213
    |> Latex.output_tokens
38d8075ebff6 maintain Latex.flag_markup;
wenzelm
parents: 11716
diff changeset
   214
    |> Buffer.add);
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   215
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   216
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   217
(* parse_thy *)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   218
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   219
datatype markup = Markup | MarkupEnv | Verbatim;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   220
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   221
local
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   222
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   223
val opt_newline = Scan.option (Scan.one T.is_newline);
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   224
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   225
fun check_level i =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   226
  if i > 0 then Scan.succeed ()
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   227
  else Scan.fail_with (K "Bad nesting of meta-comments");
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   228
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   229
val ignore =
13775
a918c547cd4d corrected swallowing of newlines after end-of-ignore: rollback
oheimb
parents: 13774
diff changeset
   230
  Scan.depend (fn i => opt_newline |-- P.position (Scan.one T.is_begin_ignore) >> pair (i + 1)) ||
a918c547cd4d corrected swallowing of newlines after end-of-ignore: rollback
oheimb
parents: 13774
diff changeset
   231
  Scan.depend (fn i => P.position (Scan.one T.is_end_ignore) --|
13774
77a1e723151d corrected swallowing of newlines after end-of-ignore (improved)
oheimb
parents: 13742
diff changeset
   232
    (opt_newline -- check_level i) >> pair (i - 1));
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   233
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   234
val ignore_cmd = Scan.state -- ignore
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15529
diff changeset
   235
  >> (fn (i, (x, pos)) => (false, (NONE, ((Latex.Basic x, ("", pos)), i))));
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   236
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   237
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   238
val is_improper = not o (T.is_proper orf T.is_begin_ignore orf T.is_end_ignore);
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   239
val improper = Scan.any is_improper;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   240
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   241
val improper_keep_indent = Scan.repeat
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   242
  (Scan.unless (Scan.one T.is_indent -- Scan.one T.is_proper) (Scan.one is_improper));
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   243
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   244
val improper_end =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   245
  (improper -- P.semicolon) |-- improper_keep_indent ||
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   246
  improper_keep_indent;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   247
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   248
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   249
val stopper =
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15529
diff changeset
   250
  ((false, (NONE, ((Latex.Basic (#1 T.stopper), ("", Position.none)), 0))),
11861
38d8075ebff6 maintain Latex.flag_markup;
wenzelm
parents: 11716
diff changeset
   251
    fn (_, (_, ((Latex.Basic x, _), _))) => (#2 T.stopper x) | _ => false);
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   252
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   253
in
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   254
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   255
fun parse_thy markup lex trs src =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   256
  let
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   257
    val text = P.position P.text;
15666
5c5925dc4921 Scan.peek;
wenzelm
parents: 15570
diff changeset
   258
    val token = Scan.peek (fn i =>
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   259
     (improper |-- markup Markup -- P.!!!! (improper |-- text --| improper_end)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15529
diff changeset
   260
        >> (fn (x, y) => (true, (SOME true, ((Latex.Markup (T.val_of x), y), i)))) ||
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   261
      improper |-- markup MarkupEnv -- P.!!!! (improper |-- text --| improper_end)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15529
diff changeset
   262
        >> (fn (x, y) => (true, (SOME true, ((Latex.MarkupEnv (T.val_of x), y), i)))) ||
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   263
      (P.$$$ "--" |-- P.!!!! (improper |-- text))
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15529
diff changeset
   264
        >> (fn y => (false, (NONE, ((Latex.Markup "cmt", y), i)))) ||
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   265
      (improper -- markup Verbatim) |-- P.!!!! (improper |-- text --| improper_end)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15529
diff changeset
   266
        >> (fn y => (true, (NONE, ((Latex.Verbatim, y), i)))) ||
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   267
      P.position (Scan.one T.not_eof)
15666
5c5925dc4921 Scan.peek;
wenzelm
parents: 15570
diff changeset
   268
        >> (fn (x, pos) => (T.is_kind T.Command x, (SOME false, ((Latex.Basic x, ("", pos)), i))))));
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   269
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   270
    val body = Scan.any (not o fst andf not o #2 stopper);
11861
38d8075ebff6 maintain Latex.flag_markup;
wenzelm
parents: 11716
diff changeset
   271
    val section = body -- Scan.one fst -- body
38d8075ebff6 maintain Latex.flag_markup;
wenzelm
parents: 11716
diff changeset
   272
      >> (fn ((b1, c), b2) => (#1 (#2 c), map (snd o snd) (b1 @ (c :: b2))));
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   273
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   274
    val cmds =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   275
      src
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   276
      |> Source.filter (not o T.is_semicolon)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15529
diff changeset
   277
      |> Source.source' 0 T.stopper (Scan.error (Scan.bulk (ignore_cmd || token))) NONE
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15529
diff changeset
   278
      |> Source.source stopper (Scan.error (Scan.bulk section)) NONE
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   279
      |> Source.exhaust;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   280
  in
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   281
    if length cmds = length trs then
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   282
      (trs ~~ map (present_tokens lex) cmds, Buffer.empty)
11861
38d8075ebff6 maintain Latex.flag_markup;
wenzelm
parents: 11716
diff changeset
   283
    else error "Messed-up outer syntax for presentation"
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   284
  end;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   285
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   286
end;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   287
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   288
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   289
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   290
(** setup default output **)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   291
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   292
(* options *)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   293
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   294
val _ = add_options
9220
d0506ced27c8 added options "eta_contract", "long_names";
wenzelm
parents: 9213
diff changeset
   295
 [("show_types", Library.setmp Syntax.show_types o boolean),
d0506ced27c8 added options "eta_contract", "long_names";
wenzelm
parents: 9213
diff changeset
   296
  ("show_sorts", Library.setmp Syntax.show_sorts o boolean),
14707
2d6350d7b9b7 show_structs option;
wenzelm
parents: 14696
diff changeset
   297
  ("show_structs", Library.setmp show_structs o boolean),
15988
181bbcee76f5 renamed show_var_qmarks to show_question_marks;
wenzelm
parents: 15960
diff changeset
   298
  ("show_question_marks", Library.setmp show_question_marks o boolean),
14696
wenzelm
parents: 14345
diff changeset
   299
  ("long_names", Library.setmp NameSpace.long_names o boolean),
16142
8eead5356ccb added short_names, unique_names options;
wenzelm
parents: 16064
diff changeset
   300
  ("short_names", Library.setmp NameSpace.short_names o boolean),
8eead5356ccb added short_names, unique_names options;
wenzelm
parents: 16064
diff changeset
   301
  ("unique_names", Library.setmp NameSpace.unique_names o boolean),
9220
d0506ced27c8 added options "eta_contract", "long_names";
wenzelm
parents: 9213
diff changeset
   302
  ("eta_contract", Library.setmp Syntax.eta_contract o boolean),
14899
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
   303
  ("locale", Library.setmp locale),
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   304
  ("display", Library.setmp display o boolean),
13929
21615e44ba88 Added "break" flag to allow line breaks within \isa{...}
berghofe
parents: 13775
diff changeset
   305
  ("break", Library.setmp break o boolean),
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   306
  ("quotes", Library.setmp quotes o boolean),
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   307
  ("mode", fn s => fn f => fn () => Library.setmp print_mode (s :: ! print_mode) f ()),
9732
c32c7ef228c6 added "name" antiq and "indent" option;
wenzelm
parents: 9504
diff changeset
   308
  ("margin", Pretty.setmp_margin o integer),
9750
270cd9831e7b added "source" option;
wenzelm
parents: 9732
diff changeset
   309
  ("indent", Library.setmp indent o integer),
10321
bbaad3045e37 let commands access Toplevel.state;
wenzelm
parents: 9863
diff changeset
   310
  ("source", Library.setmp source o boolean),
bbaad3045e37 let commands access Toplevel.state;
wenzelm
parents: 9863
diff changeset
   311
  ("goals_limit", Library.setmp goals_limit o integer)];
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   312
16002
wenzelm
parents: 15988
diff changeset
   313
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   314
(* commands *)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   315
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   316
fun cond_quote prt =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   317
  if ! quotes then Pretty.quote prt else prt;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   318
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   319
fun cond_display prt =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   320
  if ! display then
14835
695ee8ad0bb6 Library.read_int; Output.output;
wenzelm
parents: 14776
diff changeset
   321
    Output.output (Pretty.string_of (Pretty.indent (! indent) prt))
9863
67cdb658e422 tuned output of isabelle env;
wenzelm
parents: 9828
diff changeset
   322
    |> enclose "\\begin{isabelle}%\n" "%\n\\end{isabelle}"
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   323
  else
14835
695ee8ad0bb6 Library.read_int; Output.output;
wenzelm
parents: 14776
diff changeset
   324
    Output.output ((if ! break then Pretty.string_of else Pretty.str_of) prt)
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   325
    |> enclose "\\isa{" "}";
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   326
14345
3023d90dc59e separate thm lists in latex output by \isasep
kleing
parents: 13929
diff changeset
   327
fun cond_seq_display prts =
3023d90dc59e separate thm lists in latex output by \isasep
kleing
parents: 13929
diff changeset
   328
  if ! display then
14835
695ee8ad0bb6 Library.read_int; Output.output;
wenzelm
parents: 14776
diff changeset
   329
    map (Output.output o Pretty.string_of o Pretty.indent (! indent)) prts
14345
3023d90dc59e separate thm lists in latex output by \isasep
kleing
parents: 13929
diff changeset
   330
    |> separate "\\isasep\\isanewline%\n"
3023d90dc59e separate thm lists in latex output by \isasep
kleing
parents: 13929
diff changeset
   331
    |> implode
3023d90dc59e separate thm lists in latex output by \isasep
kleing
parents: 13929
diff changeset
   332
    |> enclose "\\begin{isabelle}%\n" "%\n\\end{isabelle}"
3023d90dc59e separate thm lists in latex output by \isasep
kleing
parents: 13929
diff changeset
   333
  else
14835
695ee8ad0bb6 Library.read_int; Output.output;
wenzelm
parents: 14776
diff changeset
   334
    map (Output.output o (if ! break then Pretty.string_of else Pretty.str_of)) prts
14345
3023d90dc59e separate thm lists in latex output by \isasep
kleing
parents: 13929
diff changeset
   335
    |> separate "\\isasep\\isanewline%\n"
3023d90dc59e separate thm lists in latex output by \isasep
kleing
parents: 13929
diff changeset
   336
    |> implode
3023d90dc59e separate thm lists in latex output by \isasep
kleing
parents: 13929
diff changeset
   337
    |> enclose "\\isa{" "}";
3023d90dc59e separate thm lists in latex output by \isasep
kleing
parents: 13929
diff changeset
   338
11011
14b78c0c9f05 pretty_text: tweak_lines handles linebreaks gracefully;
wenzelm
parents: 10739
diff changeset
   339
fun tweak_line s =
14b78c0c9f05 pretty_text: tweak_lines handles linebreaks gracefully;
wenzelm
parents: 10739
diff changeset
   340
  if ! display then s else Symbol.strip_blanks s;
9750
270cd9831e7b added "source" option;
wenzelm
parents: 9732
diff changeset
   341
11011
14b78c0c9f05 pretty_text: tweak_lines handles linebreaks gracefully;
wenzelm
parents: 10739
diff changeset
   342
val pretty_text = Pretty.chunks o map Pretty.str o map tweak_line o Library.split_lines;
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   343
9750
270cd9831e7b added "source" option;
wenzelm
parents: 9732
diff changeset
   344
val pretty_source =
270cd9831e7b added "source" option;
wenzelm
parents: 9732
diff changeset
   345
  pretty_text o space_implode " " o map Args.string_of o #2 o #1 o Args.dest_src;
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   346
12055
a9c44895cc8c pretty/print functions with context;
wenzelm
parents: 11861
diff changeset
   347
fun pretty_term ctxt = ProofContext.pretty_term ctxt o ProofContext.extern_skolem ctxt;
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   348
16002
wenzelm
parents: 15988
diff changeset
   349
fun pretty_term_typ ctxt t =
wenzelm
parents: 15988
diff changeset
   350
  (Syntax.const Syntax.constrainC $
wenzelm
parents: 15988
diff changeset
   351
    ProofContext.extern_skolem ctxt t $
wenzelm
parents: 15988
diff changeset
   352
    Syntax.term_of_typ (! show_sorts) (Term.fastype_of t))
wenzelm
parents: 15988
diff changeset
   353
  |> ProofContext.pretty_term ctxt;
15880
d6aa6c707acf added antiquotations typeof, const, term_style, thm_style, term_type (something still to be done)
haftmann
parents: 15666
diff changeset
   354
16002
wenzelm
parents: 15988
diff changeset
   355
fun pretty_term_typeof ctxt = ProofContext.pretty_typ ctxt o Term.fastype_of;
15880
d6aa6c707acf added antiquotations typeof, const, term_style, thm_style, term_type (something still to be done)
haftmann
parents: 15666
diff changeset
   356
16002
wenzelm
parents: 15988
diff changeset
   357
fun pretty_term_const ctxt t =
wenzelm
parents: 15988
diff changeset
   358
  if Term.is_Const t then pretty_term ctxt t
wenzelm
parents: 15988
diff changeset
   359
  else error ("Logical constant expected: " ^ ProofContext.string_of_term ctxt t);
15880
d6aa6c707acf added antiquotations typeof, const, term_style, thm_style, term_type (something still to be done)
haftmann
parents: 15666
diff changeset
   360
14345
3023d90dc59e separate thm lists in latex output by \isasep
kleing
parents: 13929
diff changeset
   361
fun pretty_thm ctxt = pretty_term ctxt o Thm.prop_of;
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   362
15960
9bd6550dc004 added Proof.context to antiquotation
haftmann
parents: 15918
diff changeset
   363
fun pretty_term_style ctxt (name, term) =
9bd6550dc004 added Proof.context to antiquotation
haftmann
parents: 15918
diff changeset
   364
  let
9bd6550dc004 added Proof.context to antiquotation
haftmann
parents: 15918
diff changeset
   365
    val thy = ProofContext.theory_of ctxt
15988
181bbcee76f5 renamed show_var_qmarks to show_question_marks;
wenzelm
parents: 15960
diff changeset
   366
  in pretty_term ctxt (TermStyle.the_style thy name ctxt term) end;
15880
d6aa6c707acf added antiquotations typeof, const, term_style, thm_style, term_type (something still to be done)
haftmann
parents: 15666
diff changeset
   367
d6aa6c707acf added antiquotations typeof, const, term_style, thm_style, term_type (something still to be done)
haftmann
parents: 15666
diff changeset
   368
fun pretty_thm_style ctxt (name, thm) = pretty_term_style ctxt (name, Thm.prop_of thm);
d6aa6c707acf added antiquotations typeof, const, term_style, thm_style, term_type (something still to be done)
haftmann
parents: 15666
diff changeset
   369
12055
a9c44895cc8c pretty/print functions with context;
wenzelm
parents: 11861
diff changeset
   370
fun pretty_prf full ctxt thms =    (* FIXME context syntax!? *)
11524
197f2e14a714 Added functions for printing primitive proof terms.
berghofe
parents: 11240
diff changeset
   371
  Pretty.chunks (map (ProofSyntax.pretty_proof_of full) thms);
197f2e14a714 Added functions for printing primitive proof terms.
berghofe
parents: 11240
diff changeset
   372
9750
270cd9831e7b added "source" option;
wenzelm
parents: 9732
diff changeset
   373
fun output_with pretty src ctxt x =
270cd9831e7b added "source" option;
wenzelm
parents: 9732
diff changeset
   374
  let
12055
a9c44895cc8c pretty/print functions with context;
wenzelm
parents: 11861
diff changeset
   375
    val prt = pretty ctxt x;      (*always pretty in order to catch errors!*)
9750
270cd9831e7b added "source" option;
wenzelm
parents: 9732
diff changeset
   376
    val prt' = if ! source then pretty_source src else prt;
270cd9831e7b added "source" option;
wenzelm
parents: 9732
diff changeset
   377
  in cond_display (cond_quote prt') end;
9732
c32c7ef228c6 added "name" antiq and "indent" option;
wenzelm
parents: 9504
diff changeset
   378
14345
3023d90dc59e separate thm lists in latex output by \isasep
kleing
parents: 13929
diff changeset
   379
fun output_seq_with pretty src ctxt xs =
3023d90dc59e separate thm lists in latex output by \isasep
kleing
parents: 13929
diff changeset
   380
  let
3023d90dc59e separate thm lists in latex output by \isasep
kleing
parents: 13929
diff changeset
   381
    val prts = map (pretty ctxt) xs;   (*always pretty in order to catch errors!*)
3023d90dc59e separate thm lists in latex output by \isasep
kleing
parents: 13929
diff changeset
   382
    val prts' = if ! source then [pretty_source src] else prts;
3023d90dc59e separate thm lists in latex output by \isasep
kleing
parents: 13929
diff changeset
   383
  in cond_seq_display (map cond_quote prts') end;
3023d90dc59e separate thm lists in latex output by \isasep
kleing
parents: 13929
diff changeset
   384
10360
807992b67edd tuned goals output;
wenzelm
parents: 10350
diff changeset
   385
fun output_goals main_goal src state = args (Scan.succeed ()) (output_with (fn _ => fn _ =>
807992b67edd tuned goals output;
wenzelm
parents: 10350
diff changeset
   386
  Pretty.chunks (Proof.pretty_goals main_goal (Toplevel.proof_of state
807992b67edd tuned goals output;
wenzelm
parents: 10350
diff changeset
   387
      handle Toplevel.UNDEF => error "No proof state")))) src state;
807992b67edd tuned goals output;
wenzelm
parents: 10350
diff changeset
   388
16064
7953879aa6cf ML_idf antiquotation
haftmann
parents: 16002
diff changeset
   389
(*this is just experimental*)
7953879aa6cf ML_idf antiquotation
haftmann
parents: 16002
diff changeset
   390
fun output_ml_idf src ctxt idf = snd (use_text Context.ml_output true idf,
7953879aa6cf ML_idf antiquotation
haftmann
parents: 16002
diff changeset
   391
    output_with (K pretty_text) src ctxt idf);
7953879aa6cf ML_idf antiquotation
haftmann
parents: 16002
diff changeset
   392
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   393
val _ = add_commands
14696
wenzelm
parents: 14345
diff changeset
   394
 [("thm", args Attrib.local_thmss (output_seq_with pretty_thm)),
16165
dbe9ee8ffcdd concl antiqutations
haftmann
parents: 16142
diff changeset
   395
  ("thm_style", args ((Scan.lift (Args.name || Args.symbol)) -- Attrib.local_thm) (output_with pretty_thm_style)),
9750
270cd9831e7b added "source" option;
wenzelm
parents: 9732
diff changeset
   396
  ("prop", args Args.local_prop (output_with pretty_term)),
270cd9831e7b added "source" option;
wenzelm
parents: 9732
diff changeset
   397
  ("term", args Args.local_term (output_with pretty_term)),
16165
dbe9ee8ffcdd concl antiqutations
haftmann
parents: 16142
diff changeset
   398
  ("term_style", args ((Scan.lift (Args.name || Args.symbol)) -- Args.local_term) (output_with pretty_term_style)),
15880
d6aa6c707acf added antiquotations typeof, const, term_style, thm_style, term_type (something still to be done)
haftmann
parents: 15666
diff changeset
   399
  ("term_type", args Args.local_term (output_with pretty_term_typ)),
d6aa6c707acf added antiquotations typeof, const, term_style, thm_style, term_type (something still to be done)
haftmann
parents: 15666
diff changeset
   400
  ("typeof", args Args.local_term (output_with pretty_term_typeof)),
d6aa6c707acf added antiquotations typeof, const, term_style, thm_style, term_type (something still to be done)
haftmann
parents: 15666
diff changeset
   401
  ("const", args Args.local_term (output_with pretty_term_const)),
16345
b035482bed02 Args.local_typ_abbrev;
wenzelm
parents: 16194
diff changeset
   402
  ("typ", args Args.local_typ_abbrev (output_with ProofContext.pretty_typ)),
14696
wenzelm
parents: 14345
diff changeset
   403
  ("text", args (Scan.lift Args.name) (output_with (K pretty_text))),
10360
807992b67edd tuned goals output;
wenzelm
parents: 10350
diff changeset
   404
  ("goals", output_goals true),
14696
wenzelm
parents: 14345
diff changeset
   405
  ("subgoals", output_goals false),
wenzelm
parents: 14345
diff changeset
   406
  ("prf", args Attrib.local_thmss (output_with (pretty_prf false))),
16064
7953879aa6cf ML_idf antiquotation
haftmann
parents: 16002
diff changeset
   407
  ("full_prf", args Attrib.local_thmss (output_with (pretty_prf true))),
7953879aa6cf ML_idf antiquotation
haftmann
parents: 16002
diff changeset
   408
  (*this is just experimental*)
7953879aa6cf ML_idf antiquotation
haftmann
parents: 16002
diff changeset
   409
  ("ML_idf", args (Scan.lift Args.name) output_ml_idf)];
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   410
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   411
end;