src/Pure/Isar/isar_syn.ML
author wenzelm
Tue Jul 12 15:12:50 2011 +0200 (2011-07-12 ago)
changeset 43775 b361c7d184e7
parent 43227 359c190ede75
child 43947 9b00f09f7721
permissions -rw-r--r--
added Parse.properties (again) -- allow empty list like Parse_Value.properties but unlike Parse.properties of ef86de9c98aa;
wenzelm@5832
     1
(*  Title:      Pure/Isar/isar_syn.ML
wenzelm@5832
     2
    Author:     Markus Wenzel, TU Muenchen
wenzelm@5832
     3
wenzelm@6353
     4
Isar/Pure outer syntax.
wenzelm@5832
     5
*)
wenzelm@5832
     6
wenzelm@37216
     7
structure Isar_Syn: sig end =
wenzelm@5832
     8
struct
wenzelm@5832
     9
wenzelm@24868
    10
(** keywords **)
wenzelm@24868
    11
wenzelm@24868
    12
(*keep keywords consistent with the parsers, otherwise be prepared for
wenzelm@24868
    13
  unexpected errors*)
wenzelm@24868
    14
wenzelm@36950
    15
val _ = List.app Keyword.keyword
wenzelm@24868
    16
 ["!!", "!", "%", "(", ")", "+", ",", "--", ":", "::", ";", "<", "<=",
wenzelm@24868
    17
  "=", "==", "=>", "?", "[", "\\<equiv>", "\\<leftharpoondown>",
wenzelm@24868
    18
  "\\<rightharpoonup>", "\\<rightleftharpoons>", "\\<subseteq>", "]",
wenzelm@26888
    19
  "advanced", "and", "assumes", "attach", "begin", "binder",
wenzelm@24868
    20
  "constrains", "defines", "fixes", "for", "identifier", "if",
ballarin@28721
    21
  "imports", "in", "infix", "infixl", "infixr", "is",
wenzelm@33456
    22
  "notes", "obtains", "open", "output", "overloaded", "pervasive",
wenzelm@33456
    23
  "shows", "structure", "unchecked", "uses", "where", "|"];
wenzelm@33456
    24
wenzelm@24868
    25
wenzelm@24868
    26
wenzelm@5832
    27
(** init and exit **)
wenzelm@5832
    28
wenzelm@24868
    29
val _ =
wenzelm@36953
    30
  Outer_Syntax.command "theory" "begin theory" (Keyword.tag_theory Keyword.thy_begin)
wenzelm@37977
    31
    (Thy_Header.args >> (fn (name, imports, uses) =>
wenzelm@37977
    32
      Toplevel.print o
wenzelm@41536
    33
        Toplevel.init_theory NONE name
wenzelm@41536
    34
          (fn master =>
wenzelm@41536
    35
            Thy_Info.toplevel_begin_theory master name imports (map (apfst Path.explode) uses))));
wenzelm@5832
    36
wenzelm@24868
    37
val _ =
wenzelm@36953
    38
  Outer_Syntax.command "end" "end (local) theory" (Keyword.tag_theory Keyword.thy_end)
wenzelm@40960
    39
    (Scan.succeed
wenzelm@40960
    40
      (Toplevel.exit o Toplevel.end_local_theory o Toplevel.end_proof (K Proof.end_notepad)));
wenzelm@6687
    41
wenzelm@5832
    42
wenzelm@30142
    43
wenzelm@7749
    44
(** markup commands **)
wenzelm@5832
    45
wenzelm@37216
    46
val _ = Outer_Syntax.markup_command Thy_Output.Markup "header" "theory header" Keyword.diag
wenzelm@37216
    47
  (Parse.doc_source >> Isar_Cmd.header_markup);
wenzelm@6353
    48
wenzelm@37216
    49
val _ = Outer_Syntax.markup_command Thy_Output.Markup "chapter" "chapter heading"
wenzelm@37216
    50
  Keyword.thy_heading (Parse.opt_target -- Parse.doc_source >> Isar_Cmd.local_theory_markup);
wenzelm@5958
    51
wenzelm@37216
    52
val _ = Outer_Syntax.markup_command Thy_Output.Markup "section" "section heading"
wenzelm@37216
    53
  Keyword.thy_heading (Parse.opt_target -- Parse.doc_source >> Isar_Cmd.local_theory_markup);
wenzelm@5958
    54
wenzelm@37216
    55
val _ = Outer_Syntax.markup_command Thy_Output.Markup "subsection" "subsection heading"
wenzelm@37216
    56
  Keyword.thy_heading (Parse.opt_target -- Parse.doc_source >> Isar_Cmd.local_theory_markup);
wenzelm@5958
    57
wenzelm@24868
    58
val _ =
wenzelm@37216
    59
  Outer_Syntax.markup_command Thy_Output.Markup "subsubsection" "subsubsection heading"
wenzelm@37216
    60
  Keyword.thy_heading (Parse.opt_target -- Parse.doc_source >> Isar_Cmd.local_theory_markup);
wenzelm@5832
    61
wenzelm@37216
    62
val _ = Outer_Syntax.markup_command Thy_Output.MarkupEnv "text" "formal comment (theory)"
wenzelm@37216
    63
  Keyword.thy_decl (Parse.opt_target -- Parse.doc_source >> Isar_Cmd.local_theory_markup);
wenzelm@7172
    64
wenzelm@37216
    65
val _ = Outer_Syntax.markup_command Thy_Output.Verbatim "text_raw" "raw document preparation text"
wenzelm@37216
    66
  Keyword.thy_decl (Parse.opt_target -- Parse.doc_source >> Isar_Cmd.local_theory_markup);
wenzelm@7172
    67
wenzelm@37216
    68
val _ = Outer_Syntax.markup_command Thy_Output.Markup "sect" "formal comment (proof)"
wenzelm@37216
    69
  (Keyword.tag_proof Keyword.prf_heading) (Parse.doc_source >> Isar_Cmd.proof_markup);
wenzelm@7172
    70
wenzelm@37216
    71
val _ = Outer_Syntax.markup_command Thy_Output.Markup "subsect" "formal comment (proof)"
wenzelm@37216
    72
  (Keyword.tag_proof Keyword.prf_heading) (Parse.doc_source >> Isar_Cmd.proof_markup);
wenzelm@7172
    73
wenzelm@37216
    74
val _ = Outer_Syntax.markup_command Thy_Output.Markup "subsubsect" "formal comment (proof)"
wenzelm@37216
    75
  (Keyword.tag_proof Keyword.prf_heading) (Parse.doc_source >> Isar_Cmd.proof_markup);
wenzelm@7172
    76
wenzelm@37216
    77
val _ = Outer_Syntax.markup_command Thy_Output.MarkupEnv "txt" "formal comment (proof)"
wenzelm@37216
    78
  (Keyword.tag_proof Keyword.prf_decl) (Parse.doc_source >> Isar_Cmd.proof_markup);
wenzelm@7172
    79
wenzelm@37216
    80
val _ = Outer_Syntax.markup_command Thy_Output.Verbatim "txt_raw"
wenzelm@36950
    81
  "raw document preparation text (proof)" (Keyword.tag_proof Keyword.prf_decl)
wenzelm@37216
    82
  (Parse.doc_source >> Isar_Cmd.proof_markup);
wenzelm@7775
    83
wenzelm@5832
    84
wenzelm@6886
    85
wenzelm@30142
    86
(** theory commands **)
wenzelm@6886
    87
wenzelm@5832
    88
(* classes and sorts *)
wenzelm@5832
    89
wenzelm@24868
    90
val _ =
wenzelm@36953
    91
  Outer_Syntax.command "classes" "declare type classes" Keyword.thy_decl
wenzelm@36950
    92
    (Scan.repeat1 (Parse.binding -- Scan.optional ((Parse.$$$ "\\<subseteq>" || Parse.$$$ "<") |--
wenzelm@36950
    93
        Parse.!!! (Parse.list1 Parse.xname)) [])
wenzelm@36950
    94
      >> (Toplevel.theory o fold AxClass.axiomatize_class_cmd));
wenzelm@5832
    95
wenzelm@24868
    96
val _ =
wenzelm@36953
    97
  Outer_Syntax.command "classrel" "state inclusion of type classes (axiomatic!)" Keyword.thy_decl
wenzelm@36950
    98
    (Parse.and_list1 (Parse.xname -- ((Parse.$$$ "\\<subseteq>" || Parse.$$$ "<")
wenzelm@36950
    99
        |-- Parse.!!! Parse.xname))
wenzelm@24932
   100
    >> (Toplevel.theory o AxClass.axiomatize_classrel_cmd));
wenzelm@5832
   101
wenzelm@24868
   102
val _ =
wenzelm@36953
   103
  Outer_Syntax.local_theory "default_sort" "declare default sort for explicit type variables"
wenzelm@36950
   104
    Keyword.thy_decl
wenzelm@36950
   105
    (Parse.sort >> (fn s => fn lthy => Local_Theory.set_defsort (Syntax.read_sort lthy s) lthy));
wenzelm@5832
   106
wenzelm@5832
   107
wenzelm@5832
   108
(* types *)
wenzelm@5832
   109
wenzelm@24868
   110
val _ =
wenzelm@36953
   111
  Outer_Syntax.local_theory "typedecl" "type declaration" Keyword.thy_decl
