author | wenzelm |
Thu, 13 Apr 2023 23:16:18 +0200 | |
changeset 77842 | 0eb54e7004eb |
parent 65358 | e345e9420109 |
child 77843 | f56697bfd67b |
permissions | -rw-r--r-- |
30359
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
1 |
(* Title: Pure/General/long_name.ML |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
3 |
|
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
4 |
Long names. |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
5 |
*) |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
6 |
|
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
7 |
signature LONG_NAME = |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
8 |
sig |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
9 |
val separator: string |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
10 |
val is_qualified: string -> bool |
55669 | 11 |
val hidden: string -> string |
59916 | 12 |
val is_hidden: string -> bool |
59888 | 13 |
val dest_hidden: string -> string option |
56162
ea6303e2261b
clarified completion ordering: prefer local names;
wenzelm
parents:
56023
diff
changeset
|
14 |
val localN: string |
59888 | 15 |
val dest_local: string -> string option |
30359
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
16 |
val implode: string list -> string |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
17 |
val explode: string -> string list |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
18 |
val append: string -> string -> string |
56023 | 19 |
val qualification: string -> int |
30359
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
20 |
val qualify: string -> string -> string |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
21 |
val qualifier: string -> string |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
22 |
val base_name: string -> string |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
23 |
val map_base_name: (string -> string) -> string -> string |
77842
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
24 |
type chunks |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
25 |
val count_chunks: chunks -> int |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
26 |
val size_chunks: chunks -> int |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
27 |
val empty_chunks: chunks |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
28 |
val make_chunks: bool list -> string -> chunks |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
29 |
val chunks: string -> chunks |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
30 |
val explode_chunks: chunks -> string list |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
31 |
val implode_chunks: chunks -> string |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
32 |
val compare_chunks: chunks * chunks -> order |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
33 |
val eq_chunks: chunks * chunks -> bool |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
34 |
structure Chunks: CHANGE_TABLE |
30359
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
35 |
end; |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
36 |
|
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
37 |
structure Long_Name: LONG_NAME = |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
38 |
struct |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
39 |
|
77842
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
40 |
(* long names separated by "." *) |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
41 |
|
30359
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
42 |
val separator = "."; |
77842
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
43 |
val separator_char = String.sub (separator, 0); |
56800 | 44 |
|
30359
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
45 |
val is_qualified = exists_string (fn s => s = separator); |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
46 |
|
59916 | 47 |
val hidden_prefix = "??." |
48 |
val hidden = prefix hidden_prefix; |
|
49 |
val is_hidden = String.isPrefix hidden_prefix; |
|
50 |
val dest_hidden = try (unprefix hidden_prefix); |
|
55669 | 51 |
|
56162
ea6303e2261b
clarified completion ordering: prefer local names;
wenzelm
parents:
56023
diff
changeset
|
52 |
val localN = "local"; |
59888 | 53 |
val dest_local = try (unprefix "local."); |
56162
ea6303e2261b
clarified completion ordering: prefer local names;
wenzelm
parents:
56023
diff
changeset
|
54 |
|
30359
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
55 |
val implode = space_implode separator; |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
56 |
val explode = space_explode separator; |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
57 |
|
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
58 |
fun append name1 "" = name1 |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
59 |
| append "" name2 = name2 |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
60 |
| append name1 name2 = name1 ^ separator ^ name2; |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
61 |
|
56023 | 62 |
fun qualification "" = 0 |
63 |
| qualification name = fold_string (fn s => s = separator ? Integer.add 1) name 1; |
|
64 |
||
30359
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
65 |
fun qualify qual name = |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
66 |
if qual = "" orelse name = "" then name |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
67 |
else qual ^ separator ^ name; |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
68 |
|
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
69 |
fun qualifier "" = "" |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
70 |
| qualifier name = implode (#1 (split_last (explode name))); |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
71 |
|
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
72 |
fun base_name "" = "" |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
73 |
| base_name name = List.last (explode name); |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
74 |
|
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
75 |
fun map_base_name _ "" = "" |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
76 |
| map_base_name f name = |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
77 |
let val names = explode name |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
78 |
in implode (nth_map (length names - 1) f names) end; |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
79 |
|
77842
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
80 |
|
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
81 |
(* compact representation of chunks *) |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
82 |
|
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
83 |
local |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
84 |
|
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
85 |
fun mask_bad s = s = 0w0; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
86 |
fun mask_set s m = Word.orb (m, s); |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
87 |
fun mask_push s = Word.<< (s, 0w1); |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
88 |
fun mask_next m = Word.>> (m, 0w1); |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
89 |
fun mask_keep m = Word.andb (m, 0w1) = 0w0; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
90 |
|
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
91 |
fun string_ops string = |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
92 |
let |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
93 |
val n = size string; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
94 |
fun char i = String.sub (string, i); |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
95 |
fun string_end i = i >= n; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
96 |
fun chunk_end i = string_end i orelse char i = separator_char; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
97 |
in {string_end = string_end, chunk_end = chunk_end} end; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
98 |
|
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
99 |
in |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
100 |
|
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
101 |
abstype chunks = Chunks of {count: int, size: int, mask: word, string: string} |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
102 |
with |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
103 |
|
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
104 |
fun count_chunks (Chunks {count, ...}) = count; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
105 |
fun size_chunks (Chunks {size, ...}) = size; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
106 |
|
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
107 |
val empty_chunks = Chunks {count = 0, size = 0, mask = 0w0, string = ""}; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
108 |
|
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
109 |
fun make_chunks suppress string = |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
110 |
let |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
111 |
val {string_end, chunk_end, ...} = string_ops string; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
112 |
|
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
113 |
fun err msg = raise Fail ("Malformed qualified name " ^ quote string ^ ":\n " ^ msg); |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
114 |
|
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
115 |
fun make suppr i k l m s = |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
116 |
let |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
117 |
val is_end = chunk_end i; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
118 |
val keep = null suppr orelse not (hd suppr); |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
119 |
|
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
120 |
val suppr' = if is_end andalso not (null suppr) then tl suppr else suppr; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
121 |
val l' = if keep then l + 1 else l; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
122 |
val k' = if is_end andalso keep andalso l' > 0 then k + 1 else k; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
123 |
val m' = |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
124 |
if not is_end orelse keep then m |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
125 |
else if mask_bad s then |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
126 |
err ("cannot suppress chunks beyond word size " ^ string_of_int Word.wordSize) |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
127 |
else mask_set s m; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
128 |
val s' = if is_end then mask_push s else s; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
129 |
in |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
130 |
if not (string_end i) then make suppr' (i + 1) k' l' m' s' |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
131 |
else if not (null suppr') then err ("cannot suppress chunks beyond " ^ string_of_int k') |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
132 |
else if k' = 0 then empty_chunks |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
133 |
else Chunks {count = k', size = Int.max (0, l' - 1), mask = m', string = string} |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
134 |
end; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
135 |
in make suppress 0 0 0 0w0 0w1 end; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
136 |
|
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
137 |
val chunks = make_chunks []; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
138 |
|
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
139 |
fun expand_chunks f (Chunks {count, size, mask, string}) = |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
140 |
let |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
141 |
val {string_end, chunk_end, ...} = string_ops string; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
142 |
|
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
143 |
fun explode bg en m acc = |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
144 |
let |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
145 |
val is_end = chunk_end en; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
146 |
|
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
147 |
val en' = en + 1; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
148 |
val bg' = if is_end then en' else bg; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
149 |
val m' = if is_end then mask_next m else m; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
150 |
val acc' = if is_end andalso mask_keep m then f (string, bg, en - bg) :: acc else acc; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
151 |
in if string_end en then rev acc' else explode bg' en' m' acc' end; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
152 |
in |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
153 |
if count = 0 then [] |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
154 |
else if count = 1 andalso size = String.size string then [f (string, 0, size)] |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
155 |
else explode 0 0 mask [] |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
156 |
end; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
157 |
|
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
158 |
val explode_chunks = expand_chunks String.substring; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
159 |
val implode_chunks = implode o explode_chunks; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
160 |
|
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
161 |
val compare_chunks = |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
162 |
pointer_eq_ord (fn (chunks1, chunks2) => |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
163 |
let |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
164 |
val Chunks args1 = chunks1; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
165 |
val Chunks args2 = chunks2; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
166 |
val ord1 = |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
167 |
int_ord o apply2 #size ||| |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
168 |
int_ord o apply2 #count; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
169 |
val ord2 = |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
170 |
dict_ord int_ord o apply2 (expand_chunks #3) ||| |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
171 |
dict_ord Substring.compare o apply2 (expand_chunks Substring.substring); |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
172 |
in |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
173 |
(case ord1 (args1, args2) of |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
174 |
EQUAL => |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
175 |
if #mask args1 = #mask args2 andalso #string args1 = #string args2 then EQUAL |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
176 |
else ord2 (chunks1, chunks2) |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
177 |
| ord => ord) |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
178 |
end); |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
179 |
|
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
180 |
val eq_chunks = is_equal o compare_chunks; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
181 |
|
30359
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
182 |
end; |
77842
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
183 |
|
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
184 |
end; |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
185 |
|
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
186 |
structure Chunks = Change_Table(type key = chunks val ord = compare_chunks); |
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
187 |
|
0eb54e7004eb
compact representation of long name "chunks", with bitmask to suppress elements (i.e. "accesses" in name space terminology);
wenzelm
parents:
65358
diff
changeset
|
188 |
end; |