src/Pure/Isar/isar_cmd.ML
author wenzelm
Tue Nov 11 18:16:25 2014 +0100 (2014-11-11 ago)
changeset 58978 e42da880c61e
parent 58928 23d0ffd48006
child 58979 162a4c2e97bc
permissions -rw-r--r--
more position information, e.g. relevant for errors in generated ML source;
wenzelm@5831
     1
(*  Title:      Pure/Isar/isar_cmd.ML
wenzelm@5831
     2
    Author:     Markus Wenzel, TU Muenchen
wenzelm@5831
     3
wenzelm@30805
     4
Miscellaneous Isar commands.
wenzelm@5831
     5
*)
wenzelm@5831
     6
wenzelm@5831
     7
signature ISAR_CMD =
wenzelm@5831
     8
sig
wenzelm@55828
     9
  val global_setup: Symbol_Pos.source -> theory -> theory
wenzelm@55828
    10
  val local_setup: Symbol_Pos.source -> Proof.context -> Proof.context
wenzelm@55828
    11
  val parse_ast_translation: Symbol_Pos.source -> theory -> theory
wenzelm@55828
    12
  val parse_translation: Symbol_Pos.source -> theory -> theory
wenzelm@55828
    13
  val print_translation: Symbol_Pos.source -> theory -> theory
wenzelm@55828
    14
  val typed_print_translation: Symbol_Pos.source -> theory -> theory
wenzelm@55828
    15
  val print_ast_translation: Symbol_Pos.source -> theory -> theory
wenzelm@42204
    16
  val translations: (xstring * string) Syntax.trrule list -> theory -> theory
wenzelm@42204
    17
  val no_translations: (xstring * string) Syntax.trrule list -> theory -> theory
wenzelm@55828
    18
  val oracle: bstring * Position.T -> Symbol_Pos.source -> theory -> theory
wenzelm@58011
    19
  val add_defs: (bool * bool) * ((binding * string) * Token.src list) list -> theory -> theory
wenzelm@40784
    20
  val declaration: {syntax: bool, pervasive: bool} ->
wenzelm@55828
    21
    Symbol_Pos.source -> local_theory -> local_theory
wenzelm@55828
    22
  val simproc_setup: string * Position.T -> string list -> Symbol_Pos.source ->
wenzelm@42464
    23
    string list -> local_theory -> local_theory
wenzelm@28084
    24
  val have: (Attrib.binding * (string * string list) list) list -> bool -> Proof.state -> Proof.state
wenzelm@28084
    25
  val hence: (Attrib.binding * (string * string list) list) list -> bool -> Proof.state -> Proof.state
wenzelm@28084
    26
  val show: (Attrib.binding * (string * string list) list) list -> bool -> Proof.state -> Proof.state
wenzelm@28084
    27
  val thus: (Attrib.binding * (string * string list) list) list -> bool -> Proof.state -> Proof.state
wenzelm@49889
    28
  val qed: Method.text_range option -> Toplevel.transition -> Toplevel.transition
wenzelm@49889
    29
  val terminal_proof: Method.text_range * Method.text_range option ->
wenzelm@21350
    30
    Toplevel.transition -> Toplevel.transition
wenzelm@21350
    31
  val default_proof: Toplevel.transition -> Toplevel.transition
wenzelm@21350
    32
  val immediate_proof: Toplevel.transition -> Toplevel.transition
wenzelm@21350
    33
  val done_proof: Toplevel.transition -> Toplevel.transition
wenzelm@21350
    34
  val skip_proof: Toplevel.transition -> Toplevel.transition
wenzelm@55828
    35
  val ml_diag: bool -> Symbol_Pos.source -> Toplevel.transition -> Toplevel.transition
wenzelm@48776
    36
  val diag_state: Proof.context -> Toplevel.state
wenzelm@48776
    37
  val diag_goal: Proof.context -> {context: Proof.context, facts: thm list, goal: thm}
