author | wenzelm |
Mon, 02 Dec 2024 14:08:28 +0100 | |
changeset 81537 | d230683a35fc |
parent 81535 | db073d1733ab |
permissions | -rw-r--r-- |
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
1 |
(* Title: Pure/facts.ML |
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
3 |
|
26307 | 4 |
Environment of named facts, optionally indexed by proposition. |
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
5 |
*) |
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
6 |
|
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
7 |
signature FACTS = |
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
8 |
sig |
70574 | 9 |
val err_selection: string * Position.T -> int -> thm list -> 'a |
10 |
val err_single: string * Position.T -> thm list -> 'a |
|
55740 | 11 |
val the_single: string * Position.T -> thm list -> thm |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
12 |
datatype interval = FromTo of int * int | From of int | Single of int |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
13 |
datatype ref = |
26361 | 14 |
Named of (string * Position.T) * interval list option | |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
15 |
Fact of string |
26361 | 16 |
val named: string -> ref |
70545 | 17 |
val ref_name: ref -> string |
18 |
val ref_pos: ref -> Position.T |
|
19 |
val map_ref_name: (string -> string) -> ref -> ref |
|
49887 | 20 |
val string_of_selection: interval list option -> string |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
21 |
val string_of_ref: ref -> string |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
22 |
val select: ref -> thm list -> thm list |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
23 |
val selections: string * thm list -> (ref * thm) list |
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
24 |
type T |
26393 | 25 |
val empty: T |
33095
bbd52d2f8696
renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
wenzelm
parents:
33093
diff
changeset
|
26 |
val space_of: T -> Name_Space.T |
77979
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
wenzelm
parents:
77970
diff
changeset
|
27 |
val alias: Name_Space.naming -> binding -> string -> T -> T |
33163 | 28 |
val is_concealed: T -> string -> bool |
56003 | 29 |
val check: Context.generic -> T -> xstring * Position.T -> string |
26664
167d879a89b0
renamed dest to dest_table, and extern to extern table;
wenzelm
parents:
26654
diff
changeset
|
30 |
val intern: T -> xstring -> string |
42358
b47d41d9f4b5
Name_Space: proper configuration options long_names, short_names, unique_names instead of former unsynchronized references;
wenzelm
parents:
35408
diff
changeset
|
31 |
val extern: Proof.context -> T -> string -> xstring |
56140
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
wenzelm
parents:
56137
diff
changeset
|
32 |
val markup_extern: Proof.context -> T -> string -> Markup.T * xstring |
81535 | 33 |
val pretty_thm_name: Proof.context -> T -> Thm_Name.T -> Pretty.T |
63080
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
34 |
val defined: T -> string -> bool |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
35 |
val is_dynamic: T -> string -> bool |
63255 | 36 |
val lookup: Context.generic -> T -> string -> {dynamic: bool, thms: thm list} option |
57942
e5bec882fdd0
more informative Token.Fact: retain name of dynamic fact (without selection);
wenzelm
parents:
57887
diff
changeset
|
37 |
val retrieve: Context.generic -> T -> xstring * Position.T -> |
63255 | 38 |
{name: string, dynamic: bool, thms: thm list} |
26692 | 39 |
val fold_static: (string * thm list -> 'a -> 'a) -> T -> 'a -> 'a |
56158
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
wenzelm
parents:
56140
diff
changeset
|
40 |
val dest_static: bool -> T list -> T -> (string * thm list) list |
63080
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
41 |
val dest_all: Context.generic -> bool -> T list -> T -> (string * thm list) list |
63337 | 42 |
val props: T -> (thm * Position.T) list |
43 |
val could_unify: T -> term -> (thm * Position.T) list |
|
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
44 |
val merge: T * T -> T |
49747 | 45 |
val add_static: Context.generic -> {strict: bool, index: bool} -> |
67662 | 46 |
binding * thm list lazy -> T -> string * T |
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
42375
diff
changeset
|
47 |
val add_dynamic: Context.generic -> binding * (Context.generic -> thm list) -> T -> string * T |
26654
1f711934f221
disallow duplicate entries (weak version for merge);
wenzelm
parents:
26393
diff
changeset
|
48 |
val del: string -> T -> T |
1f711934f221
disallow duplicate entries (weak version for merge);
wenzelm
parents:
26393
diff
changeset
|
49 |
val hide: bool -> string -> T -> T |
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
50 |
end; |
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
51 |
|
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
52 |
structure Facts: FACTS = |
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
53 |
struct |
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
54 |
|
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
55 |
(** fact references **) |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
56 |
|
70546 | 57 |
fun length_msg (thms: thm list) pos = |
58 |
" (length " ^ string_of_int (length thms) ^ ")" ^ Position.here pos; |
|
59 |
||
60 |
fun err_selection (name, pos) i thms = |
|
61 |
error ("Bad fact selection " ^ quote (name ^ enclose "(" ")" (string_of_int i)) ^ |
|
62 |
length_msg thms pos); |
|
63 |
||
70574 | 64 |
fun err_single (name, pos) thms = |
65 |
error ("Expected singleton fact " ^ quote name ^ length_msg thms pos); |
|
66 |
||
70546 | 67 |
fun the_single _ [thm] = thm |
68 |
| the_single name_pos thms = err_single name_pos thms; |
|
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
69 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
70 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
71 |
(* datatype interval *) |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
72 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
73 |
datatype interval = |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
74 |
FromTo of int * int | |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
75 |
From of int | |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
76 |
Single of int; |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
77 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
78 |
fun string_of_interval (FromTo (i, j)) = string_of_int i ^ "-" ^ string_of_int j |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
79 |
| string_of_interval (From i) = string_of_int i ^ "-" |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
80 |
| string_of_interval (Single i) = string_of_int i; |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
81 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
82 |
fun interval n iv = |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
83 |
let fun err () = raise Fail ("Bad interval specification " ^ string_of_interval iv) in |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
84 |
(case iv of |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
85 |
FromTo (i, j) => if i <= j then i upto j else err () |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
86 |
| From i => if i <= n then i upto n else err () |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
87 |
| Single i => [i]) |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
88 |
end; |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
89 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
90 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
91 |
(* datatype ref *) |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
92 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
93 |
datatype ref = |
26361 | 94 |
Named of (string * Position.T) * interval list option | |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
95 |
Fact of string; |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
96 |
|
26361 | 97 |
fun named name = Named ((name, Position.none), NONE); |
98 |
||
70545 | 99 |
fun ref_name (Named ((name, _), _)) = name |
100 |
| ref_name (Fact _) = raise Fail "Illegal literal fact"; |
|
55740 | 101 |
|
70545 | 102 |
fun ref_pos (Named ((_, pos), _)) = pos |
103 |
| ref_pos (Fact _) = Position.none; |
|
55740 | 104 |
|
70545 | 105 |
fun map_ref_name f (Named ((name, pos), is)) = Named ((f name, pos), is) |
106 |
| map_ref_name _ r = r; |
|
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
107 |
|
49887 | 108 |
fun string_of_selection NONE = "" |
109 |
| string_of_selection (SOME is) = enclose "(" ")" (commas (map string_of_interval is)); |
|
110 |
||
111 |
fun string_of_ref (Named ((name, _), sel)) = name ^ string_of_selection sel |
|
112 |
| string_of_ref (Fact _) = raise Fail "Illegal literal fact"; |
|
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
113 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
114 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
115 |
(* select *) |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
116 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
117 |
fun select (Fact _) ths = ths |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
118 |
| select (Named (_, NONE)) ths = ths |
26361 | 119 |
| select (Named ((name, pos), SOME ivs)) ths = |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
120 |
let |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
121 |
val n = length ths; |
70546 | 122 |
fun err msg = error (msg ^ " for fact " ^ quote name ^ length_msg ths pos); |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
123 |
fun sel i = |
70546 | 124 |
if i > 0 andalso i <= n then nth ths (i - 1) |
125 |
else err_selection (name, pos) i ths; |
|
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
126 |
val is = maps (interval n) ivs handle Fail msg => err msg; |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
127 |
in map sel is end; |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
128 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
129 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
130 |
(* selections *) |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
131 |
|
26361 | 132 |
fun selections (name, [th]) = [(Named ((name, Position.none), NONE), th)] |
133 |
| selections (name, ths) = map2 (fn i => fn th => |
|
134 |
(Named ((name, Position.none), SOME [Single i]), th)) (1 upto length ths) ths; |
|
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
135 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
136 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
137 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
138 |
(** fact environment **) |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
139 |
|
26393 | 140 |
(* datatypes *) |
141 |
||
67662 | 142 |
datatype fact = Static of thm list lazy | Dynamic of Context.generic -> thm list; |
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
143 |
|
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
144 |
datatype T = Facts of |
33095
bbd52d2f8696
renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
wenzelm
parents:
33093
diff
changeset
|
145 |
{facts: fact Name_Space.table, |
63337 | 146 |
props: (thm * Position.T) Net.net}; |
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
147 |
|
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
148 |
fun make_facts facts props = Facts {facts = facts, props = props}; |
33163 | 149 |
|
74112 | 150 |
val empty = make_facts (Name_Space.empty_table Markup.factN) Net.empty; |
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
151 |
|
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
152 |
|
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
153 |
(* named facts *) |
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
154 |
|
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
155 |
fun facts_of (Facts {facts, ...}) = facts; |
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
156 |
|
56025 | 157 |
val space_of = Name_Space.space_of_table o facts_of; |
26393 | 158 |
|
77979
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
wenzelm
parents:
77970
diff
changeset
|
159 |
fun alias naming binding name (Facts {facts, props}) = |
a12c48fbf10f
back to more elementary concept of aliases as adhoc change of accesses, but now with "suppress" information (see also 31ea5c1f874d);
wenzelm
parents:
77970
diff
changeset
|
160 |
make_facts (Name_Space.alias_table naming binding name facts) props; |
57887 | 161 |
|
33163 | 162 |
val is_concealed = Name_Space.is_concealed o space_of; |
163 |
||
56003 | 164 |
fun check context facts (xname, pos) = |
165 |
let |
|
166 |
val (name, fact) = Name_Space.check context (facts_of facts) (xname, pos); |
|
167 |
val _ = |
|
168 |
(case fact of |
|
169 |
Static _ => () |
|
170 |
| Dynamic _ => Context_Position.report_generic context pos (Markup.dynamic_fact name)); |
|
171 |
in name end; |
|
172 |
||
33095
bbd52d2f8696
renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
wenzelm
parents:
33093
diff
changeset
|
173 |
val intern = Name_Space.intern o space_of; |
42358
b47d41d9f4b5
Name_Space: proper configuration options long_names, short_names, unique_names instead of former unsynchronized references;
wenzelm
parents:
35408
diff
changeset
|
174 |
fun extern ctxt = Name_Space.extern ctxt o space_of; |
57887 | 175 |
fun markup_extern ctxt = Name_Space.markup_extern ctxt o space_of; |
26664
167d879a89b0
renamed dest to dest_table, and extern to extern table;
wenzelm
parents:
26654
diff
changeset
|
176 |
|
81535 | 177 |
fun pretty_thm_name ctxt facts thm_name = |
80299
a397fd0c451a
more accurate output of Thm_Name.T wrt. facts name space;
wenzelm
parents:
77979
diff
changeset
|
178 |
let |
81535 | 179 |
val prfx = Thm_Name.print_prefix ctxt (space_of facts) thm_name; |
80299
a397fd0c451a
more accurate output of Thm_Name.T wrt. facts name space;
wenzelm
parents:
77979
diff
changeset
|
180 |
val sffx = Thm_Name.print_suffix thm_name; |
a397fd0c451a
more accurate output of Thm_Name.T wrt. facts name space;
wenzelm
parents:
77979
diff
changeset
|
181 |
in Pretty.block [Pretty.mark_str prfx, Pretty.str sffx] end; |
a397fd0c451a
more accurate output of Thm_Name.T wrt. facts name space;
wenzelm
parents:
77979
diff
changeset
|
182 |
|
56158
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
wenzelm
parents:
56140
diff
changeset
|
183 |
|
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
wenzelm
parents:
56140
diff
changeset
|
184 |
(* retrieve *) |
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
wenzelm
parents:
56140
diff
changeset
|
185 |
|
59883 | 186 |
val defined = Name_Space.defined o facts_of; |
26692 | 187 |
|
63080
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
188 |
fun is_dynamic facts name = |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
189 |
(case Name_Space.lookup (facts_of facts) name of |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
190 |
SOME (Dynamic _) => true |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
191 |
| _ => false); |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
192 |
|
26393 | 193 |
fun lookup context facts name = |
59884 | 194 |
(case Name_Space.lookup (facts_of facts) name of |
26393 | 195 |
NONE => NONE |
67662 | 196 |
| SOME (Static ths) => SOME {dynamic = false, thms = Lazy.force ths} |
63255 | 197 |
| SOME (Dynamic f) => SOME {dynamic = true, thms = f context}); |
26393 | 198 |
|
56140
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
wenzelm
parents:
56137
diff
changeset
|
199 |
fun retrieve context facts (xname, pos) = |
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
wenzelm
parents:
56137
diff
changeset
|
200 |
let |
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
wenzelm
parents:
56137
diff
changeset
|
201 |
val name = check context facts (xname, pos); |
63255 | 202 |
val {dynamic, thms} = |
56140
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
wenzelm
parents:
56137
diff
changeset
|
203 |
(case lookup context facts name of |
63255 | 204 |
SOME res => |
205 |
(if #dynamic res |
|
206 |
then Context_Position.report_generic context pos (Markup.dynamic_fact name) |
|
207 |
else (); |
|
208 |
res) |
|
56140
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
wenzelm
parents:
56137
diff
changeset
|
209 |
| NONE => error ("Unknown fact " ^ quote name ^ Position.here pos)); |
57942
e5bec882fdd0
more informative Token.Fact: retain name of dynamic fact (without selection);
wenzelm
parents:
57887
diff
changeset
|
210 |
in |
e5bec882fdd0
more informative Token.Fact: retain name of dynamic fact (without selection);
wenzelm
parents:
57887
diff
changeset
|
211 |
{name = name, |
63255 | 212 |
dynamic = dynamic, |
67649 | 213 |
thms = map (Thm.transfer'' context) thms} |
57942
e5bec882fdd0
more informative Token.Fact: retain name of dynamic fact (without selection);
wenzelm
parents:
57887
diff
changeset
|
214 |
end; |
56140
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
wenzelm
parents:
56137
diff
changeset
|
215 |
|
56158
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
wenzelm
parents:
56140
diff
changeset
|
216 |
|
63080
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
217 |
(* content *) |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
218 |
|
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
219 |
local |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
220 |
|
67662 | 221 |
fun fold_static_lazy f = |
222 |
Name_Space.fold_table (fn (a, Static ths) => f (a, ths) | _ => I) o facts_of; |
|
223 |
||
67668 | 224 |
fun consolidate facts = |
67662 | 225 |
let |
68698
6ee53660a911
eliminated non-monotomnic Lazy.is_pending: Result may return to Expr due to Interrupt;
wenzelm
parents:
67676
diff
changeset
|
226 |
val unfinished = |
74234 | 227 |
build (facts |> fold_static_lazy (fn (_, ths) => |
228 |
if Lazy.is_finished ths then I else cons ths)); |
|
68698
6ee53660a911
eliminated non-monotomnic Lazy.is_pending: Result may return to Expr due to Interrupt;
wenzelm
parents:
67676
diff
changeset
|
229 |
val _ = Lazy.consolidate unfinished; |
67668 | 230 |
in facts end; |
67662 | 231 |
|
63080
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
232 |
fun included verbose prev_facts facts name = |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
233 |
not (exists (fn prev => defined prev name) prev_facts orelse |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
234 |
not verbose andalso is_concealed facts name); |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
235 |
|
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
236 |
in |
56158
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
wenzelm
parents:
56140
diff
changeset
|
237 |
|
67662 | 238 |
fun fold_static f facts = |
67668 | 239 |
fold_static_lazy (f o apsnd Lazy.force) (consolidate facts); |
26393 | 240 |
|
56158
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
wenzelm
parents:
56140
diff
changeset
|
241 |
fun dest_static verbose prev_facts facts = |
63080
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
242 |
fold_static (fn (a, ths) => included verbose prev_facts facts a ? cons (a, ths)) facts [] |
60924
610794dff23c
tuned signature, in accordance to sortBy in Scala;
wenzelm
parents:
59884
diff
changeset
|
243 |
|> sort_by #1; |
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
244 |
|
63080
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
245 |
fun dest_all context verbose prev_facts facts = |
67668 | 246 |
(facts_of (consolidate facts), []) |
67662 | 247 |
|-> Name_Space.fold_table (fn (a, fact) => |
248 |
let val ths = (case fact of Static ths => Lazy.force ths | Dynamic f => f context) |
|
249 |
in included verbose prev_facts facts a ? cons (a, ths) end) |
|
63080
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
250 |
|> sort_by #1; |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
251 |
|
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
252 |
end; |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
253 |
|
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
254 |
|
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
255 |
(* indexed props *) |
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
256 |
|
63337 | 257 |
val prop_ord = Term_Ord.term_ord o apply2 (Thm.full_prop_of o fst); |
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
258 |
|
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
259 |
fun props (Facts {props, ...}) = sort_distinct prop_ord (Net.content props); |
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
260 |
fun could_unify (Facts {props, ...}) = Net.unify_term props; |
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
261 |
|
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
262 |
|
26393 | 263 |
(* merge facts *) |
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
264 |
|
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
265 |
fun merge (Facts {facts = facts1, props = props1}, Facts {facts = facts2, props = props2}) = |
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
266 |
let |
33095
bbd52d2f8696
renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
wenzelm
parents:
33093
diff
changeset
|
267 |
val facts' = Name_Space.merge_tables (facts1, facts2); |
56137
af71fb1cb31f
minor tuning -- NB: props are usually empty for global facts;
wenzelm
parents:
56025
diff
changeset
|
268 |
val props' = |
af71fb1cb31f
minor tuning -- NB: props are usually empty for global facts;
wenzelm
parents:
56025
diff
changeset
|
269 |
if Net.is_empty props2 then props1 |
af71fb1cb31f
minor tuning -- NB: props are usually empty for global facts;
wenzelm
parents:
56025
diff
changeset
|
270 |
else if Net.is_empty props1 then props2 |
af71fb1cb31f
minor tuning -- NB: props are usually empty for global facts;
wenzelm
parents:
56025
diff
changeset
|
271 |
else Net.merge (is_equal o prop_ord) (props1, props2); (*beware of non-canonical merge*) |
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
272 |
in make_facts facts' props' end; |
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
273 |
|
26393 | 274 |
|
67662 | 275 |
(* add entries *) |
276 |
||
277 |
fun add_prop pos th = |
|
278 |
Net.insert_term (K false) (Thm.full_prop_of th, (th, pos)); |
|
26393 | 279 |
|
49747 | 280 |
fun add_static context {strict, index} (b, ths) (Facts {facts, props}) = |
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
281 |
let |
67662 | 282 |
val ths' = ths |
283 |
|> index ? Lazy.force_value |
|
284 |
|> Lazy.map_finished (map Thm.trim_context); |
|
33093
d010f61d3702
eliminated separate stamp -- NameSpace.define/merge etc. ensure uniqueness already;
wenzelm
parents:
29848
diff
changeset
|
285 |
val (name, facts') = |
d010f61d3702
eliminated separate stamp -- NameSpace.define/merge etc. ensure uniqueness already;
wenzelm
parents:
29848
diff
changeset
|
286 |
if Binding.is_empty b then ("", facts) |
61054 | 287 |
else Name_Space.define context strict (b, Static ths') facts; |
67676
47ffe7184cdd
avoid premature Lazy.force due to strict "?" operator;
wenzelm
parents:
67668
diff
changeset
|
288 |
val props' = |
47ffe7184cdd
avoid premature Lazy.force due to strict "?" operator;
wenzelm
parents:
67668
diff
changeset
|
289 |
if index then |
47ffe7184cdd
avoid premature Lazy.force due to strict "?" operator;
wenzelm
parents:
67668
diff
changeset
|
290 |
props |> fold (add_prop (Binding.pos_of (Binding.default_pos b))) (Lazy.force ths') |
47ffe7184cdd
avoid premature Lazy.force due to strict "?" operator;
wenzelm
parents:
67668
diff
changeset
|
291 |
else props; |
28864 | 292 |
in (name, make_facts facts' props') end; |
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
293 |
|
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
42375
diff
changeset
|
294 |
fun add_dynamic context (b, f) (Facts {facts, props}) = |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
42375
diff
changeset
|
295 |
let val (name, facts') = Name_Space.define context true (b, Dynamic f) facts; |
33093
d010f61d3702
eliminated separate stamp -- NameSpace.define/merge etc. ensure uniqueness already;
wenzelm
parents:
29848
diff
changeset
|
296 |
in (name, make_facts facts' props) end; |
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
297 |
|
26654
1f711934f221
disallow duplicate entries (weak version for merge);
wenzelm
parents:
26393
diff
changeset
|
298 |
|
1f711934f221
disallow duplicate entries (weak version for merge);
wenzelm
parents:
26393
diff
changeset
|
299 |
(* remove entries *) |
1f711934f221
disallow duplicate entries (weak version for merge);
wenzelm
parents:
26393
diff
changeset
|
300 |
|
56025 | 301 |
fun del name (Facts {facts, props}) = |
302 |
make_facts (Name_Space.del_table name facts) props; |
|
26654
1f711934f221
disallow duplicate entries (weak version for merge);
wenzelm
parents:
26393
diff
changeset
|
303 |
|
56025 | 304 |
fun hide fully name (Facts {facts, props}) = |
305 |
make_facts (Name_Space.hide_table fully name facts) props; |
|
26654
1f711934f221
disallow duplicate entries (weak version for merge);
wenzelm
parents:
26393
diff
changeset
|
306 |
|
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
307 |
end; |