| author | wenzelm | 
| Tue, 03 Jun 2008 14:04:26 +0200 | |
| changeset 27066 | dbf97292e5fd | 
| parent 26657 | 35249f5367b3 | 
| child 27196 | ef2f01da7a12 | 
| permissions | -rw-r--r-- | 
| 6118 | 1  | 
(* Title: Pure/General/name_space.ML  | 
| 5012 | 2  | 
ID: $Id$  | 
3  | 
Author: Markus Wenzel, TU Muenchen  | 
|
4  | 
||
| 16137 | 5  | 
Generic name spaces with declared and hidden entries. Unknown names  | 
| 
16341
 
e573e5167eda
added type NameSpace.table with basic operations;
 
wenzelm 
parents: 
16262 
diff
changeset
 | 
6  | 
are considered global; no support for absolute addressing.  | 
| 16137 | 7  | 
*)  | 
8  | 
||
| 26440 | 9  | 
type bstring = string; (*names to be bound*)  | 
10  | 
type xstring = string; (*external names*)  | 
|
| 5012 | 11  | 
|
| 16137 | 12  | 
signature BASIC_NAME_SPACE =  | 
13  | 
sig  | 
|
14  | 
val long_names: bool ref  | 
|
15  | 
val short_names: bool ref  | 
|
16  | 
val unique_names: bool ref  | 
|
17  | 
end;  | 
|
| 5012 | 18  | 
|
19  | 
signature NAME_SPACE =  | 
|
20  | 
sig  | 
|
| 16137 | 21  | 
include BASIC_NAME_SPACE  | 
| 9120 | 22  | 
val hidden: string -> string  | 
| 25225 | 23  | 
val is_hidden: string -> bool  | 
| 16137 | 24  | 
val separator: string (*single char*)  | 
25  | 
val is_qualified: string -> bool  | 
|
| 
21858
 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 
wenzelm 
parents: 
20530 
diff
changeset
 | 
26  | 
val implode: string list -> string  | 
| 
 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 
wenzelm 
parents: 
20530 
diff
changeset
 | 
27  | 
val explode: string -> string list  | 
| 16137 | 28  | 
val append: string -> string -> string  | 
29  | 
val qualified: string -> string -> string  | 
|
| 5012 | 30  | 
val base: string -> string  | 
| 
20530
 
448594cbd82b
renamed NameSpace.drop_base to NameSpace.qualifier;
 
wenzelm 
parents: 
19367 
diff
changeset
 | 
31  | 
val qualifier: string -> string  | 
| 11829 | 32  | 
val map_base: (string -> string) -> string -> string  | 
| 5012 | 33  | 
type T  | 
34  | 
val empty: T  | 
|
| 16137 | 35  | 
val intern: T -> xstring -> string  | 
36  | 
val extern: T -> string -> xstring  | 
|
37  | 
val hide: bool -> string -> T -> T  | 
|
| 5012 | 38  | 
val merge: T * T -> T  | 
| 16137 | 39  | 
type naming  | 
40  | 
val path_of: naming -> string  | 
|
| 
25072
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
41  | 
val external_names: naming -> string -> string list  | 
| 16137 | 42  | 
val full: naming -> bstring -> string  | 
43  | 
val declare: naming -> string -> T -> T  | 
|
44  | 
val default_naming: naming  | 
|
45  | 
val add_path: string -> naming -> naming  | 
|
| 19015 | 46  | 
val no_base_names: naming -> naming  | 
| 16137 | 47  | 
val qualified_names: naming -> naming  | 
| 19055 | 48  | 
val sticky_prefix: string -> naming -> naming  | 
| 24361 | 49  | 
type 'a table = T * 'a Symtab.table  | 
| 
16341
 
e573e5167eda
added type NameSpace.table with basic operations;
 
wenzelm 
parents: 
16262 
diff
changeset
 | 
