src/Pure/Isar/isar_syn.ML
author wenzelm
Wed Sep 29 13:49:07 1999 +0200 (1999-09-29)
changeset 7632 25a0d2ba3a87
parent 7616 f677cdc7fae9
child 7678 027b6ec2f084
permissions -rw-r--r--
removed extra shyps error;
     1 (*  Title:      Pure/Isar/isar_syn.ML
     2     ID:         $Id$
     3     Author:     Markus Wenzel, TU Muenchen
     4 
     5 Isar/Pure outer syntax.
     6 *)
     7 
     8 signature ISAR_SYN =
     9 sig
    10   val keywords: string list
    11   val parsers: OuterSyntax.parser list
    12 end;
    13 
    14 structure IsarSyn: ISAR_SYN =
    15 struct
    16 
    17 structure P = OuterParse and K = OuterSyntax.Keyword;
    18 
    19 
    20 (** init and exit **)
    21 
    22 val theoryP =
    23   OuterSyntax.command "theory" "begin theory" K.thy_begin
    24     (OuterSyntax.theory_header >> (Toplevel.print oo IsarThy.theory));
    25 
    26 val end_excursionP =
    27   OuterSyntax.command "end" "end current excursion" K.thy_end
    28     (Scan.succeed (Toplevel.print o Toplevel.exit));
    29 
    30 val kill_excursionP =
    31   OuterSyntax.improper_command "kill" "kill current excursion" K.control
    32     (Scan.succeed (Toplevel.print o Toplevel.kill));
    33 
    34 val contextP =
    35   OuterSyntax.improper_command "context" "switch theory context" K.thy_switch
    36     (P.name >> (Toplevel.print oo IsarThy.context));
    37 
    38 
    39 
    40 (** formal comments **)
    41 
    42 val titleP = OuterSyntax.command "title" "document title" K.thy_heading
    43   ((P.comment -- Scan.optional P.comment Comment.none -- Scan.optional P.comment Comment.none)
    44     >> (fn ((x, y), z) => Toplevel.theory (IsarThy.add_title x y z)));
    45 
    46 val chapterP = OuterSyntax.command "chapter" "chapter heading" K.thy_heading
    47   (P.comment >> (Toplevel.theory o IsarThy.add_chapter));
    48 
    49 val sectionP = OuterSyntax.command "section" "section heading" K.thy_heading
    50   (P.comment >> (Toplevel.theory o IsarThy.add_section));
    51 
    52 val subsectionP = OuterSyntax.command "subsection" "subsection heading" K.thy_heading
    53   (P.comment >> (Toplevel.theory o IsarThy.add_subsection));
    54 
    55 val subsubsectionP = OuterSyntax.command "subsubsection" "subsubsection heading" K.thy_heading
    56   (P.comment >> (Toplevel.theory o IsarThy.add_subsubsection));
    57 
    58 val textP = OuterSyntax.command "text" "formal comment (theory)" K.thy_decl
    59   (P.comment >> (Toplevel.theory o IsarThy.add_text));
    60 
    61 
    62 val sectP = OuterSyntax.command "sect" "formal comment (proof)" K.prf_decl
    63   (P.comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_sect)));
    64 
    65 val subsectP = OuterSyntax.command "subsect" "formal comment (proof)" K.prf_decl
    66   (P.comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_subsect)));
    67 
    68 val subsubsectP = OuterSyntax.command "subsubsect" "formal comment (proof)" K.prf_decl
    69   (P.comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_subsubsect)));
    70 
    71 val txtP = OuterSyntax.command "txt" "formal comment (proof)" K.prf_decl
    72   (P.comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_txt)));
    73 
    74 
    75 
    76 (** theory sections **)
    77 
    78 (* classes and sorts *)
    79 
    80 val classesP =
    81   OuterSyntax.command "classes" "declare type classes" K.thy_decl
    82     (Scan.repeat1 (P.name -- Scan.optional (P.$$$ "<" |-- P.!!! (P.list1 P.xname)) [])
    83       -- P.marg_comment >> (Toplevel.theory o IsarThy.add_classes));
    84 
    85 val classrelP =
    86   OuterSyntax.command "classrel" "state inclusion of type classes (axiomatic!)" K.thy_decl
    87     (P.xname -- (P.$$$ "<" |-- P.!!! P.xname) -- P.marg_comment
    88       >> (Toplevel.theory o IsarThy.add_classrel));
    89 
    90 val defaultsortP =
    91   OuterSyntax.command "defaultsort" "declare default sort" K.thy_decl
    92     (P.sort -- P.marg_comment >> (Toplevel.theory o IsarThy.add_defsort));
    93 
    94 
    95 (* types *)
    96 
    97 val typedeclP =
    98   OuterSyntax.command "typedecl" "Pure type declaration" K.thy_decl
    99     (P.type_args -- P.name -- P.opt_infix -- P.marg_comment >> (fn (((args, a), mx), cmt) =>
   100       Toplevel.theory (IsarThy.add_typedecl ((a, args, mx), cmt))));
   101 
   102 val typeabbrP =
   103   OuterSyntax.command "types" "declare type abbreviations" K.thy_decl
   104     (Scan.repeat1
   105       (P.type_args -- P.name -- (P.$$$ "=" |-- P.!!! (P.typ -- P.opt_infix)) -- P.marg_comment)
   106       >> (Toplevel.theory o IsarThy.add_tyabbrs o
   107         map (fn (((args, a), (T, mx)), cmt) => ((a, args, T, mx), cmt))));
   108 
   109 val nontermP =
   110   OuterSyntax.command "nonterminals" "declare types treated as grammar nonterminal symbols"
   111     K.thy_decl (Scan.repeat1 (P.name -- P.marg_comment)
   112       >> (Toplevel.theory o IsarThy.add_nonterminals));
   113 
   114 val aritiesP =
   115   OuterSyntax.command "arities" "state type arities (axiomatic!)" K.thy_decl
   116     (Scan.repeat1 ((P.xname -- (P.$$$ "::" |-- P.!!! P.arity) >> P.triple2) -- P.marg_comment)
   117       >> (Toplevel.theory o IsarThy.add_arities));
   118 
   119 
   120 (* consts and syntax *)
   121 
   122 val constsP =
   123   OuterSyntax.command "consts" "declare constants" K.thy_decl
   124     (Scan.repeat1 (P.const -- P.marg_comment) >> (Toplevel.theory o IsarThy.add_consts));
   125 
   126 val opt_mode =
   127   Scan.optional
   128     (P.$$$ "(" |-- P.!!! (P.name -- Scan.optional (P.$$$ "output" >> K false) true --| P.$$$ ")"))
   129     ("", true);
   130 
   131 val syntaxP =
   132   OuterSyntax.command "syntax" "declare syntactic constants" K.thy_decl
   133     (opt_mode -- Scan.repeat1 (P.const -- P.marg_comment)
   134       >> (Toplevel.theory o uncurry IsarThy.add_modesyntax));
   135 
   136 
   137 (* translations *)
   138 
   139 val trans_pat =
   140   Scan.optional (P.$$$ "(" |-- P.!!! (P.xname --| P.$$$ ")")) "logic" -- P.string;
   141 
   142 fun trans_arrow toks =
   143   (P.$$$ "=>" >> K Syntax.ParseRule ||
   144     P.$$$ "<=" >> K Syntax.PrintRule ||
   145     P.$$$ "==" >> K Syntax.ParsePrintRule) toks;
   146 
   147 val trans_line =
   148   trans_pat -- P.!!! (trans_arrow -- trans_pat)
   149     >> (fn (left, (arr, right)) => arr (left, right));
   150 
   151 val translationsP =
   152   OuterSyntax.command "translations" "declare syntax translation rules" K.thy_decl
   153     (Scan.repeat1 (trans_line -- P.marg_comment) >> (Toplevel.theory o IsarThy.add_trrules));
   154 
   155 
   156 (* axioms and definitions *)
   157 
   158 val axiomsP =
   159   OuterSyntax.command "axioms" "state arbitrary propositions (axiomatic!)" K.thy_decl
   160     (Scan.repeat1 (P.spec_name -- P.marg_comment) >> (Toplevel.theory o IsarThy.add_axioms));
   161 
   162 val defsP =
   163   OuterSyntax.command "defs" "define constants" K.thy_decl
   164     (Scan.repeat1 (P.spec_name -- P.marg_comment) >> (Toplevel.theory o IsarThy.add_defs));
   165 
   166 val constdefsP =
   167   OuterSyntax.command "constdefs" "declare and define constants" K.thy_decl
   168     (Scan.repeat1 ((P.const -- P.marg_comment) -- (P.term -- P.marg_comment))
   169       >> (Toplevel.theory o IsarThy.add_constdefs));
   170 
   171 
   172 (* theorems *)
   173 
   174 val facts = P.opt_thm_name "=" -- P.xthms1;
   175 
   176 val theoremsP =
   177   OuterSyntax.command "theorems" "define theorems" K.thy_decl
   178     (facts -- P.marg_comment >> (Toplevel.theory o IsarThy.have_theorems));
   179 
   180 val lemmasP =
   181   OuterSyntax.command "lemmas" "define lemmas" K.thy_decl
   182     (facts -- P.marg_comment >> (Toplevel.theory o IsarThy.have_lemmas));
   183 
   184 
   185 (* name space entry path *)
   186 
   187 val globalP =
   188   OuterSyntax.command "global" "disable prefixing of theory name" K.thy_decl
   189     (Scan.succeed (Toplevel.theory PureThy.global_path));
   190 
   191 val localP =
   192   OuterSyntax.command "local" "enable prefixing of theory name" K.thy_decl
   193     (Scan.succeed (Toplevel.theory PureThy.local_path));
   194 
   195 
   196 (* use ML text *)
   197 
   198 val useP =
   199   OuterSyntax.command "use" "eval ML text from file" K.diag
   200     (P.name >> IsarCmd.use);
   201 
   202 val mlP =
   203   OuterSyntax.command "ML" "eval ML text (diagnostic)" K.diag
   204     (P.text >> IsarCmd.use_mltext)
   205 
   206 val ml_setupP =
   207   OuterSyntax.command "ML_setup" "eval ML text (may change theory)" K.thy_decl
   208     (P.text >> IsarCmd.use_mltext_theory);
   209 
   210 val setupP =
   211   OuterSyntax.command "setup" "apply ML theory setup" K.thy_decl
   212     (P.text >> (Toplevel.theory o IsarThy.use_setup));
   213 
   214 
   215 (* translation functions *)
   216 
   217 val parse_ast_translationP =
   218   OuterSyntax.command "parse_ast_translation" "install parse ast translation functions" K.thy_decl
   219     (P.text >> (Toplevel.theory o IsarThy.parse_ast_translation));
   220 
   221 val parse_translationP =
   222   OuterSyntax.command "parse_translation" "install parse translation functions" K.thy_decl
   223     (P.text >> (Toplevel.theory o IsarThy.parse_translation));
   224 
   225 val print_translationP =
   226   OuterSyntax.command "print_translation" "install print translation functions" K.thy_decl
   227     (P.text >> (Toplevel.theory o IsarThy.print_translation));
   228 
   229 val typed_print_translationP =
   230   OuterSyntax.command "typed_print_translation" "install typed print translation functions"
   231     K.thy_decl (P.text >> (Toplevel.theory o IsarThy.typed_print_translation));
   232 
   233 val print_ast_translationP =
   234   OuterSyntax.command "print_ast_translation" "install print ast translation functions" K.thy_decl
   235     (P.text >> (Toplevel.theory o IsarThy.print_ast_translation));
   236 
   237 val token_translationP =
   238   OuterSyntax.command "token_translation" "install token translation functions" K.thy_decl
   239     (P.text >> (Toplevel.theory o IsarThy.token_translation));
   240 
   241 
   242 (* oracles *)
   243 
   244 val oracleP =
   245   OuterSyntax.command "oracle" "install oracle" K.thy_decl
   246     ((P.name --| P.$$$ "=") -- P.text -- P.marg_comment >> (Toplevel.theory o IsarThy.add_oracle));
   247 
   248 
   249 
   250 (** proof commands **)
   251 
   252 (* statements *)
   253 
   254 fun statement f = (P.opt_thm_name ":" -- P.propp >> P.triple1) -- P.marg_comment >> f;
   255 
   256 val theoremP =
   257   OuterSyntax.command "theorem" "state theorem" K.thy_goal
   258     (statement IsarThy.theorem >> (fn f => Toplevel.print o Toplevel.theory_to_proof f));
   259 
   260 val lemmaP =
   261   OuterSyntax.command "lemma" "state lemma" K.thy_goal
   262     (statement IsarThy.lemma >> (fn f => Toplevel.print o Toplevel.theory_to_proof f));
   263 
   264 val showP =
   265   OuterSyntax.command "show" "state local goal, solving current obligation" K.prf_goal
   266     (statement IsarThy.show >> (fn f => Toplevel.print o Toplevel.proof f));
   267 
   268 val haveP =
   269   OuterSyntax.command "have" "state local goal" K.prf_goal
   270     (statement IsarThy.have >> (fn f => Toplevel.print o Toplevel.proof f));
   271 
   272 val thusP =
   273   OuterSyntax.command "thus" "abbreviates \"then show\"" K.prf_goal
   274     (statement IsarThy.thus >> (fn f => Toplevel.print o Toplevel.proof f));
   275 
   276 val henceP =
   277   OuterSyntax.command "hence" "abbreviates \"then have\"" K.prf_goal
   278     (statement IsarThy.hence >> (fn f => Toplevel.print o Toplevel.proof f));
   279 
   280 
   281 (* facts *)
   282 
   283 val thenP =
   284   OuterSyntax.command "then" "forward chaining" K.prf_chain
   285     (P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.chain)));
   286 
   287 val thenceP =
   288   OuterSyntax.command "thence" "forward chaining, including full export" K.prf_chain
   289     (P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.export_chain)));
   290 
   291 val fromP =
   292   OuterSyntax.command "from" "forward chaining from given facts" K.prf_chain
   293     (P.xthms1 -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.from_facts)));
   294 
   295 val withP =
   296   OuterSyntax.command "with" "forward chaining from given and current facts" K.prf_chain
   297     (P.xthms1 -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.with_facts)));
   298 
   299 val noteP =
   300   OuterSyntax.command "note" "define facts" K.prf_decl
   301     (facts -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.have_facts)));
   302 
   303 
   304 (* proof context *)
   305 
   306 val assumeP =
   307   OuterSyntax.command "assume" "assume propositions" K.prf_asm
   308     (P.and_list1 ((P.opt_thm_name ":" -- Scan.repeat1 P.propp >> P.triple1) -- P.marg_comment)
   309       >> (Toplevel.print oo (Toplevel.proof o IsarThy.assume)));
   310 
   311 val presumeP =
   312   OuterSyntax.command "presume" "assume propositions, to be established later" K.prf_asm
   313     (P.and_list1 ((P.opt_thm_name ":" -- Scan.repeat1 P.propp >> P.triple1) -- P.marg_comment)
   314       >> (Toplevel.print oo (Toplevel.proof o IsarThy.presume)));
   315 
   316 val defP =
   317   OuterSyntax.command "def" "local definition" K.prf_asm
   318     ((P.opt_thm_name ":" -- (P.name -- Scan.option (P.$$$ "::" |-- P.typ) --
   319       (P.$$$ "==" |-- P.termp)) >> P.triple1) -- P.marg_comment
   320       >> (Toplevel.print oo (Toplevel.proof o IsarThy.local_def)));
   321 
   322 val fixP =
   323   OuterSyntax.command "fix" "fix variables (Skolem constants)" K.prf_asm
   324     (P.and_list1 (Scan.repeat1 P.name -- Scan.option (P.$$$ "::" |-- P.typ) -- P.marg_comment)
   325       >> (Toplevel.print oo (Toplevel.proof o IsarThy.fix)));
   326 
   327 val letP =
   328   OuterSyntax.command "let" "bind text variables" K.prf_decl
   329     (P.and_list1 (P.enum1 "as" P.term -- (P.$$$ "=" |-- P.term) -- P.marg_comment)
   330       >> (Toplevel.print oo (Toplevel.proof o IsarThy.match_bind)));
   331 
   332 
   333 (* proof structure *)
   334 
   335 val beginP =
   336   OuterSyntax.command "{{" "begin explicit proof block" K.prf_block
   337     (Scan.succeed (Toplevel.print o Toplevel.proof IsarThy.begin_block));
   338 
   339 val endP =
   340   OuterSyntax.command "}}" "end explicit proof block" K.prf_block
   341     (Scan.succeed (Toplevel.print o Toplevel.proof IsarThy.end_block));
   342 
   343 val nextP =
   344   OuterSyntax.command "next" "enter next proof block" K.prf_block
   345     (Scan.succeed (Toplevel.print o Toplevel.proof IsarThy.next_block));
   346 
   347 
   348 (* end proof *)
   349 
   350 val qedP =
   351   OuterSyntax.command "qed" "conclude (sub-)proof" K.qed_block
   352     (Scan.option (P.method -- P.interest) -- P.marg_comment >> IsarThy.qed);
   353 
   354 val terminal_proofP =
   355   OuterSyntax.command "by" "terminal backward proof" K.qed
   356     (P.method -- P.interest -- Scan.option (P.method -- P.interest)
   357       -- P.marg_comment >> IsarThy.terminal_proof);
   358 
   359 val immediate_proofP =
   360   OuterSyntax.command "." "immediate proof" K.qed
   361     (P.marg_comment >> IsarThy.immediate_proof);
   362 
   363 val default_proofP =
   364   OuterSyntax.command ".." "default proof" K.qed
   365     (P.marg_comment >> IsarThy.default_proof);
   366 
   367 val skip_proofP =
   368   OuterSyntax.improper_command "sorry" "skip proof (quick-and-dirty mode only!)" K.qed
   369     (P.marg_comment >> IsarThy.skip_proof);
   370 
   371 
   372 (* proof steps *)
   373 
   374 val applyP =
   375   OuterSyntax.improper_command "apply" "unstructured backward proof step, ignoring facts"
   376     K.prf_script (P.method >> (Toplevel.print oo (Toplevel.proof o IsarThy.tac)));
   377 
   378 val then_applyP =
   379   OuterSyntax.improper_command "then_apply" "unstructured backward proof step, using facts"
   380     K.prf_script (P.method >> (Toplevel.print oo (Toplevel.proof o IsarThy.then_tac)));
   381 
   382 val proofP =
   383   OuterSyntax.command "proof" "backward proof" K.prf_block
   384     (P.interest -- Scan.option (P.method -- P.interest) -- P.marg_comment
   385       >> (Toplevel.print oo (Toplevel.proof o IsarThy.proof)));
   386 
   387 
   388 (* calculational proof commands *)
   389 
   390 val calc_args =
   391   Scan.option (P.$$$ "(" |-- P.!!! ((P.xthms1 --| P.$$$ ")") -- P.interest));
   392 
   393 val alsoP =
   394   OuterSyntax.command "also" "intermediate calculational proof step" K.prf_decl
   395     (calc_args -- P.marg_comment >> IsarThy.also);
   396 
   397 val finallyP =
   398   OuterSyntax.command "finally" "terminal calculational proof step" K.prf_chain
   399     (calc_args -- P.marg_comment >> IsarThy.finally);
   400 
   401 
   402 (* proof navigation *)
   403 
   404 val backP =
   405   OuterSyntax.improper_command "back" "backtracking of proof command" K.prf_script
   406     (Scan.optional (P.$$$ "!" >> K true) false >>
   407       (Toplevel.print oo (Toplevel.proof o ProofHistory.back)));
   408 
   409 
   410 (* history *)
   411 
   412 val cannot_undoP =
   413   OuterSyntax.improper_command "cannot_undo" "report 'cannot undo' error message" K.control
   414     (P.name >> IsarCmd.cannot_undo);
   415 
   416 val clear_undoP =
   417   OuterSyntax.improper_command "clear_undo" "clear undo information" K.control
   418     (Scan.succeed IsarCmd.clear_undo);
   419 
   420 val redoP =
   421   OuterSyntax.improper_command "redo" "redo last command" K.control
   422     (Scan.succeed (Toplevel.print o IsarCmd.redo));
   423 
   424 val undos_proofP =
   425   OuterSyntax.improper_command "undos_proof" "undo last proof commands" K.control
   426     (P.nat >> (Toplevel.print oo IsarCmd.undos_proof));
   427 
   428 val kill_proofP =
   429   OuterSyntax.improper_command "kill_proof" "undo current proof" K.control
   430     (Scan.succeed IsarCmd.kill_proof);
   431 
   432 val undoP =
   433   OuterSyntax.improper_command "undo" "undo last command" K.control
   434     (Scan.succeed IsarCmd.undo);
   435 
   436 
   437 
   438 (** diagnostic commands (for interactive mode only) **)
   439 
   440 val pretty_setmarginP =
   441   OuterSyntax.improper_command "pretty_setmargin" "change default margin for pretty printing"
   442     K.diag (P.nat >> IsarCmd.pretty_setmargin);
   443 
   444 val print_commandsP =
   445   OuterSyntax.improper_command "help" "print outer syntax (global)" K.diag
   446     (Scan.succeed OuterSyntax.print_help);
   447 
   448 val print_contextP =
   449   OuterSyntax.improper_command "print_context" "print theory context name" K.diag
   450     (Scan.succeed IsarCmd.print_context);
   451 
   452 val print_theoryP =
   453   OuterSyntax.improper_command "print_theory" "print logical theory contents (verbose!)" K.diag
   454     (Scan.succeed IsarCmd.print_theory);
   455 
   456 val print_syntaxP =
   457   OuterSyntax.improper_command "print_syntax" "print inner syntax of theory (verbose!)" K.diag
   458     (Scan.succeed IsarCmd.print_syntax);
   459 
   460 val print_theoremsP =
   461   OuterSyntax.improper_command "print_theorems" "print theorems known in this theory" K.diag
   462     (Scan.succeed IsarCmd.print_theorems);
   463 
   464 val print_attributesP =
   465   OuterSyntax.improper_command "print_attributes" "print attributes known in this theory" K.diag
   466     (Scan.succeed IsarCmd.print_attributes);
   467 
   468 val print_methodsP =
   469   OuterSyntax.improper_command "print_methods" "print methods known in this theory" K.diag
   470     (Scan.succeed IsarCmd.print_methods);
   471 
   472 val thms_containingP =
   473   OuterSyntax.improper_command "thms_containing" "print theorems containing all given constants"
   474     K.diag (Scan.repeat P.xname >> IsarCmd.print_thms_containing);
   475 
   476 val print_bindsP =
   477   OuterSyntax.improper_command "print_binds" "print term bindings of proof context" K.diag
   478     (Scan.succeed IsarCmd.print_binds);
   479 
   480 val print_lthmsP =
   481   OuterSyntax.improper_command "print_facts" "print local theorems of proof context" K.diag
   482     (Scan.succeed IsarCmd.print_lthms);
   483 
   484 val print_thmsP =
   485   OuterSyntax.improper_command "thm" "print theorems" K.diag (P.xthms1 >> IsarCmd.print_thms);
   486 
   487 val print_propP =
   488   OuterSyntax.improper_command "prop" "read and print proposition" K.diag
   489     (P.term >> IsarCmd.print_prop);
   490 
   491 val print_termP =
   492   OuterSyntax.improper_command "term" "read and print term" K.diag
   493     (P.term >> IsarCmd.print_term);
   494 
   495 val print_typeP =
   496   OuterSyntax.improper_command "typ" "read and print type" K.diag
   497     (P.typ >> IsarCmd.print_type);
   498 
   499 
   500 
   501 (** system commands (for interactive mode only) **)
   502 
   503 val cdP =
   504   OuterSyntax.improper_command "cd" "change current working directory" K.control
   505     (P.name >> IsarCmd.cd);
   506 
   507 val pwdP =
   508   OuterSyntax.improper_command "pwd" "print current working directory" K.diag
   509     (Scan.succeed IsarCmd.pwd);
   510 
   511 val use_thyP =
   512   OuterSyntax.improper_command "use_thy" "use theory file" K.diag
   513     (P.name >> IsarCmd.use_thy);
   514 
   515 val use_thy_onlyP =
   516   OuterSyntax.improper_command "use_thy_only" "use theory file only, ignoring associated ML"
   517     K.diag (P.name >> IsarCmd.use_thy_only);
   518 
   519 val update_thyP =
   520   OuterSyntax.improper_command "update_thy" "update theory file" K.diag
   521     (P.name >> IsarCmd.update_thy);
   522 
   523 val update_thy_onlyP =
   524   OuterSyntax.improper_command "update_thy_only" "update theory file, ignoring associated ML"
   525     K.diag (P.name >> IsarCmd.update_thy);
   526 
   527 val touch_thyP =
   528   OuterSyntax.improper_command "touch_thy" "outdate theory, including descendants" K.diag
   529     (P.name >> IsarCmd.touch_thy);
   530 
   531 val touch_all_thysP =
   532   OuterSyntax.improper_command "touch_all_thys" "outdate all non-finished theories" K.diag
   533     (Scan.succeed IsarCmd.touch_all_thys);
   534 
   535 val remove_thyP =
   536   OuterSyntax.improper_command "remove_thy" "remove theory from loader database" K.diag
   537     (P.name >> IsarCmd.remove_thy);
   538 
   539 val prP =
   540   OuterSyntax.improper_command "pr" "print current toplevel state" K.diag
   541     (Scan.succeed (Toplevel.print o Toplevel.imperative (fn () => Toplevel.quiet := false)));
   542 
   543 val disable_prP =
   544   OuterSyntax.improper_command "disable_pr" "disable printing of toplevel state" K.diag
   545     (Scan.succeed (Toplevel.imperative (fn () => Toplevel.quiet := true)));
   546 
   547 val enable_prP =
   548   OuterSyntax.improper_command "enable_pr" "enable printing of toplevel state" K.diag
   549     (Scan.succeed (Toplevel.imperative (fn () => Toplevel.quiet := false)));
   550 
   551 
   552 val opt_unit = Scan.optional (P.$$$ "(" -- P.$$$ ")" >> (K ())) ();
   553 
   554 val commitP =
   555   OuterSyntax.improper_command "commit" "commit current session to ML database" K.diag
   556     (opt_unit >> (K IsarCmd.use_commit));
   557 
   558 val quitP =
   559   OuterSyntax.improper_command "quit" "quit Isabelle" K.control
   560     (opt_unit >> (K IsarCmd.quit));
   561 
   562 val exitP =
   563   OuterSyntax.improper_command "exit" "exit Isar loop" K.control
   564     (Scan.succeed IsarCmd.exit);
   565 
   566 val init_toplevelP =
   567   OuterSyntax.improper_command "init_toplevel" "restart Isar toplevel loop" K.control
   568     (Scan.succeed IsarCmd.init_toplevel);
   569 
   570 val welcomeP =
   571   OuterSyntax.improper_command "welcome" "print welcome message" K.control
   572     (Scan.succeed IsarCmd.welcome);
   573 
   574 
   575 
   576 (** the Pure outer syntax **)
   577 
   578 (*keep keywords consistent with the parsers, including those in
   579   outer_parse.ML, otherwise be prepared for unexpected errors*)
   580 
   581 val keywords =
   582  ["!", "!!", "%", "%%", "(", ")", "+", ",", "--", ":", "::", ";", "<",
   583   "<=", "=", "==", "=>", "?", "[", "]", "and", "as", "binder",
   584   "concl", "files", "infixl", "infixr", "is", "output", "{", "|",
   585   "}"];
   586 
   587 val parsers = [
   588   (*theory structure*)
   589   theoryP, end_excursionP, kill_excursionP, contextP,
   590   (*formal comments*)
   591   titleP, chapterP, sectionP, subsectionP, subsubsectionP, textP,
   592   sectP, subsectP, subsubsectP, txtP,
   593   (*theory sections*)
   594   classesP, classrelP, defaultsortP, typedeclP, typeabbrP, nontermP,
   595   aritiesP, constsP, syntaxP, translationsP, axiomsP, defsP,
   596   constdefsP, theoremsP, lemmasP, globalP, localP, useP, mlP,
   597   ml_setupP, setupP, parse_ast_translationP, parse_translationP,
   598   print_translationP, typed_print_translationP,
   599   print_ast_translationP, token_translationP, oracleP,
   600   (*proof commands*)
   601   theoremP, lemmaP, showP, haveP, thusP, henceP, assumeP, presumeP,
   602   defP, fixP, letP, thenP, thenceP, fromP, withP, noteP, beginP, endP,
   603   nextP, qedP, terminal_proofP, immediate_proofP, default_proofP,
   604   skip_proofP, applyP, then_applyP, proofP, alsoP, finallyP, backP,
   605   cannot_undoP, clear_undoP, redoP, undos_proofP, kill_proofP, undoP,
   606   (*diagnostic commands*)
   607   pretty_setmarginP, print_commandsP, print_contextP, print_theoryP,
   608   print_syntaxP, print_theoremsP, print_attributesP, print_methodsP,
   609   thms_containingP, print_bindsP, print_lthmsP, print_thmsP,
   610   print_propP, print_termP, print_typeP,
   611   (*system commands*)
   612   cdP, pwdP, use_thyP, use_thy_onlyP, update_thyP, update_thy_onlyP,
   613   touch_thyP, touch_all_thysP, remove_thyP, prP, disable_prP,
   614   enable_prP, commitP, quitP, exitP, init_toplevelP, welcomeP];
   615 
   616 
   617 end;
   618 
   619 
   620 (*install the Pure outer syntax*)
   621 OuterSyntax.add_keywords IsarSyn.keywords;
   622 OuterSyntax.add_parsers IsarSyn.parsers;