src/Pure/Pure.thy
changeset 64595 511b30aa4100
parent 63871 f745c6e683b7
child 64677 8dc24130e8fe
equal deleted inserted replaced
64594:4719f13989df 64595:511b30aa4100
   191   Outer_Syntax.local_theory @{command_keyword local_setup} "ML setup for local theory"
   191   Outer_Syntax.local_theory @{command_keyword local_setup} "ML setup for local theory"
   192     (Parse.ML_source >> Isar_Cmd.local_setup);
   192     (Parse.ML_source >> Isar_Cmd.local_setup);
   193 
   193 
   194 val _ =
   194 val _ =
   195   Outer_Syntax.command @{command_keyword oracle} "declare oracle"
   195   Outer_Syntax.command @{command_keyword oracle} "declare oracle"
   196     (Parse.range Parse.name -- (@{keyword "="} |-- Parse.ML_source) >>
   196     (Parse.range Parse.name -- (@{keyword =} |-- Parse.ML_source) >>
   197       (fn (x, y) => Toplevel.theory (Isar_Cmd.oracle x y)));
   197       (fn (x, y) => Toplevel.theory (Isar_Cmd.oracle x y)));
   198 
   198 
   199 val _ =
   199 val _ =
   200   Outer_Syntax.local_theory @{command_keyword attribute_setup} "define attribute in ML"
   200   Outer_Syntax.local_theory @{command_keyword attribute_setup} "define attribute in ML"
   201     (Parse.position Parse.name --
   201     (Parse.position Parse.name --
   202         Parse.!!! (@{keyword "="} |-- Parse.ML_source -- Scan.optional Parse.text "")
   202         Parse.!!! (@{keyword =} |-- Parse.ML_source -- Scan.optional Parse.text "")
   203       >> (fn (name, (txt, cmt)) => Attrib.attribute_setup name txt cmt));
   203       >> (fn (name, (txt, cmt)) => Attrib.attribute_setup name txt cmt));
   204 
   204 
   205 val _ =
   205 val _ =
   206   Outer_Syntax.local_theory @{command_keyword method_setup} "define proof method in ML"
   206   Outer_Syntax.local_theory @{command_keyword method_setup} "define proof method in ML"
   207     (Parse.position Parse.name --
   207     (Parse.position Parse.name --
   208         Parse.!!! (@{keyword "="} |-- Parse.ML_source -- Scan.optional Parse.text "")
   208         Parse.!!! (@{keyword =} |-- Parse.ML_source -- Scan.optional Parse.text "")
   209       >> (fn (name, (txt, cmt)) => Method.method_setup name txt cmt));
   209       >> (fn (name, (txt, cmt)) => Method.method_setup name txt cmt));
   210 
   210 
   211 val _ =
   211 val _ =
   212   Outer_Syntax.local_theory @{command_keyword declaration} "generic ML declaration"
   212   Outer_Syntax.local_theory @{command_keyword declaration} "generic ML declaration"
   213     (Parse.opt_keyword "pervasive" -- Parse.ML_source
   213     (Parse.opt_keyword "pervasive" -- Parse.ML_source
   219       >> (fn (pervasive, txt) => Isar_Cmd.declaration {syntax = true, pervasive = pervasive} txt));
   219       >> (fn (pervasive, txt) => Isar_Cmd.declaration {syntax = true, pervasive = pervasive} txt));
   220 
   220 
   221 val _ =
   221 val _ =
   222   Outer_Syntax.local_theory @{command_keyword simproc_setup} "define simproc in ML"
   222   Outer_Syntax.local_theory @{command_keyword simproc_setup} "define simproc in ML"
   223     (Parse.position Parse.name --
   223     (Parse.position Parse.name --
   224       (@{keyword "("} |-- Parse.enum1 "|" Parse.term --| @{keyword ")"} --| @{keyword "="}) --
   224       (@{keyword "("} |-- Parse.enum1 "|" Parse.term --| @{keyword ")"} --| @{keyword =}) --
   225       Parse.ML_source >> (fn ((a, b), c) => Isar_Cmd.simproc_setup a b c));
   225       Parse.ML_source >> (fn ((a, b), c) => Isar_Cmd.simproc_setup a b c));
   226 
   226 
   227 in end\<close>
   227 in end\<close>
   228 
   228 
   229 
   229 
   246           Typedecl.typedecl {final = true} (a, map (rpair dummyS) args, mx) #> snd));
   246           Typedecl.typedecl {final = true} (a, map (rpair dummyS) args, mx) #> snd));
   247 
   247 
   248 val _ =
   248 val _ =
   249   Outer_Syntax.local_theory @{command_keyword type_synonym} "declare type abbreviation"
   249   Outer_Syntax.local_theory @{command_keyword type_synonym} "declare type abbreviation"
   250     (Parse.type_args -- Parse.binding --
   250     (Parse.type_args -- Parse.binding --
   251       (@{keyword "="} |-- Parse.!!! (Parse.typ -- Parse.opt_mixfix'))
   251       (@{keyword =} |-- Parse.!!! (Parse.typ -- Parse.opt_mixfix'))
   252       >> (fn ((args, a), (rhs, mx)) => snd o Typedecl.abbrev_cmd (a, args, mx) rhs));
   252       >> (fn ((args, a), (rhs, mx)) => snd o Typedecl.abbrev_cmd (a, args, mx) rhs));
   253 
   253 
   254 in end\<close>
   254 in end\<close>
   255 
   255 
   256 
   256 
   294   Scan.optional
   294   Scan.optional
   295     (@{keyword "("} |-- Parse.!!! (Parse.inner_syntax Parse.name --| @{keyword ")"})) "logic"
   295     (@{keyword "("} |-- Parse.!!! (Parse.inner_syntax Parse.name --| @{keyword ")"})) "logic"
   296     -- Parse.inner_syntax Parse.string;
   296     -- Parse.inner_syntax Parse.string;
   297 
   297 
   298 fun trans_arrow toks =
   298 fun trans_arrow toks =
   299   ((@{keyword "\<rightharpoonup>"} || @{keyword "=>"}) >> K Syntax.Parse_Rule ||
   299   ((@{keyword \<rightharpoonup>} || @{keyword =>}) >> K Syntax.Parse_Rule ||
   300     (@{keyword "\<leftharpoondown>"} || @{keyword "<="}) >> K Syntax.Print_Rule ||
   300     (@{keyword \<leftharpoondown>} || @{keyword <=}) >> K Syntax.Print_Rule ||
   301     (@{keyword "\<rightleftharpoons>"} || @{keyword "=="}) >> K Syntax.Parse_Print_Rule) toks;
   301     (@{keyword \<rightleftharpoons>} || @{keyword ==}) >> K Syntax.Parse_Print_Rule) toks;
   302 
   302 
   303 val trans_line =
   303 val trans_line =
   304   trans_pat -- Parse.!!! (trans_arrow -- trans_pat)
   304   trans_pat -- Parse.!!! (trans_arrow -- trans_pat)
   305     >> (fn (left, (arr, right)) => arr (left, right));
   305     >> (fn (left, (arr, right)) => arr (left, right));
   306 
   306 
   503 local
   503 local
   504 
   504 
   505 val _ =
   505 val _ =
   506   Outer_Syntax.maybe_begin_local_theory @{command_keyword bundle}
   506   Outer_Syntax.maybe_begin_local_theory @{command_keyword bundle}
   507     "define bundle of declarations"
   507     "define bundle of declarations"
   508     ((Parse.binding --| @{keyword "="}) -- Parse.thms1 -- Parse.for_fixes
   508     ((Parse.binding --| @{keyword =}) -- Parse.thms1 -- Parse.for_fixes
   509       >> (uncurry Bundle.bundle_cmd))
   509       >> (uncurry Bundle.bundle_cmd))
   510     (Parse.binding --| Parse.begin >> Bundle.init);
   510     (Parse.binding --| Parse.begin >> Bundle.init);
   511 
   511 
   512 val _ =
   512 val _ =
   513   Outer_Syntax.local_theory @{command_keyword unbundle}
   513   Outer_Syntax.local_theory @{command_keyword unbundle}
   561 ML \<open>
   561 ML \<open>
   562 local
   562 local
   563 
   563 
   564 val locale_val =
   564 val locale_val =
   565   Parse_Spec.locale_expression --
   565   Parse_Spec.locale_expression --
   566     Scan.optional (@{keyword "+"} |-- Parse.!!! (Scan.repeat1 Parse_Spec.context_element)) [] ||
   566     Scan.optional (@{keyword +} |-- Parse.!!! (Scan.repeat1 Parse_Spec.context_element)) [] ||
   567   Scan.repeat1 Parse_Spec.context_element >> pair ([], []);
   567   Scan.repeat1 Parse_Spec.context_element >> pair ([], []);
   568 
   568 
   569 val _ =
   569 val _ =
   570   Outer_Syntax.command @{command_keyword locale} "define named specification context"
   570   Outer_Syntax.command @{command_keyword locale} "define named specification context"
   571     (Parse.binding --
   571     (Parse.binding --
   572       Scan.optional (@{keyword "="} |-- Parse.!!! locale_val) (([], []), []) -- Parse.opt_begin
   572       Scan.optional (@{keyword =} |-- Parse.!!! locale_val) (([], []), []) -- Parse.opt_begin
   573       >> (fn ((name, (expr, elems)), begin) =>
   573       >> (fn ((name, (expr, elems)), begin) =>
   574           Toplevel.begin_local_theory begin
   574           Toplevel.begin_local_theory begin
   575             (Expression.add_locale_cmd name Binding.empty expr elems #> snd)));
   575             (Expression.add_locale_cmd name Binding.empty expr elems #> snd)));
   576 
   576 
   577 val _ =
   577 val _ =
   581           Toplevel.begin_local_theory true (Experiment.experiment_cmd elems #> snd)));
   581           Toplevel.begin_local_theory true (Experiment.experiment_cmd elems #> snd)));
   582 
   582 
   583 val interpretation_args =
   583 val interpretation_args =
   584   Parse.!!! Parse_Spec.locale_expression --
   584   Parse.!!! Parse_Spec.locale_expression --
   585     Scan.optional
   585     Scan.optional
   586       (@{keyword "rewrites"} |-- Parse.and_list1 (Parse_Spec.opt_thm_name ":" -- Parse.prop)) [];
   586       (@{keyword rewrites} |-- Parse.and_list1 (Parse_Spec.opt_thm_name ":" -- Parse.prop)) [];
   587 
   587 
   588 val _ =
   588 val _ =
   589   Outer_Syntax.command @{command_keyword interpret}
   589   Outer_Syntax.command @{command_keyword interpret}
   590     "prove interpretation of locale expression in proof context"
   590     "prove interpretation of locale expression in proof context"
   591     (interpretation_args >> (fn (expr, equations) =>
   591     (interpretation_args >> (fn (expr, equations) =>
   592       Toplevel.proof (Interpretation.interpret_cmd expr equations)));
   592       Toplevel.proof (Interpretation.interpret_cmd expr equations)));
   593 
   593 
   594 val interpretation_args_with_defs =
   594 val interpretation_args_with_defs =
   595   Parse.!!! Parse_Spec.locale_expression --
   595   Parse.!!! Parse_Spec.locale_expression --
   596     (Scan.optional (@{keyword "defines"} |-- Parse.and_list1 (Parse_Spec.opt_thm_name ":"
   596     (Scan.optional (@{keyword defines} |-- Parse.and_list1 (Parse_Spec.opt_thm_name ":"
   597       -- ((Parse.binding -- Parse.opt_mixfix') --| @{keyword "="} -- Parse.term))) [] --
   597       -- ((Parse.binding -- Parse.opt_mixfix') --| @{keyword =} -- Parse.term))) [] --
   598     Scan.optional
   598     Scan.optional
   599       (@{keyword "rewrites"} |-- Parse.and_list1 (Parse_Spec.opt_thm_name ":" -- Parse.prop)) []);
   599       (@{keyword rewrites} |-- Parse.and_list1 (Parse_Spec.opt_thm_name ":" -- Parse.prop)) []);
   600 
   600 
   601 val _ =
   601 val _ =
   602   Outer_Syntax.local_theory_to_proof @{command_keyword global_interpretation}
   602   Outer_Syntax.local_theory_to_proof @{command_keyword global_interpretation}
   603     "prove interpretation of locale expression into global theory"
   603     "prove interpretation of locale expression into global theory"
   604     (interpretation_args_with_defs >> (fn (expr, (defs, equations)) =>
   604     (interpretation_args_with_defs >> (fn (expr, (defs, equations)) =>
   605       Interpretation.global_interpretation_cmd expr defs equations));
   605       Interpretation.global_interpretation_cmd expr defs equations));
   606 
   606 
   607 val _ =
   607 val _ =
   608   Outer_Syntax.command @{command_keyword sublocale}
   608   Outer_Syntax.command @{command_keyword sublocale}
   609     "prove sublocale relation between a locale and a locale expression"
   609     "prove sublocale relation between a locale and a locale expression"
   610     ((Parse.position Parse.name --| (@{keyword "\<subseteq>"} || @{keyword "<"}) --
   610     ((Parse.position Parse.name --| (@{keyword \<subseteq>} || @{keyword <}) --
   611       interpretation_args_with_defs >> (fn (loc, (expr, (defs, equations))) =>
   611       interpretation_args_with_defs >> (fn (loc, (expr, (defs, equations))) =>
   612         Toplevel.theory_to_proof (Interpretation.global_sublocale_cmd loc expr defs equations)))
   612         Toplevel.theory_to_proof (Interpretation.global_sublocale_cmd loc expr defs equations)))
   613     || interpretation_args_with_defs >> (fn (expr, (defs, equations)) =>
   613     || interpretation_args_with_defs >> (fn (expr, (defs, equations)) =>
   614         Toplevel.local_theory_to_proof NONE NONE (Interpretation.sublocale_cmd expr defs equations)));
   614         Toplevel.local_theory_to_proof NONE NONE (Interpretation.sublocale_cmd expr defs equations)));
   615 
   615 
   628 ML \<open>
   628 ML \<open>
   629 local
   629 local
   630 
   630 
   631 val class_val =
   631 val class_val =
   632   Parse_Spec.class_expression --
   632   Parse_Spec.class_expression --
   633     Scan.optional (@{keyword "+"} |-- Parse.!!! (Scan.repeat1 Parse_Spec.context_element)) [] ||
   633     Scan.optional (@{keyword +} |-- Parse.!!! (Scan.repeat1 Parse_Spec.context_element)) [] ||
   634   Scan.repeat1 Parse_Spec.context_element >> pair [];
   634   Scan.repeat1 Parse_Spec.context_element >> pair [];
   635 
   635 
   636 val _ =
   636 val _ =
   637   Outer_Syntax.command @{command_keyword class} "define type class"
   637   Outer_Syntax.command @{command_keyword class} "define type class"
   638    (Parse.binding -- Scan.optional (@{keyword "="} |-- class_val) ([], []) -- Parse.opt_begin
   638    (Parse.binding -- Scan.optional (@{keyword =} |-- class_val) ([], []) -- Parse.opt_begin
   639     >> (fn ((name, (supclasses, elems)), begin) =>
   639     >> (fn ((name, (supclasses, elems)), begin) =>
   640         Toplevel.begin_local_theory begin
   640         Toplevel.begin_local_theory begin
   641           (Class_Declaration.class_cmd name supclasses elems #> snd)));
   641           (Class_Declaration.class_cmd name supclasses elems #> snd)));
   642 
   642 
   643 val _ =
   643 val _ =
   650      >> (fn arities => Toplevel.begin_local_theory true (Class.instantiation_cmd arities)));
   650      >> (fn arities => Toplevel.begin_local_theory true (Class.instantiation_cmd arities)));
   651 
   651 
   652 val _ =
   652 val _ =
   653   Outer_Syntax.command @{command_keyword instance} "prove type arity or subclass relation"
   653   Outer_Syntax.command @{command_keyword instance} "prove type arity or subclass relation"
   654   ((Parse.class --
   654   ((Parse.class --
   655     ((@{keyword "\<subseteq>"} || @{keyword "<"}) |-- Parse.!!! Parse.class) >> Class.classrel_cmd ||
   655     ((@{keyword \<subseteq>} || @{keyword <}) |-- Parse.!!! Parse.class) >> Class.classrel_cmd ||
   656     Parse.multi_arity >> Class.instance_arity_cmd) >> Toplevel.theory_to_proof ||
   656     Parse.multi_arity >> Class.instance_arity_cmd) >> Toplevel.theory_to_proof ||
   657     Scan.succeed (Toplevel.local_theory_to_proof NONE NONE (Class.instantiation_instance I)));
   657     Scan.succeed (Toplevel.local_theory_to_proof NONE NONE (Class.instantiation_instance I)));
   658 
   658 
   659 in end\<close>
   659 in end\<close>
   660 
   660 
   664 ML \<open>
   664 ML \<open>
   665 local
   665 local
   666 
   666 
   667 val _ =
   667 val _ =
   668   Outer_Syntax.command @{command_keyword overloading} "overloaded definitions"
   668   Outer_Syntax.command @{command_keyword overloading} "overloaded definitions"
   669    (Scan.repeat1 (Parse.name --| (@{keyword "=="} || @{keyword "\<equiv>"}) -- Parse.term --
   669    (Scan.repeat1 (Parse.name --| (@{keyword ==} || @{keyword \<equiv>}) -- Parse.term --
   670       Scan.optional (@{keyword "("} |-- (@{keyword "unchecked"} >> K false) --| @{keyword ")"}) true
   670       Scan.optional (@{keyword "("} |-- (@{keyword unchecked} >> K false) --| @{keyword ")"}) true
   671       >> Scan.triple1) --| Parse.begin
   671       >> Scan.triple1) --| Parse.begin
   672    >> (fn operations => Toplevel.begin_local_theory true (Overloading.overloading_cmd operations)));
   672    >> (fn operations => Toplevel.begin_local_theory true (Overloading.overloading_cmd operations)));
   673 
   673 
   674 in end\<close>
   674 in end\<close>
   675 
   675 
   785 val _ =
   785 val _ =
   786   Outer_Syntax.command @{command_keyword def} "local definition (non-polymorphic)"
   786   Outer_Syntax.command @{command_keyword def} "local definition (non-polymorphic)"
   787     (Parse.and_list1
   787     (Parse.and_list1
   788       (Parse_Spec.opt_thm_name ":" --
   788       (Parse_Spec.opt_thm_name ":" --
   789         ((Parse.binding -- Parse.opt_mixfix) --
   789         ((Parse.binding -- Parse.opt_mixfix) --
   790           ((@{keyword "\<equiv>"} || @{keyword "=="}) |-- Parse.!!! Parse.termp)))
   790           ((@{keyword \<equiv>} || @{keyword ==}) |-- Parse.!!! Parse.termp)))
   791     >> (fn args => Toplevel.proof (fn state =>
   791     >> (fn args => Toplevel.proof (fn state =>
   792         (legacy_feature "Old 'def' command -- use 'define' instead"; Proof.def_cmd args state))));
   792         (legacy_feature "Old 'def' command -- use 'define' instead"; Proof.def_cmd args state))));
   793 
   793 
   794 val _ =
   794 val _ =
   795   Outer_Syntax.command @{command_keyword consider} "state cases rule"
   795   Outer_Syntax.command @{command_keyword consider} "state cases rule"
   804   Outer_Syntax.command @{command_keyword guess} "wild guessing (unstructured)"
   804   Outer_Syntax.command @{command_keyword guess} "wild guessing (unstructured)"
   805     (Scan.optional Parse.vars [] >> (Toplevel.proof' o Obtain.guess_cmd));
   805     (Scan.optional Parse.vars [] >> (Toplevel.proof' o Obtain.guess_cmd));
   806 
   806 
   807 val _ =
   807 val _ =
   808   Outer_Syntax.command @{command_keyword let} "bind text variables"
   808   Outer_Syntax.command @{command_keyword let} "bind text variables"
   809     (Parse.and_list1 (Parse.and_list1 Parse.term -- (@{keyword "="} |-- Parse.term))
   809     (Parse.and_list1 (Parse.and_list1 Parse.term -- (@{keyword =} |-- Parse.term))
   810       >> (Toplevel.proof o Proof.let_bind_cmd));
   810       >> (Toplevel.proof o Proof.let_bind_cmd));
   811 
   811 
   812 val _ =
   812 val _ =
   813   Outer_Syntax.command @{command_keyword write} "add concrete syntax for constants / fixed variables"
   813   Outer_Syntax.command @{command_keyword write} "add concrete syntax for constants / fixed variables"
   814     (Parse.syntax_mode -- Parse.and_list1 (Parse.const -- Parse.mixfix)
   814     (Parse.syntax_mode -- Parse.and_list1 (Parse.const -- Parse.mixfix)
   935   Scan.optional (Parse.binding -- Parse.opt_attribs || Parse.attribs >> pair Binding.empty)
   935   Scan.optional (Parse.binding -- Parse.opt_attribs || Parse.attribs >> pair Binding.empty)
   936     Binding.empty_atts;
   936     Binding.empty_atts;
   937 
   937 
   938 val for_params =
   938 val for_params =
   939   Scan.optional
   939   Scan.optional
   940     (@{keyword "for"} |--
   940     (@{keyword for} |--
   941       Parse.!!! ((Scan.option Parse.dots >> is_some) --
   941       Parse.!!! ((Scan.option Parse.dots >> is_some) --
   942         (Scan.repeat1 (Parse.position (Parse.maybe Parse.name)))))
   942         (Scan.repeat1 (Parse.position (Parse.maybe Parse.name)))))
   943     (false, []);
   943     (false, []);
   944 
   944 
   945 val _ =
   945 val _ =
   946   Outer_Syntax.command @{command_keyword subgoal}
   946   Outer_Syntax.command @{command_keyword subgoal}
   947     "focus on first subgoal within backward refinement"
   947     "focus on first subgoal within backward refinement"
   948     (opt_fact_binding -- (Scan.option (@{keyword "premises"} |-- Parse.!!! opt_fact_binding)) --
   948     (opt_fact_binding -- (Scan.option (@{keyword premises} |-- Parse.!!! opt_fact_binding)) --
   949       for_params >> (fn ((a, b), c) =>
   949       for_params >> (fn ((a, b), c) =>
   950         Toplevel.proofs (Seq.make_results o Seq.single o #2 o Subgoal.subgoal_cmd a b c)));
   950         Toplevel.proofs (Seq.make_results o Seq.single o #2 o Subgoal.subgoal_cmd a b c)));
   951 
   951 
   952 in end\<close>
   952 in end\<close>
   953 
   953 
  1174   Outer_Syntax.command @{command_keyword term} "read and print term"
  1174   Outer_Syntax.command @{command_keyword term} "read and print term"
  1175     (opt_modes -- Parse.term >> Isar_Cmd.print_term);
  1175     (opt_modes -- Parse.term >> Isar_Cmd.print_term);
  1176 
  1176 
  1177 val _ =
  1177 val _ =
  1178   Outer_Syntax.command @{command_keyword typ} "read and print type"
  1178   Outer_Syntax.command @{command_keyword typ} "read and print type"
  1179     (opt_modes -- (Parse.typ -- Scan.option (@{keyword "::"} |-- Parse.!!! Parse.sort))
  1179     (opt_modes -- (Parse.typ -- Scan.option (@{keyword ::} |-- Parse.!!! Parse.sort))
  1180       >> Isar_Cmd.print_type);
  1180       >> Isar_Cmd.print_type);
  1181 
  1181 
  1182 val _ =
  1182 val _ =
  1183   Outer_Syntax.command @{command_keyword print_codesetup} "print code generator setup"
  1183   Outer_Syntax.command @{command_keyword print_codesetup} "print code generator setup"
  1184     (Scan.succeed (Toplevel.keep (Code.print_codesetup o Toplevel.theory_of)));
  1184     (Scan.succeed (Toplevel.keep (Code.print_codesetup o Toplevel.theory_of)));