author | wenzelm |
Wed, 02 Mar 2022 21:14:09 +0100 | |
changeset 75189 | f304a2a5080f |
parent 74766 | 71a447e4073b |
child 75983 | 34dd96a06c45 |
permissions | -rw-r--r-- |
6118 | 1 |
(* Title: Pure/General/name_space.ML |
5012 | 2 |
Author: Markus Wenzel, TU Muenchen |
3 |
||
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:
55696
diff
changeset
|
4 |
Generic name spaces with declared and hidden entries; no support for |
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:
55696
diff
changeset
|
5 |
absolute addressing. |
16137 | 6 |
*) |
7 |
||
26440 | 8 |
type xstring = string; (*external names*) |
5012 | 9 |
|
10 |
signature NAME_SPACE = |
|
11 |
sig |
|
74261
d28a51dd9da6
export other entities, e.g. relevant for formal document output;
wenzelm
parents:
74183
diff
changeset
|
12 |
type entry = |
d28a51dd9da6
export other entities, e.g. relevant for formal document output;
wenzelm
parents:
74183
diff
changeset
|
13 |
{concealed: bool, |
d28a51dd9da6
export other entities, e.g. relevant for formal document output;
wenzelm
parents:
74183
diff
changeset
|
14 |
group: serial option, |
d28a51dd9da6
export other entities, e.g. relevant for formal document output;
wenzelm
parents:
74183
diff
changeset
|
15 |
theory_long_name: string, |
d28a51dd9da6
export other entities, e.g. relevant for formal document output;
wenzelm
parents:
74183
diff
changeset
|
16 |
pos: Position.T, |
d28a51dd9da6
export other entities, e.g. relevant for formal document output;
wenzelm
parents:
74183
diff
changeset
|
17 |
serial: serial} |
5012 | 18 |
type T |
33096 | 19 |
val empty: string -> T |
20 |
val kind_of: T -> string |
|
59889 | 21 |
val markup: T -> string -> Markup.T |
62987
dc8a8a7559e7
highlighting of entity def/ref positions wrt. cursor;
wenzelm
parents:
62967
diff
changeset
|
22 |
val markup_def: T -> string -> Markup.T |
74261
d28a51dd9da6
export other entities, e.g. relevant for formal document output;
wenzelm
parents:
74183
diff
changeset
|
23 |
val get_names: T -> string list |
d28a51dd9da6
export other entities, e.g. relevant for formal document output;
wenzelm
parents:
74183
diff
changeset
|
24 |
val the_entry: T -> string -> entry |
71257 | 25 |
val the_entry_theory_name: T -> string -> string |
70586 | 26 |
val entry_ord: T -> string ord |
33157
56f836b9414f
allow name space entries to be "concealed" -- via binding/naming/local_theory;
wenzelm
parents:
33097
diff
changeset
|
27 |
val is_concealed: T -> string -> bool |
16137 | 28 |
val intern: T -> xstring -> string |
42669
04dfffda5671
more conventional naming scheme: names_long, names_short, names_unique;
wenzelm
parents:
42493
diff
changeset
|
29 |
val names_long: bool Config.T |
04dfffda5671
more conventional naming scheme: names_long, names_short, names_unique;
wenzelm
parents:
42493
diff
changeset
|
30 |
val names_short: bool Config.T |
04dfffda5671
more conventional naming scheme: names_long, names_short, names_unique;
wenzelm
parents:
42493
diff
changeset
|
31 |
val names_unique: bool Config.T |
42358
b47d41d9f4b5
Name_Space: proper configuration options long_names, short_names, unique_names instead of former unsynchronized references;
wenzelm
parents:
42327
diff
changeset
|
32 |
val extern: Proof.context -> T -> string -> xstring |
70586 | 33 |
val extern_ord: Proof.context -> T -> string ord |
55672
5e25cc741ab9
support for completion within the formal context;
wenzelm
parents:
55669
diff
changeset
|
34 |
val extern_shortest: Proof.context -> T -> string -> xstring |
51510
b4f7e6734acc
tuned print_classes: more standard order, markup, formatting;
wenzelm
parents:
50301
diff
changeset
|
35 |
val markup_extern: Proof.context -> T -> string -> Markup.T * xstring |
53539 | 36 |
val pretty: Proof.context -> T -> string -> Pretty.T |
69185 | 37 |
val completion: Context.generic -> T -> (string -> bool) -> xstring * Position.T -> Completion.T |
5012 | 38 |
val merge: T * T -> T |
16137 | 39 |
type naming |
59912 | 40 |
val get_scopes: naming -> Binding.scope list |
59886 | 41 |
val get_scope: naming -> Binding.scope option |
42 |
val new_scope: naming -> Binding.scope * naming |
|
59990
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
43 |
val restricted: bool -> Position.T -> naming -> naming |
59923
b21c82422d65
support private scope for individual local theory commands;
wenzelm
parents:
59917
diff
changeset
|
44 |
val private_scope: Binding.scope -> naming -> naming |
b21c82422d65
support private scope for individual local theory commands;
wenzelm
parents:
59917
diff
changeset
|
45 |
val private: Position.T -> naming -> naming |
59990
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
46 |
val qualified_scope: Binding.scope -> naming -> naming |
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
47 |
val qualified: Position.T -> naming -> naming |
59859 | 48 |
val concealed: naming -> naming |
33724 | 49 |
val get_group: naming -> serial option |
50 |
val set_group: serial option -> naming -> naming |
|
71257 | 51 |
val set_theory_long_name: string -> naming -> naming |
33724 | 52 |
val new_group: naming -> naming |
53 |
val reset_group: naming -> naming |
|
16137 | 54 |
val add_path: string -> naming -> naming |
30418
b5044aca0729
add_path: discontinued special meaning of "//", "/", "..";
wenzelm
parents:
30412
diff
changeset
|
55 |
val root_path: naming -> naming |
b5044aca0729
add_path: discontinued special meaning of "//", "/", "..";
wenzelm
parents:
30412
diff
changeset
|
56 |
val parent_path: naming -> naming |
30469 | 57 |
val mandatory_path: string -> naming -> naming |
35200
aaddb2b526d6
more systematic treatment of qualified names derived from binding;
wenzelm
parents:
33724
diff
changeset
|
58 |
val qualified_path: bool -> binding -> naming -> naming |
58668 | 59 |
val global_naming: naming |
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
60 |
val local_naming: naming |
59887 | 61 |
val transform_naming: naming -> naming -> naming |
33281
223ef9bc399a
let naming transform binding beforehand -- covering only the "conceal" flag for now;
wenzelm
parents:
33164
diff
changeset
|
62 |
val transform_binding: naming -> binding -> binding |
33157
56f836b9414f
allow name space entries to be "concealed" -- via binding/naming/local_theory;
wenzelm
parents:
33097
diff
changeset
|
63 |
val full_name: naming -> binding -> string |
47021
f35f654f297d
clarified Binding.name_of vs Name_Space.base_name vs Variable.check_name (see also 9bd8d4addd6e, 3305f573294e);
wenzelm
parents:
47005
diff
changeset
|
64 |
val base_name: binding -> string |
56168
088b64497a61
more uniform alias vs. hide: proper check, allow to hide global names as well;
wenzelm
parents:
56164
diff
changeset
|
65 |
val hide: bool -> string -> T -> T |
47003 | 66 |
val alias: naming -> binding -> string -> T -> T |
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
67 |
val naming_of: Context.generic -> naming |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
68 |
val map_naming: (naming -> naming) -> Context.generic -> Context.generic |
68163 | 69 |
val declared: T -> string -> bool |
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
70 |
val declare: Context.generic -> bool -> binding -> T -> string * T |
56025 | 71 |
type 'a table |
56056
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
56052
diff
changeset
|
72 |
val change_base: bool -> 'a table -> 'a table |
56139
b7add947a6ef
more frugal recording of changes: join merely requires information from one side;
wenzelm
parents:
56056
diff
changeset
|
73 |
val change_ignore: 'a table -> 'a table |
56025 | 74 |
val space_of_table: 'a table -> T |
55922
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55845
diff
changeset
|
75 |
val check_reports: Context.generic -> 'a table -> |
55956
94d384d621b0
reject internal term names outright, and complete consts instead;
wenzelm
parents:
55923
diff
changeset
|
76 |
xstring * Position.T list -> (string * Position.report list) * 'a |
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
77 |
val check: Context.generic -> 'a table -> xstring * Position.T -> string * 'a |
59883 | 78 |
val defined: 'a table -> string -> bool |
59884 | 79 |
val lookup: 'a table -> string -> 'a option |
56025 | 80 |
val lookup_key: 'a table -> string -> (string * 'a) option |
42466 | 81 |
val get: 'a table -> string -> 'a |
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
82 |
val define: Context.generic -> bool -> binding * 'a -> 'a table -> string * 'a table |
56025 | 83 |
val alias_table: naming -> binding -> string -> 'a table -> 'a table |
84 |
val hide_table: bool -> string -> 'a table -> 'a table |
|
85 |
val del_table: string -> 'a table -> 'a table |
|
86 |
val map_table_entry: string -> ('a -> 'a) -> 'a table -> 'a table |
|
87 |
val fold_table: (string * 'a -> 'b -> 'b) -> 'a table -> 'b -> 'b |
|
68163 | 88 |
val dest_table: 'a table -> (string * 'a) list |
33096 | 89 |
val empty_table: string -> 'a table |
33091
d23e75d4f7da
maintain abstract entry, with position, identity etc.;
wenzelm
parents:
33049
diff
changeset
|
90 |
val merge_tables: 'a table * 'a table -> 'a table |
56056
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
56052
diff
changeset
|
91 |
val join_tables: (string -> 'a * 'a -> 'a) (*exception Change_Table.SAME*) -> |
33097
9d501e11084a
maintain position of formal entities via name space;
wenzelm
parents:
33096
diff
changeset
|
92 |
'a table * 'a table -> 'a table |
59917
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59912
diff
changeset
|
93 |
val extern_entries: bool -> Proof.context -> T -> (string * 'a) list -> |
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59912
diff
changeset
|
94 |
((string * xstring) * 'a) list |
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59912
diff
changeset
|
95 |
val markup_entries: bool -> Proof.context -> T -> (string * 'a) list -> |
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59912
diff
changeset
|
96 |
((Markup.T * xstring) * 'a) list |
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59912
diff
changeset
|
97 |
val extern_table: bool -> Proof.context -> 'a table -> ((string * xstring) * 'a) list |
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59912
diff
changeset
|
98 |
val markup_table: bool -> Proof.context -> 'a table -> ((Markup.T * xstring) * 'a) list |
5012 | 99 |
end; |
100 |
||
33095
bbd52d2f8696
renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
wenzelm
parents:
33091
diff
changeset
|
101 |
structure Name_Space: NAME_SPACE = |
5012 | 102 |
struct |
103 |
||
30412
7f5b0a020ccd
just one naming policy based on binding content -- eliminated odd "object-oriented" style;
wenzelm
parents:
30359
diff
changeset
|
104 |
|
7f5b0a020ccd
just one naming policy based on binding content -- eliminated odd "object-oriented" style;
wenzelm
parents:
30359
diff
changeset
|
105 |
(** name spaces **) |
7f5b0a020ccd
just one naming policy based on binding content -- eliminated odd "object-oriented" style;
wenzelm
parents:
30359
diff
changeset
|
106 |
|
33091
d23e75d4f7da
maintain abstract entry, with position, identity etc.;
wenzelm
parents:
33049
diff
changeset
|
107 |
(* datatype entry *) |
d23e75d4f7da
maintain abstract entry, with position, identity etc.;
wenzelm
parents:
33049
diff
changeset
|
108 |
|
d23e75d4f7da
maintain abstract entry, with position, identity etc.;
wenzelm
parents:
33049
diff
changeset
|
109 |
type entry = |
35679
da87ffdcf7ea
added Name_Space.alias -- additional accesses for an existing entry;
wenzelm
parents:
35432
diff
changeset
|
110 |
{concealed: bool, |
33164
b8fd9b6bba7c
Name_Space.naming: maintain group and theory_name as well;
wenzelm
parents:
33157
diff
changeset
|
111 |
group: serial option, |
71257 | 112 |
theory_long_name: string, |
33091
d23e75d4f7da
maintain abstract entry, with position, identity etc.;
wenzelm
parents:
33049
diff
changeset
|
113 |
pos: Position.T, |
57899
5867d1306712
clarified signature: entity serial number is not position id;
wenzelm
parents:
56438
diff
changeset
|
114 |
serial: serial}; |
33091
d23e75d4f7da
maintain abstract entry, with position, identity etc.;
wenzelm
parents:
33049
diff
changeset
|
115 |
|
74263
be49c660ebbf
more markup, e.g. to locate defining theory node in formal document output;
wenzelm
parents:
74262
diff
changeset
|
116 |
fun entry_markup def kind (name, {pos, theory_long_name, serial, ...}: entry) = |
be49c660ebbf
more markup, e.g. to locate defining theory node in formal document output;
wenzelm
parents:
74262
diff
changeset
|
117 |
Position.make_entity_markup def serial kind (name, pos) |
74766 | 118 |
||> not (#def def orelse theory_long_name = "") ? cons (Markup.def_theoryN, theory_long_name); |
42135 | 119 |
|
49816
e63d6c55ad6d
more position information for hyperlink and placement of message;
wenzelm
parents:
49528
diff
changeset
|
120 |
fun print_entry_ref kind (name, entry) = |
74262 | 121 |
quote (Markup.markup (entry_markup {def = false} kind (name, entry)) name); |
33091
d23e75d4f7da
maintain abstract entry, with position, identity etc.;
wenzelm
parents:
33049
diff
changeset
|
122 |
|
49816
e63d6c55ad6d
more position information for hyperlink and placement of message;
wenzelm
parents:
49528
diff
changeset
|
123 |
fun err_dup kind entry1 entry2 pos = |
56038
0e2dec666152
tuned messages -- in accordance to Isabelle/Scala;
wenzelm
parents:
56025
diff
changeset
|
124 |
error ("Duplicate " ^ plain_words kind ^ " declaration " ^ |
49816
e63d6c55ad6d
more position information for hyperlink and placement of message;
wenzelm
parents:
49528
diff
changeset
|
125 |
print_entry_ref kind entry1 ^ " vs. " ^ print_entry_ref kind entry2 ^ Position.here pos); |
33096 | 126 |
|
33091
d23e75d4f7da
maintain abstract entry, with position, identity etc.;
wenzelm
parents:
33049
diff
changeset
|
127 |
|
56164 | 128 |
(* internal names *) |
129 |
||
64307
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
130 |
type internals = (string list * string list) Change_Table.T; (*xname -> visible, hidden*) |
56164 | 131 |
|
132 |
fun map_internals f xname : internals -> internals = |
|
133 |
Change_Table.map_default (xname, ([], [])) f; |
|
134 |
||
135 |
val del_name = map_internals o apfst o remove (op =); |
|
136 |
fun del_name_extra name = |
|
137 |
map_internals (apfst (fn [] => [] | x :: xs => x :: remove (op =) name xs)); |
|
138 |
val add_name = map_internals o apfst o update (op =); |
|
59881 | 139 |
fun hide_name name = map_internals (apsnd (update (op =) name)) name; |
56164 | 140 |
|
141 |
||
64307
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
142 |
(* external accesses *) |
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
143 |
|
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
144 |
type accesses = (xstring list * xstring list); (*input / output fragments*) |
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
145 |
type entries = (accesses * entry) Change_Table.T; (*name -> accesses, entry*) |
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
146 |
|
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
147 |
|
5012 | 148 |
(* datatype T *) |
149 |
||
64307
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
150 |
datatype T = Name_Space of {kind: string, internals: internals, entries: entries}; |
33096 | 151 |
|
152 |
fun make_name_space (kind, internals, entries) = |
|
153 |
Name_Space {kind = kind, internals = internals, entries = entries}; |
|
154 |
||
155 |
fun map_name_space f (Name_Space {kind = kind, internals = internals, entries = entries}) = |
|
156 |
make_name_space (f (kind, internals, entries)); |
|
157 |
||
56056
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
56052
diff
changeset
|
158 |
fun change_base_space begin = map_name_space (fn (kind, internals, entries) => |
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
56052
diff
changeset
|
159 |
(kind, Change_Table.change_base begin internals, Change_Table.change_base begin entries)); |
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
56052
diff
changeset
|
160 |
|
56139
b7add947a6ef
more frugal recording of changes: join merely requires information from one side;
wenzelm
parents:
56056
diff
changeset
|
161 |
val change_ignore_space = map_name_space (fn (kind, internals, entries) => |
b7add947a6ef
more frugal recording of changes: join merely requires information from one side;
wenzelm
parents:
56056
diff
changeset
|
162 |
(kind, Change_Table.change_ignore internals, Change_Table.change_ignore entries)); |
b7add947a6ef
more frugal recording of changes: join merely requires information from one side;
wenzelm
parents:
56056
diff
changeset
|
163 |
|
5012 | 164 |
|
56056
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
56052
diff
changeset
|
165 |
fun empty kind = make_name_space (kind, Change_Table.empty, Change_Table.empty); |
33096 | 166 |
|
167 |
fun kind_of (Name_Space {kind, ...}) = kind; |
|
5012 | 168 |
|
62987
dc8a8a7559e7
highlighting of entity def/ref positions wrt. cursor;
wenzelm
parents:
62967
diff
changeset
|
169 |
fun gen_markup def (Name_Space {kind, entries, ...}) name = |
56056
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
56052
diff
changeset
|
170 |
(case Change_Table.lookup entries name of |
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49816
diff
changeset
|
171 |
NONE => Markup.intensify |
62987
dc8a8a7559e7
highlighting of entity def/ref positions wrt. cursor;
wenzelm
parents:
62967
diff
changeset
|
172 |
| SOME (_, entry) => entry_markup def kind (name, entry)); |
dc8a8a7559e7
highlighting of entity def/ref positions wrt. cursor;
wenzelm
parents:
62967
diff
changeset
|
173 |
|
74262 | 174 |
val markup = gen_markup {def = false}; |
175 |
val markup_def = gen_markup {def = true}; |
|
42135 | 176 |
|
59889 | 177 |
fun undefined (space as Name_Space {kind, entries, ...}) bad = |
178 |
let |
|
179 |
val (prfx, sfx) = |
|
180 |
(case Long_Name.dest_hidden bad of |
|
181 |
SOME name => |
|
182 |
if Change_Table.defined entries name |
|
183 |
then ("Inaccessible", Markup.markup (markup space name) (quote name)) |
|
184 |
else ("Undefined", quote name) |
|
185 |
| NONE => ("Undefined", quote bad)); |
|
186 |
in prfx ^ " " ^ plain_words kind ^ ": " ^ sfx end; |
|
187 |
||
74261
d28a51dd9da6
export other entities, e.g. relevant for formal document output;
wenzelm
parents:
74183
diff
changeset
|
188 |
fun get_names (Name_Space {entries, ...}) = |
d28a51dd9da6
export other entities, e.g. relevant for formal document output;
wenzelm
parents:
74183
diff
changeset
|
189 |
Change_Table.fold (cons o #1) entries []; |
d28a51dd9da6
export other entities, e.g. relevant for formal document output;
wenzelm
parents:
74183
diff
changeset
|
190 |
|
59889 | 191 |
fun the_entry (space as Name_Space {entries, ...}) name = |
192 |
(case Change_Table.lookup entries name of |
|
193 |
NONE => error (undefined space name) |
|
194 |
| SOME (_, entry) => entry); |
|
195 |
||
71257 | 196 |
fun the_entry_theory_name space name = |
197 |
Long_Name.base_name (#theory_long_name (the_entry space name)); |
|
198 |
||
59889 | 199 |
fun entry_ord space = int_ord o apply2 (#serial o the_entry space); |
200 |
||
60282
496fa0fc91b1
more permissive operation: allow to print undeclared name space entries, e.g. print_simpset with "record" simproc;
wenzelm
parents:
59990
diff
changeset
|
201 |
fun is_concealed space name = |
496fa0fc91b1
more permissive operation: allow to print undeclared name space entries, e.g. print_simpset with "record" simproc;
wenzelm
parents:
59990
diff
changeset
|
202 |
#concealed (the_entry space name) handle ERROR _ => false; |
33096 | 203 |
|
204 |
||
59884 | 205 |
(* intern *) |
33096 | 206 |
|
59884 | 207 |
fun intern' (Name_Space {internals, ...}) xname = |
59885
3470a265d404
subtle change of long-standing name space policy: unknown entries are treated as hidden, consequently "private" is understood in the strict sense;
wenzelm
parents:
59884
diff
changeset
|
208 |
(case the_default ([], []) (Change_Table.lookup internals xname) of |
3470a265d404
subtle change of long-standing name space policy: unknown entries are treated as hidden, consequently "private" is understood in the strict sense;
wenzelm
parents:
59884
diff
changeset
|
209 |
([name], _) => (name, true) |
3470a265d404
subtle change of long-standing name space policy: unknown entries are treated as hidden, consequently "private" is understood in the strict sense;
wenzelm
parents:
59884
diff
changeset
|
210 |
| (name :: _, _) => (name, false) |
3470a265d404
subtle change of long-standing name space policy: unknown entries are treated as hidden, consequently "private" is understood in the strict sense;
wenzelm
parents:
59884
diff
changeset
|
211 |
| ([], []) => (Long_Name.hidden xname, true) |
3470a265d404
subtle change of long-standing name space policy: unknown entries are treated as hidden, consequently "private" is understood in the strict sense;
wenzelm
parents:
59884
diff
changeset
|
212 |
| ([], name' :: _) => (Long_Name.hidden name', true)); |
8728 | 213 |
|
59884 | 214 |
val intern = #1 oo intern'; |
215 |
||
33096 | 216 |
fun get_accesses (Name_Space {entries, ...}) name = |
56056
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
56052
diff
changeset
|
217 |
(case Change_Table.lookup entries name of |
64307
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
218 |
NONE => ([], []) |
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
219 |
| SOME (accesses, _) => accesses); |
25072
03f57b516e12
store external accesses within name space (as produced by naming policy);
wenzelm
parents:
24361
diff
changeset
|
220 |
|
64307
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
221 |
fun is_valid_access (Name_Space {internals, ...}) name xname = |
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
222 |
(case Change_Table.lookup internals xname of |
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
223 |
SOME (name' :: _, _) => name = name' |
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
224 |
| _ => false); |
8728 | 225 |
|
226 |
||
55672
5e25cc741ab9
support for completion within the formal context;
wenzelm
parents:
55669
diff
changeset
|
227 |
(* extern *) |
5e25cc741ab9
support for completion within the formal context;
wenzelm
parents:
55669
diff
changeset
|
228 |
|
69575 | 229 |
val names_long = Config.declare_option_bool ("names_long", \<^here>); |
230 |
val names_short = Config.declare_option_bool ("names_short", \<^here>); |
|
231 |
val names_unique = Config.declare_option_bool ("names_unique", \<^here>); |
|
42358
b47d41d9f4b5
Name_Space: proper configuration options long_names, short_names, unique_names instead of former unsynchronized references;
wenzelm
parents:
42327
diff
changeset
|
232 |
|
b47d41d9f4b5
Name_Space: proper configuration options long_names, short_names, unique_names instead of former unsynchronized references;
wenzelm
parents:
42327
diff
changeset
|
233 |
fun extern ctxt space name = |
16137 | 234 |
let |
42669
04dfffda5671
more conventional naming scheme: names_long, names_short, names_unique;
wenzelm
parents:
42493
diff
changeset
|
235 |
val names_long = Config.get ctxt names_long; |
04dfffda5671
more conventional naming scheme: names_long, names_short, names_unique;
wenzelm
parents:
42493
diff
changeset
|
236 |
val names_short = Config.get ctxt names_short; |
04dfffda5671
more conventional naming scheme: names_long, names_short, names_unique;
wenzelm
parents:
42493
diff
changeset
|
237 |
val names_unique = Config.get ctxt names_unique; |
42358
b47d41d9f4b5
Name_Space: proper configuration options long_names, short_names, unique_names instead of former unsynchronized references;
wenzelm
parents:
42327
diff
changeset
|
238 |
|
30277 | 239 |
fun valid require_unique xname = |
59884 | 240 |
let val (name', is_unique) = intern' space xname |
30277 | 241 |
in name = name' andalso (not require_unique orelse is_unique) end; |
8728 | 242 |
|
55669 | 243 |
fun ext [] = if valid false name then name else Long_Name.hidden name |
42669
04dfffda5671
more conventional naming scheme: names_long, names_short, names_unique;
wenzelm
parents:
42493
diff
changeset
|
244 |
| ext (nm :: nms) = if valid names_unique nm then nm else ext nms; |
16137 | 245 |
in |
42669
04dfffda5671
more conventional naming scheme: names_long, names_short, names_unique;
wenzelm
parents:
42493
diff
changeset
|
246 |
if names_long then name |
04dfffda5671
more conventional naming scheme: names_long, names_short, names_unique;
wenzelm
parents:
42493
diff
changeset
|
247 |
else if names_short then Long_Name.base_name name |
64307
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
248 |
else ext (#2 (get_accesses space name)) |
16137 | 249 |
end; |
250 |
||
59058
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
wenzelm
parents:
58668
diff
changeset
|
251 |
fun extern_ord ctxt space = string_ord o apply2 (extern ctxt space); |
51510
b4f7e6734acc
tuned print_classes: more standard order, markup, formatting;
wenzelm
parents:
50301
diff
changeset
|
252 |
|
55672
5e25cc741ab9
support for completion within the formal context;
wenzelm
parents:
55669
diff
changeset
|
253 |
fun extern_shortest ctxt = |
5e25cc741ab9
support for completion within the formal context;
wenzelm
parents:
55669
diff
changeset
|
254 |
extern |
5e25cc741ab9
support for completion within the formal context;
wenzelm
parents:
55669
diff
changeset
|
255 |
(ctxt |
5e25cc741ab9
support for completion within the formal context;
wenzelm
parents:
55669
diff
changeset
|
256 |
|> Config.put names_long false |
5e25cc741ab9
support for completion within the formal context;
wenzelm
parents:
55669
diff
changeset
|
257 |
|> Config.put names_short false |
5e25cc741ab9
support for completion within the formal context;
wenzelm
parents:
55669
diff
changeset
|
258 |
|> Config.put names_unique false); |
5e25cc741ab9
support for completion within the formal context;
wenzelm
parents:
55669
diff
changeset
|
259 |
|
51510
b4f7e6734acc
tuned print_classes: more standard order, markup, formatting;
wenzelm
parents:
50301
diff
changeset
|
260 |
fun markup_extern ctxt space name = (markup space name, extern ctxt space name); |
55672
5e25cc741ab9
support for completion within the formal context;
wenzelm
parents:
55669
diff
changeset
|
261 |
fun pretty ctxt space name = Pretty.mark_str (markup_extern ctxt space name); |
5e25cc741ab9
support for completion within the formal context;
wenzelm
parents:
55669
diff
changeset
|
262 |
|
51510
b4f7e6734acc
tuned print_classes: more standard order, markup, formatting;
wenzelm
parents:
50301
diff
changeset
|
263 |
|
55672
5e25cc741ab9
support for completion within the formal context;
wenzelm
parents:
55669
diff
changeset
|
264 |
(* completion *) |
5e25cc741ab9
support for completion within the formal context;
wenzelm
parents:
55669
diff
changeset
|
265 |
|
69185 | 266 |
fun completion context space pred (xname, pos) = |
59812 | 267 |
Completion.make (xname, pos) (fn completed => |
55672
5e25cc741ab9
support for completion within the formal context;
wenzelm
parents:
55669
diff
changeset
|
268 |
let |
66249 | 269 |
fun result_ord ((pri1, (xname1, (_, name1))), (pri2, (xname2, (_, name2)))) = |
270 |
(case int_ord (pri2, pri1) of |
|
56162
ea6303e2261b
clarified completion ordering: prefer local names;
wenzelm
parents:
56160
diff
changeset
|
271 |
EQUAL => |
62967
5e8b1aead28f
more completions, independently on accidental external form (e.g. "Map.empty" with its redundant prefix);
wenzelm
parents:
62241
diff
changeset
|
272 |
(case bool_ord (apply2 (is_some o Long_Name.dest_local) (name2, name1)) of |
5e8b1aead28f
more completions, independently on accidental external form (e.g. "Map.empty" with its redundant prefix);
wenzelm
parents:
62241
diff
changeset
|
273 |
EQUAL => |
5e8b1aead28f
more completions, independently on accidental external form (e.g. "Map.empty" with its redundant prefix);
wenzelm
parents:
62241
diff
changeset
|
274 |
(case int_ord (apply2 Long_Name.qualification (xname1, xname2)) of |
5e8b1aead28f
more completions, independently on accidental external form (e.g. "Map.empty" with its redundant prefix);
wenzelm
parents:
62241
diff
changeset
|
275 |
EQUAL => string_ord (xname1, xname2) |
5e8b1aead28f
more completions, independently on accidental external form (e.g. "Map.empty" with its redundant prefix);
wenzelm
parents:
62241
diff
changeset
|
276 |
| ord => ord) |
56162
ea6303e2261b
clarified completion ordering: prefer local names;
wenzelm
parents:
56160
diff
changeset
|
277 |
| ord => ord) |
56024 | 278 |
| ord => ord); |
55975 | 279 |
val Name_Space {kind, internals, ...} = space; |
55694
a1184dfb8e00
clarified semantic completion: retain kind.full_name as official item name for history;
wenzelm
parents:
55687
diff
changeset
|
280 |
val ext = extern_shortest (Context.proof_of context) space; |
63232 | 281 |
val full = Name.clean xname = ""; |
66247 | 282 |
|
66249 | 283 |
fun complete xname' name = |
284 |
if (completed xname' orelse exists completed (Long_Name.explode xname')) andalso |
|
69185 | 285 |
not (is_concealed space name) andalso pred name |
66249 | 286 |
then |
287 |
let |
|
288 |
val xname'' = ext name; |
|
289 |
val pri = (if xname' = xname'' then 1 else 0) + (if completed xname' then 1 else 0); |
|
290 |
in |
|
66247 | 291 |
if xname' <> xname'' andalso full then I |
66249 | 292 |
else cons (pri, (xname', (kind, name))) |
66247 | 293 |
end |
294 |
else I; |
|
59812 | 295 |
in |
66249 | 296 |
Change_Table.fold (fn (xname', (name :: _, _)) => complete xname' name | _ => I) internals [] |
59812 | 297 |
|> sort_distinct result_ord |
62967
5e8b1aead28f
more completions, independently on accidental external form (e.g. "Map.empty" with its redundant prefix);
wenzelm
parents:
62241
diff
changeset
|
298 |
|> map #2 |
59812 | 299 |
end); |
53539 | 300 |
|
5012 | 301 |
|
16137 | 302 |
(* merge *) |
5012 | 303 |
|
33096 | 304 |
fun merge |
305 |
(Name_Space {kind = kind1, internals = internals1, entries = entries1}, |
|
306 |
Name_Space {kind = kind2, internals = internals2, entries = entries2}) = |
|
25072
03f57b516e12
store external accesses within name space (as produced by naming policy);
wenzelm
parents:
24361
diff
changeset
|
307 |
let |
33096 | 308 |
val kind' = |
309 |
if kind1 = kind2 then kind1 |
|
310 |
else error ("Attempt to merge different kinds of name spaces " ^ |
|
311 |
quote kind1 ^ " vs. " ^ quote kind2); |
|
56056
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
56052
diff
changeset
|
312 |
val internals' = (internals1, internals2) |> Change_Table.join |
30465 | 313 |
(K (fn ((names1, names1'), (names2, names2')) => |
33091
d23e75d4f7da
maintain abstract entry, with position, identity etc.;
wenzelm
parents:
33049
diff
changeset
|
314 |
if pointer_eq (names1, names2) andalso pointer_eq (names1', names2') |
56056
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
56052
diff
changeset
|
315 |
then raise Change_Table.SAME |
30233
6eb726e43ed1
eliminated internal stamp equality, replaced by bare-metal pointer_eq;
wenzelm
parents:
30222
diff
changeset
|
316 |
else (Library.merge (op =) (names1, names2), Library.merge (op =) (names1', names2')))); |
56056
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
56052
diff
changeset
|
317 |
val entries' = (entries1, entries2) |> Change_Table.join |
35679
da87ffdcf7ea
added Name_Space.alias -- additional accesses for an existing entry;
wenzelm
parents:
35432
diff
changeset
|
318 |
(fn name => fn ((_, entry1), (_, entry2)) => |
57899
5867d1306712
clarified signature: entity serial number is not position id;
wenzelm
parents:
56438
diff
changeset
|
319 |
if #serial entry1 = #serial entry2 then raise Change_Table.SAME |
49816
e63d6c55ad6d
more position information for hyperlink and placement of message;
wenzelm
parents:
49528
diff
changeset
|
320 |
else err_dup kind' (name, entry1) (name, entry2) Position.none); |
33096 | 321 |
in make_name_space (kind', internals', entries') end; |
5012 | 322 |
|
16137 | 323 |
|
26440 | 324 |
|
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
325 |
(** naming context **) |
16137 | 326 |
|
327 |
(* datatype naming *) |
|
328 |
||
33164
b8fd9b6bba7c
Name_Space.naming: maintain group and theory_name as well;
wenzelm
parents:
33157
diff
changeset
|
329 |
datatype naming = Naming of |
59886 | 330 |
{scopes: Binding.scope list, |
59990
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
331 |
restricted: (bool * Binding.scope) option, |
59859 | 332 |
concealed: bool, |
33164
b8fd9b6bba7c
Name_Space.naming: maintain group and theory_name as well;
wenzelm
parents:
33157
diff
changeset
|
333 |
group: serial option, |
71257 | 334 |
theory_long_name: string, |
33164
b8fd9b6bba7c
Name_Space.naming: maintain group and theory_name as well;
wenzelm
parents:
33157
diff
changeset
|
335 |
path: (string * bool) list}; |
b8fd9b6bba7c
Name_Space.naming: maintain group and theory_name as well;
wenzelm
parents:
33157
diff
changeset
|
336 |
|
71257 | 337 |
fun make_naming (scopes, restricted, concealed, group, theory_long_name, path) = |
59990
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
338 |
Naming {scopes = scopes, restricted = restricted, concealed = concealed, |
71257 | 339 |
group = group, theory_long_name = theory_long_name, path = path}; |
33164
b8fd9b6bba7c
Name_Space.naming: maintain group and theory_name as well;
wenzelm
parents:
33157
diff
changeset
|
340 |
|
71257 | 341 |
fun map_naming f (Naming {scopes, restricted, concealed, group, theory_long_name, path}) = |
342 |
make_naming (f (scopes, restricted, concealed, group, theory_long_name, path)); |
|
16137 | 343 |
|
33164
b8fd9b6bba7c
Name_Space.naming: maintain group and theory_name as well;
wenzelm
parents:
33157
diff
changeset
|
344 |
|
59990
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
345 |
(* scope and access restriction *) |
33164
b8fd9b6bba7c
Name_Space.naming: maintain group and theory_name as well;
wenzelm
parents:
33157
diff
changeset
|
346 |
|
59886 | 347 |
fun get_scopes (Naming {scopes, ...}) = scopes; |
348 |
val get_scope = try hd o get_scopes; |
|
33164
b8fd9b6bba7c
Name_Space.naming: maintain group and theory_name as well;
wenzelm
parents:
33157
diff
changeset
|
349 |
|
59886 | 350 |
fun new_scope naming = |
351 |
let |
|
352 |
val scope = Binding.new_scope (); |
|
353 |
val naming' = |
|
71257 | 354 |
naming |> map_naming (fn (scopes, restricted, concealed, group, theory_long_name, path) => |
355 |
(scope :: scopes, restricted, concealed, group, theory_long_name, path)); |
|
59886 | 356 |
in (scope, naming') end; |
59858 | 357 |
|
59990
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
358 |
fun restricted_scope strict scope = |
71257 | 359 |
map_naming (fn (scopes, _, concealed, group, theory_long_name, path) => |
360 |
(scopes, SOME (strict, scope), concealed, group, theory_long_name, path)); |
|
16137 | 361 |
|
59990
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
362 |
fun restricted strict pos naming = |
59923
b21c82422d65
support private scope for individual local theory commands;
wenzelm
parents:
59917
diff
changeset
|
363 |
(case get_scope naming of |
59990
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
364 |
SOME scope => restricted_scope strict scope naming |
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
365 |
| NONE => error ("Missing local scope -- cannot restrict name space accesses" ^ Position.here pos)); |
59939
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents:
59925
diff
changeset
|
366 |
|
59990
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
367 |
val private_scope = restricted_scope true; |
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
368 |
val private = restricted true; |
59939
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents:
59925
diff
changeset
|
369 |
|
59990
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
370 |
val qualified_scope = restricted_scope false; |
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
371 |
val qualified = restricted false; |
59923
b21c82422d65
support private scope for individual local theory commands;
wenzelm
parents:
59917
diff
changeset
|
372 |
|
71257 | 373 |
val concealed = map_naming (fn (scopes, restricted, _, group, theory_long_name, path) => |
374 |
(scopes, restricted, true, group, theory_long_name, path)); |
|
59939
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents:
59925
diff
changeset
|
375 |
|
59886 | 376 |
|
59939
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents:
59925
diff
changeset
|
377 |
(* additional structural info *) |
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents:
59925
diff
changeset
|
378 |
|
71257 | 379 |
fun set_theory_long_name theory_long_name = |
380 |
map_naming (fn (scopes, restricted, concealed, group, _, path) => |
|
381 |
(scopes, restricted, concealed, group, theory_long_name, path)); |
|
33724 | 382 |
|
383 |
fun get_group (Naming {group, ...}) = group; |
|
384 |
||
71257 | 385 |
fun set_group group = |
386 |
map_naming (fn (scopes, restricted, concealed, _, theory_long_name, path) => |
|
387 |
(scopes, restricted, concealed, group, theory_long_name, path)); |
|
33724 | 388 |
|
389 |
fun new_group naming = set_group (SOME (serial ())) naming; |
|
390 |
val reset_group = set_group NONE; |
|
391 |
||
59939
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents:
59925
diff
changeset
|
392 |
|
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents:
59925
diff
changeset
|
393 |
(* name entry path *) |
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents:
59925
diff
changeset
|
394 |
|
59874 | 395 |
fun get_path (Naming {path, ...}) = path; |
396 |
||
71257 | 397 |
fun map_path f = |
398 |
map_naming (fn (scopes, restricted, concealed, group, theory_long_name, path) => |
|
399 |
(scopes, restricted, concealed, group, theory_long_name, f path)); |
|
59939
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents:
59925
diff
changeset
|
400 |
|
33157
56f836b9414f
allow name space entries to be "concealed" -- via binding/naming/local_theory;
wenzelm
parents:
33097
diff
changeset
|
401 |
fun add_path elems = map_path (fn path => path @ [(elems, false)]); |
56f836b9414f
allow name space entries to be "concealed" -- via binding/naming/local_theory;
wenzelm
parents:
33097
diff
changeset
|
402 |
val root_path = map_path (fn _ => []); |
56f836b9414f
allow name space entries to be "concealed" -- via binding/naming/local_theory;
wenzelm
parents:
33097
diff
changeset
|
403 |
val parent_path = map_path (perhaps (try (#1 o split_last))); |
56f836b9414f
allow name space entries to be "concealed" -- via binding/naming/local_theory;
wenzelm
parents:
33097
diff
changeset
|
404 |
fun mandatory_path elems = map_path (fn path => path @ [(elems, true)]); |
56f836b9414f
allow name space entries to be "concealed" -- via binding/naming/local_theory;
wenzelm
parents:
33097
diff
changeset
|
405 |
|
35200
aaddb2b526d6
more systematic treatment of qualified names derived from binding;
wenzelm
parents:
33724
diff
changeset
|
406 |
fun qualified_path mandatory binding = map_path (fn path => |
63003 | 407 |
path @ Binding.path_of (Binding.qualify_name mandatory binding "")); |
35200
aaddb2b526d6
more systematic treatment of qualified names derived from binding;
wenzelm
parents:
33724
diff
changeset
|
408 |
|
59886 | 409 |
val global_naming = make_naming ([], NONE, false, NONE, "", []); |
58668 | 410 |
val local_naming = global_naming |> add_path Long_Name.localN; |
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
411 |
|
28860 | 412 |
|
59939
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents:
59925
diff
changeset
|
413 |
(* transform *) |
59887 | 414 |
|
59990
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
415 |
fun transform_naming (Naming {restricted = restricted', concealed = concealed', ...}) = |
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
416 |
(case restricted' of |
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
417 |
SOME (strict, scope) => restricted_scope strict scope |
59939
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents:
59925
diff
changeset
|
418 |
| NONE => I) #> |
59887 | 419 |
concealed' ? concealed; |
30233
6eb726e43ed1
eliminated internal stamp equality, replaced by bare-metal pointer_eq;
wenzelm
parents:
30222
diff
changeset
|
420 |
|
59990
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
421 |
fun transform_binding (Naming {restricted, concealed, ...}) = |
62241 | 422 |
Binding.restricted restricted #> |
59859 | 423 |
concealed ? Binding.concealed; |
33281
223ef9bc399a
let naming transform binding beforehand -- covering only the "conceal" flag for now;
wenzelm
parents:
33164
diff
changeset
|
424 |
|
59887 | 425 |
|
426 |
(* full name *) |
|
427 |
||
59874 | 428 |
fun name_spec naming binding = |
59886 | 429 |
Binding.name_spec (get_scopes naming) (get_path naming) (transform_binding naming binding); |
30412
7f5b0a020ccd
just one naming policy based on binding content -- eliminated odd "object-oriented" style;
wenzelm
parents:
30359
diff
changeset
|
430 |
|
33157
56f836b9414f
allow name space entries to be "concealed" -- via binding/naming/local_theory;
wenzelm
parents:
33097
diff
changeset
|
431 |
fun full_name naming = |
59858 | 432 |
name_spec naming #> #spec #> map #1 #> Long_Name.implode; |
30412
7f5b0a020ccd
just one naming policy based on binding content -- eliminated odd "object-oriented" style;
wenzelm
parents:
30359
diff
changeset
|
433 |
|
58668 | 434 |
val base_name = full_name global_naming #> Long_Name.base_name; |
47021
f35f654f297d
clarified Binding.name_of vs Name_Space.base_name vs Variable.check_name (see also 9bd8d4addd6e, 3305f573294e);
wenzelm
parents:
47005
diff
changeset
|
435 |
|
30412
7f5b0a020ccd
just one naming policy based on binding content -- eliminated odd "object-oriented" style;
wenzelm
parents:
30359
diff
changeset
|
436 |
|
7f5b0a020ccd
just one naming policy based on binding content -- eliminated odd "object-oriented" style;
wenzelm
parents:
30359
diff
changeset
|
437 |
(* accesses *) |
7f5b0a020ccd
just one naming policy based on binding content -- eliminated odd "object-oriented" style;
wenzelm
parents:
30359
diff
changeset
|
438 |
|
7f5b0a020ccd
just one naming policy based on binding content -- eliminated odd "object-oriented" style;
wenzelm
parents:
30359
diff
changeset
|
439 |
fun mandatory xs = map_filter (fn (x, true) => SOME x | _ => NONE) xs; |
7f5b0a020ccd
just one naming policy based on binding content -- eliminated odd "object-oriented" style;
wenzelm
parents:
30359
diff
changeset
|
440 |
|
7f5b0a020ccd
just one naming policy based on binding content -- eliminated odd "object-oriented" style;
wenzelm
parents:
30359
diff
changeset
|
441 |
fun mandatory_prefixes xs = mandatory xs :: mandatory_prefixes1 xs |
7f5b0a020ccd
just one naming policy based on binding content -- eliminated odd "object-oriented" style;
wenzelm
parents:
30359
diff
changeset
|
442 |
and mandatory_prefixes1 [] = [] |
7f5b0a020ccd
just one naming policy based on binding content -- eliminated odd "object-oriented" style;
wenzelm
parents:
30359
diff
changeset
|
443 |
| mandatory_prefixes1 ((x, true) :: xs) = map (cons x) (mandatory_prefixes1 xs) |
7f5b0a020ccd
just one naming policy based on binding content -- eliminated odd "object-oriented" style;
wenzelm
parents:
30359
diff
changeset
|
444 |
| mandatory_prefixes1 ((x, false) :: xs) = map (cons x) (mandatory_prefixes xs); |
7f5b0a020ccd
just one naming policy based on binding content -- eliminated odd "object-oriented" style;
wenzelm
parents:
30359
diff
changeset
|
445 |
|
7f5b0a020ccd
just one naming policy based on binding content -- eliminated odd "object-oriented" style;
wenzelm
parents:
30359
diff
changeset
|
446 |
fun mandatory_suffixes xs = map rev (mandatory_prefixes (rev xs)); |
7f5b0a020ccd
just one naming policy based on binding content -- eliminated odd "object-oriented" style;
wenzelm
parents:
30359
diff
changeset
|
447 |
|
64307
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
448 |
fun make_accesses naming binding = |
59858 | 449 |
(case name_spec naming binding of |
59990
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
450 |
{restriction = SOME true, ...} => ([], []) |
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
451 |
| {restriction, spec, ...} => |
59858 | 452 |
let |
59990
a81dc82ecba3
clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents:
59939
diff
changeset
|
453 |
val restrict = is_some restriction ? filter (fn [_] => false | _ => true); |
59939
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents:
59925
diff
changeset
|
454 |
val sfxs = restrict (mandatory_suffixes spec); |
7d46aa03696e
support for 'restricted' modifier: only qualified accesses outside the local scope;
wenzelm
parents:
59925
diff
changeset
|
455 |
val pfxs = restrict (mandatory_prefixes spec); |
59858 | 456 |
in apply2 (map Long_Name.implode) (sfxs @ pfxs, sfxs) end); |
30412
7f5b0a020ccd
just one naming policy based on binding content -- eliminated odd "object-oriented" style;
wenzelm
parents:
30359
diff
changeset
|
457 |
|
30233
6eb726e43ed1
eliminated internal stamp equality, replaced by bare-metal pointer_eq;
wenzelm
parents:
30222
diff
changeset
|
458 |
|
56168
088b64497a61
more uniform alias vs. hide: proper check, allow to hide global names as well;
wenzelm
parents:
56164
diff
changeset
|
459 |
(* hide *) |
088b64497a61
more uniform alias vs. hide: proper check, allow to hide global names as well;
wenzelm
parents:
56164
diff
changeset
|
460 |
|
088b64497a61
more uniform alias vs. hide: proper check, allow to hide global names as well;
wenzelm
parents:
56164
diff
changeset
|
461 |
fun hide fully name space = |
088b64497a61
more uniform alias vs. hide: proper check, allow to hide global names as well;
wenzelm
parents:
56164
diff
changeset
|
462 |
space |> map_name_space (fn (kind, internals, entries) => |
088b64497a61
more uniform alias vs. hide: proper check, allow to hide global names as well;
wenzelm
parents:
56164
diff
changeset
|
463 |
let |
59889 | 464 |
val _ = the_entry space name; |
64307
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
465 |
val (accs, accs') = get_accesses space name; |
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
466 |
val xnames = filter (is_valid_access space name) accs; |
56168
088b64497a61
more uniform alias vs. hide: proper check, allow to hide global names as well;
wenzelm
parents:
56164
diff
changeset
|
467 |
val internals' = internals |
59881 | 468 |
|> hide_name name |
56168
088b64497a61
more uniform alias vs. hide: proper check, allow to hide global names as well;
wenzelm
parents:
56164
diff
changeset
|
469 |
|> fold (del_name name) |
64307
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
470 |
(if fully then xnames else inter (op =) [Long_Name.base_name name] xnames) |
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
471 |
|> fold (del_name_extra name) accs'; |
56168
088b64497a61
more uniform alias vs. hide: proper check, allow to hide global names as well;
wenzelm
parents:
56164
diff
changeset
|
472 |
in (kind, internals', entries) end); |
088b64497a61
more uniform alias vs. hide: proper check, allow to hide global names as well;
wenzelm
parents:
56164
diff
changeset
|
473 |
|
088b64497a61
more uniform alias vs. hide: proper check, allow to hide global names as well;
wenzelm
parents:
56164
diff
changeset
|
474 |
|
47003 | 475 |
(* alias *) |
476 |
||
477 |
fun alias naming binding name space = |
|
56168
088b64497a61
more uniform alias vs. hide: proper check, allow to hide global names as well;
wenzelm
parents:
56164
diff
changeset
|
478 |
space |> map_name_space (fn (kind, internals, entries) => |
088b64497a61
more uniform alias vs. hide: proper check, allow to hide global names as well;
wenzelm
parents:
56164
diff
changeset
|
479 |
let |
59889 | 480 |
val _ = the_entry space name; |
64307
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
481 |
val (more_accs, more_accs') = make_accesses naming binding; |
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
482 |
val internals' = internals |> fold (add_name name) more_accs; |
56168
088b64497a61
more uniform alias vs. hide: proper check, allow to hide global names as well;
wenzelm
parents:
56164
diff
changeset
|
483 |
val entries' = entries |
64307
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
484 |
|> Change_Table.map_entry name (apfst (fn (accs, accs') => |
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
485 |
(fold_rev (update op =) more_accs accs, |
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
486 |
fold_rev (update op =) more_accs' accs'))) |
56168
088b64497a61
more uniform alias vs. hide: proper check, allow to hide global names as well;
wenzelm
parents:
56164
diff
changeset
|
487 |
in (kind, internals', entries') end); |
47003 | 488 |
|
489 |
||
490 |
||
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
491 |
(** context naming **) |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
492 |
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
493 |
structure Data_Args = |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
494 |
struct |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
495 |
type T = naming; |
58668 | 496 |
val empty = global_naming; |
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
497 |
fun init _ = local_naming; |
72053
4ed33ea8d957
prefer conservative extend/merge of theory naming;
wenzelm
parents:
71674
diff
changeset
|
498 |
val merge = #1; |
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
499 |
end; |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
500 |
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
501 |
structure Global_Naming = Theory_Data(Data_Args); |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
502 |
structure Local_Naming = Proof_Data(Data_Args); |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
503 |
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
504 |
fun naming_of (Context.Theory thy) = Global_Naming.get thy |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
505 |
| naming_of (Context.Proof ctxt) = Local_Naming.get ctxt; |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
506 |
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
507 |
fun map_naming f (Context.Theory thy) = Context.Theory (Global_Naming.map f thy) |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
508 |
| map_naming f (Context.Proof ctxt) = Context.Proof (Local_Naming.map f ctxt); |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
509 |
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
510 |
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
511 |
|
47003 | 512 |
(** entry definition **) |
513 |
||
30233
6eb726e43ed1
eliminated internal stamp equality, replaced by bare-metal pointer_eq;
wenzelm
parents:
30222
diff
changeset
|
514 |
(* declaration *) |
28860 | 515 |
|
68163 | 516 |
fun declared (Name_Space {entries, ...}) = Change_Table.defined entries; |
517 |
||
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
518 |
fun declare context strict binding space = |
30233
6eb726e43ed1
eliminated internal stamp equality, replaced by bare-metal pointer_eq;
wenzelm
parents:
30222
diff
changeset
|
519 |
let |
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
520 |
val naming = naming_of context; |
71257 | 521 |
val Naming {group, theory_long_name, ...} = naming; |
59859 | 522 |
val {concealed, spec, ...} = name_spec naming binding; |
64307
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
523 |
val accesses = make_accesses naming binding; |
33157
56f836b9414f
allow name space entries to be "concealed" -- via binding/naming/local_theory;
wenzelm
parents:
33097
diff
changeset
|
524 |
|
56f836b9414f
allow name space entries to be "concealed" -- via binding/naming/local_theory;
wenzelm
parents:
33097
diff
changeset
|
525 |
val name = Long_Name.implode (map fst spec); |
59874 | 526 |
val _ = name = "" andalso error (Binding.bad binding); |
33157
56f836b9414f
allow name space entries to be "concealed" -- via binding/naming/local_theory;
wenzelm
parents:
33097
diff
changeset
|
527 |
|
49528
789b73fcca72
report proper binding positions only -- avoid swamping document model with unspecific information;
wenzelm
parents:
49358
diff
changeset
|
528 |
val (proper_pos, pos) = Position.default (Binding.pos_of binding); |
33096 | 529 |
val entry = |
59859 | 530 |
{concealed = concealed, |
33164
b8fd9b6bba7c
Name_Space.naming: maintain group and theory_name as well;
wenzelm
parents:
33157
diff
changeset
|
531 |
group = group, |
71257 | 532 |
theory_long_name = theory_long_name, |
42375
774df7c59508
report Name_Space.declare/define, relatively to context;
wenzelm
parents:
42358
diff
changeset
|
533 |
pos = pos, |
57899
5867d1306712
clarified signature: entity serial number is not position id;
wenzelm
parents:
56438
diff
changeset
|
534 |
serial = serial ()}; |
56164 | 535 |
val space' = |
536 |
space |> map_name_space (fn (kind, internals, entries) => |
|
537 |
let |
|
64307
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
538 |
val internals' = internals |> fold (add_name name) (#1 accesses); |
56164 | 539 |
val entries' = |
540 |
(if strict then Change_Table.update_new else Change_Table.update) |
|
64307
c4d16f35c6e7
replaced inefficient valid_accesses by is_valid_access, based on stored input accesses: e.g. relevant for Proof_Context.update_thms;
wenzelm
parents:
63232
diff
changeset
|
541 |
(name, (accesses, entry)) entries |
56164 | 542 |
handle Change_Table.DUP dup => |
543 |
err_dup kind (dup, #2 (the (Change_Table.lookup entries dup))) |
|
544 |
(name, entry) (#pos entry); |
|
545 |
in (kind, internals', entries') end); |
|
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47003
diff
changeset
|
546 |
val _ = |
56160 | 547 |
if proper_pos andalso Context_Position.is_reported_generic context pos then |
74262 | 548 |
Position.report pos (entry_markup {def = true} (kind_of space) (name, entry)) |
49528
789b73fcca72
report proper binding positions only -- avoid swamping document model with unspecific information;
wenzelm
parents:
49358
diff
changeset
|
549 |
else (); |
30233
6eb726e43ed1
eliminated internal stamp equality, replaced by bare-metal pointer_eq;
wenzelm
parents:
30222
diff
changeset
|
550 |
in (name, space') end; |
28860 | 551 |
|
16137 | 552 |
|
47003 | 553 |
(* definition in symbol table *) |
16341
e573e5167eda
added type NameSpace.table with basic operations;
wenzelm
parents:
16262
diff
changeset
|
554 |
|
56056
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
56052
diff
changeset
|
555 |
datatype 'a table = Table of T * 'a Change_Table.T; |
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
56052
diff
changeset
|
556 |
|
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
56052
diff
changeset
|
557 |
fun change_base begin (Table (space, tab)) = |
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
56052
diff
changeset
|
558 |
Table (change_base_space begin space, Change_Table.change_base begin tab); |
16341
e573e5167eda
added type NameSpace.table with basic operations;
wenzelm
parents:
16262
diff
changeset
|
559 |
|
56139
b7add947a6ef
more frugal recording of changes: join merely requires information from one side;
wenzelm
parents:
56056
diff
changeset
|
560 |
fun change_ignore (Table (space, tab)) = |
b7add947a6ef
more frugal recording of changes: join merely requires information from one side;
wenzelm
parents:
56056
diff
changeset
|
561 |
Table (change_ignore_space space, Change_Table.change_ignore tab); |
b7add947a6ef
more frugal recording of changes: join merely requires information from one side;
wenzelm
parents:
56056
diff
changeset
|
562 |
|
56025 | 563 |
fun space_of_table (Table (space, _)) = space; |
564 |
||
565 |
fun check_reports context (Table (space, tab)) (xname, ps) = |
|
42466 | 566 |
let val name = intern space xname in |
56056
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
56052
diff
changeset
|
567 |
(case Change_Table.lookup tab name of |
55696 | 568 |
SOME x => |
55922
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55845
diff
changeset
|
569 |
let |
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55845
diff
changeset
|
570 |
val reports = |
55956
94d384d621b0
reject internal term names outright, and complete consts instead;
wenzelm
parents:
55923
diff
changeset
|
571 |
filter (Context_Position.is_reported_generic context) ps |
94d384d621b0
reject internal term names outright, and complete consts instead;
wenzelm
parents:
55923
diff
changeset
|
572 |
|> map (fn pos => (pos, markup space name)); |
55922
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55845
diff
changeset
|
573 |
in ((name, reports), x) end |
55672
5e25cc741ab9
support for completion within the formal context;
wenzelm
parents:
55669
diff
changeset
|
574 |
| NONE => |
69289 | 575 |
error (undefined space name ^ Position.here_list ps ^ |
576 |
Completion.markup_report |
|
577 |
(map (fn pos => completion context space (K true) (xname, pos)) ps))) |
|
42466 | 578 |
end; |
579 |
||
55956
94d384d621b0
reject internal term names outright, and complete consts instead;
wenzelm
parents:
55923
diff
changeset
|
580 |
fun check context table (xname, pos) = |
55922
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55845
diff
changeset
|
581 |
let |
55956
94d384d621b0
reject internal term names outright, and complete consts instead;
wenzelm
parents:
55923
diff
changeset
|
582 |
val ((name, reports), x) = check_reports context table (xname, [pos]); |
71674 | 583 |
val _ = Context_Position.reports_generic context reports; |
55922
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55845
diff
changeset
|
584 |
in (name, x) end; |
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55845
diff
changeset
|
585 |
|
59883 | 586 |
fun defined (Table (_, tab)) name = Change_Table.defined tab name; |
59884 | 587 |
fun lookup (Table (_, tab)) name = Change_Table.lookup tab name; |
56056
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
56052
diff
changeset
|
588 |
fun lookup_key (Table (_, tab)) name = Change_Table.lookup_key tab name; |
56025 | 589 |
|
590 |
fun get table name = |
|
591 |
(case lookup_key table name of |
|
592 |
SOME (_, x) => x |
|
59889 | 593 |
| NONE => error (undefined (space_of_table table) name)); |
42466 | 594 |
|
56025 | 595 |
fun define context strict (binding, x) (Table (space, tab)) = |
596 |
let |
|
597 |
val (name, space') = declare context strict binding space; |
|
56056
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
56052
diff
changeset
|
598 |
val tab' = Change_Table.update (name, x) tab; |
56025 | 599 |
in (name, Table (space', tab')) end; |
600 |
||
601 |
||
602 |
(* derived table operations *) |
|
603 |
||
604 |
fun alias_table naming binding name (Table (space, tab)) = |
|
605 |
Table (alias naming binding name space, tab); |
|
606 |
||
607 |
fun hide_table fully name (Table (space, tab)) = |
|
608 |
Table (hide fully name space, tab); |
|
16341
e573e5167eda
added type NameSpace.table with basic operations;
wenzelm
parents:
16262
diff
changeset
|
609 |
|
56025 | 610 |
fun del_table name (Table (space, tab)) = |
611 |
let |
|
612 |
val space' = hide true name space handle ERROR _ => space; |
|
56056
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
56052
diff
changeset
|
613 |
val tab' = Change_Table.delete_safe name tab; |
56025 | 614 |
in Table (space', tab') end; |
28860 | 615 |
|
56025 | 616 |
fun map_table_entry name f (Table (space, tab)) = |
56056
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
56052
diff
changeset
|
617 |
Table (space, Change_Table.map_entry name f tab); |
56025 | 618 |
|
56056
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
56052
diff
changeset
|
619 |
fun fold_table f (Table (_, tab)) = Change_Table.fold f tab; |
68163 | 620 |
fun dest_table (Table (_, tab)) = Change_Table.dest tab; |
16341
e573e5167eda
added type NameSpace.table with basic operations;
wenzelm
parents:
16262
diff
changeset
|
621 |
|
56056
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
56052
diff
changeset
|
622 |
fun empty_table kind = Table (empty kind, Change_Table.empty); |
56025 | 623 |
|
624 |
fun merge_tables (Table (space1, tab1), Table (space2, tab2)) = |
|
56056
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
56052
diff
changeset
|
625 |
Table (merge (space1, space2), Change_Table.merge (K true) (tab1, tab2)); |
28991 | 626 |
|
56025 | 627 |
fun join_tables f (Table (space1, tab1), Table (space2, tab2)) = |
56056
4d46d53566e6
more efficient local theory operations, by imposing a linear change discipline on the main types/consts tables, in order to speed-up Proof_Context.transfer_syntax required for Local_Theory.raw_theory_result;
wenzelm
parents:
56052
diff
changeset
|
628 |
Table (merge (space1, space2), Change_Table.join f (tab1, tab2)); |
56025 | 629 |
|
630 |
||
631 |
(* present table content *) |
|
632 |
||
59917
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59912
diff
changeset
|
633 |
fun extern_entries verbose ctxt space entries = |
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59912
diff
changeset
|
634 |
fold (fn (name, x) => |
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59912
diff
changeset
|
635 |
(verbose orelse not (is_concealed space name)) ? |
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59912
diff
changeset
|
636 |
cons ((name, extern ctxt space name), x)) entries [] |
60924
610794dff23c
tuned signature, in accordance to sortBy in Scala;
wenzelm
parents:
60284
diff
changeset
|
637 |
|> sort_by (#2 o #1); |
16848 | 638 |
|
59917
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59912
diff
changeset
|
639 |
fun markup_entries verbose ctxt space entries = |
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59912
diff
changeset
|
640 |
extern_entries verbose ctxt space entries |
56025 | 641 |
|> map (fn ((name, xname), x) => ((markup space name, xname), x)); |
642 |
||
59917
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59912
diff
changeset
|
643 |
fun extern_table verbose ctxt (Table (space, tab)) = |
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59912
diff
changeset
|
644 |
extern_entries verbose ctxt space (Change_Table.dest tab); |
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59912
diff
changeset
|
645 |
|
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59912
diff
changeset
|
646 |
fun markup_table verbose ctxt (Table (space, tab)) = |
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59912
diff
changeset
|
647 |
markup_entries verbose ctxt space (Change_Table.dest tab); |
16341
e573e5167eda
added type NameSpace.table with basic operations;
wenzelm
parents:
16262
diff
changeset
|
648 |
|
5012 | 649 |
end; |