author | wenzelm |
Tue, 21 Jun 2016 14:42:47 +0200 | |
changeset 63337 | ae9330fdbc16 |
parent 63255 | 3f594efa9504 |
child 63369 | 4698dd1106ae |
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 |
55740 | 9 |
val the_single: string * Position.T -> thm list -> thm |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
10 |
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
|
11 |
datatype ref = |
26361 | 12 |
Named of (string * Position.T) * interval list option | |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
13 |
Fact of string |
26361 | 14 |
val named: string -> ref |
49887 | 15 |
val string_of_selection: interval list option -> string |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
16 |
val string_of_ref: ref -> string |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
17 |
val name_of_ref: ref -> string |
26366 | 18 |
val pos_of_ref: ref -> Position.T |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
19 |
val map_name_of_ref: (string -> string) -> ref -> ref |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
20 |
val select: ref -> thm list -> thm list |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
21 |
val selections: string * thm list -> (ref * thm) list |
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
22 |
type T |
26393 | 23 |
val empty: T |
33095
bbd52d2f8696
renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
wenzelm
parents:
33093
diff
changeset
|
24 |
val space_of: T -> Name_Space.T |
57887 | 25 |
val alias: Name_Space.naming -> binding -> string -> T -> T |
33163 | 26 |
val is_concealed: T -> string -> bool |
56003 | 27 |
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
|
28 |
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
|
29 |
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
|
30 |
val markup_extern: Proof.context -> T -> string -> Markup.T * xstring |
63080
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
31 |
val defined: T -> string -> bool |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
32 |
val is_dynamic: T -> string -> bool |
63255 | 33 |
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
|
34 |
val retrieve: Context.generic -> T -> xstring * Position.T -> |
63255 | 35 |
{name: string, dynamic: bool, thms: thm list} |
26692 | 36 |
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
|
37 |
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
|
38 |
val dest_all: Context.generic -> bool -> T list -> T -> (string * thm list) list |
63337 | 39 |
val props: T -> (thm * Position.T) list |
40 |
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
|
41 |
val merge: T * T -> T |
49747 | 42 |
val add_static: Context.generic -> {strict: bool, index: bool} -> |
43 |
binding * thm list -> 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
|
44 |
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
|
45 |
val del: string -> T -> T |
1f711934f221
disallow duplicate entries (weak version for merge);
wenzelm
parents:
26393
diff
changeset
|
46 |
val hide: bool -> string -> T -> T |
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
47 |
end; |
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
48 |
|
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
49 |
structure Facts: FACTS = |
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
50 |
struct |
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
51 |
|
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
52 |
(** fact references **) |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
53 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
54 |
fun the_single _ [th] : thm = th |
55740 | 55 |
| the_single (name, pos) ths = |
56 |
error ("Expected singleton fact " ^ quote name ^ |
|
57 |
" (length " ^ string_of_int (length ths) ^ ")" ^ Position.here pos); |
|
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
58 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
59 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
60 |
(* datatype interval *) |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
61 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
62 |
datatype interval = |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
63 |
FromTo of int * int | |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
64 |
From of int | |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
65 |
Single of int; |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
66 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
67 |
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
|
68 |
| string_of_interval (From i) = string_of_int i ^ "-" |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
69 |
| string_of_interval (Single i) = string_of_int i; |
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 |
fun interval n iv = |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
72 |
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
|
73 |
(case iv of |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
74 |
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
|
75 |
| 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
|
76 |
| Single i => [i]) |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
77 |
end; |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
78 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
79 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
80 |
(* datatype ref *) |
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 |
datatype ref = |
26361 | 83 |
Named of (string * Position.T) * interval list option | |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
84 |
Fact of string; |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
85 |
|
26361 | 86 |
fun named name = Named ((name, Position.none), NONE); |
87 |
||
55740 | 88 |
fun name_of_ref (Named ((name, _), _)) = name |
89 |
| name_of_ref (Fact _) = raise Fail "Illegal literal fact"; |
|
90 |
||
91 |
fun pos_of_ref (Named ((_, pos), _)) = pos |
|
92 |
| pos_of_ref (Fact _) = Position.none; |
|
93 |
||
26361 | 94 |
fun map_name_of_ref f (Named ((name, pos), is)) = Named ((f name, pos), is) |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
95 |
| map_name_of_ref _ r = r; |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
96 |
|
49887 | 97 |
fun string_of_selection NONE = "" |
98 |
| string_of_selection (SOME is) = enclose "(" ")" (commas (map string_of_interval is)); |
|
99 |
||
100 |
fun string_of_ref (Named ((name, _), sel)) = name ^ string_of_selection sel |
|
101 |
| string_of_ref (Fact _) = raise Fail "Illegal literal fact"; |
|
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
102 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
103 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
104 |
(* select *) |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
105 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
106 |
fun select (Fact _) ths = ths |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
107 |
| select (Named (_, NONE)) ths = ths |
26361 | 108 |
| select (Named ((name, pos), SOME ivs)) ths = |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
109 |
let |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
110 |
val n = length ths; |
26361 | 111 |
fun err msg = |
55740 | 112 |
error (msg ^ " for fact " ^ quote name ^ " (length " ^ string_of_int n ^ ")" ^ |
48992 | 113 |
Position.here pos); |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
114 |
fun sel i = |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
115 |
if i < 1 orelse i > n then err ("Bad subscript " ^ string_of_int i) |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
116 |
else nth ths (i - 1); |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
117 |
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
|
118 |
in map sel is end; |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
119 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
120 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
121 |
(* selections *) |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
122 |
|
26361 | 123 |
fun selections (name, [th]) = [(Named ((name, Position.none), NONE), th)] |
124 |
| selections (name, ths) = map2 (fn i => fn th => |
|
125 |
(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
|
126 |
|
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
127 |
|
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 |
(** fact environment **) |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26307
diff
changeset
|
130 |
|
26393 | 131 |
(* datatypes *) |
132 |
||
133 |
datatype fact = Static of thm list | Dynamic of Context.generic -> thm list; |
|
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
134 |
|
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
135 |
datatype T = Facts of |
33095
bbd52d2f8696
renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
wenzelm
parents:
33093
diff
changeset
|
136 |
{facts: fact Name_Space.table, |
63337 | 137 |
props: (thm * Position.T) Net.net}; |
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
138 |
|
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
139 |
fun make_facts facts props = Facts {facts = facts, props = props}; |
33163 | 140 |
|
33096 | 141 |
val empty = make_facts (Name_Space.empty_table "fact") Net.empty; |
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
142 |
|
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 |
(* named facts *) |
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
145 |
|
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
146 |
fun facts_of (Facts {facts, ...}) = facts; |
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
147 |
|
56025 | 148 |
val space_of = Name_Space.space_of_table o facts_of; |
26393 | 149 |
|
57887 | 150 |
fun alias naming binding name (Facts {facts, props}) = |
151 |
make_facts (Name_Space.alias_table naming binding name facts) props; |
|
152 |
||
33163 | 153 |
val is_concealed = Name_Space.is_concealed o space_of; |
154 |
||
56003 | 155 |
fun check context facts (xname, pos) = |
156 |
let |
|
157 |
val (name, fact) = Name_Space.check context (facts_of facts) (xname, pos); |
|
158 |
val _ = |
|
159 |
(case fact of |
|
160 |
Static _ => () |
|
161 |
| Dynamic _ => Context_Position.report_generic context pos (Markup.dynamic_fact name)); |
|
162 |
in name end; |
|
163 |
||
33095
bbd52d2f8696
renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
wenzelm
parents:
33093
diff
changeset
|
164 |
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
|
165 |
fun extern ctxt = Name_Space.extern ctxt o space_of; |
57887 | 166 |
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
|
167 |
|
56158
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
wenzelm
parents:
56140
diff
changeset
|
168 |
|
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
wenzelm
parents:
56140
diff
changeset
|
169 |
(* retrieve *) |
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
wenzelm
parents:
56140
diff
changeset
|
170 |
|
59883 | 171 |
val defined = Name_Space.defined o facts_of; |
26692 | 172 |
|
63080
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
173 |
fun is_dynamic facts name = |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
174 |
(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
|
175 |
SOME (Dynamic _) => true |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
176 |
| _ => false); |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
177 |
|
26393 | 178 |
fun lookup context facts name = |
59884 | 179 |
(case Name_Space.lookup (facts_of facts) name of |
26393 | 180 |
NONE => NONE |
63255 | 181 |
| SOME (Static ths) => SOME {dynamic = false, thms = ths} |
182 |
| SOME (Dynamic f) => SOME {dynamic = true, thms = f context}); |
|
26393 | 183 |
|
56140
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
wenzelm
parents:
56137
diff
changeset
|
184 |
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
|
185 |
let |
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
wenzelm
parents:
56137
diff
changeset
|
186 |
val name = check context facts (xname, pos); |
63255 | 187 |
val {dynamic, thms} = |
56140
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
wenzelm
parents:
56137
diff
changeset
|
188 |
(case lookup context facts name of |
63255 | 189 |
SOME res => |
190 |
(if #dynamic res |
|
191 |
then Context_Position.report_generic context pos (Markup.dynamic_fact name) |
|
192 |
else (); |
|
193 |
res) |
|
56140
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
wenzelm
parents:
56137
diff
changeset
|
194 |
| 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
|
195 |
in |
e5bec882fdd0
more informative Token.Fact: retain name of dynamic fact (without selection);
wenzelm
parents:
57887
diff
changeset
|
196 |
{name = name, |
63255 | 197 |
dynamic = dynamic, |
57942
e5bec882fdd0
more informative Token.Fact: retain name of dynamic fact (without selection);
wenzelm
parents:
57887
diff
changeset
|
198 |
thms = map (Thm.transfer (Context.theory_of context)) thms} |
e5bec882fdd0
more informative Token.Fact: retain name of dynamic fact (without selection);
wenzelm
parents:
57887
diff
changeset
|
199 |
end; |
56140
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
wenzelm
parents:
56137
diff
changeset
|
200 |
|
56158
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
wenzelm
parents:
56140
diff
changeset
|
201 |
|
63080
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
202 |
(* content *) |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
203 |
|
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
204 |
local |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
205 |
|
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
206 |
fun included verbose prev_facts facts name = |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
207 |
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
|
208 |
not verbose andalso is_concealed facts name); |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
209 |
|
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
210 |
in |
56158
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
wenzelm
parents:
56140
diff
changeset
|
211 |
|
33093
d010f61d3702
eliminated separate stamp -- NameSpace.define/merge etc. ensure uniqueness already;
wenzelm
parents:
29848
diff
changeset
|
212 |
fun fold_static f = |
63080
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
213 |
Name_Space.fold_table (fn (a, Static ths) => f (a, ths) | _ => I) o facts_of; |
26393 | 214 |
|
56158
c2c6d560e7b2
more explicit treatment of verbose mode, which includes concealed entries;
wenzelm
parents:
56140
diff
changeset
|
215 |
fun dest_static verbose prev_facts facts = |
63080
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
216 |
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
|
217 |
|> sort_by #1; |
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
218 |
|
63080
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
219 |
fun dest_all context verbose prev_facts facts = |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
220 |
Name_Space.fold_table (fn (a, fact) => |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
221 |
let val ths = (case fact of Static ths => ths | Dynamic f => f context) |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
222 |
in included verbose prev_facts facts a ? cons (a, ths) end) (facts_of facts) [] |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
223 |
|> sort_by #1; |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
224 |
|
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
225 |
end; |
8326aa594273
find dynamic facts as well, but static ones are preferred;
wenzelm
parents:
61054
diff
changeset
|
226 |
|
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
227 |
|
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
228 |
(* indexed props *) |
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
229 |
|
63337 | 230 |
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
|
231 |
|
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
232 |
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
|
233 |
fun could_unify (Facts {props, ...}) = Net.unify_term props; |
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
234 |
|
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
235 |
|
26393 | 236 |
(* merge facts *) |
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
237 |
|
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
238 |
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
|
239 |
let |
33095
bbd52d2f8696
renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
wenzelm
parents:
33093
diff
changeset
|
240 |
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
|
241 |
val props' = |
af71fb1cb31f
minor tuning -- NB: props are usually empty for global facts;
wenzelm
parents:
56025
diff
changeset
|
242 |
if Net.is_empty props2 then props1 |
af71fb1cb31f
minor tuning -- NB: props are usually empty for global facts;
wenzelm
parents:
56025
diff
changeset
|
243 |
else if Net.is_empty props1 then props2 |
af71fb1cb31f
minor tuning -- NB: props are usually empty for global facts;
wenzelm
parents:
56025
diff
changeset
|
244 |
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
|
245 |
in make_facts facts' props' end; |
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
246 |
|
26393 | 247 |
|
26654
1f711934f221
disallow duplicate entries (weak version for merge);
wenzelm
parents:
26393
diff
changeset
|
248 |
(* add static entries *) |
26393 | 249 |
|
49747 | 250 |
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
|
251 |
let |
61054 | 252 |
val ths' = map Thm.trim_context ths; |
63337 | 253 |
val pos = #2 (Position.default (Binding.pos_of b)); |
254 |
||
33093
d010f61d3702
eliminated separate stamp -- NameSpace.define/merge etc. ensure uniqueness already;
wenzelm
parents:
29848
diff
changeset
|
255 |
val (name, facts') = |
d010f61d3702
eliminated separate stamp -- NameSpace.define/merge etc. ensure uniqueness already;
wenzelm
parents:
29848
diff
changeset
|
256 |
if Binding.is_empty b then ("", facts) |
61054 | 257 |
else Name_Space.define context strict (b, Static ths') facts; |
49747 | 258 |
val props' = props |
63337 | 259 |
|> index ? fold (fn th => Net.insert_term (K false) (Thm.full_prop_of th, (th, pos))) ths'; |
28864 | 260 |
in (name, make_facts facts' props') end; |
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
261 |
|
26393 | 262 |
|
26654
1f711934f221
disallow duplicate entries (weak version for merge);
wenzelm
parents:
26393
diff
changeset
|
263 |
(* add dynamic entries *) |
26393 | 264 |
|
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
42375
diff
changeset
|
265 |
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
|
266 |
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
|
267 |
in (name, make_facts facts' props) end; |
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
268 |
|
26654
1f711934f221
disallow duplicate entries (weak version for merge);
wenzelm
parents:
26393
diff
changeset
|
269 |
|
1f711934f221
disallow duplicate entries (weak version for merge);
wenzelm
parents:
26393
diff
changeset
|
270 |
(* remove entries *) |
1f711934f221
disallow duplicate entries (weak version for merge);
wenzelm
parents:
26393
diff
changeset
|
271 |
|
56025 | 272 |
fun del name (Facts {facts, props}) = |
273 |
make_facts (Name_Space.del_table name facts) props; |
|
26654
1f711934f221
disallow duplicate entries (weak version for merge);
wenzelm
parents:
26393
diff
changeset
|
274 |
|
56025 | 275 |
fun hide fully name (Facts {facts, props}) = |
276 |
make_facts (Name_Space.hide_table fully name facts) props; |
|
26654
1f711934f221
disallow duplicate entries (weak version for merge);
wenzelm
parents:
26393
diff
changeset
|
277 |
|
26281
328fd1c551ef
Environment of named facts (admits overriding). Optional indexing by proposition.
wenzelm
parents:
diff
changeset
|
278 |
end; |