wenzelm@57605
    38
  val pretty_theorems: bool -> Toplevel.state -> Pretty.T list
wenzelm@49569
    39
  val thy_deps: Toplevel.transition -> Toplevel.transition
wenzelm@49569
    40
  val locale_deps: Toplevel.transition -> Toplevel.transition
wenzelm@58011
    41
  val print_stmts: string list * (Facts.ref * Token.src list) list
wenzelm@19268
    42
    -> Toplevel.transition -> Toplevel.transition
wenzelm@58011
    43
  val print_thms: string list * (Facts.ref * Token.src list) list
wenzelm@10581
    44
    -> Toplevel.transition -> Toplevel.transition
wenzelm@58011
    45
  val print_prfs: bool -> string list * (Facts.ref * Token.src list) list option
berghofe@11524
    46
    -> Toplevel.transition -> Toplevel.transition
wenzelm@12876
    47
  val print_prop: (string list * string) -> Toplevel.transition -> Toplevel.transition
wenzelm@12876
    48
  val print_term: (string list * string) -> Toplevel.transition -> Toplevel.transition
wenzelm@48792
    49
  val print_type: (string list * (string * string option)) ->
wenzelm@48792
    50
    Toplevel.transition -> Toplevel.transition
wenzelm@5831
    51
end;
wenzelm@5831
    52
wenzelm@37216
    53
structure Isar_Cmd: ISAR_CMD =
wenzelm@5831
    54
struct
wenzelm@5831
    55
wenzelm@5831
    56
wenzelm@22116
    57
(** theory declarations **)
wenzelm@22116
    58
wenzelm@30461
    59
(* generic setup *)
wenzelm@22116
    60
wenzelm@55828
    61
fun global_setup source =
wenzelm@56278
    62
  ML_Lex.read_source false source
