src/Pure/Isar/isar_output.ML
author wenzelm
Thu, 15 Sep 2005 17:16:56 +0200
changeset 17412 e26cb20ef0cc
parent 17263 8bf9126d8dcd
child 17557 cbfd12c61a1f
permissions -rw-r--r--
TableFun/Symtab: curried lookup and update;
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
11714
bc0a84063a9c added global modes ref;
wenzelm
parents: 11524
diff changeset
    22
  val modes: string list ref
12939
279a3cf23a98 export eval_antiquote;
wenzelm
parents: 12881
diff changeset
    23
  val eval_antiquote: Scan.lexicon -> Toplevel.state -> string * Position.T -> string
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
    24
  val present_thy: Scan.lexicon -> (string -> string list) -> (markup -> string -> bool) ->
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
    25
    Toplevel.transition list -> (OuterLex.token, 'a) Source.source -> Buffer.T
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
    26
  val output_list: (Proof.context -> 'a -> Pretty.T) -> Args.src ->
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
    27
    Proof.context -> 'a list -> string
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
    28
  val output: (Proof.context -> 'a -> Pretty.T) -> Args.src -> Proof.context -> 'a -> string
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    29
end;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    30
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    31
structure IsarOutput: ISAR_OUTPUT =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    32
struct
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    33
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    34
structure T = OuterLex;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    35
structure P = OuterParse;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    36
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
    37
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
    38
(** global options **)
14899
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
    39
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
    40
val locale = ref "";
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
    41
val display = ref false;
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
    42
val quotes = ref false;
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
    43
val indent = ref 0;
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
    44
val source = ref false;
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
    45
val break = ref false;
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
    46
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
    47
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
    48
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    49
(** maintain global commands **)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    50
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    51
local
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    52
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    53
val global_commands =
10321
bbaad3045e37 let commands access Toplevel.state;
wenzelm
parents: 9863
diff changeset
    54
  ref (Symtab.empty: (Args.src -> Toplevel.state -> string) Symtab.table);
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    55
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    56
val global_options =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    57
  ref (Symtab.empty: (string -> (unit -> string) -> unit -> string) Symtab.table);
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    58
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
    59
fun add_item kind (name, x) tab =
16894
40f80823b451 Inttab.defined;
wenzelm
parents: 16345
diff changeset
    60
 (if not (Symtab.defined tab name) then ()
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
    61
  else warning ("Redefined antiquotation " ^ kind ^ ": " ^ quote name);
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17263
diff changeset
    62
  Symtab.update (name, x) tab);
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    63
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    64
in
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    65
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
    66
val add_commands = Library.change global_commands o fold (add_item "command");
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
    67
val add_options = Library.change global_options o fold (add_item "option");
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    68
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    69
fun command src =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    70
  let val ((name, _), pos) = Args.dest_src src in
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17263
diff changeset
    71
    (case Symtab.lookup (! global_commands) name of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15529
diff changeset
    72
      NONE => error ("Unknown antiquotation command: " ^ quote name ^ Position.str_of pos)
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15529
diff changeset
    73
    | SOME f => transform_failure (curry Antiquote.ANTIQUOTE_FAIL (name, pos)) (f src))
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    74
  end;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    75
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    76
fun option (name, s) f () =
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17263
diff changeset
    77
  (case Symtab.lookup (! global_options) name of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15529
diff changeset
    78
    NONE => error ("Unknown antiquotation option: " ^ quote name)
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15529
diff changeset
    79
  | SOME opt => opt s f ());
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    80
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    81
fun options [] f = f
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    82
  | options (opt :: opts) f = option opt (options opts f);
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    83
9213
2651a4db8883 help_antiquotations;
wenzelm
parents: 9140
diff changeset
    84
9220
d0506ced27c8 added options "eta_contract", "long_names";
wenzelm
parents: 9213
diff changeset
    85
fun print_antiquotations () =
d0506ced27c8 added options "eta_contract", "long_names";
wenzelm
parents: 9213
diff changeset
    86
 [Pretty.big_list "antiquotation commands:" (map Pretty.str (Symtab.keys (! global_commands))),
d0506ced27c8 added options "eta_contract", "long_names";
wenzelm
parents: 9213
diff changeset
    87
  Pretty.big_list "antiquotation options:" (map Pretty.str (Symtab.keys (! global_options)))]
d0506ced27c8 added options "eta_contract", "long_names";
wenzelm
parents: 9213
diff changeset
    88
 |> Pretty.chunks |> Pretty.writeln;
9213
2651a4db8883 help_antiquotations;
wenzelm
parents: 9140
diff changeset
    89
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    90
end;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    91
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    92
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    93
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    94
(** syntax of antiquotations **)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    95
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    96
(* option values *)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    97
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    98
fun boolean "" = true
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
    99
  | boolean "true" = true
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   100
  | boolean "false" = false
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   101
  | boolean s = error ("Bad boolean value: " ^ quote s);
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   102
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   103
fun integer s =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   104
  let
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   105
    fun int ss =
14899
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
   106
      (case Library.read_int ss of (i, []) => i
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
   107
      | _ => error ("Bad integer value: " ^ quote s));
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   108
  in (case Symbol.explode s of "-" :: ss => ~ (int ss) | ss => int ss) end;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   109
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   110
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   111
(* args syntax *)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   112
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   113
fun syntax (scan: (Proof.context * Args.T list -> 'a * (Proof.context * Args.T list))) =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   114
  Args.syntax "antiquotation" scan;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   115
10321
bbaad3045e37 let commands access Toplevel.state;
wenzelm
parents: 9863
diff changeset
   116
fun args scan f src state : string =
14899
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
   117
  let
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
   118
    val ctxt0 =
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   119
      if ! locale = "" then Toplevel.body_context_of state
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15529
diff changeset
   120
      else #3 (Locale.read_context_statement (SOME (! locale)) [] []
14899
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
   121
        (ProofContext.init (Toplevel.theory_of state)));
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
   122
    val (ctxt, x) = syntax scan src ctxt0;
10321
bbaad3045e37 let commands access Toplevel.state;
wenzelm
parents: 9863
diff changeset
   123
  in f src ctxt x end;
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   124
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   125
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   126
(* outer syntax *)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   127
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   128
local
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   129
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   130
val property = P.xname -- Scan.optional (P.$$$ "=" |-- P.!!! P.xname) "";
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   131
val properties = Scan.optional (P.$$$ "[" |-- P.!!! (P.enum "," property --| P.$$$ "]")) [];
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   132
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   133
val antiq = P.position P.xname -- properties -- P.arguments --| Scan.ahead P.eof
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   134
  >> (fn (((x, pos), y), z) => (y, Args.src ((x, z), pos)));
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   135
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   136
fun antiq_args_aux keyword_lexicon (str, pos) =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   137
  Source.of_string str
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   138
  |> Symbol.source false
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   139
  |> T.source false (K (keyword_lexicon, Scan.empty_lexicon)) pos
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   140
  |> T.source_proper
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15529
diff changeset
   141
  |> Source.source T.stopper (Scan.error (Scan.bulk (P.!!! antiq))) NONE
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   142
  |> Source.exhaust;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   143
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   144
in
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   145
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   146
fun antiq_args lex (s, pos) =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   147
  (case antiq_args_aux lex (s, pos) of [x] => x | _ => raise ERROR) handle ERROR =>
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   148
    error ("Malformed antiquotation: " ^ quote ("@{" ^ s ^ "}") ^ Position.str_of pos);
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   149
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   150
end;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   151
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   152
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   153
(* eval_antiquote *)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   154
11714
bc0a84063a9c added global modes ref;
wenzelm
parents: 11524
diff changeset
   155
val modes = ref ([]: string list);
bc0a84063a9c added global modes ref;
wenzelm
parents: 11524
diff changeset
   156
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   157
fun eval_antiquote lex state (str, pos) =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   158
  let
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   159
    fun expand (Antiquote.Text s) = s
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   160
      | expand (Antiquote.Antiq x) =
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   161
          let val (opts, src) = antiq_args lex x in
10739
ec19f5902ef5 antiq: preview errors;
wenzelm
parents: 10570
diff changeset
   162
            options opts (fn () => command src state) ();  (*preview errors!*)
11714
bc0a84063a9c added global modes ref;
wenzelm
parents: 11524
diff changeset
   163
            Library.setmp print_mode (! modes @ Latex.modes @ ! print_mode)
16194
3d192ab9907b Output.no_warnings;
wenzelm
parents: 16165
diff changeset
   164
              (Output.no_warnings (options opts (fn () => command src state))) ()
10321
bbaad3045e37 let commands access Toplevel.state;
wenzelm
parents: 9863
diff changeset
   165
          end;
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   166
    val ants = Antiquote.antiquotes_of (str, pos);
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   167
  in
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   168
    if Toplevel.is_toplevel state andalso exists Antiquote.is_antiq ants then
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   169
      error ("Cannot expand antiquotations at top-level" ^ Position.str_of pos)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   170
    else implode (map expand ants)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   171
  end;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   172
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   173
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   174
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   175
(** present theory source **)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   176
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   177
(* presentation tokens *)
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   178
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   179
datatype token =
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   180
    NoToken
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   181
  | BasicToken of T.token
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   182
  | MarkupToken of string * (string * Position.T)
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   183
  | MarkupEnvToken of string * (string * Position.T)
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   184
  | VerbatimToken of string * Position.T;
15430
1e1aeaf1dec3 Implemented hiding of proofs and other commands.
berghofe
parents: 15349
diff changeset
   185
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   186
fun output_token lex state =
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   187
  let
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   188
    val eval = eval_antiquote lex state
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   189
  in
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   190
    fn NoToken => ""
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   191
     | BasicToken tok => Latex.output_basic tok
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   192
     | MarkupToken (cmd, txt) => Latex.output_markup cmd (eval txt)
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   193
     | MarkupEnvToken (cmd, txt) => Latex.output_markup_env cmd (eval txt)
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   194
     | VerbatimToken txt => Latex.output_verbatim (eval txt)
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   195
  end;
15430
1e1aeaf1dec3 Implemented hiding of proofs and other commands.
berghofe
parents: 15349
diff changeset
   196
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   197
fun basic_token pred (BasicToken tok) = pred tok
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   198
  | basic_token _ _ = false;
15430
1e1aeaf1dec3 Implemented hiding of proofs and other commands.
berghofe
parents: 15349
diff changeset
   199
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   200
val improper_token = basic_token (not o T.is_proper);
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   201
val comment_token = basic_token T.is_comment;
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   202
val blank_token = basic_token T.is_blank;
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   203
val newline_token = basic_token T.is_newline;
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   204
15430
1e1aeaf1dec3 Implemented hiding of proofs and other commands.
berghofe
parents: 15349
diff changeset
   205
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   206
(* command spans *)
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   207
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   208
type command = string * Position.T * string list;   (*name, position, tags*)
17263
8bf9126d8dcd markup commands: optional locale specification;
wenzelm
parents: 17221
diff changeset
   209
type tok = token * string * int;         (*token, markup flag, meta-comment depth*)
17185
5140808111d1 clarify type tok, do not emit markup flag for suppressed tokens;
wenzelm
parents: 17151
diff changeset
   210
type source = tok list;
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   211
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   212
datatype span = Span of command * (source * source * source * source) * bool;
15529
b86d5c84a9a7 Optimized present_tokens to produce fewer newlines when hiding proofs.
berghofe
parents: 15473
diff changeset
   213
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   214
fun make_span cmd src =
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   215
  let
17089
f708a31fa8bb made SML/XL happy;
wenzelm
parents: 17067
diff changeset
   216
    fun take_newline ((tok: tok) :: toks) =
17185
5140808111d1 clarify type tok, do not emit markup flag for suppressed tokens;
wenzelm
parents: 17151
diff changeset
   217
          if newline_token (#1 tok) then ([tok], toks, true)
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   218
          else ([], tok :: toks, false)
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   219
      | take_newline [] = ([], [], false);
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   220
    val (((src_prefix, src_main), src_suffix1), (src_suffix2, src_appendix, newline)) =
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   221
      src
17185
5140808111d1 clarify type tok, do not emit markup flag for suppressed tokens;
wenzelm
parents: 17151
diff changeset
   222
      |> take_prefix (improper_token o #1)
5140808111d1 clarify type tok, do not emit markup flag for suppressed tokens;
wenzelm
parents: 17151
diff changeset
   223
      ||>> take_suffix (improper_token o #1)
5140808111d1 clarify type tok, do not emit markup flag for suppressed tokens;
wenzelm
parents: 17151
diff changeset
   224
      ||>> take_prefix (comment_token o #1)
5140808111d1 clarify type tok, do not emit markup flag for suppressed tokens;
wenzelm
parents: 17151
diff changeset
   225
      ||> take_newline;
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   226
  in Span (cmd, (src_prefix, src_main, src_suffix1 @ src_suffix2, src_appendix), newline) end;
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   227
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   228
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   229
(* present spans *)
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   230
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   231
local
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   232
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   233
fun err_bad_nesting pos =
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   234
  error ("Bad nesting of commands in presentation" ^ pos);
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   235
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   236
fun edge1 f (x, y) = if_none (Option.map (Buffer.add o f) (if x = y then NONE else x)) I;
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   237
fun edge2 f (x, y) = if_none (Option.map (Buffer.add o f) (if x = y then NONE else y)) I;
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   238
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   239
val begin_tag = edge2 Latex.begin_tag;
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   240
val end_tag = edge1 Latex.end_tag;
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   241
fun open_delim delim e = edge2 Latex.begin_delim e #> delim #> edge2 Latex.end_delim e;
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   242
fun close_delim delim e = edge1 Latex.begin_delim e #> delim #> edge1 Latex.end_delim e;
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   243
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   244
in
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   245
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   246
fun present_span lex default_tags span state state'
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   247
    (tag_stack, active_tag, newline, buffer, present_cont) =
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   248
  let
17185
5140808111d1 clarify type tok, do not emit markup flag for suppressed tokens;
wenzelm
parents: 17151
diff changeset
   249
    val present = fold (fn (tok, flag, 0) =>
17263
8bf9126d8dcd markup commands: optional locale specification;
wenzelm
parents: 17221
diff changeset
   250
        Buffer.add (output_token lex state' tok)
8bf9126d8dcd markup commands: optional locale specification;
wenzelm
parents: 17221
diff changeset
   251
        #> Buffer.add flag
8bf9126d8dcd markup commands: optional locale specification;
wenzelm
parents: 17221
diff changeset
   252
      | _ => I);
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   253
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   254
    val Span ((cmd_name, cmd_pos, cmd_tags), srcs, span_newline) = span;
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   255
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   256
    val (tag, tags) = tag_stack;
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   257
    val tag' =
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   258
      (case tag of NONE => [] | SOME tg => [tg])
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   259
      |> fold OuterKeyword.update_tags cmd_tags
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   260
      |> try hd;
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   261
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   262
    val active_tag' =
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   263
      if is_some tag' then tag'
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   264
      else try hd (default_tags cmd_name);
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   265
    val edge = (active_tag, active_tag');
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   266
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   267
    val newline' =
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   268
      if is_none active_tag' then span_newline else newline;
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   269
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   270
    val nesting = Toplevel.level state' - Toplevel.level state;
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   271
    val tag_stack' =
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   272
      if nesting = 0 andalso not (Toplevel.is_proof state) then tag_stack
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   273
      else if nesting >= 0 then (tag', replicate nesting tag @ tags)
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   274
      else
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   275
        (case Library.drop (~ nesting - 1, tags) of
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   276
          tgs :: tgss => (tgs, tgss)
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   277
        | [] => err_bad_nesting (Position.str_of cmd_pos));
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   278
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   279
    val buffer' =
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   280
      buffer
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   281
      |> end_tag edge
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   282
      |> close_delim (fst present_cont) edge
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   283
      |> snd present_cont
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   284
      |> open_delim (present (#1 srcs)) edge
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   285
      |> begin_tag edge
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   286
      |> present (#2 srcs);
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   287
    val present_cont' =
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   288
      if newline then (present (#3 srcs), present (#4 srcs))
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   289
      else (I, present (#3 srcs) #> present (#4 srcs));
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   290
  in (tag_stack', active_tag', newline', buffer', present_cont') end;
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   291
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   292
fun present_trailer ((_, tags), active_tag, _, buffer, present_cont) =
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   293
  if not (null tags) then err_bad_nesting " at end of theory"
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   294
  else
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   295
    buffer
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   296
    |> end_tag (active_tag, NONE)
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   297
    |> close_delim (fst present_cont) (active_tag, NONE)
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   298
    |> snd present_cont;
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   299
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   300
end;
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   301
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   302
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   303
(* present_thy *)
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   304
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   305
datatype markup = Markup | MarkupEnv | Verbatim;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   306
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   307
local
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   308
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   309
val space_proper =
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   310
  Scan.one T.is_blank -- Scan.any T.is_comment -- Scan.one T.is_proper;
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   311
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   312
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
   313
val improper = Scan.any is_improper;
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   314
val improper_end = Scan.repeat (Scan.unless space_proper (Scan.one is_improper));
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   315
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   316
val opt_newline = Scan.option (Scan.one T.is_newline);
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   317
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   318
val ignore =
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   319
  Scan.depend (fn d => opt_newline |-- Scan.one T.is_begin_ignore
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   320
    >> pair (d + 1)) ||
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   321
  Scan.depend (fn d => Scan.one T.is_end_ignore --|
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   322
    (if d = 0 then Scan.fail_with (K "Bad nesting of meta-comments") else opt_newline)
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   323
    >> pair (d - 1));
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   324
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   325
val tag = (improper -- P.$$$ "%" -- improper) |-- P.!!! (P.tag_name --| improper_end);
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   326
17263
8bf9126d8dcd markup commands: optional locale specification;
wenzelm
parents: 17221
diff changeset
   327
val locale =
8bf9126d8dcd markup commands: optional locale specification;
wenzelm
parents: 17221
diff changeset
   328
  Scan.option ((P.$$$ "(" -- improper -- P.$$$ "in") |--
8bf9126d8dcd markup commands: optional locale specification;
wenzelm
parents: 17221
diff changeset
   329
    P.!!! (improper |-- P.xname --| (improper -- P.$$$ ")")));
8bf9126d8dcd markup commands: optional locale specification;
wenzelm
parents: 17221
diff changeset
   330
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   331
in
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   332
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   333
fun present_thy lex default_tags is_markup trs src =
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   334
  let
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   335
    (* tokens *)
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   336
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   337
    val ignored = Scan.state --| ignore
17185
5140808111d1 clarify type tok, do not emit markup flag for suppressed tokens;
wenzelm
parents: 17151
diff changeset
   338
      >> (fn d => (NONE, (NoToken, "", d)));
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   339
17185
5140808111d1 clarify type tok, do not emit markup flag for suppressed tokens;
wenzelm
parents: 17151
diff changeset
   340
    fun markup mark mk flag = Scan.peek (fn d =>
17263
8bf9126d8dcd markup commands: optional locale specification;
wenzelm
parents: 17221
diff changeset
   341
      improper |-- P.position (Scan.one (T.is_kind T.Command andf is_markup mark o T.val_of)) --
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   342
      Scan.repeat tag --
17263
8bf9126d8dcd markup commands: optional locale specification;
wenzelm
parents: 17221
diff changeset
   343
      P.!!!! ((improper -- locale -- improper) |-- P.position P.text --| improper_end)
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   344
      >> (fn (((tok, pos), tags), txt) =>
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   345
        let val name = T.val_of tok
17185
5140808111d1 clarify type tok, do not emit markup flag for suppressed tokens;
wenzelm
parents: 17151
diff changeset
   346
        in (SOME (name, pos, tags), (mk (name, txt), flag, d)) end));
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   347
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   348
    val command = Scan.peek (fn d =>
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   349
      P.position (Scan.one (T.is_kind T.Command)) --
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   350
      Scan.repeat tag
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   351
      >> (fn ((tok, pos), tags) =>
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   352
        let val name = T.val_of tok
17185
5140808111d1 clarify type tok, do not emit markup flag for suppressed tokens;
wenzelm
parents: 17151
diff changeset
   353
        in (SOME (name, pos, tags), (BasicToken tok, Latex.markup_false, d)) end));
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   354
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   355
    val cmt = Scan.peek (fn d =>
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   356
      P.$$$ "--" |-- P.!!!! (improper |-- P.position P.text)
17185
5140808111d1 clarify type tok, do not emit markup flag for suppressed tokens;
wenzelm
parents: 17151
diff changeset
   357
      >> (fn txt => (NONE, (MarkupToken ("cmt", txt), "", d))));
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   358
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   359
    val other = Scan.peek (fn d =>
17185
5140808111d1 clarify type tok, do not emit markup flag for suppressed tokens;
wenzelm
parents: 17151
diff changeset
   360
       Scan.one T.not_eof >> (fn tok => (NONE, (BasicToken tok, "", d))));
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   361
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   362
    val token =
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   363
      ignored ||
17185
5140808111d1 clarify type tok, do not emit markup flag for suppressed tokens;
wenzelm
parents: 17151
diff changeset
   364
      markup Markup MarkupToken Latex.markup_true ||
5140808111d1 clarify type tok, do not emit markup flag for suppressed tokens;
wenzelm
parents: 17151
diff changeset
   365
      markup MarkupEnv MarkupEnvToken Latex.markup_true ||
5140808111d1 clarify type tok, do not emit markup flag for suppressed tokens;
wenzelm
parents: 17151
diff changeset
   366
      markup Verbatim (VerbatimToken o #2) "" ||
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   367
      command || cmt || other;
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   368
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   369
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   370
    (* spans *)
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   371
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   372
    val stopper =
17185
5140808111d1 clarify type tok, do not emit markup flag for suppressed tokens;
wenzelm
parents: 17151
diff changeset
   373
      ((NONE, (BasicToken (#1 T.stopper), "", 0)),
5140808111d1 clarify type tok, do not emit markup flag for suppressed tokens;
wenzelm
parents: 17151
diff changeset
   374
        fn (_, (BasicToken x, _, _)) => #2 T.stopper x | _ => false);
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   375
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   376
    val cmd = Scan.one (is_some o #1);
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   377
    val non_cmd = Scan.one (is_none o #1 andf not o #2 stopper) >> #2;
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   378
17185
5140808111d1 clarify type tok, do not emit markup flag for suppressed tokens;
wenzelm
parents: 17151
diff changeset
   379
    val comments = Scan.any (comment_token o #1 o #2);
5140808111d1 clarify type tok, do not emit markup flag for suppressed tokens;
wenzelm
parents: 17151
diff changeset
   380
    val blank = Scan.one (blank_token o #1 o #2);
5140808111d1 clarify type tok, do not emit markup flag for suppressed tokens;
wenzelm
parents: 17151
diff changeset
   381
    val newline = Scan.one (newline_token o #1 o #2);
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   382
    val before_cmd =
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   383
      Scan.option (newline -- comments) --
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   384
      Scan.option (newline -- comments) --
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   385
      Scan.option (blank -- comments) -- cmd;
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   386
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   387
    val span =
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   388
      Scan.repeat non_cmd -- cmd --
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   389
        Scan.repeat (Scan.unless before_cmd non_cmd) --
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   390
        Scan.option (newline >> (single o #2))
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   391
      >> (fn (((toks1, (cmd, tok2)), toks3), tok4) =>
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   392
          make_span (the cmd) (toks1 @ tok2 :: toks3 @ if_none tok4 []));
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   393
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   394
    val spans =
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   395
      src
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   396
      |> Source.filter (not o T.is_semicolon)
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   397
      |> Source.source' 0 T.stopper (Scan.error (Scan.bulk token)) NONE
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   398
      |> Source.source stopper (Scan.error (Scan.bulk span)) NONE
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   399
      |> Source.exhaust;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   400
  in
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   401
    if length trs = length spans then
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   402
      ((NONE, []), NONE, true, Buffer.empty, (I, I))
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   403
      |> Toplevel.present_excursion (trs ~~ map (present_span lex default_tags) spans)
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   404
      |> present_trailer
11861
38d8075ebff6 maintain Latex.flag_markup;
wenzelm
parents: 11716
diff changeset
   405
    else error "Messed-up outer syntax for presentation"
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   406
  end;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   407
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   408
end;
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   409
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   410
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   411
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   412
(** setup default output **)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   413
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   414
(* options *)
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   415
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   416
val _ = add_options
9220
d0506ced27c8 added options "eta_contract", "long_names";
wenzelm
parents: 9213
diff changeset
   417
 [("show_types", Library.setmp Syntax.show_types o boolean),
d0506ced27c8 added options "eta_contract", "long_names";
wenzelm
parents: 9213
diff changeset
   418
  ("show_sorts", Library.setmp Syntax.show_sorts o boolean),
14707
2d6350d7b9b7 show_structs option;
wenzelm
parents: 14696
diff changeset
   419
  ("show_structs", Library.setmp show_structs o boolean),
15988
181bbcee76f5 renamed show_var_qmarks to show_question_marks;
wenzelm
parents: 15960
diff changeset
   420
  ("show_question_marks", Library.setmp show_question_marks o boolean),
14696
wenzelm
parents: 14345
diff changeset
   421
  ("long_names", Library.setmp NameSpace.long_names o boolean),
16142
8eead5356ccb added short_names, unique_names options;
wenzelm
parents: 16064
diff changeset
   422
  ("short_names", Library.setmp NameSpace.short_names o boolean),
8eead5356ccb added short_names, unique_names options;
wenzelm
parents: 16064
diff changeset
   423
  ("unique_names", Library.setmp NameSpace.unique_names o boolean),
9220
d0506ced27c8 added options "eta_contract", "long_names";
wenzelm
parents: 9213
diff changeset
   424
  ("eta_contract", Library.setmp Syntax.eta_contract o boolean),
14899
d9b6c81b52ac added option 'locale=NAME';
wenzelm
parents: 14835
diff changeset
   425
  ("locale", Library.setmp locale),
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   426
  ("display", Library.setmp display o boolean),
13929
21615e44ba88 Added "break" flag to allow line breaks within \isa{...}
berghofe
parents: 13775
diff changeset
   427
  ("break", Library.setmp break o boolean),
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   428
  ("quotes", Library.setmp quotes o boolean),
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   429
  ("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
   430
  ("margin", Pretty.setmp_margin o integer),
9750
270cd9831e7b added "source" option;
wenzelm
parents: 9732
diff changeset
   431
  ("indent", Library.setmp indent o integer),
10321
bbaad3045e37 let commands access Toplevel.state;
wenzelm
parents: 9863
diff changeset
   432
  ("source", Library.setmp source o boolean),
bbaad3045e37 let commands access Toplevel.state;
wenzelm
parents: 9863
diff changeset
   433
  ("goals_limit", Library.setmp goals_limit o integer)];
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   434
16002
wenzelm
parents: 15988
diff changeset
   435
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   436
(* basic pretty printing *)
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   437
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   438
val str_of_source = space_implode " " o map Args.string_of o #2 o #1 o Args.dest_src;
14345
3023d90dc59e separate thm lists in latex output by \isasep
kleing
parents: 13929
diff changeset
   439
11011
14b78c0c9f05 pretty_text: tweak_lines handles linebreaks gracefully;
wenzelm
parents: 10739
diff changeset
   440
fun tweak_line s =
14b78c0c9f05 pretty_text: tweak_lines handles linebreaks gracefully;
wenzelm
parents: 10739
diff changeset
   441
  if ! display then s else Symbol.strip_blanks s;
9750
270cd9831e7b added "source" option;
wenzelm
parents: 9732
diff changeset
   442
11011
14b78c0c9f05 pretty_text: tweak_lines handles linebreaks gracefully;
wenzelm
parents: 10739
diff changeset
   443
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
   444
12055
a9c44895cc8c pretty/print functions with context;
wenzelm
parents: 11861
diff changeset
   445
fun pretty_term ctxt = ProofContext.pretty_term ctxt o ProofContext.extern_skolem ctxt;
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   446
16002
wenzelm
parents: 15988
diff changeset
   447
fun pretty_term_typ ctxt t =
wenzelm
parents: 15988
diff changeset
   448
  (Syntax.const Syntax.constrainC $
wenzelm
parents: 15988
diff changeset
   449
    ProofContext.extern_skolem ctxt t $
wenzelm
parents: 15988
diff changeset
   450
    Syntax.term_of_typ (! show_sorts) (Term.fastype_of t))
wenzelm
parents: 15988
diff changeset
   451
  |> 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
   452
16002
wenzelm
parents: 15988
diff changeset
   453
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
   454
16002
wenzelm
parents: 15988
diff changeset
   455
fun pretty_term_const ctxt t =
wenzelm
parents: 15988
diff changeset
   456
  if Term.is_Const t then pretty_term ctxt t
wenzelm
parents: 15988
diff changeset
   457
  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
   458
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   459
fun pretty_thm ctxt = pretty_term ctxt o Thm.full_prop_of;
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   460
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   461
fun pretty_term_style ctxt (name, t) =
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   462
  pretty_term ctxt (TermStyle.the_style (ProofContext.theory_of ctxt) name ctxt t);
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   463
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   464
fun pretty_thm_style ctxt (name, th) =
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   465
  pretty_term_style ctxt (name, Thm.full_prop_of th);
15880
d6aa6c707acf added antiquotations typeof, const, term_style, thm_style, term_type (something still to be done)
haftmann
parents: 15666
diff changeset
   466
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   467
fun pretty_prf full ctxt thms =
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   468
  Pretty.chunks (map (ProofContext.pretty_proof_of ctxt full) thms);
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   469
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   470
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   471
(* Isar output *)
15880
d6aa6c707acf added antiquotations typeof, const, term_style, thm_style, term_type (something still to be done)
haftmann
parents: 15666
diff changeset
   472
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   473
fun output_list pretty src ctxt xs =
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   474
  map (pretty ctxt) xs        (*always pretty in order to exhibit errors!*)
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   475
  |> (if ! source then K [pretty_text (str_of_source src)] else I)
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   476
  |> (if ! quotes then map Pretty.quote else I)
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   477
  |> (if ! display then
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   478
    map (Output.output o Pretty.string_of o Pretty.indent (! indent))
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   479
    #> space_implode "\\isasep\\isanewline%\n"
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   480
    #> enclose "\\begin{isabelle}%\n" "%\n\\end{isabelle}"
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   481
  else
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   482
    map (Output.output o (if ! break then Pretty.string_of else Pretty.str_of))
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   483
    #> space_implode "\\isasep\\isanewline%\n"
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   484
    #> enclose "\\isa{" "}");
11524
197f2e14a714 Added functions for printing primitive proof terms.
berghofe
parents: 11240
diff changeset
   485
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   486
fun output pretty src ctxt = output_list pretty src ctxt o single;
9732
c32c7ef228c6 added "name" antiq and "indent" option;
wenzelm
parents: 9504
diff changeset
   487
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   488
fun output_goals main_goal src state = args (Scan.succeed ()) (output (fn _ => fn _ =>
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   489
  Pretty.chunks (Proof.pretty_goals main_goal (Toplevel.proof_of state
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   490
      handle Toplevel.UNDEF => error "No proof state")))) src state;
14345
3023d90dc59e separate thm lists in latex output by \isasep
kleing
parents: 13929
diff changeset
   491
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   492
fun output_ml src ctxt txt =
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   493
 (Context.use_mltext ("fn _ => (" ^ txt ^ ")") false (SOME (ProofContext.theory_of ctxt));
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   494
  (if ! source then str_of_source src else txt)
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   495
  |> (if ! quotes then quote else I)
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   496
  |> (if ! display then enclose "\\begin{verbatim}\n" "\n\\end{verbatim}"
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   497
  else
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   498
    split_lines
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   499
    #> map (space_implode "\\verb,|," o map (enclose "\\verb|" "|") o space_explode "|")
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   500
    #> space_implode "\\isasep\\isanewline%\n"));
10360
807992b67edd tuned goals output;
wenzelm
parents: 10350
diff changeset
   501
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   502
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   503
(* commands *)
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   504
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   505
val _ = add_commands
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   506
 [("thm", args Attrib.local_thmss (output_list pretty_thm)),
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   507
  ("thm_style", args (Scan.lift Args.liberal_name -- Attrib.local_thm) (output pretty_thm_style)),
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   508
  ("prop", args Args.local_prop (output pretty_term)),
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   509
  ("term", args Args.local_term (output pretty_term)),
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   510
  ("term_style", args (Scan.lift Args.liberal_name -- Args.local_term) (output pretty_term_style)),
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   511
  ("term_type", args Args.local_term (output pretty_term_typ)),
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   512
  ("typeof", args Args.local_term (output pretty_term_typeof)),
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   513
  ("const", args Args.local_term (output pretty_term_const)),
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   514
  ("typ", args Args.local_typ_abbrev (output ProofContext.pretty_typ)),
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   515
  ("text", args (Scan.lift Args.name) (output (K pretty_text))),
10360
807992b67edd tuned goals output;
wenzelm
parents: 10350
diff changeset
   516
  ("goals", output_goals true),
14696
wenzelm
parents: 14345
diff changeset
   517
  ("subgoals", output_goals false),
17067
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   518
  ("prf", args Attrib.local_thmss (output (pretty_prf false))),
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   519
  ("full_prf", args Attrib.local_thmss (output (pretty_prf true))),
eb07469a4cdd reimplemented theory presentation, with support for tagged command regions;
wenzelm
parents: 17030
diff changeset
   520
  ("ML", args (Scan.lift Args.name) output_ml)];
9140
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   521
69e8938c2409 Isar theory output.
wenzelm
parents:
diff changeset
   522
end;