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