-
Notifications
You must be signed in to change notification settings - Fork 0
/
Local_Method.thy
55 lines (45 loc) · 1.43 KB
/
Local_Method.thy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
(*
* Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
*
* SPDX-License-Identifier: BSD-2-Clause
*)
theory Local_Method
imports Main
keywords "supply_local_method" :: prf_script % "proof"
begin
text \<open>See documentation in @{path Local_Method_Tests.thy}.\<close>
ML \<open>
structure MethodData = Proof_Data(
type T = Method.method Symtab.table
val init = K Symtab.empty);
\<close>
method_setup local_method = \<open>
Scan.lift Parse.liberal_name >>
(fn name => fn _ => fn facts => fn (ctxt, st) =>
case (ctxt |> MethodData.get |> Symtab.lookup) name of
SOME method => method facts (ctxt, st)
| NONE => Seq.succeed (Seq.Error (K ("Couldn't find method text named " ^ quote name))))
\<close>
ML \<open>
local
val parse_name_text_ranges =
Scan.repeat1 (Parse.liberal_name --| Parse.!!! @{keyword "="} -- Method.parse)
fun supply_method_cmd name_text_ranges ctxt =
let
fun add_method ((name, (text, range)), ctxt) =
let
val _ = Method.report (text, range)
val method = Method.evaluate text ctxt
in
MethodData.map (Symtab.update (name, method)) ctxt
end
in
List.foldr add_method ctxt name_text_ranges
end
val _ =
Outer_Syntax.command @{command_keyword\<open>supply_local_method\<close>}
"Add a local method alias to the current proof context"
(parse_name_text_ranges >> (Toplevel.proof o Proof.map_context o supply_method_cmd))
in end
\<close>
end