author | wenzelm |
Thu, 01 Dec 2011 14:29:14 +0100 | |
changeset 45709 | 87017fcbad83 |
parent 30359 | 3f9b3ff851ca |
child 55669 | 4612c450b59c |
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 |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
11 |
val implode: string list -> string |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
12 |
val explode: string -> string list |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
13 |
val append: string -> string -> string |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
14 |
val qualify: string -> string -> string |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
15 |
val qualifier: string -> string |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
16 |
val base_name: string -> string |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
17 |
val map_base_name: (string -> string) -> string -> string |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
18 |
end; |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
19 |
|
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
20 |
structure Long_Name: LONG_NAME = |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
21 |
struct |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
22 |
|
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
23 |
val separator = "."; |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
24 |
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
|
25 |
|
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
26 |
val implode = space_implode separator; |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
27 |
val explode = space_explode separator; |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
28 |
|
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
29 |
fun append name1 "" = name1 |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
30 |
| append "" name2 = name2 |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
31 |
| append name1 name2 = name1 ^ separator ^ name2; |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
32 |
|
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
33 |
fun qualify qual name = |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
34 |
if qual = "" orelse name = "" then name |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
35 |
else qual ^ separator ^ name; |
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 |
fun qualifier "" = "" |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
38 |
| 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
|
39 |
|
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
40 |
fun base_name "" = "" |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
41 |
| base_name name = List.last (explode name); |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
42 |
|
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
43 |
fun map_base_name _ "" = "" |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
44 |
| map_base_name f name = |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
45 |
let val names = explode name |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
46 |
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
|
47 |
|
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
48 |
end; |
3f9b3ff851ca
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
diff
changeset
|
49 |