50  | 
val empty_table: 'a table  | 
| 23086 | 51  | 
val extend_table: naming -> (bstring * 'a) list -> 'a table -> 'a table  | 
| 
16341
 
e573e5167eda
added type NameSpace.table with basic operations;
 
wenzelm 
parents: 
16262 
diff
changeset
 | 
52  | 
  val merge_tables: ('a * 'a -> bool) -> 'a table * 'a table -> 'a table
 | 
| 16848 | 53  | 
val dest_table: 'a table -> (string * 'a) list  | 
| 
16341
 
e573e5167eda
added type NameSpace.table with basic operations;
 
wenzelm 
parents: 
16262 
diff
changeset
 | 
54  | 
val extern_table: 'a table -> (xstring * 'a) list  | 
| 5012 | 55  | 
end;  | 
56  | 
||
57  | 
structure NameSpace: NAME_SPACE =  | 
|
58  | 
struct  | 
|
59  | 
||
60  | 
(** long identifiers **)  | 
|
61  | 
||
| 16137 | 62  | 
fun hidden name = "??." ^ name;  | 
63  | 
val is_hidden = String.isPrefix "??."  | 
|
64  | 
||
| 5012 | 65  | 
val separator = ".";  | 
| 19305 | 66  | 
val is_qualified = exists_string (fn s => s = separator);  | 
| 5012 | 67  | 
|
| 
21858
 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 
wenzelm 
parents: 
20530 
diff
changeset
 | 
68  | 
val implode_name = space_implode separator;  | 
| 
 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 
wenzelm 
parents: 
20530 
diff
changeset
 | 
69  | 
val explode_name = space_explode separator;  | 
| 5012 | 70  | 
|
| 16137 | 71  | 
fun append name1 "" = name1  | 
72  | 
| append "" name2 = name2  | 
|
73  | 
| append name1 name2 = name1 ^ separator ^ name2;  | 
|
74  | 
||
75  | 
fun qualified path name =  | 
|
76  | 
if path = "" orelse name = "" then name  | 
|
77  | 
else path ^ separator ^ name;  | 
|
| 11829 | 78  | 
|
| 16137 | 79  | 
fun base "" = ""  | 
| 
21858
 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 
wenzelm 
parents: 
20530 
diff
changeset
 | 
80  | 
| base name = List.last (explode_name name);  | 
| 11829 | 81  | 
|
| 
20530
 
448594cbd82b
renamed NameSpace.drop_base to NameSpace.qualifier;
 
wenzelm 
parents: 
19367 
diff
changeset
 | 
82  | 
fun qualifier "" = ""  | 
| 
21858
 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 
wenzelm 
parents: 
20530 
diff
changeset
 | 