wenzelm@36950
   112
    (Parse.type_args -- Parse.binding -- Parse.opt_mixfix
wenzelm@35835
   113
      >> (fn ((args, a), mx) => Typedecl.typedecl (a, map (rpair dummyS) args, mx) #> snd));
wenzelm@5832
   114
wenzelm@41249
   115
val type_abbrev =
wenzelm@41249
   116
  Parse.type_args -- Parse.binding --
wenzelm@41249
   117
    (Parse.$$$ "=" |-- Parse.!!! (Parse.typ -- Parse.opt_mixfix'));
wenzelm@41249
   118
wenzelm@24868
   119
val _ =
wenzelm@36953
   120
  Outer_Syntax.local_theory "types" "declare type abbreviations" Keyword.thy_decl
wenzelm@41249
   121
    (Scan.repeat1 type_abbrev >> (fn specs => fn lthy =>
blanchet@43227
   122
     (legacy_feature "Old 'types' command -- use 'type_synonym' instead";
wenzelm@41249
   123
      fold (fn ((args, a), (rhs, mx)) => snd o Typedecl.abbrev_cmd (a, args, mx) rhs) specs lthy)));
wenzelm@41249
   124
wenzelm@41249
   125
val _ =
wenzelm@41249
   126
  Outer_Syntax.local_theory "type_synonym" "declare type abbreviation" Keyword.thy_decl
wenzelm@41249
   127
    (type_abbrev >> (fn ((args, a), (rhs, mx)) => snd o Typedecl.abbrev_cmd (a, args, mx) rhs));
wenzelm@5832
   128
wenzelm@24868
   129
val _ =
wenzelm@41229
   130
  Outer_Syntax.command "nonterminal"
wenzelm@41229
   131
    "declare syntactic type constructors (grammar nonterminal symbols)" Keyword.thy_decl
wenzelm@42375
   132
    (Parse.and_list1 Parse.binding >> (Toplevel.theory o Sign.add_nonterminals_global));
wenzelm@5832
   133
wenzelm@24868
   134
val _ =
wenzelm@36953
   135
  Outer_Syntax.command "arities" "state type arities (axiomatic!)" Keyword.thy_decl
wenzelm@36950
   136
    (Scan.repeat1 Parse.arity >> (Toplevel.theory o fold AxClass.axiomatize_arity_cmd));
wenzelm@5832
   137
wenzelm@5832
   138
wenzelm@5832
   139
(* consts and syntax *)
wenzelm@5832
   140
wenzelm@24868
   141
val _ =
wenzelm@36953
   142
  Outer_Syntax.command "judgment" "declare object-logic judgment" Keyword.thy_decl
wenzelm@36950
   143
    (Parse.const_binding >> (Toplevel.theory o Object_Logic.add_judgment_cmd));
wenzelm@8227
   144
wenzelm@24868
   145
val _ =
wenzelm@36953
   146
  Outer_Syntax.command "consts" "declare constants" Keyword.thy_decl
wenzelm@36950
   147
    (Scan.repeat1 Parse.const_binding >> (Toplevel.theory o Sign.add_consts));
wenzelm@5832
   148
wenzelm@36950
   149
val opt_overloaded = Parse.opt_keyword "overloaded";
skalberg@14223
   150
wenzelm@24868
   151
val _ =
wenzelm@36953
   152
  Outer_Syntax.command "finalconsts" "declare constants as final" Keyword.thy_decl
wenzelm@36950
   153
    (opt_overloaded -- Scan.repeat1 Parse.term >> (uncurry (Toplevel.theory oo Theory.add_finals)));
wenzelm@9731
   154
wenzelm@12142
   155
val mode_spec =
wenzelm@36950
   156
  (Parse.$$$ "output" >> K ("", false)) ||
wenzelm@36950
   157
    Parse.name -- Scan.optional (Parse.$$$ "output" >> K false) true;
wenzelm@9731
   158
wenzelm@14900
   159
val opt_mode =
wenzelm@36950
   160
  Scan.optional (Parse.$$$ "(" |-- Parse.!!! (mode_spec --| Parse.$$$ ")")) Syntax.mode_default;
wenzelm@5832
   161
wenzelm@24868
   162
val _ =
wenzelm@36953
   163
  Outer_Syntax.command "syntax" "declare syntactic constants" Keyword.thy_decl
wenzelm@42299
   164
    (opt_mode -- Scan.repeat1 Parse.const_decl >> (Toplevel.theory o uncurry Sign.add_modesyntax));
wenzelm@5832
   165
wenzelm@24868
   166
val _ =
wenzelm@36953
   167
  Outer_Syntax.command "no_syntax" "delete syntax declarations" Keyword.thy_decl
wenzelm@42299
   168
    (opt_mode -- Scan.repeat1 Parse.const_decl >> (Toplevel.theory o uncurry Sign.del_modesyntax));
wenzelm@15748
   169
wenzelm@5832
   170
wenzelm@5832
   171
(* translations *)
wenzelm@5832
   172
wenzelm@5832
   173
val trans_pat =
wenzelm@42326
   174
  Scan.optional
wenzelm@42326
   175
    (Parse.$$$ "(" |-- Parse.!!! (Parse.xname --| Parse.$$$ ")")) "logic"
wenzelm@42326
   176
    -- Parse.inner_syntax Parse.string;
wenzelm@5832
   177
wenzelm@5832
   178
fun trans_arrow toks =
wenzelm@42204
   179
  ((Parse.$$$ "\\<rightharpoonup>" || Parse.$$$ "=>") >> K Syntax.Parse_Rule ||
wenzelm@42204
   180
    (Parse.$$$ "\\<leftharpoondown>" || Parse.$$$ "<=") >> K Syntax.Print_Rule ||
wenzelm@42204
   181
    (Parse.$$$ "\\<rightleftharpoons>" || Parse.$$$ "==") >> K Syntax.Parse_Print_Rule) toks;
wenzelm@5832
   182
wenzelm@5832
   183
val trans_line =
wenzelm@36950
   184
  trans_pat -- Parse.!!! (trans_arrow -- trans_pat)
wenzelm@5832
   185
    >> (fn (left, (arr, right)) => arr (left, right));
wenzelm@5832
   186
wenzelm@24868
   187
val _ =
wenzelm@36953
   188
  Outer_Syntax.command "translations" "declare syntax translation rules" Keyword.thy_decl
wenzelm@42204
   189
    (Scan.repeat1 trans_line >> (Toplevel.theory o Isar_Cmd.translations));
wenzelm@5832
   190
wenzelm@24868
   191
val _ =
wenzelm@36953
   192
  Outer_Syntax.command "no_translations" "remove syntax translation rules" Keyword.thy_decl
wenzelm@42204
   193
    (Scan.repeat1 trans_line >> (Toplevel.theory o Isar_Cmd.no_translations));
wenzelm@19260
   194
wenzelm@5832
   195
wenzelm@5832
   196
(* axioms and definitions *)
wenzelm@5832
   197
wenzelm@24868
   198
val _ =
wenzelm@36953
   199
  Outer_Syntax.command "axioms" "state arbitrary propositions (axiomatic!)" Keyword.thy_decl
wenzelm@36952
   200
    (Scan.repeat1 Parse_Spec.spec >>
wenzelm@37861
   201
      (fn spec => Toplevel.theory (fn thy =>
wenzelm@37861
   202
        (legacy_feature "Old 'axioms' command -- use 'axiomatization' instead";
wenzelm@37861
   203
          Isar_Cmd.add_axioms spec thy))));
wenzelm@5832
   204
wenzelm@19631
   205
val opt_unchecked_overloaded =
wenzelm@36950
   206
  Scan.optional (Parse.$$$ "(" |-- Parse.!!!
wenzelm@36950
   207
    (((Parse.$$$ "unchecked" >> K true) -- Scan.optional (Parse.$$$ "overloaded" >> K true) false ||
wenzelm@36950
   208
      Parse.$$$ "overloaded" >> K (false, true)) --| Parse.$$$ ")")) (false, false);
wenzelm@19631
   209
wenzelm@24868
   210
val _ =
wenzelm@36953
   211
  Outer_Syntax.command "defs" "define constants" Keyword.thy_decl
wenzelm@35852
   212
    (opt_unchecked_overloaded --
wenzelm@36952
   213
      Scan.repeat1 (Parse_Spec.thm_name ":" -- Parse.prop >> (fn ((x, y), z) => ((x, z), y)))
wenzelm@37216
   214
      >> (Toplevel.theory o Isar_Cmd.add_defs));
wenzelm@6370
   215
wenzelm@14642
   216
wenzelm@21601
   217
(* constant definitions and abbreviations *)
wenzelm@21601
   218
wenzelm@24868
   219
val _ =
wenzelm@36953
   220
  Outer_Syntax.local_theory "definition" "constant definition" Keyword.thy_decl
wenzelm@36952
   221
    (Parse_Spec.constdef >> (fn args => #2 o Specification.definition_cmd args));
wenzelm@18780
   222
wenzelm@24868
   223
val _ =
wenzelm@36953
   224
  Outer_Syntax.local_theory "abbreviation" "constant abbreviation" Keyword.thy_decl
wenzelm@36952
   225
    (opt_mode -- (Scan.option Parse_Spec.constdecl -- Parse.prop)
wenzelm@36950
   226
      >> (fn (mode, args) => Specification.abbreviation_cmd mode args));
wenzelm@19659
   227
wenzelm@24868
   228
val _ =
wenzelm@36953
   229
  Outer_Syntax.local_theory "type_notation" "add concrete syntax for type constructors"
wenzelm@36950
   230
    Keyword.thy_decl
wenzelm@42300
   231
    (opt_mode -- Parse.and_list1 (Parse.type_const -- Parse.mixfix)
wenzelm@36950
   232
      >> (fn (mode, args) => Specification.type_notation_cmd true mode args));
wenzelm@35413
   233
wenzelm@35413
   234
val _ =
wenzelm@36953
   235
  Outer_Syntax.local_theory "no_type_notation" "delete concrete syntax for type constructors"
wenzelm@36950
   236
    Keyword.thy_decl
wenzelm@42300
   237
    (opt_mode -- Parse.and_list1 (Parse.type_const -- Parse.mixfix)
wenzelm@36950
   238
      >> (fn (mode, args) => Specification.type_notation_cmd false mode args));
wenzelm@35413
   239
wenzelm@35413
   240
val _ =
wenzelm@36953
   241
  Outer_Syntax.local_theory "notation" "add concrete syntax for constants / fixed variables"
wenzelm@36950
   242
    Keyword.thy_decl
wenzelm@42300
   243
    (opt_mode -- Parse.and_list1 (Parse.const -- Parse_Spec.locale_mixfix)
wenzelm@36950
   244
      >> (fn (mode, args) => Specification.notation_cmd true mode args));
wenzelm@24950
   245
wenzelm@24950
   246
val _ =
wenzelm@36953
   247
  Outer_Syntax.local_theory "no_notation" "delete concrete syntax for constants / fixed variables"
wenzelm@36950
   248
    Keyword.thy_decl
wenzelm@42300
   249
    (opt_mode -- Parse.and_list1 (Parse.const -- Parse_Spec.locale_mixfix)
wenzelm@36950
   250
      >> (fn (mode, args) => Specification.notation_cmd false mode args));
wenzelm@19076
   251
wenzelm@5832
   252
wenzelm@18616
   253
(* constant specifications *)
wenzelm@18616
   254
wenzelm@24868
   255
val _ =
wenzelm@36953
   256
  Outer_Syntax.command "axiomatization" "axiomatic constant specification" Keyword.thy_decl
wenzelm@36950
   257
    (Scan.optional Parse.fixes [] --
wenzelm@36952
   258
      Scan.optional (Parse.where_ |-- Parse.!!! (Parse.and_list1 Parse_Spec.specs)) []
wenzelm@36950
   259
      >> (fn (x, y) => Toplevel.theory (#2 o Specification.axiomatization_cmd x y)));
wenzelm@18616
   260
wenzelm@18616
   261
wenzelm@5914
   262
(* theorems *)
wenzelm@5914
   263
wenzelm@26988
   264
fun theorems kind =
wenzelm@36952
   265
  Parse_Spec.name_facts >> (fn args => #2 o Specification.theorems_cmd kind args);
wenzelm@12712
   266
wenzelm@24868
   267
val _ =
wenzelm@36953
   268
  Outer_Syntax.local_theory "theorems" "define theorems" Keyword.thy_decl (theorems Thm.theoremK);
wenzelm@5914
   269
wenzelm@24868
   270
val _ =
wenzelm@36953
   271
  Outer_Syntax.local_theory "lemmas" "define lemmas" Keyword.thy_decl (theorems Thm.lemmaK);
wenzelm@5914
   272
wenzelm@24868
   273
val _ =
wenzelm@36953
   274
  Outer_Syntax.local_theory "declare" "declare theorems" Keyword.thy_decl
wenzelm@36952
   275
    (Parse.and_list1 Parse_Spec.xthms1
haftmann@28965
   276
      >> (fn args => #2 o Specification.theorems_cmd "" [(Attrib.empty_binding, flat args)]));
wenzelm@9589
   277
wenzelm@5914
   278
wenzelm@5832
   279
(* name space entry path *)
wenzelm@5832
   280
wenzelm@36176
   281
fun hide_names name hide what =
wenzelm@36953
   282
  Outer_Syntax.command name ("hide " ^ what ^ " from name space") Keyword.thy_decl
wenzelm@36950
   283
    ((Parse.opt_keyword "open" >> not) -- Scan.repeat1 Parse.xname >>
wenzelm@36176
   284
      (Toplevel.theory o uncurry hide));
wenzelm@36176
   285
wenzelm@37216
   286
val _ = hide_names "hide_class" Isar_Cmd.hide_class "classes";
wenzelm@37216
   287
val _ = hide_names "hide_type" Isar_Cmd.hide_type "types";
wenzelm@37216
   288
val _ = hide_names "hide_const" Isar_Cmd.hide_const "constants";
wenzelm@37216
   289
val _ = hide_names "hide_fact" Isar_Cmd.hide_fact "facts";
wenzelm@5832
   290
wenzelm@5832
   291
wenzelm@5832
   292
(* use ML text *)
wenzelm@5832
   293
wenzelm@24868
   294
val _ =
wenzelm@36953
   295
  Outer_Syntax.command "use" "ML text from file" (Keyword.tag_ml Keyword.thy_decl)
wenzelm@37949
   296
    (Parse.path >> (fn path => Toplevel.generic_theory (Thy_Load.exec_ml path)));
wenzelm@7891
   297
wenzelm@24868
   298
val _ =
wenzelm@36953
   299
  Outer_Syntax.command "ML" "ML text within theory or local theory"
wenzelm@36950
   300
    (Keyword.tag_ml Keyword.thy_decl)
wenzelm@36950
   301
    (Parse.ML_source >> (fn (txt, pos) =>
wenzelm@30579
   302
      Toplevel.generic_theory
wenzelm@37949
   303
        (ML_Context.exec (fn () => ML_Context.eval_text true pos txt) #>
wenzelm@37949
   304
          Local_Theory.propagate_ml_env)));
wenzelm@30579
   305
wenzelm@30579
   306
val _ =
wenzelm@36953
   307
  Outer_Syntax.command "ML_prf" "ML text within proof" (Keyword.tag_proof Keyword.prf_decl)
wenzelm@36950
   308
    (Parse.ML_source >> (fn (txt, pos) =>
wenzelm@28269
   309
      Toplevel.proof (Proof.map_context (Context.proof_map
wenzelm@37949
   310
        (ML_Context.exec (fn () => ML_Context.eval_text true pos txt))) #> Proof.propagate_ml_env)));
wenzelm@28269
   311
wenzelm@28269
   312
val _ =
wenzelm@36953
   313
  Outer_Syntax.command "ML_val" "diagnostic ML text" (Keyword.tag_ml Keyword.diag)
wenzelm@37216
   314
    (Parse.ML_source >> Isar_Cmd.ml_diag true);
wenzelm@26396
   315
wenzelm@26396
   316
val _ =
wenzelm@36953
   317
  Outer_Syntax.command "ML_command" "diagnostic ML text (silent)" (Keyword.tag_ml Keyword.diag)
wenzelm@37216
   318
    (Parse.ML_source >> (Toplevel.no_timing oo Isar_Cmd.ml_diag false));
wenzelm@5832
   319
wenzelm@24868
   320
val _ =
wenzelm@36953
   321
  Outer_Syntax.command "setup" "ML theory setup" (Keyword.tag_ml Keyword.thy_decl)
wenzelm@37216
   322
    (Parse.ML_source >> (Toplevel.theory o Isar_Cmd.global_setup));
wenzelm@30461
   323
wenzelm@30461
   324
val _ =
wenzelm@36953
   325
  Outer_Syntax.local_theory "local_setup" "ML local theory setup" (Keyword.tag_ml Keyword.thy_decl)
wenzelm@37216
   326
    (Parse.ML_source >> Isar_Cmd.local_setup);
wenzelm@5832
   327
wenzelm@24868
   328
val _ =
wenzelm@36953
   329
  Outer_Syntax.command "attribute_setup" "define attribute in ML" (Keyword.tag_ml Keyword.thy_decl)
wenzelm@42813
   330
    (Parse.position Parse.name --
wenzelm@42813
   331
        Parse.!!! (Parse.$$$ "=" |-- Parse.ML_source -- Scan.optional Parse.text "")
wenzelm@36950
   332
      >> (fn (name, (txt, cmt)) => Toplevel.theory (Attrib.attribute_setup name txt cmt)));
wenzelm@30526
   333
wenzelm@30526
   334
val _ =
wenzelm@36953
   335
  Outer_Syntax.command "method_setup" "define proof method in ML" (Keyword.tag_ml Keyword.thy_decl)
wenzelm@42813
   336
    (Parse.position Parse.name --
wenzelm@42813
   337
        Parse.!!! (Parse.$$$ "=" |-- Parse.ML_source -- Scan.optional Parse.text "")
wenzelm@36950
   338
      >> (fn (name, (txt, cmt)) => Toplevel.theory (Method.method_setup name txt cmt)));
wenzelm@9197
   339
wenzelm@24868
   340
val _ =
wenzelm@40784
   341
  Outer_Syntax.local_theory "declaration" "generic ML declaration"
wenzelm@40784
   342
    (Keyword.tag_ml Keyword.thy_decl)
wenzelm@40784
   343
    (Parse.opt_keyword "pervasive" -- Parse.ML_source
wenzelm@40784
   344
      >> (fn (pervasive, txt) => Isar_Cmd.declaration {syntax = false, pervasive = pervasive} txt));
wenzelm@40784
   345
wenzelm@40784
   346
val _ =
wenzelm@40784
   347
  Outer_Syntax.local_theory "syntax_declaration" "generic ML declaration"
wenzelm@40784
   348
    (Keyword.tag_ml Keyword.thy_decl)
wenzelm@40784
   349
    (Parse.opt_keyword "pervasive" -- Parse.ML_source
wenzelm@40784
   350
      >> (fn (pervasive, txt) => Isar_Cmd.declaration {syntax = true, pervasive = pervasive} txt));
wenzelm@22088
   351
wenzelm@24868
   352
val _ =
wenzelm@36953
   353
  Outer_Syntax.local_theory "simproc_setup" "define simproc in ML" (Keyword.tag_ml Keyword.thy_decl)
wenzelm@42464
   354
    (Parse.position Parse.name --
wenzelm@36950
   355
      (Parse.$$$ "(" |-- Parse.enum1 "|" Parse.term --| Parse.$$$ ")" --| Parse.$$$ "=") --
wenzelm@36950
   356
      Parse.ML_source -- Scan.optional (Parse.$$$ "identifier" |-- Scan.repeat1 Parse.xname) []
wenzelm@37216
   357
    >> (fn (((a, b), c), d) => Isar_Cmd.simproc_setup a b c d));
wenzelm@22202
   358
wenzelm@5832
   359
wenzelm@5832
   360
(* translation functions *)
wenzelm@5832
   361
wenzelm@36950
   362
val trfun = Parse.opt_keyword "advanced" -- Parse.ML_source;
wenzelm@14642
   363
wenzelm@24868
   364
val _ =
wenzelm@36953
   365
  Outer_Syntax.command "parse_ast_translation" "install parse ast translation functions"
wenzelm@36950
   366
    (Keyword.tag_ml Keyword.thy_decl)
wenzelm@37216
   367
    (trfun >> (Toplevel.theory o Isar_Cmd.parse_ast_translation));
wenzelm@5832
   368
wenzelm@24868
   369
val _ =
wenzelm@36953
   370
  Outer_Syntax.command "parse_translation" "install parse translation functions"
wenzelm@36950
   371
    (Keyword.tag_ml Keyword.thy_decl)
wenzelm@37216
   372
    (trfun >> (Toplevel.theory o Isar_Cmd.parse_translation));
wenzelm@5832
   373
wenzelm@24868
   374
val _ =
wenzelm@36953
   375
  Outer_Syntax.command "print_translation" "install print translation functions"
wenzelm@36950
   376
    (Keyword.tag_ml Keyword.thy_decl)
wenzelm@37216
   377
    (trfun >> (Toplevel.theory o Isar_Cmd.print_translation));
wenzelm@5832
   378
wenzelm@24868
   379
val _ =
wenzelm@36953
   380
  Outer_Syntax.command "typed_print_translation" "install typed print translation functions"
wenzelm@36950
   381
    (Keyword.tag_ml Keyword.thy_decl)
wenzelm@37216
   382
    (trfun >> (Toplevel.theory o Isar_Cmd.typed_print_translation));
wenzelm@5832
   383
wenzelm@24868
   384
val _ =
wenzelm@36953
   385
  Outer_Syntax.command "print_ast_translation" "install print ast translation functions"
wenzelm@36950
   386
    (Keyword.tag_ml Keyword.thy_decl)
wenzelm@37216
   387
    (trfun >> (Toplevel.theory o Isar_Cmd.print_ast_translation));
wenzelm@5832
   388
wenzelm@5832
   389
wenzelm@5832
   390
(* oracles *)
wenzelm@5832
   391
wenzelm@24868
   392
val _ =
wenzelm@36953
   393
  Outer_Syntax.command "oracle" "declare oracle" (Keyword.tag_ml Keyword.thy_decl)
wenzelm@36950
   394
    (Parse.position Parse.name -- (Parse.$$$ "=" |-- Parse.ML_source) >>
wenzelm@37216
   395
      (fn (x, y) => Toplevel.theory (Isar_Cmd.oracle x y)));
wenzelm@5832
   396
wenzelm@5832
   397
wenzelm@21306
   398
(* local theories *)
wenzelm@21306
   399
wenzelm@24868
   400
val _ =
wenzelm@36953
   401
  Outer_Syntax.command "context" "enter local theory context" Keyword.thy_decl
wenzelm@36950
   402
    (Parse.name --| Parse.begin >> (fn name =>
haftmann@38350
   403
      Toplevel.print o Toplevel.begin_local_theory true (Named_Target.context_cmd name)));
wenzelm@21306
   404
wenzelm@21306
   405
wenzelm@12061
   406
(* locales *)
wenzelm@12061
   407
wenzelm@12758
   408
val locale_val =
wenzelm@36952
   409
  Parse_Spec.locale_expression false --
wenzelm@36952
   410
    Scan.optional (Parse.$$$ "+" |-- Parse.!!! (Scan.repeat1 Parse_Spec.context_element)) [] ||
wenzelm@36952
   411
  Scan.repeat1 Parse_Spec.context_element >> pair ([], []);
wenzelm@12061
   412
wenzelm@24868
   413
val _ =
wenzelm@36953
   414
  Outer_Syntax.command "locale" "define named proof context" Keyword.thy_decl
wenzelm@36950
   415
    (Parse.binding --
wenzelm@36950
   416
      Scan.optional (Parse.$$$ "=" |-- Parse.!!! locale_val) (([], []), []) -- Parse.opt_begin
haftmann@27681
   417
      >> (fn ((name, (expr, elems)), begin) =>
wenzelm@21843
   418
          (begin ? Toplevel.print) o Toplevel.begin_local_theory begin
wenzelm@41585
   419
            (Expression.add_locale_cmd I name Binding.empty expr elems #> snd)));
ballarin@28085
   420
ballarin@41270
   421
fun parse_interpretation_arguments mandatory =
ballarin@41270
   422
  Parse.!!! (Parse_Spec.locale_expression mandatory) --
ballarin@41270
   423
    Scan.optional
ballarin@41270
   424
      (Parse.where_ |-- Parse.and_list1 (Parse_Spec.opt_thm_name ":" -- Parse.prop)) [];
ballarin@41270
   425
wenzelm@24868
   426
val _ =
wenzelm@36953
   427
  Outer_Syntax.command "sublocale"
wenzelm@36950
   428
    "prove sublocale relation between a locale and a locale expression" Keyword.thy_goal
wenzelm@36950
   429
    (Parse.xname --| (Parse.$$$ "\\<subseteq>" || Parse.$$$ "<") --
ballarin@41270
   430
      parse_interpretation_arguments false
ballarin@41270
   431
      >> (fn (loc, (expr, equations)) =>
wenzelm@41585
   432
          Toplevel.print o Toplevel.theory_to_proof (Expression.sublocale_cmd I loc expr equations)));
ballarin@28895
   433
ballarin@28895
   434
val _ =
wenzelm@36953
   435
  Outer_Syntax.command "interpretation"
wenzelm@36950
   436
    "prove interpretation of locale expression in theory" Keyword.thy_goal
ballarin@41270
   437
    (parse_interpretation_arguments true
wenzelm@30727
   438
      >> (fn (expr, equations) => Toplevel.print o
wenzelm@30727
   439
          Toplevel.theory_to_proof (Expression.interpretation_cmd expr equations)));
ballarin@29223
   440
ballarin@29223
   441
val _ =
wenzelm@36953
   442
  Outer_Syntax.command "interpret"
ballarin@29223
   443
    "prove interpretation of locale expression in proof context"
wenzelm@36950
   444
    (Keyword.tag_proof Keyword.prf_goal)
ballarin@41270
   445
    (parse_interpretation_arguments true
ballarin@38108
   446
      >> (fn (expr, equations) => Toplevel.print o
ballarin@38108
   447
          Toplevel.proof' (Expression.interpret_cmd expr equations)));
ballarin@29223
   448
wenzelm@15703
   449
haftmann@22299
   450
(* classes *)
haftmann@22299
   451
wenzelm@24868
   452
val class_val =
wenzelm@36952
   453
  Parse_Spec.class_expr --
wenzelm@36952
   454
    Scan.optional (Parse.$$$ "+" |-- Parse.!!! (Scan.repeat1 Parse_Spec.context_element)) [] ||
wenzelm@36952
   455
  Scan.repeat1 Parse_Spec.context_element >> pair [];
haftmann@22299
   456
wenzelm@24868
   457
val _ =
wenzelm@36953
   458
  Outer_Syntax.command "class" "define type class" Keyword.thy_decl
wenzelm@36950
   459
   (Parse.binding -- Scan.optional (Parse.$$$ "=" |-- class_val) ([], []) -- Parse.opt_begin
haftmann@26516
   460
    >> (fn ((name, (supclasses, elems)), begin) =>
wenzelm@24938
   461
        (begin ? Toplevel.print) o Toplevel.begin_local_theory begin
wenzelm@41585
   462
          (Class_Declaration.class_cmd I name supclasses elems #> snd)));
haftmann@22299
   463
wenzelm@24868
   464
val _ =
wenzelm@36953
   465
  Outer_Syntax.local_theory_to_proof "subclass" "prove a subclass relation" Keyword.thy_goal
wenzelm@41585
   466
    (Parse.xname >> Class_Declaration.subclass_cmd I);
haftmann@24914
   467
haftmann@24914
   468
val _ =
wenzelm@36953
   469
  Outer_Syntax.command "instantiation" "instantiate and prove type arity" Keyword.thy_decl
wenzelm@36950
   470
   (Parse.multi_arity --| Parse.begin
haftmann@25462
   471
     >> (fn arities => Toplevel.print o
haftmann@38348
   472
         Toplevel.begin_local_theory true (Class.instantiation_cmd arities)));
haftmann@24589
   473
haftmann@25485
   474
val _ =
wenzelm@36953
   475
  Outer_Syntax.command "instance" "prove type arity or subclass relation" Keyword.thy_goal
wenzelm@36950
   476
  ((Parse.xname -- ((Parse.$$$ "\\<subseteq>" || Parse.$$$ "<") |-- Parse.!!! Parse.xname)
wenzelm@36950
   477
        >> Class.classrel_cmd ||
wenzelm@36950
   478
    Parse.multi_arity >> Class.instance_arity_cmd)
wenzelm@36950
   479
    >> (Toplevel.print oo Toplevel.theory_to_proof) ||
wenzelm@36950
   480
    Scan.succeed
wenzelm@36950
   481
      (Toplevel.print o Toplevel.local_theory_to_proof NONE (Class.instantiation_instance I)));
haftmann@22299
   482
haftmann@22299
   483
haftmann@25519
   484
(* arbitrary overloading *)
haftmann@25519
   485
haftmann@25519
   486
val _ =
wenzelm@36953
   487
  Outer_Syntax.command "overloading" "overloaded definitions" Keyword.thy_decl
wenzelm@36950
   488
   (Scan.repeat1 (Parse.name --| (Parse.$$$ "\\<equiv>" || Parse.$$$ "==") -- Parse.term --
wenzelm@36950
   489
      Scan.optional (Parse.$$$ "(" |-- (Parse.$$$ "unchecked" >> K false) --| Parse.$$$ ")") true
wenzelm@36950
   490
      >> Parse.triple1) --| Parse.begin
haftmann@25519
   491
   >> (fn operations => Toplevel.print o
haftmann@38342
   492
         Toplevel.begin_local_theory true (Overloading.overloading_cmd operations)));
haftmann@25519
   493
haftmann@25519
   494
wenzelm@22866
   495
(* code generation *)
wenzelm@22866
   496
wenzelm@24868
   497
val _ =
wenzelm@36953
   498
  Outer_Syntax.command "code_datatype" "define set of code datatype constructors" Keyword.thy_decl
wenzelm@36950
   499
    (Scan.repeat1 Parse.term >> (Toplevel.theory o Code.add_datatype_cmd));
wenzelm@22866
   500
wenzelm@22866
   501
wenzelm@5832
   502
wenzelm@5832
   503
(** proof commands **)
wenzelm@5832
   504
wenzelm@5832
   505
(* statements *)
wenzelm@5832
   506
wenzelm@36317
   507
fun gen_theorem schematic kind =
wenzelm@36953
   508
  Outer_Syntax.local_theory_to_proof'
wenzelm@36317
   509
    (if schematic then "schematic_" ^ kind else kind)
wenzelm@36317
   510
    ("state " ^ (if schematic then "schematic " ^ kind else kind))
wenzelm@36950
   511
    (if schematic then Keyword.thy_schematic_goal else Keyword.thy_goal)
wenzelm@36952
   512
    (Scan.optional (Parse_Spec.opt_thm_name ":" --|
wenzelm@36952
   513
      Scan.ahead (Parse_Spec.locale_keyword || Parse_Spec.statement_keyword)) Attrib.empty_binding --
wenzelm@36952
   514
      Parse_Spec.general_statement >> (fn (a, (elems, concl)) =>
wenzelm@36317
   515
        ((if schematic then Specification.schematic_theorem_cmd else Specification.theorem_cmd)
wenzelm@36317
   516
          kind NONE (K I) a elems concl)));
wenzelm@5832
   517
wenzelm@36317
   518
val _ = gen_theorem false Thm.theoremK;
wenzelm@36317
   519
val _ = gen_theorem false Thm.lemmaK;
wenzelm@36317
   520
val _ = gen_theorem false Thm.corollaryK;
wenzelm@36317
   521
val _ = gen_theorem true Thm.theoremK;
wenzelm@36317
   522
val _ = gen_theorem true Thm.lemmaK;
wenzelm@36317
   523
val _ = gen_theorem true Thm.corollaryK;
wenzelm@5832
   524
wenzelm@24868
   525
val _ =
wenzelm@40960
   526
  Outer_Syntax.local_theory_to_proof "notepad"
wenzelm@40960
   527
    "Isar proof state as formal notepad, without any result" Keyword.thy_decl
wenzelm@40960
   528
    (Parse.begin >> K Proof.begin_notepad);
wenzelm@40960
   529
wenzelm@40960
   530
val _ =
wenzelm@36953
   531
  Outer_Syntax.command "have" "state local goal"
wenzelm@36950
   532
    (Keyword.tag_proof Keyword.prf_goal)
wenzelm@37216
   533
    (Parse_Spec.statement >> ((Toplevel.print oo Toplevel.proof') o Isar_Cmd.have));
wenzelm@17353
   534
wenzelm@24868
   535
val _ =
wenzelm@36953
   536
  Outer_Syntax.command "hence" "abbreviates \"then have\""
wenzelm@36950
   537
    (Keyword.tag_proof Keyword.prf_goal)
wenzelm@37216
   538
    (Parse_Spec.statement >> ((Toplevel.print oo Toplevel.proof') o Isar_Cmd.hence));
wenzelm@17353
   539
wenzelm@24868
   540
val _ =
wenzelm@36953
   541
  Outer_Syntax.command "show" "state local goal, solving current obligation"
wenzelm@36950
   542
    (Keyword.tag_proof Keyword.prf_asm_goal)
wenzelm@37216
   543
    (Parse_Spec.statement >> ((Toplevel.print oo Toplevel.proof') o Isar_Cmd.show));
wenzelm@5832
   544
wenzelm@24868
   545
val _ =
wenzelm@36953
   546
  Outer_Syntax.command "thus" "abbreviates \"then show\""
wenzelm@36950
   547
    (Keyword.tag_proof Keyword.prf_asm_goal)
wenzelm@37216
   548
    (Parse_Spec.statement >> ((Toplevel.print oo Toplevel.proof') o Isar_Cmd.thus));
wenzelm@6501
   549
wenzelm@5832
   550
wenzelm@5914
   551
(* facts *)
wenzelm@5832
   552
wenzelm@36952
   553
val facts = Parse.and_list1 Parse_Spec.xthms1;
wenzelm@9197
   554
wenzelm@24868
   555
val _ =
wenzelm@36953
   556
  Outer_Syntax.command "then" "forward chaining"
wenzelm@36950
   557
    (Keyword.tag_proof Keyword.prf_chain)
wenzelm@17900
   558
    (Scan.succeed (Toplevel.print o Toplevel.proof Proof.chain));
wenzelm@5832
   559
wenzelm@24868
   560
val _ =
wenzelm@36953
   561
  Outer_Syntax.command "from" "forward chaining from given facts"
wenzelm@36950
   562
    (Keyword.tag_proof Keyword.prf_chain)
wenzelm@36323
   563
    (facts >> (Toplevel.print oo (Toplevel.proof o Proof.from_thmss_cmd)));
wenzelm@5914
   564
wenzelm@24868
   565
val _ =
wenzelm@36953
   566
  Outer_Syntax.command "with" "forward chaining from given and current facts"
wenzelm@36950
   567
    (Keyword.tag_proof Keyword.prf_chain)
wenzelm@36323
   568
    (facts >> (Toplevel.print oo (Toplevel.proof o Proof.with_thmss_cmd)));
wenzelm@6878
   569
wenzelm@24868
   570
val _ =
wenzelm@36953
   571
  Outer_Syntax.command "note" "define facts"
wenzelm@36950
   572
    (Keyword.tag_proof Keyword.prf_decl)
wenzelm@36952
   573
    (Parse_Spec.name_facts >> (Toplevel.print oo (Toplevel.proof o Proof.note_thmss_cmd)));
wenzelm@5832
   574
wenzelm@24868
   575
val _ =
wenzelm@36953
   576
  Outer_Syntax.command "using" "augment goal facts"
wenzelm@36950
   577
    (Keyword.tag_proof Keyword.prf_decl)
wenzelm@36323
   578
    (facts >> (Toplevel.print oo (Toplevel.proof o Proof.using_cmd)));
wenzelm@18544
   579
wenzelm@24868
   580
val _ =
wenzelm@36953
   581
  Outer_Syntax.command "unfolding" "unfold definitions in goal and facts"
wenzelm@36950
   582
    (Keyword.tag_proof Keyword.prf_decl)
wenzelm@36323
   583
    (facts >> (Toplevel.print oo (Toplevel.proof o Proof.unfolding_cmd)));
wenzelm@12926
   584
wenzelm@5832
   585
wenzelm@5832
   586
(* proof context *)
wenzelm@5832
   587
wenzelm@24868
   588
val _ =
wenzelm@36953
   589
  Outer_Syntax.command "fix" "fix local variables (Skolem constants)"
wenzelm@36950
   590
    (Keyword.tag_proof Keyword.prf_asm)
wenzelm@36950
   591
    (Parse.fixes >> (Toplevel.print oo (Toplevel.proof o Proof.fix_cmd)));
wenzelm@11890
   592
wenzelm@24868
   593
val _ =
wenzelm@36953
   594
  Outer_Syntax.command "assume" "assume propositions"
wenzelm@36950
   595
    (Keyword.tag_proof Keyword.prf_asm)
wenzelm@36952
   596
    (Parse_Spec.statement >> (Toplevel.print oo (Toplevel.proof o Proof.assume_cmd)));
wenzelm@5832
   597
wenzelm@24868
   598
val _ =
wenzelm@36953
   599
  Outer_Syntax.command "presume" "assume propositions, to be established later"
wenzelm@36950
   600
    (Keyword.tag_proof Keyword.prf_asm)
wenzelm@36952
   601
    (Parse_Spec.statement >> (Toplevel.print oo (Toplevel.proof o Proof.presume_cmd)));
wenzelm@6850
   602
wenzelm@24868
   603
val _ =
wenzelm@36953
   604
  Outer_Syntax.command "def" "local definition"
wenzelm@36950
   605
    (Keyword.tag_proof Keyword.prf_asm)
wenzelm@36950
   606
    (Parse.and_list1
wenzelm@36952
   607
      (Parse_Spec.opt_thm_name ":" --
wenzelm@36950
   608
        ((Parse.binding -- Parse.opt_mixfix) --
wenzelm@36950
   609
          ((Parse.$$$ "\\<equiv>" || Parse.$$$ "==") |-- Parse.!!! Parse.termp)))
wenzelm@36323
   610
    >> (Toplevel.print oo (Toplevel.proof o Proof.def_cmd)));
wenzelm@6953
   611
wenzelm@24868
   612
val _ =
wenzelm@36953
   613
  Outer_Syntax.command "obtain" "generalized existence"
wenzelm@36950
   614
    (Keyword.tag_proof Keyword.prf_asm_goal)
wenzelm@36952
   615
    (Parse.parname -- Scan.optional (Parse.fixes --| Parse.where_) [] -- Parse_Spec.statement
wenzelm@36323
   616
      >> (fn ((x, y), z) => Toplevel.print o Toplevel.proof' (Obtain.obtain_cmd x y z)));
wenzelm@5832
   617
wenzelm@24868
   618
val _ =
wenzelm@36953
   619
  Outer_Syntax.command "guess" "wild guessing (unstructured)"
wenzelm@36950
   620
    (Keyword.tag_proof Keyword.prf_asm_goal)
wenzelm@36950
   621
    (Scan.optional Parse.fixes [] >> (Toplevel.print oo (Toplevel.proof' o Obtain.guess_cmd)));
wenzelm@17854
   622
wenzelm@24868
   623
val _ =
wenzelm@36953
   624
  Outer_Syntax.command "let" "bind text variables"
wenzelm@36950
   625
    (Keyword.tag_proof Keyword.prf_decl)
wenzelm@36950
   626
    (Parse.and_list1 (Parse.and_list1 Parse.term -- (Parse.$$$ "=" |-- Parse.term))
wenzelm@36323
   627
      >> (Toplevel.print oo (Toplevel.proof o Proof.let_bind_cmd)));
wenzelm@5832
   628
wenzelm@36505
   629
val _ =
wenzelm@36953
   630
  Outer_Syntax.command "write" "add concrete syntax for constants / fixed variables"
wenzelm@36950
   631
    (Keyword.tag_proof Keyword.prf_decl)
wenzelm@42300
   632
    (opt_mode -- Parse.and_list1 (Parse.const -- Parse_Spec.locale_mixfix)
wenzelm@36505
   633
    >> (fn (mode, args) => Toplevel.print o Toplevel.proof (Proof.write_cmd mode args)));
wenzelm@36505
   634
wenzelm@11793
   635
val case_spec =
wenzelm@36950
   636
  (Parse.$$$ "(" |--
wenzelm@42496
   637
    Parse.!!! (Parse.xname -- Scan.repeat1 (Parse.maybe Parse.binding) --| Parse.$$$ ")") ||
wenzelm@36952
   638
    Parse.xname >> rpair []) -- Parse_Spec.opt_attribs >> Parse.triple1;
wenzelm@11793
   639
wenzelm@24868
   640
val _ =
wenzelm@36953
   641
  Outer_Syntax.command "case" "invoke local context"
wenzelm@36950
   642
    (Keyword.tag_proof Keyword.prf_asm)
wenzelm@36323
   643
    (case_spec >> (Toplevel.print oo (Toplevel.proof o Proof.invoke_case_cmd)));
wenzelm@8370
   644
wenzelm@5832
   645
wenzelm@5832
   646
(* proof structure *)
wenzelm@5832
   647
wenzelm@24868
   648
val _ =
wenzelm@36953
   649
  Outer_Syntax.command "{" "begin explicit proof block"
wenzelm@36950
   650
    (Keyword.tag_proof Keyword.prf_open)
wenzelm@17900
   651
    (Scan.succeed (Toplevel.print o Toplevel.proof Proof.begin_block));
wenzelm@5832
   652
wenzelm@24868
   653
val _ =
wenzelm@36953
   654
  Outer_Syntax.command "}" "end explicit proof block"
wenzelm@36950
   655
    (Keyword.tag_proof Keyword.prf_close)
wenzelm@20305
   656
    (Scan.succeed (Toplevel.print o Toplevel.proof Proof.end_block));
wenzelm@6687
   657
wenzelm@24868
   658
val _ =
wenzelm@36953
   659
  Outer_Syntax.command "next" "enter next proof block"
wenzelm@36950
   660
    (Keyword.tag_proof Keyword.prf_block)
wenzelm@17900
   661
    (Scan.succeed (Toplevel.print o Toplevel.proof Proof.next_block));
wenzelm@5832
   662
wenzelm@5832
   663
wenzelm@5832
   664
(* end proof *)
wenzelm@5832
   665
wenzelm@24868
   666
val _ =
wenzelm@36953
   667
  Outer_Syntax.command "qed" "conclude (sub-)proof"
wenzelm@36950
   668
    (Keyword.tag_proof Keyword.qed_block)
wenzelm@37216
   669
    (Scan.option Method.parse >> Isar_Cmd.qed);
wenzelm@5832
   670
wenzelm@24868
   671
val _ =
wenzelm@36953
   672
  Outer_Syntax.command "by" "terminal backward proof"
wenzelm@36950
   673
    (Keyword.tag_proof Keyword.qed)
wenzelm@37216
   674
    (Method.parse -- Scan.option Method.parse >> Isar_Cmd.terminal_proof);
wenzelm@6404
   675
wenzelm@24868
   676
val _ =
wenzelm@36953
   677
  Outer_Syntax.command ".." "default proof"
wenzelm@36950
   678
    (Keyword.tag_proof Keyword.qed)
wenzelm@37216
   679
    (Scan.succeed Isar_Cmd.default_proof);
wenzelm@8966
   680
wenzelm@24868
   681
val _ =
wenzelm@36953
   682
  Outer_Syntax.command "." "immediate proof"
wenzelm@36950
   683
    (Keyword.tag_proof Keyword.qed)
wenzelm@37216
   684
    (Scan.succeed Isar_Cmd.immediate_proof);
wenzelm@6404
   685
wenzelm@24868
   686
val _ =
wenzelm@36953
   687
  Outer_Syntax.command "done" "done proof"
wenzelm@36950
   688
    (Keyword.tag_proof Keyword.qed)
wenzelm@37216
   689
    (Scan.succeed Isar_Cmd.done_proof);
wenzelm@5832
   690
wenzelm@24868
   691
val _ =
wenzelm@36953
   692
  Outer_Syntax.command "sorry" "skip proof (quick-and-dirty mode only!)"
wenzelm@36950
   693
    (Keyword.tag_proof Keyword.qed)
wenzelm@37216
   694
    (Scan.succeed Isar_Cmd.skip_proof);
wenzelm@6888
   695
wenzelm@24868
   696
val _ =
wenzelm@36953
   697
  Outer_Syntax.command "oops" "forget proof"
wenzelm@36950
   698
    (Keyword.tag_proof Keyword.qed_global)
wenzelm@18561
   699
    (Scan.succeed Toplevel.forget_proof);
wenzelm@8210
   700
wenzelm@5832
   701
wenzelm@5832
   702
(* proof steps *)
wenzelm@5832
   703
wenzelm@24868
   704
val _ =
wenzelm@36953
   705
  Outer_Syntax.command "defer" "shuffle internal proof state"
wenzelm@36950
   706
    (Keyword.tag_proof Keyword.prf_script)
wenzelm@36950
   707
    (Scan.option Parse.nat >> (Toplevel.print oo (Toplevel.proofs o Proof.defer)));
wenzelm@8165
   708
wenzelm@24868
   709
val _ =
wenzelm@36953
   710
  Outer_Syntax.command "prefer" "shuffle internal proof state"
wenzelm@36950
   711
    (Keyword.tag_proof Keyword.prf_script)
wenzelm@36950
   712
    (Parse.nat >> (Toplevel.print oo (Toplevel.proofs o Proof.prefer)));
wenzelm@8165
   713
wenzelm@24868
   714
val _ =
wenzelm@36953
   715
  Outer_Syntax.command "apply" "initial refinement step (unstructured)"
wenzelm@36950
   716
    (Keyword.tag_proof Keyword.prf_script)
wenzelm@22117
   717
    (Method.parse >> (Toplevel.print oo (Toplevel.proofs o Proof.apply)));
wenzelm@5832
   718
wenzelm@24868
   719
val _ =
wenzelm@36953
   720
  Outer_Syntax.command "apply_end" "terminal refinement (unstructured)"
wenzelm@36950
   721
    (Keyword.tag_proof Keyword.prf_script)
wenzelm@22117
   722
    (Method.parse >> (Toplevel.print oo (Toplevel.proofs o Proof.apply_end)));
wenzelm@5832
   723
wenzelm@24868
   724
val _ =
wenzelm@36953
   725
  Outer_Syntax.command "proof" "backward proof"
wenzelm@36950
   726
    (Keyword.tag_proof Keyword.prf_block)
wenzelm@22117
   727
    (Scan.option Method.parse >> (fn m => Toplevel.print o
wenzelm@33390
   728
      Toplevel.actual_proof (Proof_Node.applys (Proof.proof m)) o
wenzelm@27563
   729
      Toplevel.skip_proof (fn i => i + 1)));
wenzelm@5832
   730
wenzelm@5832
   731
wenzelm@6773
   732
(* calculational proof commands *)
wenzelm@6773
   733
wenzelm@6878
   734
val calc_args =
wenzelm@36952
   735
  Scan.option (Parse.$$$ "(" |-- Parse.!!! ((Parse_Spec.xthms1 --| Parse.$$$ ")")));
wenzelm@6878
   736
wenzelm@24868
   737
val _ =
wenzelm@36953
   738
  Outer_Syntax.command "also" "combine calculation and current facts"
wenzelm@36950
   739
    (Keyword.tag_proof Keyword.prf_decl)
wenzelm@36323
   740
    (calc_args >> (Toplevel.proofs' o Calculation.also_cmd));
wenzelm@6773
   741
wenzelm@24868
   742
val _ =
wenzelm@36953
   743
  Outer_Syntax.command "finally" "combine calculation and current facts, exhibit result"
wenzelm@36950
   744
    (Keyword.tag_proof Keyword.prf_chain)
wenzelm@36323
   745
    (calc_args >> (Toplevel.proofs' o Calculation.finally_cmd));
wenzelm@6773
   746
wenzelm@24868
   747
val _ =
wenzelm@36953
   748
  Outer_Syntax.command "moreover" "augment calculation by current facts"
wenzelm@36950
   749
    (Keyword.tag_proof Keyword.prf_decl)
wenzelm@17900
   750
    (Scan.succeed (Toplevel.proof' Calculation.moreover));
wenzelm@8562
   751
wenzelm@24868
   752
val _ =
wenzelm@36953
   753
  Outer_Syntax.command "ultimately" "augment calculation by current facts, exhibit result"
wenzelm@36950
   754
    (Keyword.tag_proof Keyword.prf_chain)
wenzelm@17900
   755
    (Scan.succeed (Toplevel.proof' Calculation.ultimately));
wenzelm@8588
   756
wenzelm@6773
   757
wenzelm@6742
   758
(* proof navigation *)
wenzelm@5944
   759
wenzelm@24868
   760
val _ =
wenzelm@36953
   761
  Outer_Syntax.command "back" "backtracking of proof command"
wenzelm@36950
   762
    (Keyword.tag_proof Keyword.prf_script)
wenzelm@33390
   763
    (Scan.succeed (Toplevel.print o Toplevel.actual_proof Proof_Node.back o Toplevel.skip_proof I));
wenzelm@6742
   764
haftmann@22744
   765
wenzelm@27614
   766
(* nested commands *)
wenzelm@25578
   767
wenzelm@29309
   768
val props_text =
wenzelm@43775
   769
  Scan.optional Parse.properties [] -- Parse.position Parse.string
wenzelm@36950
   770
  >> (fn (props, (str, pos)) =>
wenzelm@36950
   771
      (Position.of_properties (Position.default_properties pos props), str));
wenzelm@29309
   772
wenzelm@25578
   773
val _ =
wenzelm@36953
   774
  Outer_Syntax.improper_command "Isabelle.command" "nested Isabelle command" Keyword.control
wenzelm@29309
   775
    (props_text :|-- (fn (pos, str) =>
wenzelm@36953
   776
      (case Outer_Syntax.parse pos str of
wenzelm@27838
   777
        [tr] => Scan.succeed (K tr)
wenzelm@27838
   778
      | _ => Scan.fail_with (K "exactly one command expected"))
wenzelm@27838
   779
      handle ERROR msg => Scan.fail_with (K msg)));
wenzelm@25578
   780
wenzelm@25578
   781
haftmann@22744
   782
wenzelm@5832
   783
(** diagnostic commands (for interactive mode only) **)
wenzelm@5832
   784
wenzelm@36950
   785
val opt_modes =
wenzelm@36950
   786
  Scan.optional (Parse.$$$ "(" |-- Parse.!!! (Scan.repeat1 Parse.xname --| Parse.$$$ ")")) [];
wenzelm@36950
   787
wenzelm@36950
   788
val opt_bang = Scan.optional (Parse.$$$ "!" >> K true) false;
wenzelm@8464
   789
wenzelm@24868
   790
val _ =
wenzelm@36953
   791
  Outer_Syntax.improper_command "pretty_setmargin" "change default margin for pretty printing"
wenzelm@38870
   792
    Keyword.diag (Parse.nat >>
wenzelm@38870
   793
      (fn n => Toplevel.no_timing o Toplevel.imperative (fn () => Pretty.margin_default := n)));
wenzelm@7124
   794
wenzelm@24868
   795
val _ =
wenzelm@36953
   796
  Outer_Syntax.improper_command "help" "print outer syntax commands" Keyword.diag
wenzelm@36953
   797
    (Scan.succeed (Toplevel.no_timing o Toplevel.imperative Outer_Syntax.print_outer_syntax));
wenzelm@21714
   798
wenzelm@24868
   799
val _ =
wenzelm@36953
   800
  Outer_Syntax.improper_command "print_commands" "print outer syntax commands" Keyword.diag
wenzelm@36953
   801
    (Scan.succeed (Toplevel.no_timing o Toplevel.imperative Outer_Syntax.print_outer_syntax));
wenzelm@5832
   802
wenzelm@24868
   803
val _ =
wenzelm@36953
   804
  Outer_Syntax.improper_command "print_configs" "print configuration options" Keyword.diag
wenzelm@37216
   805
    (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_configs));
wenzelm@23989
   806
wenzelm@24868
   807
val _ =
wenzelm@36953
   808
  Outer_Syntax.improper_command "print_context" "print theory context name" Keyword.diag
wenzelm@37216
   809
    (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_context));
wenzelm@7308
   810
wenzelm@24868
   811
val _ =
wenzelm@36953
   812
  Outer_Syntax.improper_command "print_theory" "print logical theory contents (verbose!)"
wenzelm@37216
   813
    Keyword.diag (opt_bang >> (Toplevel.no_timing oo Isar_Cmd.print_theory));
wenzelm@5832
   814
wenzelm@24868
   815
val _ =
wenzelm@36953
   816
  Outer_Syntax.improper_command "print_syntax" "print inner syntax of context (verbose!)"
wenzelm@37216
   817
    Keyword.diag (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_syntax));
wenzelm@5832
   818
wenzelm@24868
   819
val _ =
wenzelm@36953
   820
  Outer_Syntax.improper_command "print_abbrevs" "print constant abbreviation of context"
wenzelm@37216
   821
    Keyword.diag (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_abbrevs));
wenzelm@21726
   822
wenzelm@24868
   823
val _ =
wenzelm@36953
   824
  Outer_Syntax.improper_command "print_theorems"
wenzelm@36950
   825
      "print theorems of local theory or proof context" Keyword.diag
wenzelm@37216
   826
    (opt_bang >> (Toplevel.no_timing oo Isar_Cmd.print_theorems));
wenzelm@5881
   827
wenzelm@24868
   828
val _ =
wenzelm@36953
   829
  Outer_Syntax.improper_command "print_locales" "print locales of this theory" Keyword.diag
wenzelm@37216
   830
    (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_locales));
wenzelm@12061
   831
wenzelm@24868
   832
val _ =
wenzelm@36953
   833
  Outer_Syntax.improper_command "print_classes" "print classes of this theory" Keyword.diag
wenzelm@42359
   834
    (Scan.succeed (Toplevel.no_timing o Toplevel.unknown_theory o
wenzelm@42359
   835
      Toplevel.keep (Class.print_classes o Toplevel.context_of)));
haftmann@22744
   836
wenzelm@24868
   837
val _ =
wenzelm@36953
   838
  Outer_Syntax.improper_command "print_locale" "print locale of this theory" Keyword.diag
wenzelm@37216
   839
    (opt_bang -- Parse.xname >> (Toplevel.no_timing oo Isar_Cmd.print_locale));
wenzelm@12061
   840
wenzelm@24868
   841
val _ =
wenzelm@36953
   842
  Outer_Syntax.improper_command "print_interps"
ballarin@41435
   843
    "print interpretations of locale for this theory or proof context" Keyword.diag
wenzelm@37216
   844
    (Parse.xname >> (Toplevel.no_timing oo Isar_Cmd.print_registrations));
ballarin@32804
   845
ballarin@32804
   846
val _ =
ballarin@41435
   847
  Outer_Syntax.improper_command "print_dependencies"
ballarin@41435
   848
    "print dependencies of locale expression" Keyword.diag
ballarin@41435
   849
    (opt_bang -- Parse_Spec.locale_expression true >>
ballarin@41435
   850
      (Toplevel.no_timing oo Isar_Cmd.print_dependencies));
ballarin@41435
   851
ballarin@41435
   852
val _ =
wenzelm@36953
   853
  Outer_Syntax.improper_command "print_attributes" "print attributes of this theory" Keyword.diag
wenzelm@37216
   854
    (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_attributes));
wenzelm@5832
   855
wenzelm@24868
   856
val _ =
wenzelm@36953
   857
  Outer_Syntax.improper_command "print_simpset" "print context of Simplifier" Keyword.diag
wenzelm@37216
   858
    (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_simpset));
wenzelm@16027
   859
wenzelm@24868
   860
val _ =
wenzelm@36953
   861
  Outer_Syntax.improper_command "print_rules" "print intro/elim rules" Keyword.diag
wenzelm@37216
   862
    (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_rules));
wenzelm@12383
   863
wenzelm@24868
   864
val _ =
wenzelm@36953
   865
  Outer_Syntax.improper_command "print_trans_rules" "print transitivity rules" Keyword.diag
wenzelm@37216
   866
    (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_trans_rules));
wenzelm@9221
   867
wenzelm@24868
   868
val _ =
wenzelm@36953
   869
  Outer_Syntax.improper_command "print_methods" "print methods of this theory" Keyword.diag
wenzelm@37216
   870
    (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_methods));
wenzelm@5832
   871
wenzelm@24868
   872
val _ =
wenzelm@36953
   873
  Outer_Syntax.improper_command "print_antiquotations" "print antiquotations (global)" Keyword.diag
wenzelm@37216
   874
    (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_antiquotations));
wenzelm@9221
   875
wenzelm@24868
   876
val _ =
wenzelm@36953
   877
  Outer_Syntax.improper_command "thy_deps" "visualize theory dependencies"
wenzelm@37216
   878
    Keyword.diag (Scan.succeed (Toplevel.no_timing o Isar_Cmd.thy_deps));
haftmann@22485
   879
wenzelm@24868
   880
val _ =
wenzelm@36953
   881
  Outer_Syntax.improper_command "class_deps" "visualize class dependencies"
wenzelm@37216
   882
    Keyword.diag (Scan.succeed (Toplevel.no_timing o Isar_Cmd.class_deps));
wenzelm@20574
   883
wenzelm@24868
   884
val _ =
wenzelm@36953
   885
  Outer_Syntax.improper_command "thm_deps" "visualize theorem dependencies"
wenzelm@37216
   886
    Keyword.diag (Parse_Spec.xthms1 >> (Toplevel.no_timing oo Isar_Cmd.thm_deps));
wenzelm@9454
   887
wenzelm@24868
   888
val _ =
wenzelm@36953
   889
  Outer_Syntax.improper_command "print_binds" "print term bindings of proof context" Keyword.diag
wenzelm@37216
   890
    (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_binds));
wenzelm@5832
   891
wenzelm@24868
   892
val _ =
wenzelm@36953
   893
  Outer_Syntax.improper_command "print_facts" "print facts of proof context" Keyword.diag
wenzelm@37216
   894
    (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_facts));
wenzelm@5832
   895
wenzelm@24868
   896
val _ =
wenzelm@36953
   897
  Outer_Syntax.improper_command "print_cases" "print cases of proof context" Keyword.diag
wenzelm@37216
   898
    (Scan.succeed (Toplevel.no_timing o Isar_Cmd.print_cases));
wenzelm@8370
   899
wenzelm@24868
   900
val _ =
wenzelm@36953
   901
  Outer_Syntax.improper_command "print_statement" "print theorems as long statements" Keyword.diag
wenzelm@37216
   902
    (opt_modes -- Parse_Spec.xthms1 >> (Toplevel.no_timing oo Isar_Cmd.print_stmts));
wenzelm@19269
   903
wenzelm@24868
   904
val _ =
wenzelm@36953
   905
  Outer_Syntax.improper_command "thm" "print theorems" Keyword.diag
wenzelm@37216
   906
    (opt_modes -- Parse_Spec.xthms1 >> (Toplevel.no_timing oo Isar_Cmd.print_thms));
wenzelm@5832
   907
wenzelm@24868
   908
val _ =
wenzelm@36953
   909
  Outer_Syntax.improper_command "prf" "print proof terms of theorems" Keyword.diag
wenzelm@36952
   910
    (opt_modes -- Scan.option Parse_Spec.xthms1
wenzelm@37216
   911
      >> (Toplevel.no_timing oo Isar_Cmd.print_prfs false));
berghofe@11524
   912
wenzelm@24868
   913
val _ =
wenzelm@36953
   914
  Outer_Syntax.improper_command "full_prf" "print full proof terms of theorems" Keyword.diag
wenzelm@37216
   915
    (opt_modes -- Scan.option Parse_Spec.xthms1 >> (Toplevel.no_timing oo Isar_Cmd.print_prfs true));
berghofe@11524
   916
wenzelm@24868
   917
val _ =
wenzelm@36953
   918
  Outer_Syntax.improper_command "prop" "read and print proposition" Keyword.diag
wenzelm@37216
   919
    (opt_modes -- Parse.term >> (Toplevel.no_timing oo Isar_Cmd.print_prop));
wenzelm@5832
   920
wenzelm@24868
   921
val _ =
wenzelm@36953
   922
  Outer_Syntax.improper_command "term" "read and print term" Keyword.diag
wenzelm@37216
   923
    (opt_modes -- Parse.term >> (Toplevel.no_timing oo Isar_Cmd.print_term));
wenzelm@5832
   924
wenzelm@24868
   925
val _ =
wenzelm@36953
   926
  Outer_Syntax.improper_command "typ" "read and print type" Keyword.diag
wenzelm@37216
   927
    (opt_modes -- Parse.typ >> (Toplevel.no_timing oo Isar_Cmd.print_type));
wenzelm@5832
   928
wenzelm@24868
   929
val _ =
wenzelm@36953
   930
  Outer_Syntax.improper_command "print_codesetup" "print code generator setup" Keyword.diag
haftmann@22744
   931
    (Scan.succeed
haftmann@22744
   932
      (Toplevel.no_timing o Toplevel.unknown_theory o Toplevel.keep
haftmann@24219
   933
        (Code.print_codesetup o Toplevel.theory_of)));
wenzelm@5832
   934
berghofe@26184
   935
val _ =
wenzelm@36953
   936
  Outer_Syntax.improper_command "unused_thms" "find unused theorems" Keyword.diag
wenzelm@36950
   937
    (Scan.option ((Scan.repeat1 (Scan.unless Parse.minus Parse.name) --| Parse.minus) --
wenzelm@36950
   938
       Scan.option (Scan.repeat1 (Scan.unless Parse.minus Parse.name))) >>
wenzelm@37216
   939
         (Toplevel.no_timing oo Isar_Cmd.unused_thms));
berghofe@26184
   940
wenzelm@5832
   941
wenzelm@30142
   942
wenzelm@5832
   943
(** system commands (for interactive mode only) **)
wenzelm@5832
   944
wenzelm@24868
   945
val _ =
wenzelm@40395
   946
  Outer_Syntax.improper_command "cd" "change current working directory" Keyword.control
wenzelm@40395
   947
    (Parse.path >> (fn path => Toplevel.no_timing o Toplevel.imperative (fn () => File.cd path)));
wenzelm@5832
   948
wenzelm@24868
   949
val _ =
wenzelm@36953
   950
  Outer_Syntax.improper_command "pwd" "print current working directory" Keyword.diag
wenzelm@40395
   951
    (Scan.succeed (Toplevel.no_timing o
wenzelm@41944
   952
      Toplevel.imperative (fn () => writeln (Path.print (File.pwd ())))));
wenzelm@5832
   953
wenzelm@24868
   954
val _ =
wenzelm@37987
   955
  Outer_Syntax.improper_command "use_thy" "use theory file" Keyword.control
wenzelm@36950
   956
    (Parse.name >> (fn name =>
wenzelm@37216
   957
      Toplevel.no_timing o Toplevel.imperative (fn () => Thy_Info.use_thy name)));
wenzelm@5832
   958
wenzelm@24868
   959
val _ =
wenzelm@37987
   960
  Outer_Syntax.improper_command "remove_thy" "remove theory from loader database" Keyword.control
wenzelm@36950
   961
    (Parse.name >> (fn name =>
wenzelm@37216
   962
      Toplevel.no_timing o Toplevel.imperative (fn () => Thy_Info.remove_thy name)));
wenzelm@7102
   963
wenzelm@24868
   964
val _ =
wenzelm@36953
   965
  Outer_Syntax.improper_command "kill_thy" "kill theory -- try to remove from loader database"
wenzelm@37987
   966
    Keyword.control (Parse.name >> (fn name =>
wenzelm@37216
   967
      Toplevel.no_timing o Toplevel.imperative (fn () => Thy_Info.kill_thy name)));
wenzelm@7931
   968
wenzelm@24868
   969
val _ =
wenzelm@36953
   970
  Outer_Syntax.improper_command "display_drafts" "display raw source files with symbols"
wenzelm@37216
   971
    Keyword.diag (Scan.repeat1 Parse.path >> (Toplevel.no_timing oo Isar_Cmd.display_drafts));
wenzelm@14934
   972
wenzelm@24868
   973
val _ =
wenzelm@36953
   974
  Outer_Syntax.improper_command "print_drafts" "print raw source files with symbols"
wenzelm@37216
   975
    Keyword.diag (Scan.repeat1 Parse.path >> (Toplevel.no_timing oo Isar_Cmd.print_drafts));
wenzelm@14934
   976
wenzelm@39165
   977
val _ =  (* FIXME tty only *)
wenzelm@36953
   978
  Outer_Syntax.improper_command "pr" "print current proof state (if present)" Keyword.diag
wenzelm@39165
   979
    (opt_modes -- Scan.option Parse.nat >> (fn (modes, limit) =>
wenzelm@39165
   980
      Toplevel.no_timing o Toplevel.keep (fn state =>
wenzelm@39165
   981
       (case limit of NONE => () | SOME n => Goal_Display.goals_limit_default := n;
wenzelm@39165
   982
        Toplevel.quiet := false;
wenzelm@39165
   983
        Print_Mode.with_modes modes (Toplevel.print_state true) state))));
wenzelm@7199
   984
wenzelm@24868
   985
val _ =
wenzelm@37987
   986
  Outer_Syntax.improper_command "disable_pr" "disable printing of toplevel state" Keyword.control
wenzelm@39165
   987
    (Scan.succeed (Toplevel.no_timing o Toplevel.imperative (fn () => Toplevel.quiet := true)));
wenzelm@5832
   988
wenzelm@24868
   989
val _ =
wenzelm@37987
   990
  Outer_Syntax.improper_command "enable_pr" "enable printing of toplevel state" Keyword.control
wenzelm@39165
   991
    (Scan.succeed (Toplevel.no_timing o Toplevel.imperative (fn () => Toplevel.quiet := false)));
wenzelm@7222
   992
wenzelm@24868
   993
val _ =
wenzelm@40395
   994
  Outer_Syntax.improper_command "commit" "commit current session to ML database" Keyword.control
wenzelm@36950
   995
    (Parse.opt_unit >> K (Toplevel.no_timing o Toplevel.imperative Secure.commit));
wenzelm@5832
   996
wenzelm@24868
   997
val _ =
wenzelm@36953
   998
  Outer_Syntax.improper_command "quit" "quit Isabelle" Keyword.control
wenzelm@37977
   999
    (Parse.opt_unit >> (Toplevel.no_timing oo K (Toplevel.imperative quit)));
wenzelm@5832
  1000
wenzelm@24868
  1001
val _ =
wenzelm@36953
  1002
  Outer_Syntax.improper_command "exit" "exit Isar loop" Keyword.control
wenzelm@37977
  1003
    (Scan.succeed
wenzelm@37977
  1004
      (Toplevel.no_timing o Toplevel.keep (fn state =>
wenzelm@37977
  1005
        (Context.set_thread_data (try Toplevel.generic_theory_of state);
wenzelm@38888
  1006
          raise Runtime.TERMINATE))));
wenzelm@5832
  1007
wenzelm@5832
  1008
end;
wenzelm@27614
  1009