wenzelm@58978
    63
  |> ML_Context.expression (#range source)
wenzelm@58978
    64
    "val setup: theory -> theory" "Context.map_theory setup"
wenzelm@26435
    65
  |> Context.theory_map;
wenzelm@22116
    66
wenzelm@55828
    67
fun local_setup source =
wenzelm@56278
    68
  ML_Lex.read_source false source
wenzelm@58978
    69
  |> ML_Context.expression (#range source)
wenzelm@58978
    70
    "val setup: local_theory -> local_theory" "Context.map_proof setup"
wenzelm@30461
    71
  |> Context.proof_map;
wenzelm@30461
    72
wenzelm@22116
    73
wenzelm@22116
    74
(* translation functions *)
wenzelm@22116
    75
wenzelm@55828
    76
fun parse_ast_translation source =
wenzelm@56278
    77
  ML_Lex.read_source false source
wenzelm@58978
    78
  |> ML_Context.expression (#range source)
wenzelm@52143
    79
    "val parse_ast_translation: (string * (Proof.context -> Ast.ast list -> Ast.ast)) list"
wenzelm@52143
    80
    "Context.map_theory (Sign.parse_ast_translation parse_ast_translation)"
wenzelm@22116
    81
  |> Context.theory_map;
wenzelm@22116
    82
wenzelm@55828
    83
fun parse_translation source =
wenzelm@56278
    84
  ML_Lex.read_source false source
wenzelm@58978
    85
  |> ML_Context.expression (#range source)
wenzelm@52143
    86
    "val parse_translation: (string * (Proof.context -> term list -> term)) list"
wenzelm@52143
    87
    "Context.map_theory (Sign.parse_translation parse_translation)"
wenzelm@52143
    88
  |> Context.theory_map;
wenzelm@52143
    89
wenzelm@55828
    90
fun print_translation source =
wenzelm@56278
    91
  ML_Lex.read_source false source
wenzelm@58978
    92
  |> ML_Context.expression (#range source)
wenzelm@52143
    93
    "val print_translation: (string * (Proof.context -> term list -> term)) list"
wenzelm@52143
    94
    "Context.map_theory (Sign.print_translation print_translation)"
wenzelm@22116
    95
  |> Context.theory_map;
wenzelm@22116
    96
wenzelm@55828
    97
fun typed_print_translation source =
wenzelm@56278
    98
  ML_Lex.read_source false source
wenzelm@58978
    99
  |> ML_Context.expression (#range source)
wenzelm@52143
   100
    "val typed_print_translation: (string * (Proof.context -> typ -> term list -> term)) list"
wenzelm@52143
   101
    "Context.map_theory (Sign.typed_print_translation typed_print_translation)"
wenzelm@22116
   102
  |> Context.theory_map;
wenzelm@22116
   103
wenzelm@55828
   104
fun print_ast_translation source =
wenzelm@56278
   105
  ML_Lex.read_source false source
wenzelm@58978
   106
  |> ML_Context.expression (#range source)
wenzelm@52143
   107
    "val print_ast_translation: (string * (Proof.context -> Ast.ast list -> Ast.ast)) list"
wenzelm@52143
   108
    "Context.map_theory (Sign.print_ast_translation print_ast_translation)"
wenzelm@22116
   109
  |> Context.theory_map;
wenzelm@22116
   110
wenzelm@22116
   111
wenzelm@42204
   112
(* translation rules *)
wenzelm@42204
   113
wenzelm@42204
   114
fun read_trrules thy raw_rules =
wenzelm@42204
   115
  let
wenzelm@42360
   116
    val ctxt = Proof_Context.init_global thy;
wenzelm@56006
   117
    val read_root =
wenzelm@56006
   118
      #1 o dest_Type o Proof_Context.read_type_name {proper = true, strict = false} ctxt;
wenzelm@42204
   119
  in
wenzelm@56006
   120
    raw_rules
wenzelm@56006
   121
    |> map (Syntax.map_trrule (fn (r, s) => Syntax_Phases.parse_ast_pattern ctxt (read_root r, s)))
wenzelm@42204
   122
  end;
wenzelm@42204
   123
wenzelm@42204
   124
fun translations args thy = Sign.add_trrules (read_trrules thy args) thy;
wenzelm@42204
   125
fun no_translations args thy = Sign.del_trrules (read_trrules thy args) thy;
wenzelm@42204
   126
wenzelm@42204
   127
wenzelm@22116
   128
(* oracles *)
wenzelm@22116
   129
wenzelm@55828
   130
fun oracle (name, pos) source =
wenzelm@27871
   131
  let
wenzelm@56278
   132
    val body = ML_Lex.read_source false source;
wenzelm@37198
   133
    val ants =
wenzelm@37198
   134
      ML_Lex.read Position.none
wenzelm@37198
   135
       ("local\n\
wenzelm@37198
   136
        \  val binding = " ^ ML_Syntax.make_binding (name, pos) ^ ";\n\
wenzelm@37198
   137
        \  val body = ") @ body @ ML_Lex.read Position.none (";\n\
wenzelm@37198
   138
        \in\n\
wenzelm@55828
   139
        \  val " ^ name ^
wenzelm@55828
   140
        " = snd (Context.>>> (Context.map_theory_result (Thm.add_oracle (binding, body))));\n\
wenzelm@37198
   141
        \end;\n");
wenzelm@56304
   142
  in
wenzelm@56304
   143
    Context.theory_map
wenzelm@58978
   144
      (ML_Context.exec (fn () => ML_Context.eval ML_Compiler.flags (#1 (#range source)) ants))
wenzelm@56304
   145
  end;
wenzelm@22116
   146
wenzelm@22116
   147
wenzelm@50737
   148
(* old-style defs *)
wenzelm@21350
   149
wenzelm@35852
   150
fun add_defs ((unchecked, overloaded), args) thy =
wenzelm@57683
   151
 (legacy_feature "Old 'defs' command -- use 'definition' (with 'overloading') instead";
wenzelm@39557
   152
  thy |>
wenzelm@39557
   153
    (if unchecked then Global_Theory.add_defs_unchecked_cmd else Global_Theory.add_defs_cmd)
wenzelm@47815
   154
      overloaded
wenzelm@47815
   155
      (map (fn ((b, ax), srcs) => ((b, ax), map (Attrib.attribute_cmd_global thy) srcs)) args)
wenzelm@57683
   156
  |> snd);
wenzelm@21350
   157
wenzelm@21350
   158
wenzelm@22087
   159
(* declarations *)
wenzelm@22087
   160
wenzelm@55828
   161
fun declaration {syntax, pervasive} source =
wenzelm@56278
   162
  ML_Lex.read_source false source
wenzelm@58978
   163
  |> ML_Context.expression (#range source)
wenzelm@26455
   164
    "val declaration: Morphism.declaration"
wenzelm@45291
   165
    ("Context.map_proof (Local_Theory.declaration {syntax = " ^ Bool.toString syntax ^ ", \
wenzelm@45291
   166
      \pervasive = " ^ Bool.toString pervasive ^ "} declaration)")
wenzelm@26385
   167
  |> Context.proof_map;
wenzelm@22087
   168
wenzelm@22087
   169
wenzelm@22202
   170
(* simprocs *)
wenzelm@22202
   171
wenzelm@55828
   172
fun simproc_setup name lhss source identifier =
wenzelm@56278
   173
  ML_Lex.read_source false source
wenzelm@58978
   174
  |> ML_Context.expression (#range source)
wenzelm@51717
   175
    "val proc: Morphism.morphism -> Proof.context -> cterm -> thm option"
wenzelm@42464
   176
    ("Context.map_proof (Simplifier.def_simproc_cmd {name = " ^ ML_Syntax.make_binding name ^ ", \
wenzelm@37198
   177
      \lhss = " ^ ML_Syntax.print_strings lhss ^ ", proc = proc, \
wenzelm@37198
   178
      \identifier = Library.maps ML_Context.thms " ^ ML_Syntax.print_strings identifier ^ "})")
wenzelm@22202
   179
  |> Context.proof_map;
wenzelm@22202
   180
wenzelm@22202
   181
wenzelm@21350
   182
(* goals *)
wenzelm@21350
   183
wenzelm@21350
   184
fun goal opt_chain goal stmt int =
wenzelm@29383
   185
  opt_chain #> goal NONE (K I) stmt int;
wenzelm@21350
   186
wenzelm@36323
   187
val have = goal I Proof.have_cmd;
wenzelm@36323
   188
val hence = goal Proof.chain Proof.have_cmd;
wenzelm@36323
   189
val show = goal I Proof.show_cmd;
wenzelm@36323
   190
val thus = goal Proof.chain Proof.show_cmd;
wenzelm@21350
   191
wenzelm@21350
   192
wenzelm@21350
   193
(* local endings *)
wenzelm@21350
   194
wenzelm@29383
   195
fun local_qed m = Toplevel.proof (Proof.local_qed (m, true));
wenzelm@32061
   196
val local_terminal_proof = Toplevel.proof' o Proof.local_future_terminal_proof;
wenzelm@29383
   197
val local_default_proof = Toplevel.proof Proof.local_default_proof;
wenzelm@29383
   198
val local_immediate_proof = Toplevel.proof Proof.local_immediate_proof;
wenzelm@29383
   199
val local_done_proof = Toplevel.proof Proof.local_done_proof;
wenzelm@29383
   200
val local_skip_proof = Toplevel.proof' Proof.local_skip_proof;
wenzelm@21350
   201
wenzelm@27562
   202
val skip_local_qed = Toplevel.skip_proof (fn i => if i > 1 then i - 1 else raise Toplevel.UNDEF);
wenzelm@21350
   203
wenzelm@21350
   204
wenzelm@21350
   205
(* global endings *)
wenzelm@21350
   206
wenzelm@21350
   207
fun global_qed m = Toplevel.end_proof (K (Proof.global_qed (m, true)));
wenzelm@49012
   208
val global_terminal_proof = Toplevel.end_proof o Proof.global_future_terminal_proof;
wenzelm@21350
   209
val global_default_proof = Toplevel.end_proof (K Proof.global_default_proof);
wenzelm@21350
   210
val global_immediate_proof = Toplevel.end_proof (K Proof.global_immediate_proof);
wenzelm@21350
   211
val global_skip_proof = Toplevel.end_proof Proof.global_skip_proof;
wenzelm@21350
   212
val global_done_proof = Toplevel.end_proof (K Proof.global_done_proof);
wenzelm@21350
   213
wenzelm@28375
   214
val skip_global_qed = Toplevel.skip_proof_to_theory (fn n => n = 1);
wenzelm@21350
   215
wenzelm@21350
   216
wenzelm@21350
   217
(* common endings *)
wenzelm@21350
   218
wenzelm@21350
   219
fun qed m = local_qed m o global_qed m o skip_local_qed o skip_global_qed;
wenzelm@21350
   220
fun terminal_proof m = local_terminal_proof m o global_terminal_proof m;
wenzelm@21350
   221
val default_proof = local_default_proof o global_default_proof;
wenzelm@21350
   222
val immediate_proof = local_immediate_proof o global_immediate_proof;
wenzelm@21350
   223
val done_proof = local_done_proof o global_done_proof;
wenzelm@21350
   224
val skip_proof = local_skip_proof o global_skip_proof;
wenzelm@21350
   225
wenzelm@21350
   226
wenzelm@26489
   227
(* diagnostic ML evaluation *)
wenzelm@5831
   228
wenzelm@37305
   229
structure Diag_State = Proof_Data
wenzelm@37305
   230
(
wenzelm@37305
   231
  type T = Toplevel.state;
wenzelm@37305
   232
  fun init _ = Toplevel.toplevel;
wenzelm@37305
   233
);
wenzelm@37305
   234
wenzelm@55828
   235
fun ml_diag verbose source = Toplevel.keep (fn state =>
wenzelm@56304
   236
  let
wenzelm@56304
   237
    val opt_ctxt =
wenzelm@56304
   238
      try Toplevel.generic_theory_of state
wenzelm@56304
   239
      |> Option.map (Context.proof_of #> Diag_State.put state);
wenzelm@56304
   240
    val flags = ML_Compiler.verbose verbose ML_Compiler.flags;
wenzelm@56304
   241
  in ML_Context.eval_source_in opt_ctxt flags source end);
wenzelm@37305
   242
wenzelm@48776
   243
val diag_state = Diag_State.get;
wenzelm@37305
   244
wenzelm@48776
   245
fun diag_goal ctxt =
wenzelm@48776
   246
  Proof.goal (Toplevel.proof_of (diag_state ctxt))
wenzelm@37305
   247
    handle Toplevel.UNDEF => error "No goal present";
wenzelm@37305
   248
wenzelm@53171
   249
val _ = Theory.setup
wenzelm@56204
   250
  (ML_Antiquotation.value (Binding.qualify true "Isar" @{binding state})
wenzelm@53171
   251
    (Scan.succeed "Isar_Cmd.diag_state ML_context") #>
wenzelm@56204
   252
   ML_Antiquotation.value (Binding.qualify true "Isar" @{binding goal})
wenzelm@53171
   253
    (Scan.succeed "Isar_Cmd.diag_goal ML_context"));
wenzelm@5831
   254
wenzelm@5831
   255
wenzelm@56868
   256
(* theorems of theory or proof context *)
wenzelm@17066
   257
wenzelm@56868
   258
fun pretty_theorems verbose st =
wenzelm@56868
   259
  if Toplevel.is_proof st then
wenzelm@57605
   260
    Proof_Context.pretty_local_facts (Toplevel.context_of st) verbose
wenzelm@56868
   261
  else
wenzelm@56868
   262
    let
wenzelm@56868
   263
      val thy = Toplevel.theory_of st;
wenzelm@56868
   264
      val prev_thys =
wenzelm@56868
   265
        (case Toplevel.previous_context_of st of
wenzelm@56868
   266
          SOME prev => [Proof_Context.theory_of prev]
wenzelm@56868
   267
        | NONE => Theory.parents_of thy);
wenzelm@56868
   268
    in Proof_Display.pretty_theorems_diff verbose prev_thys thy end;
wenzelm@9513
   269
wenzelm@12060
   270
wenzelm@50737
   271
(* display dependencies *)
wenzelm@5831
   272
haftmann@22485
   273
val thy_deps = Toplevel.unknown_theory o Toplevel.keep (fn state =>
haftmann@22485
   274
  let
haftmann@22485
   275
    val thy = Toplevel.theory_of state;
wenzelm@37866
   276
    val thy_session = Present.session_name thy;
wenzelm@37866
   277
wenzelm@42425
   278
    val gr = rev (Theory.nodes_of thy) |> map (fn node =>
wenzelm@22602
   279
      let
wenzelm@22602
   280
        val name = Context.theory_name node;
wenzelm@22602
   281
        val parents = map Context.theory_name (Theory.parents_of node);
wenzelm@37866
   282
        val session = Present.session_name node;
wenzelm@37866
   283
        val unfold = (session = thy_session);
wenzelm@49561
   284
      in
wenzelm@49561
   285
       {name = name, ID = name, parents = parents, dir = session,
wenzelm@49561
   286
        unfold = unfold, path = "", content = []}
wenzelm@49561
   287
      end);
wenzelm@49561
   288
  in Graph_Display.display_graph gr end);
haftmann@22485
   289
wenzelm@49569
   290
val locale_deps = Toplevel.unknown_theory o Toplevel.keep (fn state =>
wenzelm@49569
   291
  let
wenzelm@49569
   292
    val thy = Toplevel.theory_of state;
wenzelm@49569
   293
    val gr = Locale.pretty_locale_deps thy |> map (fn {name, parents, body} =>
wenzelm@49569
   294
     {name = Locale.extern thy name, ID = name, parents = parents,
wenzelm@49569
   295
      dir = "", unfold = true, path = "", content = [body]});
wenzelm@49569
   296
  in Graph_Display.display_graph gr end);
wenzelm@49569
   297
berghofe@26184
   298
wenzelm@19268
   299
(* print theorems, terms, types etc. *)
wenzelm@19268
   300
wenzelm@19385
   301
local
wenzelm@19385
   302
wenzelm@38331
   303
fun string_of_stmts ctxt args =
wenzelm@38331
   304
  Attrib.eval_thms ctxt args
wenzelm@38331
   305
  |> map (Element.pretty_statement ctxt Thm.theoremK)
wenzelm@19385
   306
  |> Pretty.chunks2 |> Pretty.string_of;
wenzelm@5880
   307
wenzelm@38331
   308
fun string_of_thms ctxt args =
wenzelm@51583
   309
  Pretty.string_of (Proof_Context.pretty_fact ctxt ("", Attrib.eval_thms ctxt args));
wenzelm@5895
   310
wenzelm@19385
   311
fun string_of_prfs full state arg =
wenzelm@32859
   312
  Pretty.string_of
wenzelm@32859
   313
    (case arg of
skalberg@15531
   314
      NONE =>
berghofe@12125
   315
        let
wenzelm@38331
   316
          val {context = ctxt, goal = thm} = Proof.simple_goal (Toplevel.proof_of state);
wenzelm@42360
   317
          val thy = Proof_Context.theory_of ctxt;
wenzelm@28814
   318
          val prf = Thm.proof_of thm;
wenzelm@17066
   319
          val prop = Thm.full_prop_of thm;
wenzelm@32859
   320
          val prf' = Proofterm.rewrite_proof_notypes ([], []) prf;
berghofe@12125
   321
        in
wenzelm@33388
   322
          Proof_Syntax.pretty_proof ctxt
wenzelm@17066
   323
            (if full then Reconstruct.reconstruct_proof thy prop prf' else prf')
berghofe@12125
   324
        end
wenzelm@38331
   325
    | SOME srcs =>
wenzelm@38331
   326
        let val ctxt = Toplevel.context_of state
wenzelm@38331
   327
        in map (Proof_Syntax.pretty_proof_of ctxt full) (Attrib.eval_thms ctxt srcs) end
wenzelm@38331
   328
        |> Pretty.chunks);
berghofe@11524
   329
wenzelm@38331
   330
fun string_of_prop ctxt s =
wenzelm@5831
   331
  let
wenzelm@24508
   332
    val prop = Syntax.read_prop ctxt s;
wenzelm@26704
   333
    val ctxt' = Variable.auto_fixes prop ctxt;
wenzelm@26704
   334
  in Pretty.string_of (Pretty.quote (Syntax.pretty_term ctxt' prop)) end;
wenzelm@5831
   335
wenzelm@38331
   336
fun string_of_term ctxt s =
wenzelm@5831
   337
  let
wenzelm@24508
   338
    val t = Syntax.read_term ctxt s;
wenzelm@5831
   339
    val T = Term.type_of t;
wenzelm@26704
   340
    val ctxt' = Variable.auto_fixes t ctxt;
wenzelm@5831
   341
  in
wenzelm@19385
   342
    Pretty.string_of
wenzelm@26704
   343
      (Pretty.block [Pretty.quote (Syntax.pretty_term ctxt' t), Pretty.fbrk,
wenzelm@26704
   344
        Pretty.str "::", Pretty.brk 1, Pretty.quote (Syntax.pretty_typ ctxt' T)])
wenzelm@9128
   345
  end;
wenzelm@5831
   346
wenzelm@48792
   347
fun string_of_type ctxt (s, NONE) =
wenzelm@48792
   348
      let val T = Syntax.read_typ ctxt s
wenzelm@48792
   349
      in Pretty.string_of (Pretty.quote (Syntax.pretty_typ ctxt T)) end
wenzelm@48792
   350
  | string_of_type ctxt (s1, SOME s2) =
wenzelm@48792
   351
      let
wenzelm@48792
   352
        val ctxt' = Config.put show_sorts true ctxt;
wenzelm@48792
   353
        val raw_T = Syntax.parse_typ ctxt' s1;
wenzelm@48792
   354
        val S = Syntax.read_sort ctxt' s2;
wenzelm@48792
   355
        val T =
wenzelm@48792
   356
          Syntax.check_term ctxt'
wenzelm@48792
   357
            (Logic.mk_type raw_T |> Type.constraint (Term.itselfT (Type_Infer.anyT S)))
wenzelm@48792
   358
          |> Logic.dest_type;
wenzelm@48792
   359
      in Pretty.string_of (Pretty.quote (Syntax.pretty_typ ctxt' T)) end;
wenzelm@9128
   360
wenzelm@23935
   361
fun print_item string_of (modes, arg) = Toplevel.keep (fn state =>
wenzelm@38331
   362
  Print_Mode.with_modes modes (fn () => writeln (string_of state arg)) ());
wenzelm@19385
   363
wenzelm@19385
   364
in
wenzelm@9128
   365
wenzelm@38331
   366
val print_stmts = print_item (string_of_stmts o Toplevel.context_of);
wenzelm@38331
   367
val print_thms = print_item (string_of_thms o Toplevel.context_of);
wenzelm@19385
   368
val print_prfs = print_item o string_of_prfs;
wenzelm@38331
   369
val print_prop = print_item (string_of_prop o Toplevel.context_of);
wenzelm@38331
   370
val print_term = print_item (string_of_term o Toplevel.context_of);
wenzelm@38331
   371
val print_type = print_item (string_of_type o Toplevel.context_of);
wenzelm@5831
   372
wenzelm@19385
   373
end;
wenzelm@19385
   374
wenzelm@5831
   375
end;