src/Pure/Isar/isar_syn.ML
changeset 12876 a70df1e5bf10
parent 12768 8b69dcccaabc
child 12926 cd0dd6e0bf5c
equal deleted inserted replaced
12875:bda60442bf02 12876:a70df1e5bf10
    35 
    35 
    36 
    36 
    37 (** markup commands **)
    37 (** markup commands **)
    38 
    38 
    39 val headerP = OuterSyntax.markup_command IsarOutput.Markup "header" "theory header" K.diag
    39 val headerP = OuterSyntax.markup_command IsarOutput.Markup "header" "theory header" K.diag
    40   (P.comment >> IsarThy.add_header);
    40   (P.text >> IsarThy.add_header);
    41 
    41 
    42 val chapterP = OuterSyntax.markup_command IsarOutput.Markup "chapter" "chapter heading"
    42 val chapterP = OuterSyntax.markup_command IsarOutput.Markup "chapter" "chapter heading"
    43   K.thy_heading (P.comment >> (Toplevel.theory o IsarThy.add_chapter));
    43   K.thy_heading (P.text >> (Toplevel.theory o IsarThy.add_chapter));
    44 
    44 
    45 val sectionP = OuterSyntax.markup_command IsarOutput.Markup "section" "section heading"
    45 val sectionP = OuterSyntax.markup_command IsarOutput.Markup "section" "section heading"
    46   K.thy_heading (P.comment >> (Toplevel.theory o IsarThy.add_section));
    46   K.thy_heading (P.text >> (Toplevel.theory o IsarThy.add_section));
    47 
    47 
    48 val subsectionP = OuterSyntax.markup_command IsarOutput.Markup "subsection" "subsection heading"
    48 val subsectionP = OuterSyntax.markup_command IsarOutput.Markup "subsection" "subsection heading"
    49   K.thy_heading (P.comment >> (Toplevel.theory o IsarThy.add_subsection));
    49   K.thy_heading (P.text >> (Toplevel.theory o IsarThy.add_subsection));
    50 
    50 
    51 val subsubsectionP =
    51 val subsubsectionP =
    52   OuterSyntax.markup_command IsarOutput.Markup "subsubsection" "subsubsection heading"
    52   OuterSyntax.markup_command IsarOutput.Markup "subsubsection" "subsubsection heading"
    53   K.thy_heading (P.comment >> (Toplevel.theory o IsarThy.add_subsubsection));
    53   K.thy_heading (P.text >> (Toplevel.theory o IsarThy.add_subsubsection));
    54 
    54 
    55 val textP = OuterSyntax.markup_command IsarOutput.MarkupEnv "text" "formal comment (theory)"
    55 val textP = OuterSyntax.markup_command IsarOutput.MarkupEnv "text" "formal comment (theory)"
    56   K.thy_decl (P.comment >> (Toplevel.theory o IsarThy.add_text));
    56   K.thy_decl (P.text >> (Toplevel.theory o IsarThy.add_text));
    57 
    57 
    58 val text_rawP = OuterSyntax.markup_command IsarOutput.Verbatim "text_raw"
    58 val text_rawP = OuterSyntax.markup_command IsarOutput.Verbatim "text_raw"
    59   "raw document preparation text" K.thy_decl
    59   "raw document preparation text" K.thy_decl
    60   (P.comment >> (Toplevel.theory o IsarThy.add_text_raw));
    60   (P.text >> (Toplevel.theory o IsarThy.add_text_raw));
    61 
    61 
    62 
    62 
    63 val sectP = OuterSyntax.markup_command IsarOutput.Markup "sect" "formal comment (proof)"
    63 val sectP = OuterSyntax.markup_command IsarOutput.Markup "sect" "formal comment (proof)"
    64   K.prf_heading (P.comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_sect)));
    64   K.prf_heading (P.text >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_sect)));
    65 
    65 
    66 val subsectP = OuterSyntax.markup_command IsarOutput.Markup "subsect" "formal comment (proof)"
    66 val subsectP = OuterSyntax.markup_command IsarOutput.Markup "subsect" "formal comment (proof)"
    67   K.prf_heading (P.comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_subsect)));
    67   K.prf_heading (P.text >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_subsect)));
    68 
    68 
    69 val subsubsectP = OuterSyntax.markup_command IsarOutput.Markup "subsubsect"
    69 val subsubsectP = OuterSyntax.markup_command IsarOutput.Markup "subsubsect"
    70   "formal comment (proof)" K.prf_heading
    70   "formal comment (proof)" K.prf_heading
    71   (P.comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_subsubsect)));
    71   (P.text >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_subsubsect)));
    72 
    72 
    73 val txtP = OuterSyntax.markup_command IsarOutput.MarkupEnv "txt" "formal comment (proof)"
    73 val txtP = OuterSyntax.markup_command IsarOutput.MarkupEnv "txt" "formal comment (proof)"
    74   K.prf_decl (P.comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_txt)));
    74   K.prf_decl (P.text >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_txt)));
    75 
    75 
    76 val txt_rawP = OuterSyntax.markup_command IsarOutput.Verbatim "txt_raw"
    76 val txt_rawP = OuterSyntax.markup_command IsarOutput.Verbatim "txt_raw"
    77   "raw document preparation text (proof)" K.prf_decl
    77   "raw document preparation text (proof)" K.prf_decl
    78   (P.comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_txt_raw)));
    78   (P.text >> (Toplevel.print oo (Toplevel.proof o IsarThy.add_txt_raw)));
    79 
    79 
    80 
    80 
    81 
    81 
    82 (** theory sections **)
    82 (** theory sections **)
    83 
    83 
    84 (* classes and sorts *)
    84 (* classes and sorts *)
    85 
    85 
    86 val classesP =
    86 val classesP =
    87   OuterSyntax.command "classes" "declare type classes" K.thy_decl
    87   OuterSyntax.command "classes" "declare type classes" K.thy_decl
    88     (Scan.repeat1 (P.name -- Scan.optional ((P.$$$ "\\<subseteq>" || P.$$$ "<") |--
    88     (Scan.repeat1 (P.name -- Scan.optional ((P.$$$ "\\<subseteq>" || P.$$$ "<") |--
    89         P.!!! (P.list1 P.xname)) [])
    89         P.!!! (P.list1 P.xname)) []) >> (Toplevel.theory o Theory.add_classes));
    90       -- P.marg_comment >> (Toplevel.theory o IsarThy.add_classes));
       
    91 
    90 
    92 val classrelP =
    91 val classrelP =
    93   OuterSyntax.command "classrel" "state inclusion of type classes (axiomatic!)" K.thy_decl
    92   OuterSyntax.command "classrel" "state inclusion of type classes (axiomatic!)" K.thy_decl
    94     (P.xname -- ((P.$$$ "\\<subseteq>" || P.$$$ "<") |-- P.!!! P.xname) -- P.marg_comment
    93     (P.xname -- ((P.$$$ "\\<subseteq>" || P.$$$ "<") |-- P.!!! P.xname)
    95       >> (Toplevel.theory o IsarThy.add_classrel));
    94     >> (Toplevel.theory o Theory.add_classrel o single));
    96 
    95 
    97 val defaultsortP =
    96 val defaultsortP =
    98   OuterSyntax.command "defaultsort" "declare default sort" K.thy_decl
    97   OuterSyntax.command "defaultsort" "declare default sort" K.thy_decl
    99     (P.sort -- P.marg_comment >> (Toplevel.theory o IsarThy.add_defsort));
    98     (P.sort >> (Toplevel.theory o Theory.add_defsort));
   100 
    99 
   101 
   100 
   102 (* types *)
   101 (* types *)
   103 
   102 
   104 val typedeclP =
   103 val typedeclP =
   105   OuterSyntax.command "typedecl" "type declaration" K.thy_decl
   104   OuterSyntax.command "typedecl" "type declaration" K.thy_decl
   106     (P.type_args -- P.name -- P.opt_infix -- P.marg_comment >> (fn (((args, a), mx), cmt) =>
   105     (P.type_args -- P.name -- P.opt_infix >> (fn ((args, a), mx) =>
   107       Toplevel.theory (IsarThy.add_typedecl ((a, args, mx), cmt))));
   106       Toplevel.theory (PureThy.add_typedecls [(a, args, mx)])));
   108 
   107 
   109 val typeabbrP =
   108 val typeabbrP =
   110   OuterSyntax.command "types" "declare type abbreviations" K.thy_decl
   109   OuterSyntax.command "types" "declare type abbreviations" K.thy_decl
   111     (Scan.repeat1
   110     (Scan.repeat1
   112       (P.type_args -- P.name -- (P.$$$ "=" |-- P.!!! (P.typ -- P.opt_infix')) -- P.marg_comment)
   111       (P.type_args -- P.name -- (P.$$$ "=" |-- P.!!! (P.typ -- P.opt_infix')))
   113       >> (Toplevel.theory o IsarThy.add_tyabbrs o
   112       >> (Toplevel.theory o Theory.add_tyabbrs o
   114         map (fn (((args, a), (T, mx)), cmt) => ((a, args, T, mx), cmt))));
   113         map (fn ((args, a), (T, mx)) => (a, args, T, mx))));
   115 
   114 
   116 val nontermP =
   115 val nontermP =
   117   OuterSyntax.command "nonterminals" "declare types treated as grammar nonterminal symbols"
   116   OuterSyntax.command "nonterminals" "declare types treated as grammar nonterminal symbols"
   118     K.thy_decl (Scan.repeat1 (P.name -- P.marg_comment)
   117     K.thy_decl (Scan.repeat1 P.name >> (Toplevel.theory o Theory.add_nonterminals));
   119       >> (Toplevel.theory o IsarThy.add_nonterminals));
       
   120 
   118 
   121 val aritiesP =
   119 val aritiesP =
   122   OuterSyntax.command "arities" "state type arities (axiomatic!)" K.thy_decl
   120   OuterSyntax.command "arities" "state type arities (axiomatic!)" K.thy_decl
   123     (Scan.repeat1 ((P.xname -- (P.$$$ "::" |-- P.!!! P.arity) >> P.triple2) -- P.marg_comment)
   121     (Scan.repeat1 (P.xname -- (P.$$$ "::" |-- P.!!! P.arity) >> P.triple2)
   124       >> (Toplevel.theory o IsarThy.add_arities));
   122       >> (Toplevel.theory o Theory.add_arities));
   125 
   123 
   126 
   124 
   127 (* consts and syntax *)
   125 (* consts and syntax *)
   128 
   126 
   129 val judgmentP =
   127 val judgmentP =
   130   OuterSyntax.command "judgment" "declare object-logic judgment" K.thy_decl
   128   OuterSyntax.command "judgment" "declare object-logic judgment" K.thy_decl
   131     (P.const -- P.marg_comment >> (Toplevel.theory o IsarThy.add_judgment));
   129     (P.const >> (Toplevel.theory o ObjectLogic.add_judgment));
   132 
   130 
   133 val constsP =
   131 val constsP =
   134   OuterSyntax.command "consts" "declare constants" K.thy_decl
   132   OuterSyntax.command "consts" "declare constants" K.thy_decl
   135     (Scan.repeat1 (P.const -- P.marg_comment) >> (Toplevel.theory o IsarThy.add_consts));
   133     (Scan.repeat1 P.const >> (Toplevel.theory o Theory.add_consts));
   136 
   134 
   137 
   135 
   138 val mode_spec =
   136 val mode_spec =
   139   (P.$$$ "output" >> K ("", false)) || P.name -- Scan.optional (P.$$$ "output" >> K false) true;
   137   (P.$$$ "output" >> K ("", false)) || P.name -- Scan.optional (P.$$$ "output" >> K false) true;
   140 
   138 
   141 val opt_mode = Scan.optional (P.$$$ "(" |-- P.!!! (mode_spec --| P.$$$ ")")) ("", true);
   139 val opt_mode = Scan.optional (P.$$$ "(" |-- P.!!! (mode_spec --| P.$$$ ")")) ("", true);
   142 
   140 
   143 val syntaxP =
   141 val syntaxP =
   144   OuterSyntax.command "syntax" "declare syntactic constants" K.thy_decl
   142   OuterSyntax.command "syntax" "declare syntactic constants" K.thy_decl
   145     (opt_mode -- Scan.repeat1 (P.const -- P.marg_comment)
   143     (opt_mode -- Scan.repeat1 P.const >> (Toplevel.theory o uncurry Theory.add_modesyntax));
   146       >> (Toplevel.theory o uncurry IsarThy.add_modesyntax));
       
   147 
   144 
   148 
   145 
   149 (* translations *)
   146 (* translations *)
   150 
   147 
   151 val trans_pat =
   148 val trans_pat =
   160   trans_pat -- P.!!! (trans_arrow -- trans_pat)
   157   trans_pat -- P.!!! (trans_arrow -- trans_pat)
   161     >> (fn (left, (arr, right)) => arr (left, right));
   158     >> (fn (left, (arr, right)) => arr (left, right));
   162 
   159 
   163 val translationsP =
   160 val translationsP =
   164   OuterSyntax.command "translations" "declare syntax translation rules" K.thy_decl
   161   OuterSyntax.command "translations" "declare syntax translation rules" K.thy_decl
   165     (Scan.repeat1 (trans_line -- P.marg_comment) >> (Toplevel.theory o IsarThy.add_trrules));
   162     (Scan.repeat1 trans_line >> (Toplevel.theory o Theory.add_trrules));
   166 
   163 
   167 
   164 
   168 (* axioms and definitions *)
   165 (* axioms and definitions *)
   169 
   166 
   170 val axiomsP =
   167 val axiomsP =
   171   OuterSyntax.command "axioms" "state arbitrary propositions (axiomatic!)" K.thy_decl
   168   OuterSyntax.command "axioms" "state arbitrary propositions (axiomatic!)" K.thy_decl
   172     (Scan.repeat1 (P.spec_name -- P.marg_comment) >> (Toplevel.theory o IsarThy.add_axioms));
   169     (Scan.repeat1 P.spec_name >> (Toplevel.theory o IsarThy.add_axioms));
   173 
   170 
   174 val opt_overloaded =
   171 val opt_overloaded =
   175   Scan.optional (P.$$$ "(" |-- P.!!! ((P.$$$ "overloaded" >> K true) --| P.$$$ ")")) false;
   172   Scan.optional (P.$$$ "(" |-- P.!!! ((P.$$$ "overloaded" >> K true) --| P.$$$ ")")) false;
   176 
   173 
   177 val defsP =
   174 val defsP =
   178   OuterSyntax.command "defs" "define constants" K.thy_decl
   175   OuterSyntax.command "defs" "define constants" K.thy_decl
   179     (opt_overloaded -- Scan.repeat1 (P.spec_name -- P.marg_comment)
   176     (opt_overloaded -- Scan.repeat1 P.spec_name >> (Toplevel.theory o IsarThy.add_defs));
   180   >> (Toplevel.theory o IsarThy.add_defs));
       
   181 
   177 
   182 val constdefsP =
   178 val constdefsP =
   183   OuterSyntax.command "constdefs" "declare and define constants" K.thy_decl
   179   OuterSyntax.command "constdefs" "declare and define constants" K.thy_decl
   184     (Scan.repeat1 ((P.const -- P.marg_comment) -- (P.term -- P.marg_comment))
   180     (Scan.repeat1 (P.const -- P.term) >> (Toplevel.theory o IsarThy.add_constdefs));
   185       >> (Toplevel.theory o IsarThy.add_constdefs));
       
   186 
   181 
   187 
   182 
   188 (* theorems *)
   183 (* theorems *)
   189 
   184 
   190 val in_locale = Scan.option ((P.$$$ "(" -- P.$$$ "in") |-- P.!!! (P.xname --| P.$$$ ")"));
   185 val in_locale = Scan.option ((P.$$$ "(" -- P.$$$ "in") |-- P.!!! (P.xname --| P.$$$ ")"));
   191 val name_facts = P.and_list1 (P.opt_thm_name "=" -- P.xthms1 -- P.marg_comment);
   186 val name_facts = P.and_list1 (P.opt_thm_name "=" -- P.xthms1);
   192 
   187 
   193 fun theorems kind = in_locale -- name_facts
   188 fun theorems kind = in_locale -- name_facts
   194   >> uncurry (#1 ooo IsarThy.smart_theorems kind);
   189   >> uncurry (#1 ooo IsarThy.smart_theorems kind);
   195 
   190 
   196 val theoremsP =
   191 val theoremsP =
   201   OuterSyntax.command "lemmas" "define lemmas" K.thy_decl
   196   OuterSyntax.command "lemmas" "define lemmas" K.thy_decl
   202     (theorems Drule.lemmaK >> Toplevel.theory);
   197     (theorems Drule.lemmaK >> Toplevel.theory);
   203 
   198 
   204 val declareP =
   199 val declareP =
   205   OuterSyntax.command "declare" "declare theorems (improper)" K.thy_script
   200   OuterSyntax.command "declare" "declare theorems (improper)" K.thy_script
   206     (in_locale -- (P.xthms1 -- P.marg_comment)
   201     (in_locale -- P.xthms1 >> (Toplevel.theory o uncurry IsarThy.declare_theorems));
   207     >> (Toplevel.theory o uncurry IsarThy.declare_theorems));
       
   208 
   202 
   209 
   203 
   210 (* name space entry path *)
   204 (* name space entry path *)
   211 
   205 
   212 val globalP =
   206 val globalP =
   213   OuterSyntax.command "global" "disable prefixing of theory name" K.thy_decl
   207   OuterSyntax.command "global" "disable prefixing of theory name" K.thy_decl
   214     (P.marg_comment >> (Toplevel.theory o IsarThy.global_path));
   208     (Scan.succeed (Toplevel.theory PureThy.global_path));
   215 
   209 
   216 val localP =
   210 val localP =
   217   OuterSyntax.command "local" "enable prefixing of theory name" K.thy_decl
   211   OuterSyntax.command "local" "enable prefixing of theory name" K.thy_decl
   218     (P.marg_comment >> (Toplevel.theory o IsarThy.local_path));
   212     (Scan.succeed (Toplevel.theory PureThy.local_path));
   219 
   213 
   220 val hideP =
   214 val hideP =
   221   OuterSyntax.command "hide" "hide names from given name space" K.thy_decl
   215   OuterSyntax.command "hide" "hide names from given name space" K.thy_decl
   222     (P.name -- Scan.repeat1 P.xname -- P.marg_comment >> (Toplevel.theory o IsarThy.hide_space));
   216     (P.name -- Scan.repeat1 P.xname >> (Toplevel.theory o IsarThy.hide_space));
   223 
   217 
   224 
   218 
   225 (* use ML text *)
   219 (* use ML text *)
   226 
   220 
   227 val useP =
   221 val useP =
   228   OuterSyntax.command "use" "eval ML text from file" K.diag
   222   OuterSyntax.command "use" "eval ML text from file" K.diag
   229     (P.name -- P.marg_comment >> (Toplevel.no_timing oo IsarCmd.use));
   223     (P.name >> (Toplevel.no_timing oo IsarCmd.use));
   230 
   224 
   231 val mlP =
   225 val mlP =
   232   OuterSyntax.command "ML" "eval ML text (diagnostic)" K.diag
   226   OuterSyntax.command "ML" "eval ML text (diagnostic)" K.diag
   233     (P.text -- P.marg_comment >> IsarCmd.use_mltext true);
   227     (P.text >> IsarCmd.use_mltext true);
   234 
   228 
   235 val ml_commandP =
   229 val ml_commandP =
   236   OuterSyntax.command "ML_command" "eval ML text" K.diag
   230   OuterSyntax.command "ML_command" "eval ML text" K.diag
   237     (P.text -- P.marg_comment >> (Toplevel.no_timing oo IsarCmd.use_mltext false));
   231     (P.text >> (Toplevel.no_timing oo IsarCmd.use_mltext false));
   238 
   232 
   239 val ml_setupP =
   233 val ml_setupP =
   240   OuterSyntax.command "ML_setup" "eval ML text (may change theory)" K.thy_decl
   234   OuterSyntax.command "ML_setup" "eval ML text (may change theory)" K.thy_decl
   241     (P.text -- P.marg_comment >> IsarCmd.use_mltext_theory);
   235     (P.text >> IsarCmd.use_mltext_theory);
   242 
   236 
   243 val setupP =
   237 val setupP =
   244   OuterSyntax.command "setup" "apply ML theory setup" K.thy_decl
   238   OuterSyntax.command "setup" "apply ML theory setup" K.thy_decl
   245     (P.text -- P.marg_comment >> (Toplevel.theory o IsarCmd.use_setup));
   239     (P.text >> (Toplevel.theory o Context.use_setup));
   246 
   240 
   247 val method_setupP =
   241 val method_setupP =
   248   OuterSyntax.command "method_setup" "define proof method in ML" K.thy_decl
   242   OuterSyntax.command "method_setup" "define proof method in ML" K.thy_decl
   249     (((P.name -- P.!!! (P.$$$ "=" |-- P.text -- P.text) >> P.triple2)
   243     (((P.name -- P.!!! (P.$$$ "=" |-- P.text -- P.text) >> P.triple2))
   250       -- P.marg_comment) >> (Toplevel.theory o IsarThy.method_setup));
   244       >> (Toplevel.theory o IsarThy.method_setup));
   251 
   245 
   252 
   246 
   253 (* translation functions *)
   247 (* translation functions *)
   254 
   248 
   255 val parse_ast_translationP =
   249 val parse_ast_translationP =
   256   OuterSyntax.command "parse_ast_translation" "install parse ast translation functions" K.thy_decl
   250   OuterSyntax.command "parse_ast_translation" "install parse ast translation functions" K.thy_decl
   257     (P.text -- P.marg_comment >> (Toplevel.theory o IsarThy.parse_ast_translation));
   251     (P.text >> (Toplevel.theory o IsarThy.parse_ast_translation));
   258 
   252 
   259 val parse_translationP =
   253 val parse_translationP =
   260   OuterSyntax.command "parse_translation" "install parse translation functions" K.thy_decl
   254   OuterSyntax.command "parse_translation" "install parse translation functions" K.thy_decl
   261     (P.text -- P.marg_comment >> (Toplevel.theory o IsarThy.parse_translation));
   255     (P.text >> (Toplevel.theory o IsarThy.parse_translation));
   262 
   256 
   263 val print_translationP =
   257 val print_translationP =
   264   OuterSyntax.command "print_translation" "install print translation functions" K.thy_decl
   258   OuterSyntax.command "print_translation" "install print translation functions" K.thy_decl
   265     (P.text -- P.marg_comment >> (Toplevel.theory o IsarThy.print_translation));
   259     (P.text >> (Toplevel.theory o IsarThy.print_translation));
   266 
   260 
   267 val typed_print_translationP =
   261 val typed_print_translationP =
   268   OuterSyntax.command "typed_print_translation" "install typed print translation functions"
   262   OuterSyntax.command "typed_print_translation" "install typed print translation functions"
   269     K.thy_decl (P.text -- P.marg_comment >> (Toplevel.theory o IsarThy.typed_print_translation));
   263     K.thy_decl (P.text >> (Toplevel.theory o IsarThy.typed_print_translation));
   270 
   264 
   271 val print_ast_translationP =
   265 val print_ast_translationP =
   272   OuterSyntax.command "print_ast_translation" "install print ast translation functions" K.thy_decl
   266   OuterSyntax.command "print_ast_translation" "install print ast translation functions" K.thy_decl
   273     (P.text -- P.marg_comment >> (Toplevel.theory o IsarThy.print_ast_translation));
   267     (P.text >> (Toplevel.theory o IsarThy.print_ast_translation));
   274 
   268 
   275 val token_translationP =
   269 val token_translationP =
   276   OuterSyntax.command "token_translation" "install token translation functions" K.thy_decl
   270   OuterSyntax.command "token_translation" "install token translation functions" K.thy_decl
   277     (P.text -- P.marg_comment >> (Toplevel.theory o IsarThy.token_translation));
   271     (P.text >> (Toplevel.theory o IsarThy.token_translation));
   278 
   272 
   279 
   273 
   280 (* oracles *)
   274 (* oracles *)
   281 
   275 
   282 val oracleP =
   276 val oracleP =
   283   OuterSyntax.command "oracle" "install oracle" K.thy_decl
   277   OuterSyntax.command "oracle" "install oracle" K.thy_decl
   284     ((P.name --| P.$$$ "=") -- P.text -- P.marg_comment >> (Toplevel.theory o IsarThy.add_oracle));
   278     ((P.name --| P.$$$ "=") -- P.text >> (Toplevel.theory o IsarThy.add_oracle));
   285 
   279 
   286 
   280 
   287 (* locales *)
   281 (* locales *)
   288 
   282 
   289 val locale_val =
   283 val locale_val =
   290   (P.locale_expr --
   284   (P.locale_expr --
   291     Scan.optional (P.$$$ "+" |-- P.!!! (Scan.repeat1 (P.locale_element -- P.marg_comment))) [] ||
   285     Scan.optional (P.$$$ "+" |-- P.!!! (Scan.repeat1 P.locale_element)) [] ||
   292   Scan.repeat1 (P.locale_element -- P.marg_comment) >> pair Locale.empty);
   286   Scan.repeat1 P.locale_element >> pair Locale.empty);
   293 
   287 
   294 val localeP =
   288 val localeP =
   295   OuterSyntax.command "locale" "define named proof context" K.thy_decl
   289   OuterSyntax.command "locale" "define named proof context" K.thy_decl
   296     (P.name -- (P.$$$ "=" |-- P.!!! locale_val || Scan.succeed (Locale.empty, []))
   290     (P.name -- (P.$$$ "=" |-- P.!!! locale_val || Scan.succeed (Locale.empty, []))
   297       >> (Toplevel.theory o IsarThy.add_locale o P.triple2));
   291       >> (Toplevel.theory o IsarThy.add_locale o P.triple2));
   303 (* statements *)
   297 (* statements *)
   304 
   298 
   305 val in_locale_elems = in_locale --
   299 val in_locale_elems = in_locale --
   306   Scan.optional (P.$$$ "(" |-- Scan.repeat1 P.locale_element --| P.!!! (P.$$$ ")")) [];
   300   Scan.optional (P.$$$ "(" |-- Scan.repeat1 P.locale_element --| P.!!! (P.$$$ ")")) [];
   307 
   301 
   308 val statement = P.and_list1 (P.opt_thm_name ":" -- Scan.repeat1 P.propp -- P.marg_comment);
   302 val statement = P.and_list1 (P.opt_thm_name ":" -- Scan.repeat1 P.propp);
   309 val statement' = P.$$$ "(" |-- statement --| P.!!! (P.$$$ ")") || statement;
   303 val statement' = P.$$$ "(" |-- statement --| P.!!! (P.$$$ ")") || statement;
   310 
   304 
   311 fun gen_theorem k =
   305 fun gen_theorem k =
   312   OuterSyntax.command k ("state " ^ k) K.thy_goal
   306   OuterSyntax.command k ("state " ^ k) K.thy_goal
   313     (Scan.optional (P.thm_name ":" --| Scan.ahead (P.$$$ "(")) ("", [])
   307     (Scan.optional (P.thm_name ":" --| Scan.ahead (P.$$$ "(")) ("", [])
   335     (statement >> ((Toplevel.print oo Toplevel.proof) o IsarThy.hence));
   329     (statement >> ((Toplevel.print oo Toplevel.proof) o IsarThy.hence));
   336 
   330 
   337 
   331 
   338 (* facts *)
   332 (* facts *)
   339 
   333 
   340 val facts = P.and_list1 (P.xthms1 -- P.marg_comment);
   334 val facts = P.and_list1 P.xthms1;
   341 
   335 
   342 val thenP =
   336 val thenP =
   343   OuterSyntax.command "then" "forward chaining" K.prf_chain
   337   OuterSyntax.command "then" "forward chaining" K.prf_chain
   344     (P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.chain)));
   338     (Scan.succeed (Toplevel.print o (Toplevel.proof IsarThy.chain)));
   345 
   339 
   346 val fromP =
   340 val fromP =
   347   OuterSyntax.command "from" "forward chaining from given facts" K.prf_chain
   341   OuterSyntax.command "from" "forward chaining from given facts" K.prf_chain
   348     (facts >> (Toplevel.print oo (Toplevel.proof o IsarThy.from_facts)));
   342     (facts >> (Toplevel.print oo (Toplevel.proof o IsarThy.from_facts)));
   349 
   343 
   358 
   352 
   359 (* proof context *)
   353 (* proof context *)
   360 
   354 
   361 val fixP =
   355 val fixP =
   362   OuterSyntax.command "fix" "fix variables (Skolem constants)" K.prf_asm
   356   OuterSyntax.command "fix" "fix variables (Skolem constants)" K.prf_asm
   363     (P.and_list1 (Scan.repeat1 P.name -- Scan.option (P.$$$ "::" |-- P.typ) -- P.marg_comment)
   357     (P.and_list1 (Scan.repeat1 P.name -- Scan.option (P.$$$ "::" |-- P.typ))
   364       >> (Toplevel.print oo (Toplevel.proof o IsarThy.fix)));
   358       >> (Toplevel.print oo (Toplevel.proof o IsarThy.fix)));
   365 
   359 
   366 val assumeP =
   360 val assumeP =
   367   OuterSyntax.command "assume" "assume propositions" K.prf_asm
   361   OuterSyntax.command "assume" "assume propositions" K.prf_asm
   368     (statement >> (Toplevel.print oo (Toplevel.proof o IsarThy.assume)));
   362     (statement >> (Toplevel.print oo (Toplevel.proof o IsarThy.assume)));
   372     (statement >> (Toplevel.print oo (Toplevel.proof o IsarThy.presume)));
   366     (statement >> (Toplevel.print oo (Toplevel.proof o IsarThy.presume)));
   373 
   367 
   374 val defP =
   368 val defP =
   375   OuterSyntax.command "def" "local definition" K.prf_asm
   369   OuterSyntax.command "def" "local definition" K.prf_asm
   376     (P.opt_thm_name ":" -- (P.name -- ((P.$$$ "\\<equiv>" || P.$$$ "==") |-- P.!!! P.termp))
   370     (P.opt_thm_name ":" -- (P.name -- ((P.$$$ "\\<equiv>" || P.$$$ "==") |-- P.!!! P.termp))
   377       -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.local_def)));
   371       >> (Toplevel.print oo (Toplevel.proof o IsarThy.local_def)));
   378 
   372 
   379 val obtainP =
   373 val obtainP =
   380   OuterSyntax.command "obtain" "generalized existence"
   374   OuterSyntax.command "obtain" "generalized existence"
   381     K.prf_asm_goal
   375     K.prf_asm_goal
   382     (Scan.optional
   376     (Scan.optional
   383       (P.and_list1 (Scan.repeat1 P.name -- Scan.option (P.$$$ "::" |-- P.typ) -- P.marg_comment)
   377       (P.and_list1 (Scan.repeat1 P.name -- Scan.option (P.$$$ "::" |-- P.typ))
   384         --| P.$$$ "where") [] -- statement
   378         --| P.$$$ "where") [] -- statement
   385     >> (Toplevel.print oo (Toplevel.proof o IsarThy.obtain)));
   379     >> (Toplevel.print oo (Toplevel.proof o IsarThy.obtain)));
   386 
   380 
   387 val letP =
   381 val letP =
   388   OuterSyntax.command "let" "bind text variables" K.prf_decl
   382   OuterSyntax.command "let" "bind text variables" K.prf_decl
   389     (P.and_list1 (P.enum1 "and" P.term -- (P.$$$ "=" |-- P.term) -- P.marg_comment)
   383     (P.and_list1 (P.enum1 "and" P.term -- (P.$$$ "=" |-- P.term))
   390       >> (Toplevel.print oo (Toplevel.proof o IsarThy.let_bind)));
   384       >> (Toplevel.print oo (Toplevel.proof o IsarThy.let_bind)));
   391 
   385 
   392 val case_spec =
   386 val case_spec =
   393   (P.$$$ "(" |-- P.!!! (P.xname -- Scan.repeat1 P.uname --| P.$$$ ")") ||
   387   (P.$$$ "(" |-- P.!!! (P.xname -- Scan.repeat1 P.uname --| P.$$$ ")") ||
   394     P.xname >> rpair []) -- P.opt_attribs >> P.triple1;
   388     P.xname >> rpair []) -- P.opt_attribs >> P.triple1;
   395 
   389 
   396 val caseP =
   390 val caseP =
   397   OuterSyntax.command "case" "invoke local context" K.prf_asm
   391   OuterSyntax.command "case" "invoke local context" K.prf_asm
   398     (case_spec -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.invoke_case)));
   392     (case_spec >> (Toplevel.print oo (Toplevel.proof o IsarThy.invoke_case)));
   399 
   393 
   400 
   394 
   401 (* proof structure *)
   395 (* proof structure *)
   402 
   396 
   403 val beginP =
   397 val beginP =
   404   OuterSyntax.command "{" "begin explicit proof block" K.prf_open
   398   OuterSyntax.command "{" "begin explicit proof block" K.prf_open
   405     (P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.begin_block)));
   399     (Scan.succeed (Toplevel.print o (Toplevel.proof IsarThy.begin_block)));
   406 
   400 
   407 val endP =
   401 val endP =
   408   OuterSyntax.command "}" "end explicit proof block" K.prf_close
   402   OuterSyntax.command "}" "end explicit proof block" K.prf_close
   409     (P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.end_block)));
   403     (Scan.succeed (Toplevel.print o (Toplevel.proof IsarThy.end_block)));
   410 
   404 
   411 val nextP =
   405 val nextP =
   412   OuterSyntax.command "next" "enter next proof block" K.prf_block
   406   OuterSyntax.command "next" "enter next proof block" K.prf_block
   413     (P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.next_block)));
   407     (Scan.succeed (Toplevel.print o (Toplevel.proof IsarThy.next_block)));
   414 
   408 
   415 
   409 
   416 (* end proof *)
   410 (* end proof *)
   417 
   411 
   418 val qedP =
   412 val qedP =
   419   OuterSyntax.command "qed" "conclude (sub-)proof" K.qed_block
   413   OuterSyntax.command "qed" "conclude (sub-)proof" K.qed_block
   420     (Scan.option (P.method -- P.interest) -- P.marg_comment >> IsarThy.qed);
   414     (Scan.option P.method >> IsarThy.qed);
   421 
   415 
   422 val terminal_proofP =
   416 val terminal_proofP =
   423   OuterSyntax.command "by" "terminal backward proof" K.qed
   417   OuterSyntax.command "by" "terminal backward proof" K.qed
   424     (P.method -- P.interest -- Scan.option (P.method -- P.interest)
   418     (P.method -- Scan.option P.method >> IsarThy.terminal_proof);
   425       -- P.marg_comment >> IsarThy.terminal_proof);
       
   426 
   419 
   427 val default_proofP =
   420 val default_proofP =
   428   OuterSyntax.command ".." "default proof" K.qed
   421   OuterSyntax.command ".." "default proof" K.qed
   429     (P.marg_comment >> IsarThy.default_proof);
   422     (Scan.succeed IsarThy.default_proof);
   430 
   423 
   431 val immediate_proofP =
   424 val immediate_proofP =
   432   OuterSyntax.command "." "immediate proof" K.qed
   425   OuterSyntax.command "." "immediate proof" K.qed
   433     (P.marg_comment >> IsarThy.immediate_proof);
   426     (Scan.succeed IsarThy.immediate_proof);
   434 
   427 
   435 val done_proofP =
   428 val done_proofP =
   436   OuterSyntax.command "done" "done proof" K.qed
   429   OuterSyntax.command "done" "done proof" K.qed
   437     (P.marg_comment >> IsarThy.done_proof);
   430     (Scan.succeed IsarThy.done_proof);
   438 
   431 
   439 val skip_proofP =
   432 val skip_proofP =
   440   OuterSyntax.improper_command "sorry" "skip proof (quick-and-dirty mode only!)" K.qed
   433   OuterSyntax.improper_command "sorry" "skip proof (quick-and-dirty mode only!)" K.qed
   441     (P.marg_comment >> IsarThy.skip_proof);
   434     (Scan.succeed IsarThy.skip_proof);
   442 
   435 
   443 val forget_proofP =
   436 val forget_proofP =
   444   OuterSyntax.command "oops" "forget proof" K.qed_global
   437   OuterSyntax.command "oops" "forget proof" K.qed_global
   445     (P.marg_comment >> IsarThy.forget_proof);
   438     (Scan.succeed IsarThy.forget_proof);
   446 
       
   447 
   439 
   448 
   440 
   449 (* proof steps *)
   441 (* proof steps *)
   450 
   442 
   451 val deferP =
   443 val deferP =
   452   OuterSyntax.command "defer" "shuffle internal proof state" K.prf_script
   444   OuterSyntax.command "defer" "shuffle internal proof state" K.prf_script
   453     (Scan.option P.nat -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.defer)));
   445     (Scan.option P.nat >> (Toplevel.print oo (Toplevel.proof o IsarThy.defer)));
   454 
   446 
   455 val preferP =
   447 val preferP =
   456   OuterSyntax.command "prefer" "shuffle internal proof state" K.prf_script
   448   OuterSyntax.command "prefer" "shuffle internal proof state" K.prf_script
   457     (P.nat -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.prefer)));
   449     (P.nat >> (Toplevel.print oo (Toplevel.proof o IsarThy.prefer)));
   458 
   450 
   459 val applyP =
   451 val applyP =
   460   OuterSyntax.command "apply" "initial refinement step (unstructured)" K.prf_script
   452   OuterSyntax.command "apply" "initial refinement step (unstructured)" K.prf_script
   461     (P.method -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.apply)));
   453     (P.method >> (Toplevel.print oo (Toplevel.proof o IsarThy.apply)));
   462 
   454 
   463 val apply_endP =
   455 val apply_endP =
   464   OuterSyntax.command "apply_end" "terminal refinement (unstructured)" K.prf_script
   456   OuterSyntax.command "apply_end" "terminal refinement (unstructured)" K.prf_script
   465     (P.method -- P.marg_comment >> (Toplevel.print oo (Toplevel.proof o IsarThy.apply_end)));
   457     (P.method >> (Toplevel.print oo (Toplevel.proof o IsarThy.apply_end)));
   466 
   458 
   467 val proofP =
   459 val proofP =
   468   OuterSyntax.command "proof" "backward proof" K.prf_block
   460   OuterSyntax.command "proof" "backward proof" K.prf_block
   469     (P.interest -- Scan.option (P.method -- P.interest) -- P.marg_comment
   461     (Scan.option P.method >> (Toplevel.print oo (Toplevel.proof o IsarThy.proof)));
   470       >> (Toplevel.print oo (Toplevel.proof o IsarThy.proof)));
       
   471 
   462 
   472 
   463 
   473 (* calculational proof commands *)
   464 (* calculational proof commands *)
   474 
   465 
   475 val calc_args =
   466 val calc_args =
   476   Scan.option (P.$$$ "(" |-- P.!!! ((P.xthms1 --| P.$$$ ")") -- P.interest));
   467   Scan.option (P.$$$ "(" |-- P.!!! ((P.xthms1 --| P.$$$ ")")));
   477 
   468 
   478 val alsoP =
   469 val alsoP =
   479   OuterSyntax.command "also" "combine calculation and current facts" K.prf_decl
   470   OuterSyntax.command "also" "combine calculation and current facts" K.prf_decl
   480     (calc_args -- P.marg_comment >> IsarThy.also);
   471     (calc_args >> IsarThy.also);
   481 
   472 
   482 val finallyP =
   473 val finallyP =
   483   OuterSyntax.command "finally" "combine calculation and current facts, exhibit result" K.prf_chain
   474   OuterSyntax.command "finally" "combine calculation and current facts, exhibit result" K.prf_chain
   484     (calc_args -- P.marg_comment >> IsarThy.finally);
   475     (calc_args >> IsarThy.finally);
   485 
   476 
   486 val moreoverP =
   477 val moreoverP =
   487   OuterSyntax.command "moreover" "augment calculation by current facts" K.prf_decl
   478   OuterSyntax.command "moreover" "augment calculation by current facts" K.prf_decl
   488     (P.marg_comment >> IsarThy.moreover);
   479     (Scan.succeed IsarThy.moreover);
   489 
   480 
   490 val ultimatelyP =
   481 val ultimatelyP =
   491   OuterSyntax.command "ultimately" "augment calculation by current facts, exhibit result"
   482   OuterSyntax.command "ultimately" "augment calculation by current facts, exhibit result"
   492     K.prf_chain (P.marg_comment >> IsarThy.ultimately);
   483     K.prf_chain (Scan.succeed IsarThy.ultimately);
   493 
   484 
   494 
   485 
   495 (* proof navigation *)
   486 (* proof navigation *)
   496 
   487 
   497 val backP =
   488 val backP =
   498   OuterSyntax.command "back" "backtracking of proof command" K.prf_script
   489   OuterSyntax.command "back" "backtracking of proof command" K.prf_script
   499     (Scan.optional (P.$$$ "!" >> K true) false -- P.marg_comment >>
   490     (Scan.optional (P.$$$ "!" >> K true) false >> (Toplevel.print oo IsarCmd.back));
   500       (Toplevel.print oo IsarCmd.back));
       
   501 
   491 
   502 
   492 
   503 (* history *)
   493 (* history *)
   504 
   494 
   505 val cannot_undoP =
   495 val cannot_undoP =
   609   OuterSyntax.improper_command "print_cases" "print cases of proof context" K.diag
   599   OuterSyntax.improper_command "print_cases" "print cases of proof context" K.diag
   610     (Scan.succeed (Toplevel.no_timing o IsarCmd.print_cases));
   600     (Scan.succeed (Toplevel.no_timing o IsarCmd.print_cases));
   611 
   601 
   612 val print_thmsP =
   602 val print_thmsP =
   613   OuterSyntax.improper_command "thm" "print theorems" K.diag
   603   OuterSyntax.improper_command "thm" "print theorems" K.diag
   614     (opt_modes -- P.xthms1 -- P.marg_comment >> (Toplevel.no_timing oo IsarCmd.print_thms));
   604     (opt_modes -- P.xthms1 >> (Toplevel.no_timing oo IsarCmd.print_thms));
   615 
   605 
   616 val print_prfsP =
   606 val print_prfsP =
   617   OuterSyntax.improper_command "prf" "print proof terms of theorems" K.diag
   607   OuterSyntax.improper_command "prf" "print proof terms of theorems" K.diag
   618     (opt_modes -- Scan.option P.xthms1 -- P.marg_comment >>
   608     (opt_modes -- Scan.option P.xthms1 >> (Toplevel.no_timing oo IsarCmd.print_prfs false));
   619       (Toplevel.no_timing oo IsarCmd.print_prfs false));
       
   620 
   609 
   621 val print_full_prfsP =
   610 val print_full_prfsP =
   622   OuterSyntax.improper_command "full_prf" "print full proof terms of theorems" K.diag
   611   OuterSyntax.improper_command "full_prf" "print full proof terms of theorems" K.diag
   623     (opt_modes -- Scan.option P.xthms1 -- P.marg_comment >>
   612     (opt_modes -- Scan.option P.xthms1 >> (Toplevel.no_timing oo IsarCmd.print_prfs true));
   624       (Toplevel.no_timing oo IsarCmd.print_prfs true));
       
   625 
   613 
   626 val print_propP =
   614 val print_propP =
   627   OuterSyntax.improper_command "prop" "read and print proposition" K.diag
   615   OuterSyntax.improper_command "prop" "read and print proposition" K.diag
   628     (opt_modes -- P.term -- P.marg_comment >> (Toplevel.no_timing oo IsarCmd.print_prop));
   616     (opt_modes -- P.term >> (Toplevel.no_timing oo IsarCmd.print_prop));
   629 
   617 
   630 val print_termP =
   618 val print_termP =
   631   OuterSyntax.improper_command "term" "read and print term" K.diag
   619   OuterSyntax.improper_command "term" "read and print term" K.diag
   632     (opt_modes -- P.term -- P.marg_comment >> (Toplevel.no_timing oo IsarCmd.print_term));
   620     (opt_modes -- P.term >> (Toplevel.no_timing oo IsarCmd.print_term));
   633 
   621 
   634 val print_typeP =
   622 val print_typeP =
   635   OuterSyntax.improper_command "typ" "read and print type" K.diag
   623   OuterSyntax.improper_command "typ" "read and print type" K.diag
   636     (opt_modes -- P.typ -- P.marg_comment >> (Toplevel.no_timing oo IsarCmd.print_type));
   624     (opt_modes -- P.typ >> (Toplevel.no_timing oo IsarCmd.print_type));
   637 
   625 
   638 
   626 
   639 
   627 
   640 (** system commands (for interactive mode only) **)
   628 (** system commands (for interactive mode only) **)
   641 
   629