| author | wenzelm |
| Fri, 24 Jul 2009 12:00:02 +0200 | |
| changeset 32169 | fbada8ed12e6 |
| parent 30795 | 04ebcd11add8 |
| child 32590 | 95f4f08f950f |
| permissions | -rw-r--r-- |
| 28941 | 1 |
(* Title: Pure/General/binding.ML |
2 |
Author: Florian Haftmann, TU Muenchen |
|
|
30214
f84c9f10292a
moved name space externalization flags back to name_space.ML;
wenzelm
parents:
29617
diff
changeset
|
3 |
Author: Makarius |
| 28941 | 4 |
|
5 |
Structured name bindings. |
|
6 |
*) |
|
7 |
||
|
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
8 |
type bstring = string; (*primitive names to be bound*) |
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
9 |
|
|
30214
f84c9f10292a
moved name space externalization flags back to name_space.ML;
wenzelm
parents:
29617
diff
changeset
|
10 |
signature BINDING = |
| 28941 | 11 |
sig |
| 29581 | 12 |
type binding |
| 30276 | 13 |
val dest: binding -> (string * bool) list * bstring |
|
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
14 |
val make: bstring * Position.T -> binding |
| 30276 | 15 |
val pos_of: binding -> Position.T |
|
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
16 |
val name: bstring -> binding |
| 30464 | 17 |
val name_of: binding -> bstring |
|
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
18 |
val map_name: (bstring -> bstring) -> binding -> binding |
| 30338 | 19 |
val prefix_name: string -> binding -> binding |
20 |
val suffix_name: string -> binding -> binding |
|
21 |
val eq_name: binding * binding -> bool |
|
| 29617 | 22 |
val empty: binding |
|
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
23 |
val is_empty: binding -> bool |
| 30410 | 24 |
val qualify: bool -> string -> binding -> binding |
| 30464 | 25 |
val qualified_name: string -> binding |
26 |
val qualified_name_of: binding -> string |
|
| 30276 | 27 |
val prefix_of: binding -> (string * bool) list |
|
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
28 |
val map_prefix: ((string * bool) list -> (string * bool) list) -> binding -> binding |
|
30335
b3ef64cadcad
Binding.str_of: removed verbose feature, include qualifier in output;
wenzelm
parents:
30276
diff
changeset
|
29 |
val prefix: bool -> string -> binding -> binding |
| 30410 | 30 |
val str_of: binding -> string |
| 29617 | 31 |
end; |
| 28941 | 32 |
|
| 30338 | 33 |
structure Binding:> BINDING = |
| 28941 | 34 |
struct |
35 |
||
|
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
36 |
(** representation **) |
| 29338 | 37 |
|
|
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
38 |
(* datatype *) |
| 29338 | 39 |
|
|
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
40 |
datatype binding = Binding of |
| 30276 | 41 |
{prefix: (string * bool) list, (*system prefix*)
|
42 |
qualifier: (string * bool) list, (*user qualifier*) |
|
43 |
name: bstring, (*base name*) |
|
44 |
pos: Position.T}; (*source position*) |
|
| 28941 | 45 |
|
|
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
46 |
fun make_binding (prefix, qualifier, name, pos) = |
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
47 |
Binding {prefix = prefix, qualifier = qualifier, name = name, pos = pos};
|
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
48 |
|
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
49 |
fun map_binding f (Binding {prefix, qualifier, name, pos}) =
|
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
50 |
make_binding (f (prefix, qualifier, name, pos)); |
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
51 |
|
| 30276 | 52 |
fun dest (Binding {prefix, qualifier, name, ...}) = (prefix @ qualifier, name);
|
|
30217
894eb2034f02
renamed Binding.display to Binding.str_of, which is slightly more canonical;
wenzelm
parents:
30214
diff
changeset
|
53 |
|
|
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
54 |
|
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
55 |
|
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
56 |
(** basic operations **) |
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
57 |
|
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
58 |
(* name and position *) |
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
59 |
|
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
60 |
fun make (name, pos) = make_binding ([], [], name, pos); |
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
61 |
fun name name = make (name, Position.none); |
| 28965 | 62 |
|
|
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
63 |
fun pos_of (Binding {pos, ...}) = pos;
|
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
64 |
fun name_of (Binding {name, ...}) = name;
|
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
65 |
|
| 30338 | 66 |
fun eq_name (b, b') = name_of b = name_of b'; |
67 |
||
|
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
68 |
fun map_name f = map_binding (fn (prefix, qualifier, name, pos) => (prefix, qualifier, f name, pos)); |
| 30338 | 69 |
val prefix_name = map_name o prefix; |
70 |
val suffix_name = map_name o suffix; |
|
| 28941 | 71 |
|
|
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
72 |
val empty = name ""; |
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
73 |
fun is_empty b = name_of b = ""; |
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
74 |
|
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
75 |
|
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
76 |
(* user qualifier *) |
| 28941 | 77 |
|
| 30410 | 78 |
fun qualify _ "" = I |
79 |
| qualify mandatory qual = map_binding (fn (prefix, qualifier, name, pos) => |
|
80 |
(prefix, (qual, mandatory) :: qualifier, name, pos)); |
|
81 |
||
|
30361
8ea7a197e2e6
added qualified_name -- emulates old-style qualified bstring;
wenzelm
parents:
30338
diff
changeset
|
82 |
fun qualified_name "" = empty |
|
8ea7a197e2e6
added qualified_name -- emulates old-style qualified bstring;
wenzelm
parents:
30338
diff
changeset
|
83 |
| qualified_name s = |
|
8ea7a197e2e6
added qualified_name -- emulates old-style qualified bstring;
wenzelm
parents:
30338
diff
changeset
|
84 |
let val (qualifier, name) = split_last (Long_Name.explode s) |
|
8ea7a197e2e6
added qualified_name -- emulates old-style qualified bstring;
wenzelm
parents:
30338
diff
changeset
|
85 |
in make_binding ([], map (rpair false) qualifier, name, Position.none) end; |
|
8ea7a197e2e6
added qualified_name -- emulates old-style qualified bstring;
wenzelm
parents:
30338
diff
changeset
|
86 |
|
| 30795 | 87 |
fun qualified_name_of (b as Binding {qualifier, name, ...}) =
|
88 |
if is_empty b then "" |
|
89 |
else Long_Name.implode (map #1 qualifier @ [name]); |
|
|
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
90 |
|
| 28965 | 91 |
|
|
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
92 |
(* system prefix *) |
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
93 |
|
| 30276 | 94 |
fun prefix_of (Binding {prefix, ...}) = prefix;
|
95 |
||
|
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
96 |
fun map_prefix f = map_binding (fn (prefix, qualifier, name, pos) => |
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
97 |
(f prefix, qualifier, name, pos)); |
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
98 |
|
|
30335
b3ef64cadcad
Binding.str_of: removed verbose feature, include qualifier in output;
wenzelm
parents:
30276
diff
changeset
|
99 |
fun prefix _ "" = I |
| 30410 | 100 |
| prefix mandatory prfx = map_prefix (cons (prfx, mandatory)); |
101 |
||
102 |
||
103 |
(* str_of *) |
|
104 |
||
105 |
fun str_of binding = |
|
106 |
let |
|
107 |
val text = qualified_name_of binding; |
|
108 |
val props = Position.properties_of (pos_of binding); |
|
109 |
in Markup.markup (Markup.properties props (Markup.binding (name_of binding))) text end; |
|
| 28941 | 110 |
|
111 |
end; |
|
112 |
||
|
30214
f84c9f10292a
moved name space externalization flags back to name_space.ML;
wenzelm
parents:
29617
diff
changeset
|
113 |
type binding = Binding.binding; |
|
f84c9f10292a
moved name space externalization flags back to name_space.ML;
wenzelm
parents:
29617
diff
changeset
|
114 |