59 (Symtab.update (Local_Theory.full_name lthy binding, |
59 (Symtab.update (Local_Theory.full_name lthy binding, |
60 (((map (Morphism.term phi) fixes), |
60 (((map (Morphism.term phi) fixes), |
61 (map (Morphism_name phi) declares, map (Morphism_name phi) methods)), |
61 (map (Morphism_name phi) declares, map (Morphism_name phi) methods)), |
62 (Method.map_source o map) (Token.transform phi) text)))); |
62 (Method.map_source o map) (Token.transform phi) text)))); |
63 |
63 |
|
64 |
|
65 (* context data for method definition *) |
64 |
66 |
65 structure Local_Data = Proof_Data |
67 structure Local_Data = Proof_Data |
66 ( |
68 ( |
67 type T = |
69 type T = |
68 (Proof.context -> Method.method) Symtab.table * (*dynamic methods*) |
70 (Proof.context -> Method.method) Symtab.table * (*dynamic methods*) |
112 val (text, src) = read_closure_input ctxt (Token.input_of tok); |
114 val (text, src) = read_closure_input ctxt (Token.input_of tok); |
113 val _ = Token.assign (SOME (Token.Source src)) tok; |
115 val _ = Token.assign (SOME (Token.Source src)) tok; |
114 in text end)); |
116 in text end)); |
115 |
117 |
116 |
118 |
117 fun check_attrib ctxt attrib = |
119 (* evaluate method text *) |
118 let |
|
119 val name = Binding.name_of attrib; |
|
120 val pos = Binding.pos_of attrib; |
|
121 val named_thm = Named_Theorems.check ctxt (name, pos); |
|
122 val parser: Method.modifier parser = |
|
123 Args.$$$ name -- Args.colon >> |
|
124 K {init = I, attribute = Named_Theorems.add named_thm, pos = pos}; |
|
125 in (named_thm, parser) end; |
|
126 |
|
127 |
120 |
128 fun method_evaluate text ctxt = |
121 fun method_evaluate text ctxt = |
129 let |
122 let |
130 val text' = |
123 val text' = |
131 text |> (Method.map_source o map o Token.map_facts) |
124 text |> (Method.map_source o map o Token.map_facts) |
141 let |
134 let |
142 val morphism = Morphism.term_morphism "method_instantiate" (Envir.norm_term env); |
135 val morphism = Morphism.term_morphism "method_instantiate" (Envir.norm_term env); |
143 val text' = (Method.map_source o map) (Token.transform morphism) text; |
136 val text' = (Method.map_source o map) (Token.transform morphism) text; |
144 in method_evaluate text' end; |
137 in method_evaluate text' end; |
145 |
138 |
|
139 |
|
140 |
|
141 (** Isar command **) |
|
142 |
|
143 local |
|
144 |
146 fun setup_local_method binding lthy = |
145 fun setup_local_method binding lthy = |
147 let |
146 let |
148 val full_name = Local_Theory.full_name lthy binding; |
147 val full_name = Local_Theory.full_name lthy binding; |
149 fun get_method ctxt = lookup_dynamic_method ctxt full_name ctxt; |
148 fun get_method ctxt = lookup_dynamic_method ctxt full_name ctxt; |
150 in |
149 in |
151 lthy |
150 lthy |
152 |> update_dynamic_method (full_name, K Method.fail) |
151 |> update_dynamic_method (full_name, K Method.fail) |
153 |> Method.local_setup binding (Scan.succeed get_method) "(internal)" |
152 |> Method.local_setup binding (Scan.succeed get_method) "(internal)" |
154 end; |
153 end; |
155 |
154 |
|
155 fun check_attrib ctxt attrib = |
|
156 let |
|
157 val name = Binding.name_of attrib; |
|
158 val pos = Binding.pos_of attrib; |
|
159 val named_thm = Named_Theorems.check ctxt (name, pos); |
|
160 val parser: Method.modifier parser = |
|
161 Args.$$$ name -- Args.colon >> |
|
162 K {init = I, attribute = Named_Theorems.add named_thm, pos = pos}; |
|
163 in (named_thm, parser) end; |
|
164 |
156 fun dummy_named_thm named_thm = |
165 fun dummy_named_thm named_thm = |
157 Context.proof_map |
166 Context.proof_map |
158 (Named_Theorems.clear named_thm |
167 (Named_Theorems.clear named_thm |
159 #> Named_Theorems.add_thm named_thm Drule.free_dummy_thm); |
168 #> Named_Theorems.add_thm named_thm Drule.free_dummy_thm); |
160 |
|
161 fun parse_method_args method_names = |
|
162 let |
|
163 fun bind_method (name, text) ctxt = |
|
164 let |
|
165 val method = method_evaluate text; |
|
166 val inner_update = method o update_dynamic_method (name, K (method ctxt)); |
|
167 in update_dynamic_method (name, inner_update) ctxt end; |
|
168 |
|
169 fun rep [] x = Scan.succeed [] x |
|
170 | rep (t :: ts) x = ((method_text >> pair t) ::: rep ts) x; |
|
171 in rep method_names >> fold bind_method end; |
|
172 |
|
173 |
|
174 |
|
175 (** Isar command **) |
|
176 |
|
177 local |
|
178 |
169 |
179 fun parse_term_args args = |
170 fun parse_term_args args = |
180 Args.context :|-- (fn ctxt => |
171 Args.context :|-- (fn ctxt => |
181 let |
172 let |
182 val ctxt' = Proof_Context.set_mode (Proof_Context.mode_schematic) ctxt; |
173 val ctxt' = Proof_Context.set_mode (Proof_Context.mode_schematic) ctxt; |
209 val tyenv = fold match_types (args ~~ ts) Vartab.empty; |
200 val tyenv = fold match_types (args ~~ ts) Vartab.empty; |
210 val tenv = |
201 val tenv = |
211 fold (fn ((xi, T), t) => Vartab.update_new (xi, (T, t))) |
202 fold (fn ((xi, T), t) => Vartab.update_new (xi, (T, t))) |
212 (map Term.dest_Var args ~~ ts) Vartab.empty; |
203 (map Term.dest_Var args ~~ ts) Vartab.empty; |
213 in Envir.Envir {maxidx = ~1, tenv = tenv, tyenv = tyenv} end; |
204 in Envir.Envir {maxidx = ~1, tenv = tenv, tyenv = tyenv} end; |
|
205 |
|
206 fun parse_method_args method_names = |
|
207 let |
|
208 fun bind_method (name, text) ctxt = |
|
209 let |
|
210 val method = method_evaluate text; |
|
211 val inner_update = method o update_dynamic_method (name, K (method ctxt)); |
|
212 in update_dynamic_method (name, inner_update) ctxt end; |
|
213 |
|
214 fun rep [] x = Scan.succeed [] x |
|
215 | rep (t :: ts) x = ((method_text >> pair t) ::: rep ts) x; |
|
216 in rep method_names >> fold bind_method end; |
214 |
217 |
215 fun gen_method add_fixes name vars uses declares methods source lthy = |
218 fun gen_method add_fixes name vars uses declares methods source lthy = |
216 let |
219 let |
217 val (uses_internal, lthy1) = lthy |
220 val (uses_internal, lthy1) = lthy |
218 |> Proof_Context.concealed |
221 |> Proof_Context.concealed |