src/Pure/Isar/isar_syn.ML
changeset 30240 5b25fee0362c
parent 29882 29154e67731d
child 30242 aea5d7fa7ef5
equal deleted inserted replaced
30239:179ff9cb160b 30240:5b25fee0362c
    35 val _ =
    35 val _ =
    36   OuterSyntax.command "end" "end (local) theory" (K.tag_theory K.thy_end)
    36   OuterSyntax.command "end" "end (local) theory" (K.tag_theory K.thy_end)
    37     (Scan.succeed (Toplevel.exit o Toplevel.end_local_theory));
    37     (Scan.succeed (Toplevel.exit o Toplevel.end_local_theory));
    38 
    38 
    39 
    39 
       
    40 
    40 (** markup commands **)
    41 (** markup commands **)
    41 
    42 
    42 val _ = OuterSyntax.markup_command ThyOutput.Markup "header" "theory header" K.diag
    43 val _ = OuterSyntax.markup_command ThyOutput.Markup "header" "theory header" K.diag
    43   (P.doc_source >> IsarCmd.header_markup);
    44   (P.doc_source >> IsarCmd.header_markup);
    44 
    45 
    77   "raw document preparation text (proof)" (K.tag_proof K.prf_decl)
    78   "raw document preparation text (proof)" (K.tag_proof K.prf_decl)
    78   (P.doc_source >> IsarCmd.proof_markup);
    79   (P.doc_source >> IsarCmd.proof_markup);
    79 
    80 
    80 
    81 
    81 
    82 
    82 (** theory sections **)
    83 (** theory commands **)
    83 
    84 
    84 (* classes and sorts *)
    85 (* classes and sorts *)
    85 
    86 
    86 val _ =
    87 val _ =
    87   OuterSyntax.command "classes" "declare type classes" K.thy_decl
    88   OuterSyntax.command "classes" "declare type classes" K.thy_decl
   690     (calc_args >> (Toplevel.proofs' o Calculation.also));
   691     (calc_args >> (Toplevel.proofs' o Calculation.also));
   691 
   692 
   692 val _ =
   693 val _ =
   693   OuterSyntax.command "finally" "combine calculation and current facts, exhibit result"
   694   OuterSyntax.command "finally" "combine calculation and current facts, exhibit result"
   694     (K.tag_proof K.prf_chain)
   695     (K.tag_proof K.prf_chain)
   695     (calc_args >> (Toplevel.proofs' o Calculation.finally_));
   696     (calc_args >> (Toplevel.proofs' o Calculation.finally));
   696 
   697 
   697 val _ =
   698 val _ =
   698   OuterSyntax.command "moreover" "augment calculation by current facts"
   699   OuterSyntax.command "moreover" "augment calculation by current facts"
   699     (K.tag_proof K.prf_decl)
   700     (K.tag_proof K.prf_decl)
   700     (Scan.succeed (Toplevel.proof' Calculation.moreover));
   701     (Scan.succeed (Toplevel.proof' Calculation.moreover));
   726         [tr] => Scan.succeed (K tr)
   727         [tr] => Scan.succeed (K tr)
   727       | _ => Scan.fail_with (K "exactly one command expected"))
   728       | _ => Scan.fail_with (K "exactly one command expected"))
   728       handle ERROR msg => Scan.fail_with (K msg)));
   729       handle ERROR msg => Scan.fail_with (K msg)));
   729 
   730 
   730 
   731 
   731 (* global history commands *)
       
   732 
       
   733 val _ =
       
   734   OuterSyntax.improper_command "init_toplevel" "init toplevel point-of-interest" K.control
       
   735     (Scan.succeed (Toplevel.no_timing o Toplevel.imperative Isar.init));
       
   736 
       
   737 val _ =
       
   738   OuterSyntax.improper_command "linear_undo" "undo commands" K.control
       
   739     (Scan.optional P.nat 1 >>
       
   740       (fn n => Toplevel.no_timing o Toplevel.imperative (fn () => Isar.linear_undo n)));
       
   741 
       
   742 val _ =
       
   743   OuterSyntax.improper_command "undo" "undo commands (skipping closed proofs)" K.control
       
   744     (Scan.optional P.nat 1 >>
       
   745       (fn n => Toplevel.no_timing o Toplevel.imperative (fn () => Isar.undo n)));
       
   746 
       
   747 val _ =
       
   748   OuterSyntax.improper_command "undos_proof" "undo commands (skipping closed proofs)" K.control
       
   749     (Scan.optional P.nat 1 >> (fn n => Toplevel.no_timing o
       
   750       Toplevel.keep (fn state =>
       
   751         if Toplevel.is_proof state then (Isar.undo n; Isar.print ()) else raise Toplevel.UNDEF)));
       
   752 
       
   753 val _ =
       
   754   OuterSyntax.improper_command "cannot_undo" "partial undo -- Proof General legacy" K.control
       
   755     (P.name >>
       
   756       (fn "end" => Toplevel.no_timing o Toplevel.imperative (fn () => Isar.undo 1)
       
   757         | txt => Toplevel.imperative (fn () => error ("Cannot undo " ^ quote txt))));
       
   758 
       
   759 val _ =
       
   760   OuterSyntax.improper_command "kill" "kill partial proof or theory development" K.control
       
   761     (Scan.succeed (Toplevel.no_timing o Toplevel.imperative Isar.kill));
       
   762 
       
   763 
       
   764 
   732 
   765 (** diagnostic commands (for interactive mode only) **)
   733 (** diagnostic commands (for interactive mode only) **)
   766 
   734 
   767 val opt_modes = Scan.optional (P.$$$ "(" |-- P.!!! (Scan.repeat1 P.xname --| P.$$$ ")")) [];
   735 val opt_modes = Scan.optional (P.$$$ "(" |-- P.!!! (Scan.repeat1 P.xname --| P.$$$ ")")) [];
   768 val opt_bang = Scan.optional (P.$$$ "!" >> K true) false;
   736 val opt_bang = Scan.optional (P.$$$ "!" >> K true) false;
   850     K.diag (Scan.succeed (Toplevel.no_timing o IsarCmd.class_deps));
   818     K.diag (Scan.succeed (Toplevel.no_timing o IsarCmd.class_deps));
   851 
   819 
   852 val _ =
   820 val _ =
   853   OuterSyntax.improper_command "thm_deps" "visualize theorem dependencies"
   821   OuterSyntax.improper_command "thm_deps" "visualize theorem dependencies"
   854     K.diag (SpecParse.xthms1 >> (Toplevel.no_timing oo IsarCmd.thm_deps));
   822     K.diag (SpecParse.xthms1 >> (Toplevel.no_timing oo IsarCmd.thm_deps));
   855 
       
   856 local
       
   857 
       
   858 val criterion =
       
   859   P.reserved "name" |-- P.!!! (P.$$$ ":" |-- P.xname) >> FindTheorems.Name ||
       
   860   P.reserved "intro" >> K FindTheorems.Intro ||
       
   861   P.reserved "elim" >> K FindTheorems.Elim ||
       
   862   P.reserved "dest" >> K FindTheorems.Dest ||
       
   863   P.reserved "solves" >> K FindTheorems.Solves ||
       
   864   P.reserved "simp" |-- P.!!! (P.$$$ ":" |-- P.term) >> FindTheorems.Simp ||
       
   865   P.term >> FindTheorems.Pattern;
       
   866 
       
   867 val options =
       
   868   Scan.optional
       
   869     (P.$$$ "(" |--
       
   870       P.!!! (Scan.option P.nat -- Scan.optional (P.reserved "with_dups" >> K false) true
       
   871         --| P.$$$ ")")) (NONE, true);
       
   872 in
       
   873 
       
   874 val _ =
       
   875   OuterSyntax.improper_command "find_theorems" "print theorems meeting specified criteria" K.diag
       
   876     (options -- Scan.repeat (((Scan.option P.minus >> is_none) -- criterion))
       
   877       >> (Toplevel.no_timing oo IsarCmd.find_theorems));
       
   878 
       
   879 end;
       
   880 
       
   881 local
       
   882 
       
   883 val criterion =
       
   884   P.reserved "strict" |-- P.!!! (P.$$$ ":" |-- P.xname) >> FindConsts.Strict ||
       
   885   P.reserved "name" |-- P.!!! (P.$$$ ":" |-- P.xname) >> FindConsts.Name ||
       
   886   P.xname >> FindConsts.Loose;
       
   887 
       
   888 in
       
   889 
       
   890 val _ =
       
   891   OuterSyntax.improper_command "find_consts" "search constants by type pattern"
       
   892     K.diag (Scan.repeat (((Scan.option P.minus >> is_none) -- criterion))
       
   893             >> (Toplevel.no_timing oo IsarCmd.find_consts));
       
   894 
       
   895 end;
       
   896 
   823 
   897 val _ =
   824 val _ =
   898   OuterSyntax.improper_command "print_binds" "print term bindings of proof context" K.diag
   825   OuterSyntax.improper_command "print_binds" "print term bindings of proof context" K.diag
   899     (Scan.succeed (Toplevel.no_timing o IsarCmd.print_binds));
   826     (Scan.succeed (Toplevel.no_timing o IsarCmd.print_binds));
   900 
   827 
   946     (Scan.option ((Scan.repeat1 (Scan.unless P.minus P.name) --| P.minus) --
   873     (Scan.option ((Scan.repeat1 (Scan.unless P.minus P.name) --| P.minus) --
   947        Scan.option (Scan.repeat1 (Scan.unless P.minus P.name))) >>
   874        Scan.option (Scan.repeat1 (Scan.unless P.minus P.name))) >>
   948          (Toplevel.no_timing oo IsarCmd.unused_thms));
   875          (Toplevel.no_timing oo IsarCmd.unused_thms));
   949 
   876 
   950 
   877 
       
   878 
   951 (** system commands (for interactive mode only) **)
   879 (** system commands (for interactive mode only) **)
   952 
   880 
   953 val _ =
   881 val _ =
   954   OuterSyntax.improper_command "cd" "change current working directory" K.diag
   882   OuterSyntax.improper_command "cd" "change current working directory" K.diag
   955     (P.path >> (Toplevel.no_timing oo IsarCmd.cd));
   883     (P.path >> (Toplevel.no_timing oo IsarCmd.cd));
  1011 
   939 
  1012 val _ =
   940 val _ =
  1013   OuterSyntax.improper_command "exit" "exit Isar loop" K.control
   941   OuterSyntax.improper_command "exit" "exit Isar loop" K.control
  1014     (Scan.succeed (Toplevel.no_timing o IsarCmd.exit));
   942     (Scan.succeed (Toplevel.no_timing o IsarCmd.exit));
  1015 
   943 
  1016 val _ =
       
  1017   OuterSyntax.improper_command "welcome" "print welcome message" K.diag
       
  1018     (Scan.succeed (Toplevel.no_timing o IsarCmd.welcome));
       
  1019 
       
  1020 end;
   944 end;
  1021 
   945