83  | 
| qualifier name = implode_name (#1 (split_last (explode_name name)));  | 
| 5012 | 84  | 
|
| 16137 | 85  | 
fun map_base _ "" = ""  | 
86  | 
| map_base f name =  | 
|
| 
21858
 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 
wenzelm 
parents: 
20530 
diff
changeset
 | 
87  | 
let val names = explode_name name  | 
| 
 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 
wenzelm 
parents: 
20530 
diff
changeset
 | 
88  | 
in implode_name (nth_map (length names - 1) f names) end;  | 
| 16137 | 89  | 
|
| 19015 | 90  | 
|
| 
25072
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
91  | 
(* standard accesses *)  | 
| 19015 | 92  | 
|
93  | 
infixr 6 @@;  | 
|
94  | 
fun ([] @@ yss) = []  | 
|
95  | 
| ((xs :: xss) @@ yss) = map (fn ys => xs @ ys) yss @ (xss @@ yss);  | 
|
96  | 
||
97  | 
fun suffixes_prefixes list =  | 
|
| 5012 | 98  | 
let  | 
| 19015 | 99  | 
val (xs, ws) = chop (length list - 1) list;  | 
100  | 
val sfxs = suffixes xs @@ [ws];  | 
|
101  | 
val pfxs = prefixes1 xs @@ [ws];  | 
|
| 
25072
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
102  | 
in (sfxs @ pfxs, sfxs) end;  | 
| 19015 | 103  | 
|
104  | 
fun suffixes_prefixes_split i k list =  | 
|
105  | 
let  | 
|
106  | 
val (((xs, ys), zs), ws) = list |> chop i ||>> chop k ||>> chop (length list - (i + k + 1));  | 
|
107  | 
val sfxs =  | 
|
108  | 
[ys] @@ suffixes zs @@ [ws] @  | 
|
109  | 
suffixes1 xs @@ [ys @ zs @ ws];  | 
|
110  | 
val pfxs =  | 
|
111  | 
prefixes1 xs @@ [ys @ ws] @  | 
|
112  | 
[xs @ ys] @@ prefixes1 zs @@ [ws];  | 
|
| 
25072
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
113  | 
in (sfxs @ pfxs, sfxs) end;  | 
| 13332 | 114  | 
|
| 5012 | 115  | 
|
116  | 
||
117  | 
(** name spaces **)  | 
|
118  | 
||
119  | 
(* datatype T *)  | 
|
120  | 
||
121  | 
datatype T =  | 
|
| 
25072
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
122  | 
NameSpace of  | 
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
123  | 
((string list * string list) * stamp) Symtab.table * (*internals, hidden internals*)  | 
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
124  | 
(string list * stamp) Symtab.table; (*externals*)  | 
| 5012 | 125  | 
|
| 
25072
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
126  | 
val empty = NameSpace (Symtab.empty, Symtab.empty);  | 
| 5012 | 127  | 
|
| 
25072
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
128  | 
fun lookup (NameSpace (tab, _)) xname =  | 
| 17412 | 129  | 
(case Symtab.lookup tab xname of  | 
| 16137 | 130  | 
NONE => (xname, true)  | 
| 
19030
 
78d43fe9ac65
low-level tuning of merge: maintain identity of accesses;
 
wenzelm 
parents: 
19015 
diff
changeset
 | 
131  | 
| SOME (([], []), _) => (xname, true)  | 
| 
 
78d43fe9ac65
low-level tuning of merge: maintain identity of accesses;
 
wenzelm 
parents: 
19015 
diff
changeset
 | 
132  | 
| SOME (([name], _), _) => (name, true)  | 
| 
 
78d43fe9ac65
low-level tuning of merge: maintain identity of accesses;
 
wenzelm 
parents: 
19015 
diff
changeset
 | 
133  | 
| SOME ((name :: _, _), _) => (name, false)  | 
| 
 
78d43fe9ac65
low-level tuning of merge: maintain identity of accesses;
 
wenzelm 
parents: 
19015 
diff
changeset
 | 
134  | 
| SOME (([], name' :: _), _) => (hidden name', true));  | 
| 8728 | 135  | 
|
| 
25072
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
136  | 
fun get_accesses (NameSpace (_, tab)) name =  | 
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
137  | 
(case Symtab.lookup tab name of  | 
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
138  | 
NONE => [name]  | 
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
139  | 
| SOME (xnames, _) => xnames);  | 
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
140  | 
|
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
141  | 
fun put_accesses name xnames (NameSpace (tab, xtab)) =  | 
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
142  | 
NameSpace (tab, Symtab.update (name, (xnames, stamp ())) xtab);  | 
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
143  | 
|
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
144  | 
fun valid_accesses (NameSpace (tab, _)) name = Symtab.fold (fn (xname, ((names, _), _)) =>  | 
| 16444 | 145  | 
if not (null names) andalso hd names = name then cons xname else I) tab [];  | 
| 8728 | 146  | 
|
147  | 
||
| 16137 | 148  | 
(* intern and extern *)  | 
149  | 
||
150  | 
fun intern space xname = #1 (lookup space xname);  | 
|
151  | 
||
152  | 
val long_names = ref false;  | 
|
153  | 
val short_names = ref false;  | 
|
154  | 
val unique_names = ref true;  | 
|
155  | 
||
156  | 
fun extern space name =  | 
|
157  | 
let  | 
|
158  | 
fun valid unique xname =  | 
|
159  | 
let val (name', uniq) = lookup space xname  | 
|
| 26440 | 160  | 
in name = name' andalso (uniq orelse not unique) end;  | 
| 8728 | 161  | 
|
| 26440 | 162  | 
fun ext [] = if valid false name then name else hidden name  | 
163  | 
| ext (nm :: nms) = if valid (! unique_names) nm then nm else ext nms;  | 
|
| 16137 | 164  | 
in  | 
165  | 
if ! long_names then name  | 
|
166  | 
else if ! short_names then base name  | 
|
| 26440 | 167  | 
else ext (get_accesses space name)  | 
| 16137 | 168  | 
end;  | 
169  | 
||
| 5012 | 170  | 
|
| 16137 | 171  | 
(* basic operations *)  | 
172  | 
||
| 
25072
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
173  | 
local  | 
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
174  | 
|
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
175  | 
fun map_space f xname (NameSpace (tab, xtab)) =  | 
| 23086 | 176  | 
NameSpace (Symtab.map_default (xname, (([], []), stamp ()))  | 
| 
25072
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
177  | 
(fn (entry, _) => (f entry, stamp ())) tab, xtab);  | 
| 16137 | 178  | 
|
| 
25072
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
179  | 
in  | 
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
180  | 
|
| 26440 | 181  | 
val del_name = map_space o apfst o remove (op =);  | 
182  | 
val add_name = map_space o apfst o update (op =);  | 
|
183  | 
val add_name' = map_space o apsnd o update (op =);  | 
|
| 8728 | 184  | 
|
| 
25072
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
185  | 
end;  | 
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
186  | 
|
| 8728 | 187  | 
|
188  | 
(* hide *)  | 
|
| 5012 | 189  | 
|
| 16137 | 190  | 
fun hide fully name space =  | 
| 8728 | 191  | 
if not (is_qualified name) then  | 
192  | 
    error ("Attempt to hide global name " ^ quote name)
 | 
|
193  | 
else if is_hidden name then  | 
|
194  | 
    error ("Attempt to hide hidden name " ^ quote name)
 | 
|
| 16137 | 195  | 
else  | 
196  | 
let val names = valid_accesses space name in  | 
|
197  | 
space  | 
|
198  | 
|> add_name' name name  | 
|
199  | 
|> fold (del_name name) (if fully then names else names inter_string [base name])  | 
|
200  | 
end;  | 
|
| 5012 | 201  | 
|
202  | 
||
| 16137 | 203  | 
(* merge *)  | 
| 5012 | 204  | 
|
| 
25072
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
205  | 
fun merge (NameSpace (tab1, xtab1), NameSpace (tab2, xtab2)) =  | 
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
206  | 
let  | 
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
207  | 
val tab' = (tab1, tab2) |> Symtab.join  | 
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
208  | 
(K (fn (((names1, names1'), stamp1), ((names2, names2'), stamp2)) =>  | 
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
209  | 
if stamp1 = stamp2 then raise Symtab.SAME  | 
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
210  | 
else  | 
| 26657 | 211  | 
((Library.merge (op =) (names1, names2),  | 
212  | 
Library.merge (op =) (names1', names2')), stamp ())));  | 
|
| 
25072
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
213  | 
val xtab' = (xtab1, xtab2) |> Symtab.join  | 
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
214  | 
(K (fn ((xnames1, stamp1), (xnames2, stamp2)) =>  | 
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
215  | 
if stamp1 = stamp2 then raise Symtab.SAME  | 
| 26657 | 216  | 
else (Library.merge (op =) (xnames1, xnames2), stamp ())));  | 
| 
25072
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
217  | 
in NameSpace (tab', xtab') end;  | 
| 5012 | 218  | 
|
| 16137 | 219  | 
|
| 26440 | 220  | 
|
| 16137 | 221  | 
(** naming contexts **)  | 
222  | 
||
223  | 
(* datatype naming *)  | 
|
224  | 
||
225  | 
datatype naming = Naming of  | 
|
| 
25072
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
226  | 
string * (*path*)  | 
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
227  | 
((string -> string -> string) * (*qualify*)  | 
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
228  | 
(string list -> string list list * string list list)); (*accesses*)  | 
| 16137 | 229  | 
|
230  | 
fun path_of (Naming (path, _)) = path;  | 
|
| 
25072
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
231  | 
fun accesses (Naming (_, (_, accs))) = accs;  | 
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
232  | 
|
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
233  | 
fun external_names naming = map implode_name o #2 o accesses naming o explode_name;  | 
| 16137 | 234  | 
|
235  | 
||
236  | 
(* declarations *)  | 
|
237  | 
||
238  | 
fun full (Naming (path, (qualify, _))) = qualify path;  | 
|
239  | 
||
| 
25072
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
240  | 
fun declare naming name space =  | 
| 16137 | 241  | 
if is_hidden name then  | 
242  | 
    error ("Attempt to declare hidden name " ^ quote name)
 | 
|
243  | 
else  | 
|
| 21962 | 244  | 
let  | 
245  | 
val names = explode_name name;  | 
|
| 23668 | 246  | 
val _ = (null names orelse exists (fn s => s = "") names  | 
247  | 
orelse exists_string (fn s => s = "\"") name) andalso  | 
|
| 21962 | 248  | 
        error ("Bad name declaration " ^ quote name);
 | 
| 
25072
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
249  | 
val (accs, accs') = pairself (map implode_name) (accesses naming names);  | 
| 
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
250  | 
in space |> fold (add_name name) accs |> put_accesses name accs' end;  | 
| 16137 | 251  | 
|
252  | 
||
253  | 
(* manipulate namings *)  | 
|
254  | 
||
255  | 
fun reject_qualified name =  | 
|
256  | 
if is_qualified name then  | 
|
257  | 
    error ("Attempt to declare qualified name " ^ quote name)
 | 
|
258  | 
else name;  | 
|
259  | 
||
260  | 
val default_naming =  | 
|
261  | 
  Naming ("", (fn path => qualified path o reject_qualified, suffixes_prefixes));
 | 
|
262  | 
||
263  | 
fun add_path elems (Naming (path, policy)) =  | 
|
264  | 
  if elems = "//" then Naming ("", (qualified, #2 policy))
 | 
|
265  | 
  else if elems = "/" then Naming ("", policy)
 | 
|
| 
20530
 
448594cbd82b
renamed NameSpace.drop_base to NameSpace.qualifier;
 
wenzelm 
parents: 
19367 
diff
changeset
 | 
266  | 
else if elems = ".." then Naming (qualifier path, policy)  | 
| 16137 | 267  | 
else Naming (append path elems, policy);  | 
268  | 
||
269  | 
fun no_base_names (Naming (path, (qualify, accs))) =  | 
|
| 
25072
 
03f57b516e12
store external accesses within name space (as produced by naming policy);
 
wenzelm 
parents: 
24361 
diff
changeset
 | 
270  | 
Naming (path, (qualify, pairself (filter_out (fn [_] => true | _ => false)) o accs));  | 
| 16137 | 271  | 
|
| 19015 | 272  | 
fun qualified_names (Naming (path, (_, accs))) = Naming (path, (qualified, accs));  | 
273  | 
||
| 19055 | 274  | 
fun sticky_prefix prfx (Naming (path, (qualify, _))) =  | 
275  | 
Naming (append path prfx,  | 
|
| 
21858
 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 
wenzelm 
parents: 
20530 
diff
changeset
 | 
276  | 
(qualify, suffixes_prefixes_split (length (explode_name path)) (length (explode_name prfx))));  | 
| 19015 | 277  | 
|
| 16137 | 278  | 
|
| 
16341
 
e573e5167eda
added type NameSpace.table with basic operations;
 
wenzelm 
parents: 
16262 
diff
changeset
 | 
279  | 
|
| 
 
e573e5167eda
added type NameSpace.table with basic operations;
 
wenzelm 
parents: 
16262 
diff
changeset
 | 
280  | 
(** name spaces coupled with symbol tables **)  | 
| 
 
e573e5167eda
added type NameSpace.table with basic operations;
 
wenzelm 
parents: 
16262 
diff
changeset
 | 
281  | 
|
| 
 
e573e5167eda
added type NameSpace.table with basic operations;
 
wenzelm 
parents: 
16262 
diff
changeset
 | 
282  | 
type 'a table = T * 'a Symtab.table;  | 
| 
 
e573e5167eda
added type NameSpace.table with basic operations;
 
wenzelm 
parents: 
16262 
diff
changeset
 | 
283  | 
|
| 
 
e573e5167eda
added type NameSpace.table with basic operations;
 
wenzelm 
parents: 
16262 
diff
changeset
 | 
284  | 
val empty_table = (empty, Symtab.empty);  | 
| 
 
e573e5167eda
added type NameSpace.table with basic operations;
 
wenzelm 
parents: 
16262 
diff
changeset
 | 
285  | 
|
| 23086 | 286  | 
fun extend_table naming bentries (space, tab) =  | 
| 
16341
 
e573e5167eda
added type NameSpace.table with basic operations;
 
wenzelm 
parents: 
16262 
diff
changeset
 | 
287  | 
let val entries = map (apfst (full naming)) bentries  | 
| 
 
e573e5167eda
added type NameSpace.table with basic operations;
 
wenzelm 
parents: 
16262 
diff
changeset
 | 
288  | 
in (fold (declare naming o #1) entries space, Symtab.extend (tab, entries)) end;  | 
| 
 
e573e5167eda
added type NameSpace.table with basic operations;
 
wenzelm 
parents: 
16262 
diff
changeset
 | 
289  | 
|
| 
 
e573e5167eda
added type NameSpace.table with basic operations;
 
wenzelm 
parents: 
16262 
diff
changeset
 | 
290  | 
fun merge_tables eq ((space1, tab1), (space2, tab2)) =  | 
| 19367 | 291  | 
(merge (space1, space2), Symtab.merge eq (tab1, tab2));  | 
| 
16341
 
e573e5167eda
added type NameSpace.table with basic operations;
 
wenzelm 
parents: 
16262 
diff
changeset
 | 
292  | 
|
| 16848 | 293  | 
fun ext_table (space, tab) =  | 
294  | 
Symtab.fold (fn (name, x) => cons ((name, extern space name), x)) tab []  | 
|
295  | 
|> Library.sort_wrt (#2 o #1);  | 
|
296  | 
||
297  | 
fun dest_table tab = map (apfst #1) (ext_table tab);  | 
|
298  | 
fun extern_table tab = map (apfst #2) (ext_table tab);  | 
|
| 
16341
 
e573e5167eda
added type NameSpace.table with basic operations;
 
wenzelm 
parents: 
16262 
diff
changeset
 | 
299  | 
|
| 
21858
 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 
wenzelm 
parents: 
20530 
diff
changeset
 | 
300  | 
|
| 
 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 
wenzelm 
parents: 
20530 
diff
changeset
 | 
301  | 
(*final declarations of this structure!*)  | 
| 
 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 
wenzelm 
parents: 
20530 
diff
changeset
 | 
302  | 
val implode = implode_name;  | 
| 
 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 
wenzelm 
parents: 
20530 
diff
changeset
 | 
303  | 
val explode = explode_name;  | 
| 
 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 
wenzelm 
parents: 
20530 
diff
changeset
 | 
304  | 
|
| 5012 | 305  | 
end;  | 
| 5175 | 306  | 
|
| 16137 | 307  | 
structure BasicNameSpace: BASIC_NAME_SPACE = NameSpace;  | 
308  | 
open BasicNameSpace;  |