author | blanchet |
Mon, 30 Nov 2015 13:14:56 +0100 | |
changeset 61755 | 6af17b2b773d |
parent 61476 | 1884c40f1539 |
child 61812 | 71446a608dfd |
permissions | -rw-r--r-- |
5824 | 1 |
(* Title: Pure/Isar/method.ML |
2 |
Author: Markus Wenzel, TU Muenchen |
|
3 |
||
17110 | 4 |
Isar proof methods. |
5824 | 5 |
*) |
6 |
||
7 |
signature METHOD = |
|
8 |
sig |
|
58002 | 9 |
type method = thm list -> cases_tactic |
18227 | 10 |
val METHOD_CASES: (thm list -> cases_tactic) -> method |
17110 | 11 |
val METHOD: (thm list -> tactic) -> method |
12 |
val fail: method |
|
13 |
val succeed: method |
|
14 |
val insert_tac: thm list -> int -> tactic |
|
15 |
val insert: thm list -> method |
|
16 |
val insert_facts: method |
|
17 |
val SIMPLE_METHOD: tactic -> method |
|
21592 | 18 |
val SIMPLE_METHOD': (int -> tactic) -> method |
19 |
val SIMPLE_METHOD'': ((int -> tactic) -> tactic) -> (int -> tactic) -> method |
|
61166
5976fe402824
renamed method "goals" to "goal_cases" to emphasize its meaning;
wenzelm
parents:
61164
diff
changeset
|
20 |
val goal_cases_tac: Proof.context -> string list -> cases_tactic |
52059 | 21 |
val cheating: Proof.context -> bool -> method |
58957 | 22 |
val intro: Proof.context -> thm list -> method |
23 |
val elim: Proof.context -> thm list -> method |
|
20289 | 24 |
val unfold: thm list -> Proof.context -> method |
25 |
val fold: thm list -> Proof.context -> method |
|
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
26 |
val atomize: bool -> Proof.context -> method |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59067
diff
changeset
|
27 |
val this: Proof.context -> method |
20289 | 28 |
val fact: thm list -> Proof.context -> method |
30234
7dd251bce291
renamed Method.assumption_tac back to Method.assm_tac -- as assumption_tac it would have to be exactly the tactic behind the assumption method (with facts);
wenzelm
parents:
30190
diff
changeset
|
29 |
val assm_tac: Proof.context -> int -> tactic |
30567
cd8e20f86795
close/all_assm_tac: finish all subgoals from left to right (cf. Proof.goal_tac a28d83e903ce) -- NB: ALLGOALS/THEN_ALL_NEW operate from right to left;
wenzelm
parents:
30544
diff
changeset
|
30 |
val all_assm_tac: Proof.context -> tactic |
20289 | 31 |
val assumption: Proof.context -> method |
46466
61c7214b4885
tuned signature, according to actual usage of these operations;
wenzelm
parents:
45375
diff
changeset
|
32 |
val rule_trace: bool Config.T |
20289 | 33 |
val trace: Proof.context -> thm list -> unit |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
34 |
val rule_tac: Proof.context -> thm list -> thm list -> int -> tactic |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
35 |
val some_rule_tac: Proof.context -> thm list -> thm list -> int -> tactic |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59067
diff
changeset
|
36 |
val intros_tac: Proof.context -> thm list -> thm list -> tactic |
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59067
diff
changeset
|
37 |
val try_intros_tac: Proof.context -> thm list -> thm list -> tactic |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
38 |
val rule: Proof.context -> thm list -> method |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
39 |
val erule: Proof.context -> int -> thm list -> method |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
40 |
val drule: Proof.context -> int -> thm list -> method |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
41 |
val frule: Proof.context -> int -> thm list -> method |
58018
beb4b7c0bb30
proper static closure of ML tactic -- data slot is used twice, for ML compiler and transformed declaration;
wenzelm
parents:
58016
diff
changeset
|
42 |
val set_tactic: (morphism -> thm list -> tactic) -> Context.generic -> Context.generic |
55765 | 43 |
type combinator_info |
44 |
val no_combinator_info: combinator_info |
|
59660
49e498cedd02
support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents:
59498
diff
changeset
|
45 |
datatype combinator = Then | Then_All_New | Orelse | Try | Repeat1 | Select_Goals of int |
5824 | 46 |
datatype text = |
58011
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
58007
diff
changeset
|
47 |
Source of Token.src | |
32193
c314b4836031
basic method application: avoid Position.setmp_thread_data_seq, which destroys transaction context;
wenzelm
parents:
32091
diff
changeset
|
48 |
Basic of Proof.context -> method | |
58005 | 49 |
Combinator of combinator_info * combinator * text list |
58011
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
58007
diff
changeset
|
50 |
val map_source: (Token.src -> Token.src) -> text -> text |
54883
dd04a8b654fc
proper context for norm_hhf and derived operations;
wenzelm
parents:
54742
diff
changeset
|
51 |
val primitive_text: (Proof.context -> thm -> thm) -> text |
17857 | 52 |
val succeed_text: text |
60618
4c79543cc376
renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents:
60609
diff
changeset
|
53 |
val standard_text: text |
17110 | 54 |
val this_text: text |
55 |
val done_text: text |
|
17356
09afdf37cdb3
added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents:
17314
diff
changeset
|
56 |
val sorry_text: bool -> text |
32193
c314b4836031
basic method application: avoid Position.setmp_thread_data_seq, which destroys transaction context;
wenzelm
parents:
32091
diff
changeset
|
57 |
val finish_text: text option * bool -> text |
59917
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59914
diff
changeset
|
58 |
val print_methods: bool -> Proof.context -> unit |
55742
a989bdaf8121
modernized Method.check_name/check_source (with reports) vs. strict Method.the_method (without interning nor reports), e.g. relevant for semantic completion;
wenzelm
parents:
55709
diff
changeset
|
59 |
val check_name: Proof.context -> xstring * Position.T -> string |
59907 | 60 |
val check_src: Proof.context -> Token.src -> Token.src |
58011
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
58007
diff
changeset
|
61 |
val method_syntax: (Proof.context -> method) context_parser -> |
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
58007
diff
changeset
|
62 |
Token.src -> Proof.context -> method |
30512 | 63 |
val setup: binding -> (Proof.context -> method) context_parser -> string -> theory -> theory |
57935
c578f3a37a67
localized method definitions (see also f14c1248d064);
wenzelm
parents:
57863
diff
changeset
|
64 |
val local_setup: binding -> (Proof.context -> method) context_parser -> string -> |
c578f3a37a67
localized method definitions (see also f14c1248d064);
wenzelm
parents:
57863
diff
changeset
|
65 |
local_theory -> local_theory |
59064 | 66 |
val method_setup: bstring * Position.T -> Input.source -> string -> local_theory -> local_theory |
58011
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
58007
diff
changeset
|
67 |
val method: Proof.context -> Token.src -> Proof.context -> method |
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
58007
diff
changeset
|
68 |
val method_closure: Proof.context -> Token.src -> Token.src |
59909 | 69 |
val closure: bool Config.T |
58011
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
58007
diff
changeset
|
70 |
val method_cmd: Proof.context -> Token.src -> Proof.context -> method |
60553 | 71 |
val detect_closure_state: thm -> bool |
60609 | 72 |
val STATIC: (unit -> unit) -> cases_tactic |
60553 | 73 |
val RUNTIME: cases_tactic -> cases_tactic |
60554 | 74 |
val sleep: Time.time -> cases_tactic |
58007
671c607fb4af
just one context for Method.evaluate (in contrast to a989bdaf8121, but in accordance to old global situation);
wenzelm
parents:
58006
diff
changeset
|
75 |
val evaluate: text -> Proof.context -> method |
58048
aa6296d09e0e
more explicit Method.modifier with reported position;
wenzelm
parents:
58034
diff
changeset
|
76 |
type modifier = {init: Proof.context -> Proof.context, attribute: attribute, pos: Position.T} |
aa6296d09e0e
more explicit Method.modifier with reported position;
wenzelm
parents:
58034
diff
changeset
|
77 |
val modifier: attribute -> Position.T -> modifier |
59982
f402fd001429
option for old section parser (before 2137e60b6f6d) for the sake of Eisbach;
wenzelm
parents:
59981
diff
changeset
|
78 |
val old_section_parser: bool Config.T |
f402fd001429
option for old section parser (before 2137e60b6f6d) for the sake of Eisbach;
wenzelm
parents:
59981
diff
changeset
|
79 |
val sections: modifier parser list -> unit context_parser |
49889
00ea087e83d8
more method position information, notably finished_pos after end of previous text;
wenzelm
parents:
49866
diff
changeset
|
80 |
type text_range = text * Position.range |
00ea087e83d8
more method position information, notably finished_pos after end of previous text;
wenzelm
parents:
49866
diff
changeset
|
81 |
val text: text_range option -> text option |
00ea087e83d8
more method position information, notably finished_pos after end of previous text;
wenzelm
parents:
49866
diff
changeset
|
82 |
val position: text_range option -> Position.T |
55795 | 83 |
val reports_of: text_range -> Position.report list |
84 |
val report: text_range -> unit |
|
59981 | 85 |
val parser': Proof.context -> int -> text_range parser |
86 |
val parser: int -> text_range parser |
|
55761
213b9811f59f
method language markup, e.g. relevant to prevent outer keyword completion;
wenzelm
parents:
55742
diff
changeset
|
87 |
val parse: text_range parser |
5824 | 88 |
end; |
89 |
||
90 |
structure Method: METHOD = |
|
91 |
struct |
|
92 |
||
12324
5db4b4596d1a
rule context and attributes moved to rule_context.ML;
wenzelm
parents:
12311
diff
changeset
|
93 |
(** proof methods **) |
5db4b4596d1a
rule context and attributes moved to rule_context.ML;
wenzelm
parents:
12311
diff
changeset
|
94 |
|
58006 | 95 |
(* method *) |
11731 | 96 |
|
58002 | 97 |
type method = thm list -> cases_tactic; |
11731 | 98 |
|
59953 | 99 |
fun METHOD_CASES tac : method = |
100 |
fn facts => Seq.THEN (ALLGOALS Goal.conjunction_tac, tac facts); |
|
101 |
||
102 |
fun METHOD tac : method = |
|
103 |
fn facts => EMPTY_CASES (ALLGOALS Goal.conjunction_tac THEN tac facts); |
|
5824 | 104 |
|
105 |
val fail = METHOD (K no_tac); |
|
106 |
val succeed = METHOD (K all_tac); |
|
107 |
||
108 |
||
17110 | 109 |
(* insert facts *) |
7419 | 110 |
|
111 |
local |
|
5824 | 112 |
|
21579 | 113 |
fun cut_rule_tac rule = |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59067
diff
changeset
|
114 |
resolve0_tac [Drule.forall_intr_vars rule COMP_INCR revcut_rl]; |
6981 | 115 |
|
7419 | 116 |
in |
5824 | 117 |
|
51552
c713c9505f68
clarified Skip_Proof.cheat_tac: more standard tactic;
wenzelm
parents:
51383
diff
changeset
|
118 |
fun insert_tac [] _ = all_tac |
7419 | 119 |
| insert_tac facts i = EVERY (map (fn th => cut_rule_tac th i) facts); |
6981 | 120 |
|
7555 | 121 |
val insert_facts = METHOD (ALLGOALS o insert_tac); |
7664 | 122 |
fun insert thms = METHOD (fn _ => ALLGOALS (insert_tac thms)); |
7419 | 123 |
|
9706 | 124 |
fun SIMPLE_METHOD tac = METHOD (fn facts => ALLGOALS (insert_tac facts) THEN tac); |
21592 | 125 |
fun SIMPLE_METHOD'' quant tac = METHOD (fn facts => quant (insert_tac facts THEN' tac)); |
126 |
val SIMPLE_METHOD' = SIMPLE_METHOD'' HEADGOAL; |
|
9706 | 127 |
|
12324
5db4b4596d1a
rule context and attributes moved to rule_context.ML;
wenzelm
parents:
12311
diff
changeset
|
128 |
end; |
5db4b4596d1a
rule context and attributes moved to rule_context.ML;
wenzelm
parents:
12311
diff
changeset
|
129 |
|
9706 | 130 |
|
60578 | 131 |
(* goals as cases *) |
132 |
||
61166
5976fe402824
renamed method "goals" to "goal_cases" to emphasize its meaning;
wenzelm
parents:
61164
diff
changeset
|
133 |
fun goal_cases_tac ctxt case_names st = |
60578 | 134 |
let |
135 |
val cases = |
|
136 |
(if null case_names then map string_of_int (1 upto Thm.nprems_of st) else case_names) |
|
137 |
|> map (rpair [] o rpair []) |
|
138 |
|> Rule_Cases.make_common ctxt (Thm.prop_of (Rule_Cases.internalize_params st)); |
|
139 |
in Seq.single (cases, st) end; |
|
140 |
||
141 |
||
17356
09afdf37cdb3
added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents:
17314
diff
changeset
|
142 |
(* cheating *) |
09afdf37cdb3
added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents:
17314
diff
changeset
|
143 |
|
52059 | 144 |
fun cheating ctxt int = METHOD (fn _ => fn st => |
145 |
if int orelse Config.get ctxt quick_and_dirty then |
|
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59067
diff
changeset
|
146 |
ALLGOALS (Skip_Proof.cheat_tac ctxt) st |
51552
c713c9505f68
clarified Skip_Proof.cheat_tac: more standard tactic;
wenzelm
parents:
51383
diff
changeset
|
147 |
else error "Cheating requires quick_and_dirty mode!"); |
17356
09afdf37cdb3
added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents:
17314
diff
changeset
|
148 |
|
09afdf37cdb3
added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents:
17314
diff
changeset
|
149 |
|
17110 | 150 |
(* unfold intro/elim rules *) |
151 |
||
58957 | 152 |
fun intro ctxt ths = SIMPLE_METHOD' (CHANGED_PROP o REPEAT_ALL_NEW (match_tac ctxt ths)); |
153 |
fun elim ctxt ths = SIMPLE_METHOD' (CHANGED_PROP o REPEAT_ALL_NEW (ematch_tac ctxt ths)); |
|
17110 | 154 |
|
155 |
||
12384 | 156 |
(* unfold/fold definitions *) |
157 |
||
35624 | 158 |
fun unfold_meth ths ctxt = SIMPLE_METHOD (CHANGED_PROP (Local_Defs.unfold_tac ctxt ths)); |
159 |
fun fold_meth ths ctxt = SIMPLE_METHOD (CHANGED_PROP (Local_Defs.fold_tac ctxt ths)); |
|
6532 | 160 |
|
12384 | 161 |
|
12829 | 162 |
(* atomize rule statements *) |
163 |
||
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
164 |
fun atomize false ctxt = |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
165 |
SIMPLE_METHOD' (CHANGED_PROP o Object_Logic.atomize_prems_tac ctxt) |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
166 |
| atomize true ctxt = |
59953 | 167 |
EMPTY_CASES o K (HEADGOAL (CHANGED_PROP o Object_Logic.full_atomize_tac ctxt)); |
12829 | 168 |
|
169 |
||
18039 | 170 |
(* this -- resolve facts directly *) |
12384 | 171 |
|
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59067
diff
changeset
|
172 |
fun this ctxt = METHOD (EVERY o map (HEADGOAL o resolve_tac ctxt o single)); |
9484 | 173 |
|
174 |
||
18039 | 175 |
(* fact -- composition by facts from context *) |
176 |
||
42360 | 177 |
fun fact [] ctxt = SIMPLE_METHOD' (Proof_Context.some_fact_tac ctxt) |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
178 |
| fact rules ctxt = SIMPLE_METHOD' (Proof_Context.fact_tac ctxt rules); |
18039 | 179 |
|
180 |
||
17110 | 181 |
(* assumption *) |
7419 | 182 |
|
183 |
local |
|
184 |
||
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59067
diff
changeset
|
185 |
fun cond_rtac ctxt cond rule = SUBGOAL (fn (prop, i) => |
19778 | 186 |
if cond (Logic.strip_assums_concl prop) |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59067
diff
changeset
|
187 |
then resolve_tac ctxt [rule] i else no_tac); |
7419 | 188 |
|
29857
2cc976ed8a3c
FindTheorems: add solves feature; tidy up const name subsettin; patch by Timothy Bourke
kleing
parents:
29301
diff
changeset
|
189 |
in |
2cc976ed8a3c
FindTheorems: add solves feature; tidy up const name subsettin; patch by Timothy Bourke
kleing
parents:
29301
diff
changeset
|
190 |
|
30234
7dd251bce291
renamed Method.assumption_tac back to Method.assm_tac -- as assumption_tac it would have to be exactly the tactic behind the assumption method (with facts);
wenzelm
parents:
30190
diff
changeset
|
191 |
fun assm_tac ctxt = |
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58957
diff
changeset
|
192 |
assume_tac ctxt APPEND' |
23349 | 193 |
Goal.assume_rule_tac ctxt APPEND' |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59067
diff
changeset
|
194 |
cond_rtac ctxt (can Logic.dest_equals) Drule.reflexive_thm APPEND' |
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59067
diff
changeset
|
195 |
cond_rtac ctxt (can Logic.dest_term) Drule.termI; |
17110 | 196 |
|
49846
8fae089f5a0c
refined Proof.the_finished_goal with more informative error;
wenzelm
parents:
48992
diff
changeset
|
197 |
fun all_assm_tac ctxt = |
8fae089f5a0c
refined Proof.the_finished_goal with more informative error;
wenzelm
parents:
48992
diff
changeset
|
198 |
let |
8fae089f5a0c
refined Proof.the_finished_goal with more informative error;
wenzelm
parents:
48992
diff
changeset
|
199 |
fun tac i st = |
8fae089f5a0c
refined Proof.the_finished_goal with more informative error;
wenzelm
parents:
48992
diff
changeset
|
200 |
if i > Thm.nprems_of st then all_tac st |
8fae089f5a0c
refined Proof.the_finished_goal with more informative error;
wenzelm
parents:
48992
diff
changeset
|
201 |
else ((assm_tac ctxt i THEN tac i) ORELSE tac (i + 1)) st; |
8fae089f5a0c
refined Proof.the_finished_goal with more informative error;
wenzelm
parents:
48992
diff
changeset
|
202 |
in tac 1 end; |
30567
cd8e20f86795
close/all_assm_tac: finish all subgoals from left to right (cf. Proof.goal_tac a28d83e903ce) -- NB: ALLGOALS/THEN_ALL_NEW operate from right to left;
wenzelm
parents:
30544
diff
changeset
|
203 |
|
23349 | 204 |
fun assumption ctxt = METHOD (HEADGOAL o |
30234
7dd251bce291
renamed Method.assumption_tac back to Method.assm_tac -- as assumption_tac it would have to be exactly the tactic behind the assumption method (with facts);
wenzelm
parents:
30190
diff
changeset
|
205 |
(fn [] => assm_tac ctxt |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59067
diff
changeset
|
206 |
| [fact] => solve_tac ctxt [fact] |
23349 | 207 |
| _ => K no_tac)); |
208 |
||
49846
8fae089f5a0c
refined Proof.the_finished_goal with more informative error;
wenzelm
parents:
48992
diff
changeset
|
209 |
fun finish immed ctxt = |
58950
d07464875dd4
optional proof context for unify operations, for the sake of proper local options;
wenzelm
parents:
58837
diff
changeset
|
210 |
METHOD (K ((if immed then all_assm_tac ctxt else all_tac) THEN flexflex_tac ctxt)); |
7419 | 211 |
|
212 |
end; |
|
213 |
||
214 |
||
17110 | 215 |
(* rule etc. -- single-step refinements *) |
12347 | 216 |
|
56204 | 217 |
val rule_trace = Attrib.setup_config_bool @{binding rule_trace} (fn _ => false); |
12347 | 218 |
|
17110 | 219 |
fun trace ctxt rules = |
41379 | 220 |
if Config.get ctxt rule_trace andalso not (null rules) then |
61268 | 221 |
Pretty.big_list "rules:" (map (Thm.pretty_thm_item ctxt) rules) |
21962 | 222 |
|> Pretty.string_of |> tracing |
223 |
else (); |
|
12347 | 224 |
|
225 |
local |
|
226 |
||
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
227 |
fun gen_rule_tac tac ctxt rules facts = |
18841 | 228 |
(fn i => fn st => |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59067
diff
changeset
|
229 |
if null facts then tac ctxt rules i st |
58950
d07464875dd4
optional proof context for unify operations, for the sake of proper local options;
wenzelm
parents:
58837
diff
changeset
|
230 |
else |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59067
diff
changeset
|
231 |
Seq.maps (fn rule => (tac ctxt o single) rule i st) |
58950
d07464875dd4
optional proof context for unify operations, for the sake of proper local options;
wenzelm
parents:
58837
diff
changeset
|
232 |
(Drule.multi_resolves (SOME ctxt) facts rules)) |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
233 |
THEN_ALL_NEW Goal.norm_hhf_tac ctxt; |
7130 | 234 |
|
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
235 |
fun gen_arule_tac tac ctxt j rules facts = |
58963
26bf09b95dda
proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents:
58957
diff
changeset
|
236 |
EVERY' (gen_rule_tac tac ctxt rules facts :: replicate j (assume_tac ctxt)); |
10744 | 237 |
|
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
238 |
fun gen_some_rule_tac tac ctxt arg_rules facts = SUBGOAL (fn (goal, i) => |
11785 | 239 |
let |
240 |
val rules = |
|
241 |
if not (null arg_rules) then arg_rules |
|
61049 | 242 |
else flat (Context_Rules.find_rules ctxt false facts goal); |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
243 |
in trace ctxt rules; tac ctxt rules facts i end); |
10309 | 244 |
|
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
245 |
fun meth tac x y = METHOD (HEADGOAL o tac x y); |
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
246 |
fun meth' tac x y z = METHOD (HEADGOAL o tac x y z); |
8220 | 247 |
|
7419 | 248 |
in |
249 |
||
52732 | 250 |
val rule_tac = gen_rule_tac resolve_tac; |
10744 | 251 |
val rule = meth rule_tac; |
252 |
val some_rule_tac = gen_some_rule_tac rule_tac; |
|
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
253 |
val some_rule = meth some_rule_tac; |
10744 | 254 |
|
52732 | 255 |
val erule = meth' (gen_arule_tac eresolve_tac); |
256 |
val drule = meth' (gen_arule_tac dresolve_tac); |
|
257 |
val frule = meth' (gen_arule_tac forward_tac); |
|
5824 | 258 |
|
7419 | 259 |
end; |
260 |
||
261 |
||
25270 | 262 |
(* intros_tac -- pervasive search spanned by intro rules *) |
263 |
||
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59067
diff
changeset
|
264 |
fun gen_intros_tac goals ctxt intros facts = |
36093
0880493627ca
Graceful treatment of non-locale subgoals by methods unfold_locales and intro_locales.
ballarin
parents:
33522
diff
changeset
|
265 |
goals (insert_tac facts THEN' |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59067
diff
changeset
|
266 |
REPEAT_ALL_NEW (resolve_tac ctxt intros)) |
25270 | 267 |
THEN Tactic.distinct_subgoals_tac; |
268 |
||
36093
0880493627ca
Graceful treatment of non-locale subgoals by methods unfold_locales and intro_locales.
ballarin
parents:
33522
diff
changeset
|
269 |
val intros_tac = gen_intros_tac ALLGOALS; |
0880493627ca
Graceful treatment of non-locale subgoals by methods unfold_locales and intro_locales.
ballarin
parents:
33522
diff
changeset
|
270 |
val try_intros_tac = gen_intros_tac TRYALL; |
25270 | 271 |
|
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
37198
diff
changeset
|
272 |
|
58016 | 273 |
|
274 |
(** method syntax **) |
|
275 |
||
276 |
(* context data *) |
|
8351 | 277 |
|
58016 | 278 |
structure Data = Generic_Data |
26472
9afdd61cf528
ml_tactic: non-critical version via proof data and thread data;
wenzelm
parents:
26463
diff
changeset
|
279 |
( |
58016 | 280 |
type T = |
281 |
((Token.src -> Proof.context -> method) * string) Name_Space.table * (*methods*) |
|
58018
beb4b7c0bb30
proper static closure of ML tactic -- data slot is used twice, for ML compiler and transformed declaration;
wenzelm
parents:
58016
diff
changeset
|
282 |
(morphism -> thm list -> tactic) option; (*ML tactic*) |
58016 | 283 |
val empty : T = (Name_Space.empty_table "method", NONE); |
284 |
val extend = I; |
|
285 |
fun merge ((tab, tac), (tab', tac')) : T = |
|
286 |
(Name_Space.merge_tables (tab, tab'), merge_options (tac, tac')); |
|
26472
9afdd61cf528
ml_tactic: non-critical version via proof data and thread data;
wenzelm
parents:
26463
diff
changeset
|
287 |
); |
9afdd61cf528
ml_tactic: non-critical version via proof data and thread data;
wenzelm
parents:
26463
diff
changeset
|
288 |
|
58016 | 289 |
val get_methods = fst o Data.get; |
290 |
val map_methods = Data.map o apfst; |
|
291 |
||
292 |
||
293 |
(* ML tactic *) |
|
294 |
||
295 |
val set_tactic = Data.map o apsnd o K o SOME; |
|
296 |
||
297 |
fun the_tactic context = |
|
298 |
(case snd (Data.get context) of |
|
299 |
SOME tac => tac |
|
300 |
| NONE => raise Fail "Undefined ML tactic"); |
|
8351 | 301 |
|
58018
beb4b7c0bb30
proper static closure of ML tactic -- data slot is used twice, for ML compiler and transformed declaration;
wenzelm
parents:
58016
diff
changeset
|
302 |
val parse_tactic = |
beb4b7c0bb30
proper static closure of ML tactic -- data slot is used twice, for ML compiler and transformed declaration;
wenzelm
parents:
58016
diff
changeset
|
303 |
Scan.state :|-- (fn context => |
beb4b7c0bb30
proper static closure of ML tactic -- data slot is used twice, for ML compiler and transformed declaration;
wenzelm
parents:
58016
diff
changeset
|
304 |
Scan.lift (Args.text_declaration (fn source => |
beb4b7c0bb30
proper static closure of ML tactic -- data slot is used twice, for ML compiler and transformed declaration;
wenzelm
parents:
58016
diff
changeset
|
305 |
let |
beb4b7c0bb30
proper static closure of ML tactic -- data slot is used twice, for ML compiler and transformed declaration;
wenzelm
parents:
58016
diff
changeset
|
306 |
val context' = context |> |
59064 | 307 |
ML_Context.expression (Input.range_of source) |
58991
92b6f4e68c5a
more careful ML source positions, for improved PIDE markup;
wenzelm
parents:
58979
diff
changeset
|
308 |
"tactic" "Morphism.morphism -> thm list -> tactic" |
92b6f4e68c5a
more careful ML source positions, for improved PIDE markup;
wenzelm
parents:
58979
diff
changeset
|
309 |
"Method.set_tactic tactic" |
59067 | 310 |
(ML_Lex.read "fn morphism: Morphism.morphism => fn facts: thm list =>" @ |
58991
92b6f4e68c5a
more careful ML source positions, for improved PIDE markup;
wenzelm
parents:
58979
diff
changeset
|
311 |
ML_Lex.read_source false source); |
58018
beb4b7c0bb30
proper static closure of ML tactic -- data slot is used twice, for ML compiler and transformed declaration;
wenzelm
parents:
58016
diff
changeset
|
312 |
val tac = the_tactic context'; |
beb4b7c0bb30
proper static closure of ML tactic -- data slot is used twice, for ML compiler and transformed declaration;
wenzelm
parents:
58016
diff
changeset
|
313 |
in |
beb4b7c0bb30
proper static closure of ML tactic -- data slot is used twice, for ML compiler and transformed declaration;
wenzelm
parents:
58016
diff
changeset
|
314 |
fn phi => |
beb4b7c0bb30
proper static closure of ML tactic -- data slot is used twice, for ML compiler and transformed declaration;
wenzelm
parents:
58016
diff
changeset
|
315 |
set_tactic (fn _ => Context.setmp_thread_data (SOME context) (tac phi)) |
beb4b7c0bb30
proper static closure of ML tactic -- data slot is used twice, for ML compiler and transformed declaration;
wenzelm
parents:
58016
diff
changeset
|
316 |
end)) >> (fn decl => Morphism.form (the_tactic (Morphism.form decl context)))); |
8351 | 317 |
|
318 |
||
17110 | 319 |
(* method text *) |
320 |
||
55765 | 321 |
datatype combinator_info = Combinator_Info of {keywords: Position.T list}; |
322 |
fun combinator_info keywords = Combinator_Info {keywords = keywords}; |
|
323 |
val no_combinator_info = combinator_info []; |
|
324 |
||
59660
49e498cedd02
support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents:
59498
diff
changeset
|
325 |
datatype combinator = Then | Then_All_New | Orelse | Try | Repeat1 | Select_Goals of int; |
58005 | 326 |
|
17110 | 327 |
datatype text = |
58011
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
58007
diff
changeset
|
328 |
Source of Token.src | |
32193
c314b4836031
basic method application: avoid Position.setmp_thread_data_seq, which destroys transaction context;
wenzelm
parents:
32091
diff
changeset
|
329 |
Basic of Proof.context -> method | |
58005 | 330 |
Combinator of combinator_info * combinator * text list; |
55765 | 331 |
|
58006 | 332 |
fun map_source f (Source src) = Source (f src) |
333 |
| map_source _ (Basic meth) = Basic meth |
|
334 |
| map_source f (Combinator (info, comb, txts)) = Combinator (info, comb, map (map_source f) txts); |
|
335 |
||
54883
dd04a8b654fc
proper context for norm_hhf and derived operations;
wenzelm
parents:
54742
diff
changeset
|
336 |
fun primitive_text r = Basic (SIMPLE_METHOD o PRIMITIVE o r); |
32193
c314b4836031
basic method application: avoid Position.setmp_thread_data_seq, which destroys transaction context;
wenzelm
parents:
32091
diff
changeset
|
337 |
val succeed_text = Basic (K succeed); |
60618
4c79543cc376
renamed "default" to "standard", to make semantically clear what it is;
wenzelm
parents:
60609
diff
changeset
|
338 |
val standard_text = Source (Token.src ("standard", Position.none) []); |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59067
diff
changeset
|
339 |
val this_text = Basic this; |
32193
c314b4836031
basic method application: avoid Position.setmp_thread_data_seq, which destroys transaction context;
wenzelm
parents:
32091
diff
changeset
|
340 |
val done_text = Basic (K (SIMPLE_METHOD all_tac)); |
52059 | 341 |
fun sorry_text int = Basic (fn ctxt => cheating ctxt int); |
17110 | 342 |
|
49846
8fae089f5a0c
refined Proof.the_finished_goal with more informative error;
wenzelm
parents:
48992
diff
changeset
|
343 |
fun finish_text (NONE, immed) = Basic (finish immed) |
58005 | 344 |
| finish_text (SOME txt, immed) = |
345 |
Combinator (no_combinator_info, Then, [txt, Basic (finish immed)]); |
|
17110 | 346 |
|
347 |
||
348 |
(* method definitions *) |
|
5824 | 349 |
|
57937 | 350 |
fun transfer_methods ctxt = |
57935
c578f3a37a67
localized method definitions (see also f14c1248d064);
wenzelm
parents:
57863
diff
changeset
|
351 |
let |
58016 | 352 |
val meths0 = get_methods (Context.Theory (Proof_Context.theory_of ctxt)); |
353 |
val meths' = Name_Space.merge_tables (meths0, get_methods (Context.Proof ctxt)); |
|
354 |
in Context.proof_map (map_methods (K meths')) ctxt end; |
|
55742
a989bdaf8121
modernized Method.check_name/check_source (with reports) vs. strict Method.the_method (without interning nor reports), e.g. relevant for semantic completion;
wenzelm
parents:
55709
diff
changeset
|
355 |
|
59917
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59914
diff
changeset
|
356 |
fun print_methods verbose ctxt = |
22846 | 357 |
let |
58016 | 358 |
val meths = get_methods (Context.Proof ctxt); |
50301 | 359 |
fun prt_meth (name, (_, "")) = Pretty.mark_str name |
42813
6c841fa92fa2
optional description for 'attribute_setup' and 'method_setup';
wenzelm
parents:
42616
diff
changeset
|
360 |
| prt_meth (name, (_, comment)) = |
50301 | 361 |
Pretty.block |
362 |
(Pretty.mark_str name :: Pretty.str ":" :: Pretty.brk 2 :: Pretty.text comment); |
|
22846 | 363 |
in |
59917
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59914
diff
changeset
|
364 |
[Pretty.big_list "methods:" (map prt_meth (Name_Space.markup_table verbose ctxt meths))] |
56334
6b3739fee456
some shortcuts for chunks, which sometimes avoid bulky string output;
wenzelm
parents:
56278
diff
changeset
|
365 |
|> Pretty.writeln_chunks |
22846 | 366 |
end; |
7611 | 367 |
|
57935
c578f3a37a67
localized method definitions (see also f14c1248d064);
wenzelm
parents:
57863
diff
changeset
|
368 |
|
c578f3a37a67
localized method definitions (see also f14c1248d064);
wenzelm
parents:
57863
diff
changeset
|
369 |
(* define *) |
c578f3a37a67
localized method definitions (see also f14c1248d064);
wenzelm
parents:
57863
diff
changeset
|
370 |
|
c578f3a37a67
localized method definitions (see also f14c1248d064);
wenzelm
parents:
57863
diff
changeset
|
371 |
fun define_global binding meth comment thy = |
c578f3a37a67
localized method definitions (see also f14c1248d064);
wenzelm
parents:
57863
diff
changeset
|
372 |
let |
c578f3a37a67
localized method definitions (see also f14c1248d064);
wenzelm
parents:
57863
diff
changeset
|
373 |
val context = Context.Theory thy; |
c578f3a37a67
localized method definitions (see also f14c1248d064);
wenzelm
parents:
57863
diff
changeset
|
374 |
val (name, meths') = |
58016 | 375 |
Name_Space.define context true (binding, (meth, comment)) (get_methods context); |
376 |
in (name, Context.the_theory (map_methods (K meths') context)) end; |
|
57935
c578f3a37a67
localized method definitions (see also f14c1248d064);
wenzelm
parents:
57863
diff
changeset
|
377 |
|
57941
57200bdc2aa7
localized command 'method_setup' and 'attribute_setup';
wenzelm
parents:
57938
diff
changeset
|
378 |
fun define binding meth comment = |
57200bdc2aa7
localized command 'method_setup' and 'attribute_setup';
wenzelm
parents:
57938
diff
changeset
|
379 |
Local_Theory.background_theory_result (define_global binding meth comment) |
57200bdc2aa7
localized command 'method_setup' and 'attribute_setup';
wenzelm
parents:
57938
diff
changeset
|
380 |
#-> (fn name => |
57200bdc2aa7
localized command 'method_setup' and 'attribute_setup';
wenzelm
parents:
57938
diff
changeset
|
381 |
Local_Theory.map_contexts (K transfer_methods) |
58016 | 382 |
#> Local_Theory.generic_alias map_methods binding name |
57941
57200bdc2aa7
localized command 'method_setup' and 'attribute_setup';
wenzelm
parents:
57938
diff
changeset
|
383 |
#> pair name); |
31304 | 384 |
|
55997
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55917
diff
changeset
|
385 |
|
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55917
diff
changeset
|
386 |
(* check *) |
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55917
diff
changeset
|
387 |
|
58016 | 388 |
fun check_name ctxt = |
389 |
let val context = Context.Proof ctxt |
|
390 |
in #1 o Name_Space.check context (get_methods context) end; |
|
391 |
||
59907 | 392 |
fun check_src ctxt = |
393 |
#1 o Token.check_src ctxt (get_methods (Context.Proof ctxt)); |
|
55997
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55917
diff
changeset
|
394 |
|
59914
d1ddcd8df4e4
proper treatment of internal method name as already checked Token.src;
wenzelm
parents:
59909
diff
changeset
|
395 |
fun checked_info ctxt name = |
d1ddcd8df4e4
proper treatment of internal method name as already checked Token.src;
wenzelm
parents:
59909
diff
changeset
|
396 |
let val space = Name_Space.space_of_table (get_methods (Context.Proof ctxt)) |
d1ddcd8df4e4
proper treatment of internal method name as already checked Token.src;
wenzelm
parents:
59909
diff
changeset
|
397 |
in (Name_Space.kind_of space, Name_Space.markup space name) end; |
d1ddcd8df4e4
proper treatment of internal method name as already checked Token.src;
wenzelm
parents:
59909
diff
changeset
|
398 |
|
55997
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents:
55917
diff
changeset
|
399 |
|
30512 | 400 |
(* method setup *) |
401 |
||
57935
c578f3a37a67
localized method definitions (see also f14c1248d064);
wenzelm
parents:
57863
diff
changeset
|
402 |
fun method_syntax scan src ctxt : method = |
58011
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
58007
diff
changeset
|
403 |
let val (m, ctxt') = Token.syntax scan src ctxt in m ctxt' end; |
57935
c578f3a37a67
localized method definitions (see also f14c1248d064);
wenzelm
parents:
57863
diff
changeset
|
404 |
|
c578f3a37a67
localized method definitions (see also f14c1248d064);
wenzelm
parents:
57863
diff
changeset
|
405 |
fun setup binding scan comment = define_global binding (method_syntax scan) comment #> snd; |
c578f3a37a67
localized method definitions (see also f14c1248d064);
wenzelm
parents:
57863
diff
changeset
|
406 |
fun local_setup binding scan comment = define binding (method_syntax scan) comment #> snd; |
17356
09afdf37cdb3
added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents:
17314
diff
changeset
|
407 |
|
58979
162a4c2e97bc
more careful ML source positions, for improved PIDE markup;
wenzelm
parents:
58978
diff
changeset
|
408 |
fun method_setup name source comment = |
162a4c2e97bc
more careful ML source positions, for improved PIDE markup;
wenzelm
parents:
58978
diff
changeset
|
409 |
ML_Lex.read_source false source |
59064 | 410 |
|> ML_Context.expression (Input.range_of source) "parser" |
58991
92b6f4e68c5a
more careful ML source positions, for improved PIDE markup;
wenzelm
parents:
58979
diff
changeset
|
411 |
"(Proof.context -> Proof.method) context_parser" |
58979
162a4c2e97bc
more careful ML source positions, for improved PIDE markup;
wenzelm
parents:
58978
diff
changeset
|
412 |
("Context.map_proof (Method.local_setup " ^ ML_Syntax.atomic (ML_Syntax.make_binding name) ^ |
162a4c2e97bc
more careful ML source positions, for improved PIDE markup;
wenzelm
parents:
58978
diff
changeset
|
413 |
" parser " ^ ML_Syntax.print_string comment ^ ")") |
57941
57200bdc2aa7
localized command 'method_setup' and 'attribute_setup';
wenzelm
parents:
57938
diff
changeset
|
414 |
|> Context.proof_map; |
17356
09afdf37cdb3
added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents:
17314
diff
changeset
|
415 |
|
09afdf37cdb3
added cheating, sorry_text (from skip_proofs.ML);
wenzelm
parents:
17314
diff
changeset
|
416 |
|
58006 | 417 |
(* prepare methods *) |
418 |
||
419 |
fun method ctxt = |
|
58016 | 420 |
let val table = get_methods (Context.Proof ctxt) |
58011
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
58007
diff
changeset
|
421 |
in fn src => #1 (Name_Space.get table (#1 (Token.name_of_src src))) src end; |
58006 | 422 |
|
59909 | 423 |
fun method_closure ctxt src = |
58006 | 424 |
let |
59909 | 425 |
val src' = Token.init_assignable_src src; |
426 |
val ctxt' = Context_Position.not_really ctxt; |
|
427 |
val _ = Seq.pull (method ctxt' src' ctxt' [] (Goal.protect 0 Drule.dummy_thm)); |
|
428 |
in Token.closure_src src' end; |
|
58006 | 429 |
|
59909 | 430 |
val closure = Config.bool (Config.declare ("Method.closure", @{here}) (K (Config.Bool true))); |
431 |
||
432 |
fun method_cmd ctxt = |
|
433 |
check_src ctxt #> |
|
434 |
Config.get ctxt closure ? method_closure ctxt #> |
|
435 |
method ctxt; |
|
58006 | 436 |
|
437 |
||
60609 | 438 |
(* static vs. runtime state *) |
60553 | 439 |
|
440 |
fun detect_closure_state st = |
|
441 |
(case try Logic.dest_term (Thm.concl_of (perhaps (try Goal.conclude) st)) of |
|
442 |
NONE => false |
|
443 |
| SOME t => Term.is_dummy_pattern t); |
|
444 |
||
60609 | 445 |
fun STATIC test st = |
446 |
if detect_closure_state st then (test (); Seq.single ([], st)) else Seq.empty; |
|
447 |
||
60553 | 448 |
fun RUNTIME (tac: cases_tactic) st = |
449 |
if detect_closure_state st then Seq.empty else tac st; |
|
450 |
||
60554 | 451 |
fun sleep t = RUNTIME (fn st => (OS.Process.sleep t; Seq.single ([], st))); |
452 |
||
60553 | 453 |
|
58003
250ecd2502ad
clarifed Method.evaluate: turn text into semantic method (like Basic);
wenzelm
parents:
58002
diff
changeset
|
454 |
(* evaluate method text *) |
250ecd2502ad
clarifed Method.evaluate: turn text into semantic method (like Basic);
wenzelm
parents:
58002
diff
changeset
|
455 |
|
250ecd2502ad
clarifed Method.evaluate: turn text into semantic method (like Basic);
wenzelm
parents:
58002
diff
changeset
|
456 |
local |
250ecd2502ad
clarifed Method.evaluate: turn text into semantic method (like Basic);
wenzelm
parents:
58002
diff
changeset
|
457 |
|
59660
49e498cedd02
support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents:
59498
diff
changeset
|
458 |
fun APPEND_CASES (tac: cases_tactic) ((cases, st): cases_state) = |
49e498cedd02
support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents:
59498
diff
changeset
|
459 |
tac st |> Seq.map (fn (cases', st') => (cases @ cases', st')); |
58003
250ecd2502ad
clarifed Method.evaluate: turn text into semantic method (like Basic);
wenzelm
parents:
58002
diff
changeset
|
460 |
|
59660
49e498cedd02
support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents:
59498
diff
changeset
|
461 |
fun BYPASS_CASES (tac: tactic) ((cases, st): cases_state) = |
58003
250ecd2502ad
clarifed Method.evaluate: turn text into semantic method (like Basic);
wenzelm
parents:
58002
diff
changeset
|
462 |
tac st |> Seq.map (pair cases); |
250ecd2502ad
clarifed Method.evaluate: turn text into semantic method (like Basic);
wenzelm
parents:
58002
diff
changeset
|
463 |
|
250ecd2502ad
clarifed Method.evaluate: turn text into semantic method (like Basic);
wenzelm
parents:
58002
diff
changeset
|
464 |
val op THEN = Seq.THEN; |
250ecd2502ad
clarifed Method.evaluate: turn text into semantic method (like Basic);
wenzelm
parents:
58002
diff
changeset
|
465 |
|
59660
49e498cedd02
support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents:
59498
diff
changeset
|
466 |
val preparation = BYPASS_CASES (ALLGOALS Goal.conjunction_tac); |
49e498cedd02
support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents:
59498
diff
changeset
|
467 |
|
49e498cedd02
support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents:
59498
diff
changeset
|
468 |
fun RESTRICT_GOAL i n method = |
49e498cedd02
support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents:
59498
diff
changeset
|
469 |
BYPASS_CASES (PRIMITIVE (Goal.restrict i n)) THEN |
49e498cedd02
support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents:
59498
diff
changeset
|
470 |
method THEN |
49e498cedd02
support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents:
59498
diff
changeset
|
471 |
BYPASS_CASES (PRIMITIVE (Goal.unrestrict i)); |
49e498cedd02
support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents:
59498
diff
changeset
|
472 |
|
49e498cedd02
support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents:
59498
diff
changeset
|
473 |
fun SELECT_GOAL method i = RESTRICT_GOAL i 1 method; |
49e498cedd02
support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents:
59498
diff
changeset
|
474 |
|
49e498cedd02
support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents:
59498
diff
changeset
|
475 |
fun (method1 THEN_ALL_NEW method2) i (st: cases_state) = |
49e498cedd02
support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents:
59498
diff
changeset
|
476 |
st |> (method1 i THEN (fn st' => |
49e498cedd02
support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents:
59498
diff
changeset
|
477 |
Seq.INTERVAL method2 i (i + Thm.nprems_of (snd st') - Thm.nprems_of (snd st)) st')); |
58003
250ecd2502ad
clarifed Method.evaluate: turn text into semantic method (like Basic);
wenzelm
parents:
58002
diff
changeset
|
478 |
|
58005 | 479 |
fun COMBINATOR1 comb [meth] = comb meth |
480 |
| COMBINATOR1 _ _ = raise Fail "Method combinator requires exactly one argument"; |
|
481 |
||
482 |
fun combinator Then = Seq.EVERY |
|
59660
49e498cedd02
support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents:
59498
diff
changeset
|
483 |
| combinator Then_All_New = |
49e498cedd02
support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents:
59498
diff
changeset
|
484 |
(fn [] => Seq.single |
49e498cedd02
support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents:
59498
diff
changeset
|
485 |
| methods => |
49e498cedd02
support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents:
59498
diff
changeset
|
486 |
preparation THEN foldl1 (op THEN_ALL_NEW) (map SELECT_GOAL methods) 1) |
58005 | 487 |
| combinator Orelse = Seq.FIRST |
488 |
| combinator Try = COMBINATOR1 Seq.TRY |
|
489 |
| combinator Repeat1 = COMBINATOR1 Seq.REPEAT1 |
|
59660
49e498cedd02
support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents:
59498
diff
changeset
|
490 |
| combinator (Select_Goals n) = |
49e498cedd02
support structural composition (THEN_ALL_NEW) for proof methods;
wenzelm
parents:
59498
diff
changeset
|
491 |
COMBINATOR1 (fn method => preparation THEN RESTRICT_GOAL 1 n method); |
58003
250ecd2502ad
clarifed Method.evaluate: turn text into semantic method (like Basic);
wenzelm
parents:
58002
diff
changeset
|
492 |
|
250ecd2502ad
clarifed Method.evaluate: turn text into semantic method (like Basic);
wenzelm
parents:
58002
diff
changeset
|
493 |
in |
250ecd2502ad
clarifed Method.evaluate: turn text into semantic method (like Basic);
wenzelm
parents:
58002
diff
changeset
|
494 |
|
58007
671c607fb4af
just one context for Method.evaluate (in contrast to a989bdaf8121, but in accordance to old global situation);
wenzelm
parents:
58006
diff
changeset
|
495 |
fun evaluate text ctxt = |
58003
250ecd2502ad
clarifed Method.evaluate: turn text into semantic method (like Basic);
wenzelm
parents:
58002
diff
changeset
|
496 |
let |
58007
671c607fb4af
just one context for Method.evaluate (in contrast to a989bdaf8121, but in accordance to old global situation);
wenzelm
parents:
58006
diff
changeset
|
497 |
fun eval (Basic meth) = APPEND_CASES o meth ctxt |
671c607fb4af
just one context for Method.evaluate (in contrast to a989bdaf8121, but in accordance to old global situation);
wenzelm
parents:
58006
diff
changeset
|
498 |
| eval (Source src) = APPEND_CASES o method_cmd ctxt src ctxt |
58005 | 499 |
| eval (Combinator (_, c, txts)) = |
500 |
let |
|
501 |
val comb = combinator c; |
|
58007
671c607fb4af
just one context for Method.evaluate (in contrast to a989bdaf8121, but in accordance to old global situation);
wenzelm
parents:
58006
diff
changeset
|
502 |
val meths = map eval txts; |
671c607fb4af
just one context for Method.evaluate (in contrast to a989bdaf8121, but in accordance to old global situation);
wenzelm
parents:
58006
diff
changeset
|
503 |
in fn facts => comb (map (fn meth => meth facts) meths) end; |
58003
250ecd2502ad
clarifed Method.evaluate: turn text into semantic method (like Basic);
wenzelm
parents:
58002
diff
changeset
|
504 |
val meth = eval text; |
58007
671c607fb4af
just one context for Method.evaluate (in contrast to a989bdaf8121, but in accordance to old global situation);
wenzelm
parents:
58006
diff
changeset
|
505 |
in fn facts => fn st => meth facts ([], st) end; |
58003
250ecd2502ad
clarifed Method.evaluate: turn text into semantic method (like Basic);
wenzelm
parents:
58002
diff
changeset
|
506 |
|
250ecd2502ad
clarifed Method.evaluate: turn text into semantic method (like Basic);
wenzelm
parents:
58002
diff
changeset
|
507 |
end; |
250ecd2502ad
clarifed Method.evaluate: turn text into semantic method (like Basic);
wenzelm
parents:
58002
diff
changeset
|
508 |
|
250ecd2502ad
clarifed Method.evaluate: turn text into semantic method (like Basic);
wenzelm
parents:
58002
diff
changeset
|
509 |
|
5884 | 510 |
|
17110 | 511 |
(** concrete syntax **) |
5824 | 512 |
|
58048
aa6296d09e0e
more explicit Method.modifier with reported position;
wenzelm
parents:
58034
diff
changeset
|
513 |
(* type modifier *) |
aa6296d09e0e
more explicit Method.modifier with reported position;
wenzelm
parents:
58034
diff
changeset
|
514 |
|
aa6296d09e0e
more explicit Method.modifier with reported position;
wenzelm
parents:
58034
diff
changeset
|
515 |
type modifier = |
aa6296d09e0e
more explicit Method.modifier with reported position;
wenzelm
parents:
58034
diff
changeset
|
516 |
{init: Proof.context -> Proof.context, attribute: attribute, pos: Position.T}; |
5824 | 517 |
|
58048
aa6296d09e0e
more explicit Method.modifier with reported position;
wenzelm
parents:
58034
diff
changeset
|
518 |
fun modifier attribute pos : modifier = {init = I, attribute = attribute, pos = pos}; |
aa6296d09e0e
more explicit Method.modifier with reported position;
wenzelm
parents:
58034
diff
changeset
|
519 |
|
aa6296d09e0e
more explicit Method.modifier with reported position;
wenzelm
parents:
58034
diff
changeset
|
520 |
|
aa6296d09e0e
more explicit Method.modifier with reported position;
wenzelm
parents:
58034
diff
changeset
|
521 |
(* sections *) |
7268 | 522 |
|
59982
f402fd001429
option for old section parser (before 2137e60b6f6d) for the sake of Eisbach;
wenzelm
parents:
59981
diff
changeset
|
523 |
val old_section_parser = |
f402fd001429
option for old section parser (before 2137e60b6f6d) for the sake of Eisbach;
wenzelm
parents:
59981
diff
changeset
|
524 |
Config.bool (Config.declare ("Method.old_section_parser", @{here}) (K (Config.Bool false))); |
f402fd001429
option for old section parser (before 2137e60b6f6d) for the sake of Eisbach;
wenzelm
parents:
59981
diff
changeset
|
525 |
|
f402fd001429
option for old section parser (before 2137e60b6f6d) for the sake of Eisbach;
wenzelm
parents:
59981
diff
changeset
|
526 |
local |
f402fd001429
option for old section parser (before 2137e60b6f6d) for the sake of Eisbach;
wenzelm
parents:
59981
diff
changeset
|
527 |
|
f402fd001429
option for old section parser (before 2137e60b6f6d) for the sake of Eisbach;
wenzelm
parents:
59981
diff
changeset
|
528 |
fun thms ss = |
61476 | 529 |
Scan.repeats (Scan.unless (Scan.lift (Scan.first ss)) Attrib.multi_thm); |
59982
f402fd001429
option for old section parser (before 2137e60b6f6d) for the sake of Eisbach;
wenzelm
parents:
59981
diff
changeset
|
530 |
|
f402fd001429
option for old section parser (before 2137e60b6f6d) for the sake of Eisbach;
wenzelm
parents:
59981
diff
changeset
|
531 |
fun app {init, attribute, pos = _} ths context = |
f402fd001429
option for old section parser (before 2137e60b6f6d) for the sake of Eisbach;
wenzelm
parents:
59981
diff
changeset
|
532 |
fold_map (Thm.apply_attribute attribute) ths (Context.map_proof init context); |
f402fd001429
option for old section parser (before 2137e60b6f6d) for the sake of Eisbach;
wenzelm
parents:
59981
diff
changeset
|
533 |
|
f402fd001429
option for old section parser (before 2137e60b6f6d) for the sake of Eisbach;
wenzelm
parents:
59981
diff
changeset
|
534 |
fun section ss = Scan.depend (fn context => (Scan.first ss -- Scan.pass context (thms ss)) :|-- |
f402fd001429
option for old section parser (before 2137e60b6f6d) for the sake of Eisbach;
wenzelm
parents:
59981
diff
changeset
|
535 |
(fn (m, ths) => Scan.succeed (swap (app m ths context)))); |
f402fd001429
option for old section parser (before 2137e60b6f6d) for the sake of Eisbach;
wenzelm
parents:
59981
diff
changeset
|
536 |
|
f402fd001429
option for old section parser (before 2137e60b6f6d) for the sake of Eisbach;
wenzelm
parents:
59981
diff
changeset
|
537 |
in |
f402fd001429
option for old section parser (before 2137e60b6f6d) for the sake of Eisbach;
wenzelm
parents:
59981
diff
changeset
|
538 |
|
f402fd001429
option for old section parser (before 2137e60b6f6d) for the sake of Eisbach;
wenzelm
parents:
59981
diff
changeset
|
539 |
fun old_sections ss = Scan.repeat (section ss) >> K (); |
f402fd001429
option for old section parser (before 2137e60b6f6d) for the sake of Eisbach;
wenzelm
parents:
59981
diff
changeset
|
540 |
|
f402fd001429
option for old section parser (before 2137e60b6f6d) for the sake of Eisbach;
wenzelm
parents:
59981
diff
changeset
|
541 |
end; |
f402fd001429
option for old section parser (before 2137e60b6f6d) for the sake of Eisbach;
wenzelm
parents:
59981
diff
changeset
|
542 |
|
7268 | 543 |
local |
544 |
||
58048
aa6296d09e0e
more explicit Method.modifier with reported position;
wenzelm
parents:
58034
diff
changeset
|
545 |
fun sect (modifier : modifier parser) = Scan.depend (fn context => |
60211 | 546 |
Scan.ahead Parse.not_eof -- Scan.trace modifier -- Scan.repeat (Scan.unless modifier Parse.xthm) |
547 |
>> (fn ((tok0, ({init, attribute, pos}, modifier_toks)), xthms) => |
|
58029
2137e60b6f6d
clarified Method.section: explicit declaration with static closure;
wenzelm
parents:
58026
diff
changeset
|
548 |
let |
58068 | 549 |
val decl = |
60211 | 550 |
(case Token.get_value tok0 of |
58068 | 551 |
SOME (Token.Declaration decl) => decl |
552 |
| _ => |
|
553 |
let |
|
554 |
val ctxt = Context.proof_of context; |
|
555 |
fun prep_att src = |
|
556 |
let |
|
557 |
val src' = Attrib.check_src ctxt src; |
|
558 |
val _ = List.app (Token.assign NONE) (Token.args_of_src src'); |
|
559 |
in src' end; |
|
560 |
val thms = |
|
561 |
map (fn (a, bs) => (Proof_Context.get_fact ctxt a, map prep_att bs)) xthms; |
|
562 |
val facts = |
|
563 |
Attrib.partial_evaluation ctxt [((Binding.name "dummy", []), thms)] |
|
564 |
|> map (fn (_, bs) => ((Binding.empty, [Attrib.internal (K attribute)]), bs)); |
|
60211 | 565 |
|
58068 | 566 |
fun decl phi = |
567 |
Context.mapping I init #> |
|
568 |
Attrib.generic_notes "" (Attrib.transform_facts phi facts) #> snd; |
|
60211 | 569 |
|
60212 | 570 |
val modifier_report = |
571 |
(Position.set_range (Token.range_of modifier_toks), |
|
572 |
Markup.properties (Position.def_properties_of pos) |
|
573 |
(Markup.entity Markup.method_modifierN "")); |
|
60211 | 574 |
val _ = |
60212 | 575 |
Context_Position.reports ctxt (modifier_report :: Token.reports_of_value tok0); |
60211 | 576 |
val _ = Token.assign (SOME (Token.Declaration decl)) tok0; |
58068 | 577 |
in decl end); |
578 |
in (Morphism.form decl context, decl) end)); |
|
5824 | 579 |
|
30540 | 580 |
in |
581 |
||
59982
f402fd001429
option for old section parser (before 2137e60b6f6d) for the sake of Eisbach;
wenzelm
parents:
59981
diff
changeset
|
582 |
fun sections ss = |
f402fd001429
option for old section parser (before 2137e60b6f6d) for the sake of Eisbach;
wenzelm
parents:
59981
diff
changeset
|
583 |
Args.context :|-- (fn ctxt => |
f402fd001429
option for old section parser (before 2137e60b6f6d) for the sake of Eisbach;
wenzelm
parents:
59981
diff
changeset
|
584 |
if Config.get ctxt old_section_parser then old_sections ss |
f402fd001429
option for old section parser (before 2137e60b6f6d) for the sake of Eisbach;
wenzelm
parents:
59981
diff
changeset
|
585 |
else Scan.repeat (sect (Scan.first ss)) >> K ()); |
5824 | 586 |
|
7268 | 587 |
end; |
588 |
||
5824 | 589 |
|
30515 | 590 |
(* extra rule methods *) |
591 |
||
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
592 |
fun xrule_meth meth = |
36950 | 593 |
Scan.lift (Scan.optional (Args.parens Parse.nat) 0) -- Attrib.thms >> |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
594 |
(fn (n, ths) => fn ctxt => meth ctxt n ths); |
30515 | 595 |
|
596 |
||
55761
213b9811f59f
method language markup, e.g. relevant to prevent outer keyword completion;
wenzelm
parents:
55742
diff
changeset
|
597 |
(* text range *) |
213b9811f59f
method language markup, e.g. relevant to prevent outer keyword completion;
wenzelm
parents:
55742
diff
changeset
|
598 |
|
213b9811f59f
method language markup, e.g. relevant to prevent outer keyword completion;
wenzelm
parents:
55742
diff
changeset
|
599 |
type text_range = text * Position.range; |
213b9811f59f
method language markup, e.g. relevant to prevent outer keyword completion;
wenzelm
parents:
55742
diff
changeset
|
600 |
|
213b9811f59f
method language markup, e.g. relevant to prevent outer keyword completion;
wenzelm
parents:
55742
diff
changeset
|
601 |
fun text NONE = NONE |
213b9811f59f
method language markup, e.g. relevant to prevent outer keyword completion;
wenzelm
parents:
55742
diff
changeset
|
602 |
| text (SOME (txt, _)) = SOME txt; |
213b9811f59f
method language markup, e.g. relevant to prevent outer keyword completion;
wenzelm
parents:
55742
diff
changeset
|
603 |
|
213b9811f59f
method language markup, e.g. relevant to prevent outer keyword completion;
wenzelm
parents:
55742
diff
changeset
|
604 |
fun position NONE = Position.none |
213b9811f59f
method language markup, e.g. relevant to prevent outer keyword completion;
wenzelm
parents:
55742
diff
changeset
|
605 |
| position (SOME (_, (pos, _))) = pos; |
213b9811f59f
method language markup, e.g. relevant to prevent outer keyword completion;
wenzelm
parents:
55742
diff
changeset
|
606 |
|
213b9811f59f
method language markup, e.g. relevant to prevent outer keyword completion;
wenzelm
parents:
55742
diff
changeset
|
607 |
|
55795 | 608 |
(* reports *) |
609 |
||
610 |
local |
|
611 |
||
612 |
fun keyword_positions (Source _) = [] |
|
613 |
| keyword_positions (Basic _) = [] |
|
58005 | 614 |
| keyword_positions (Combinator (Combinator_Info {keywords}, _, texts)) = |
615 |
keywords @ maps keyword_positions texts; |
|
55795 | 616 |
|
617 |
in |
|
618 |
||
619 |
fun reports_of ((text, (pos, _)): text_range) = |
|
620 |
(pos, Markup.language_method) :: |
|
55917
5438ed05e1c9
special treatment of method combinators like Args.$$$ keywords, although parsed via Parse.$$$;
wenzelm
parents:
55828
diff
changeset
|
621 |
maps (fn p => map (pair p) (Markup.keyword3 :: Completion.suppress_abbrevs "")) |
5438ed05e1c9
special treatment of method combinators like Args.$$$ keywords, although parsed via Parse.$$$;
wenzelm
parents:
55828
diff
changeset
|
622 |
(keyword_positions text); |
55795 | 623 |
|
624 |
val report = Position.reports o reports_of; |
|
625 |
||
626 |
end; |
|
627 |
||
628 |
||
59666 | 629 |
(* parser *) |
630 |
||
631 |
local |
|
27813
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
632 |
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
633 |
fun is_symid_meth s = |
36959
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents:
36950
diff
changeset
|
634 |
s <> "|" andalso s <> "?" andalso s <> "+" andalso Token.ident_or_symbolic s; |
27813
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
635 |
|
59981 | 636 |
fun gen_parser check_ctxt pri = |
59666 | 637 |
let |
638 |
val (meth_name, mk_src) = |
|
639 |
(case check_ctxt of |
|
640 |
NONE => (Parse.xname, Token.src) |
|
641 |
| SOME ctxt => |
|
642 |
(Args.checked_name (fn (xname, _) => check_name ctxt (xname, Position.none)), |
|
59914
d1ddcd8df4e4
proper treatment of internal method name as already checked Token.src;
wenzelm
parents:
59909
diff
changeset
|
643 |
fn (name, pos) => fn args => Token.src_checked (name, pos) args (checked_info ctxt name))); |
27813
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
644 |
|
59666 | 645 |
fun meth5 x = |
646 |
(Parse.position meth_name >> (fn name => Source (mk_src name [])) || |
|
647 |
Scan.ahead Parse.cartouche |-- Parse.not_eof >> (fn tok => |
|
648 |
Source (mk_src ("cartouche", Token.pos_of tok) [tok])) || |
|
649 |
Parse.$$$ "(" |-- Parse.!!! (meth0 --| Parse.$$$ ")")) x |
|
650 |
and meth4 x = |
|
651 |
(meth5 -- Parse.position (Parse.$$$ "?") |
|
652 |
>> (fn (m, (_, pos)) => Combinator (combinator_info [pos], Try, [m])) || |
|
653 |
meth5 -- Parse.position (Parse.$$$ "+") |
|
654 |
>> (fn (m, (_, pos)) => Combinator (combinator_info [pos], Repeat1, [m])) || |
|
59914
d1ddcd8df4e4
proper treatment of internal method name as already checked Token.src;
wenzelm
parents:
59909
diff
changeset
|
655 |
meth5 -- (Parse.position (Parse.$$$ "[") -- |
d1ddcd8df4e4
proper treatment of internal method name as already checked Token.src;
wenzelm
parents:
59909
diff
changeset
|
656 |
Scan.optional Parse.nat 1 -- Parse.position (Parse.$$$ "]")) |
59666 | 657 |
>> (fn (m, (((_, pos1), n), (_, pos2))) => |
658 |
Combinator (combinator_info [pos1, pos2], Select_Goals n, [m])) || |
|
659 |
meth5) x |
|
660 |
and meth3 x = |
|
661 |
(Parse.position meth_name -- Parse.args1 is_symid_meth >> (Source o uncurry mk_src) || |
|
662 |
meth4) x |
|
663 |
and meth2 x = |
|
664 |
(Parse.enum1_positions "," meth3 |
|
665 |
>> (fn ([m], _) => m | (ms, ps) => Combinator (combinator_info ps, Then, ms))) x |
|
666 |
and meth1 x = |
|
667 |
(Parse.enum1_positions ";" meth2 |
|
668 |
>> (fn ([m], _) => m | (ms, ps) => Combinator (combinator_info ps, Then_All_New, ms))) x |
|
669 |
and meth0 x = |
|
670 |
(Parse.enum1_positions "|" meth1 |
|
671 |
>> (fn ([m], _) => m | (ms, ps) => Combinator (combinator_info ps, Orelse, ms))) x; |
|
59981 | 672 |
|
673 |
val meth = |
|
674 |
nth [meth0, meth1, meth2, meth3, meth4, meth5] pri |
|
675 |
handle General.Subscript => raise Fail ("Bad method parser priority " ^ string_of_int pri); |
|
676 |
in Scan.trace meth >> (fn (m, toks) => (m, Token.range_of toks)) end; |
|
27813
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
677 |
|
49866 | 678 |
in |
679 |
||
59981 | 680 |
val parser' = gen_parser o SOME; |
681 |
val parser = gen_parser NONE; |
|
682 |
val parse = parser 4; |
|
49866 | 683 |
|
55761
213b9811f59f
method language markup, e.g. relevant to prevent outer keyword completion;
wenzelm
parents:
55742
diff
changeset
|
684 |
end; |
27813
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
685 |
|
96fbe385a0d0
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27751
diff
changeset
|
686 |
|
18708 | 687 |
(* theory setup *) |
5824 | 688 |
|
53171 | 689 |
val _ = Theory.setup |
56204 | 690 |
(setup @{binding fail} (Scan.succeed (K fail)) "force failure" #> |
691 |
setup @{binding succeed} (Scan.succeed (K succeed)) "succeed" #> |
|
60554 | 692 |
setup @{binding sleep} (Scan.lift Parse.real >> (fn s => fn _ => fn _ => sleep (seconds s))) |
693 |
"succeed after delay (in seconds)" #> |
|
56204 | 694 |
setup @{binding "-"} (Scan.succeed (K insert_facts)) |
60578 | 695 |
"insert current facts, nothing else" #> |
61166
5976fe402824
renamed method "goals" to "goal_cases" to emphasize its meaning;
wenzelm
parents:
61164
diff
changeset
|
696 |
setup @{binding goal_cases} (Scan.lift (Scan.repeat Args.name_token) >> (fn names => fn ctxt => |
61164 | 697 |
METHOD_CASES (fn facts => fn st => |
698 |
let |
|
699 |
val _ = |
|
700 |
(case drop (Thm.nprems_of st) names of |
|
701 |
[] => () |
|
702 |
| bad => |
|
703 |
if detect_closure_state st then () |
|
704 |
else |
|
705 |
(* FIXME Seq.Error *) |
|
706 |
error ("Excessive case names: " ^ commas_quote (map Token.content_of bad) ^ |
|
707 |
Position.here (Position.set_range (Token.range_of bad)))); |
|
61166
5976fe402824
renamed method "goals" to "goal_cases" to emphasize its meaning;
wenzelm
parents:
61164
diff
changeset
|
708 |
in goal_cases_tac ctxt (map Token.content_of names) st end))) |
61164 | 709 |
"bind cases for goals" #> |
56204 | 710 |
setup @{binding insert} (Attrib.thms >> (K o insert)) |
60578 | 711 |
"insert theorems, ignoring facts" #> |
58957 | 712 |
setup @{binding intro} (Attrib.thms >> (fn ths => fn ctxt => intro ctxt ths)) |
30515 | 713 |
"repeatedly apply introduction rules" #> |
58957 | 714 |
setup @{binding elim} (Attrib.thms >> (fn ths => fn ctxt => elim ctxt ths)) |
30515 | 715 |
"repeatedly apply elimination rules" #> |
56204 | 716 |
setup @{binding unfold} (Attrib.thms >> unfold_meth) "unfold definitions" #> |
717 |
setup @{binding fold} (Attrib.thms >> fold_meth) "fold definitions" #> |
|
718 |
setup @{binding atomize} (Scan.lift (Args.mode "full") >> atomize) |
|
30515 | 719 |
"present local premises as object-level statements" #> |
56204 | 720 |
setup @{binding rule} (Attrib.thms >> (fn ths => fn ctxt => some_rule ctxt ths)) |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
53171
diff
changeset
|
721 |
"apply some intro/elim rule" #> |
56204 | 722 |
setup @{binding erule} (xrule_meth erule) "apply rule in elimination manner (improper)" #> |
723 |
setup @{binding drule} (xrule_meth drule) "apply rule in destruct manner (improper)" #> |
|
724 |
setup @{binding frule} (xrule_meth frule) "apply rule in forward manner (improper)" #> |
|
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
59067
diff
changeset
|
725 |
setup @{binding this} (Scan.succeed this) "apply current facts as rules" #> |
56204 | 726 |
setup @{binding fact} (Attrib.thms >> fact) "composition by facts from context" #> |
727 |
setup @{binding assumption} (Scan.succeed assumption) |
|
30515 | 728 |
"proof by assumption, preferring facts" #> |
56204 | 729 |
setup @{binding rename_tac} (Args.goal_spec -- Scan.lift (Scan.repeat1 Args.name) >> |
52732 | 730 |
(fn (quant, xs) => K (SIMPLE_METHOD'' quant (rename_tac xs)))) |
30515 | 731 |
"rename parameters of goal" #> |
56204 | 732 |
setup @{binding rotate_tac} (Args.goal_spec -- Scan.lift (Scan.optional Parse.int 1) >> |
52732 | 733 |
(fn (quant, i) => K (SIMPLE_METHOD'' quant (rotate_tac i)))) |
30515 | 734 |
"rotate assumptions of goal" #> |
58018
beb4b7c0bb30
proper static closure of ML tactic -- data slot is used twice, for ML compiler and transformed declaration;
wenzelm
parents:
58016
diff
changeset
|
735 |
setup @{binding tactic} (parse_tactic >> (K o METHOD)) |
30515 | 736 |
"ML tactic as proof method" #> |
59953 | 737 |
setup @{binding raw_tactic} (parse_tactic >> (fn tac => fn _ => EMPTY_CASES o tac)) |
53171 | 738 |
"ML tactic as raw proof method"); |
5824 | 739 |
|
740 |
||
16145 | 741 |
(*final declarations of this structure!*) |
742 |
val unfold = unfold_meth; |
|
743 |
val fold = fold_meth; |
|
744 |
||
5824 | 745 |
end; |
746 |
||
30508
958cc116d03b
tuned Method exports: non-pervasive type method (cf. Proof.method), pervasive METHOD combinators;
wenzelm
parents:
30466
diff
changeset
|
747 |
val METHOD_CASES = Method.METHOD_CASES; |
958cc116d03b
tuned Method exports: non-pervasive type method (cf. Proof.method), pervasive METHOD combinators;
wenzelm
parents:
30466
diff
changeset
|
748 |
val METHOD = Method.METHOD; |
958cc116d03b
tuned Method exports: non-pervasive type method (cf. Proof.method), pervasive METHOD combinators;
wenzelm
parents:
30466
diff
changeset
|
749 |
val SIMPLE_METHOD = Method.SIMPLE_METHOD; |
958cc116d03b
tuned Method exports: non-pervasive type method (cf. Proof.method), pervasive METHOD combinators;
wenzelm
parents:
30466
diff
changeset
|
750 |
val SIMPLE_METHOD' = Method.SIMPLE_METHOD'; |
958cc116d03b
tuned Method exports: non-pervasive type method (cf. Proof.method), pervasive METHOD combinators;
wenzelm
parents:
30466
diff
changeset
|
751 |
val SIMPLE_METHOD'' = Method.SIMPLE_METHOD''; |