author | wenzelm |
Sat, 07 Mar 2009 11:32:31 +0100 | |
changeset 30335 | b3ef64cadcad |
parent 30276 | 51b92d34af79 |
child 30338 | 51d488f3dd72 |
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 |
30217
894eb2034f02
renamed Binding.display to Binding.str_of, which is slightly more canonical;
wenzelm
parents:
30214
diff
changeset
|
14 |
val str_of: binding -> string |
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
15 |
val make: bstring * Position.T -> binding |
30276 | 16 |
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
|
17 |
val name: bstring -> binding |
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 name_of: binding -> string |
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
19 |
val map_name: (bstring -> bstring) -> binding -> binding |
29617 | 20 |
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
|
21 |
val is_empty: binding -> bool |
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
22 |
val qualify: bool -> string -> binding -> binding |
30276 | 23 |
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
|
24 |
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
|
25 |
val prefix: bool -> string -> binding -> binding |
29617 | 26 |
end; |
28941 | 27 |
|
30217
894eb2034f02
renamed Binding.display to Binding.str_of, which is slightly more canonical;
wenzelm
parents:
30214
diff
changeset
|
28 |
structure Binding: BINDING = |
28941 | 29 |
struct |
30 |
||
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
31 |
(** representation **) |
29338 | 32 |
|
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
33 |
(* datatype *) |
29338 | 34 |
|
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
35 |
datatype binding = Binding of |
30276 | 36 |
{prefix: (string * bool) list, (*system prefix*) |
37 |
qualifier: (string * bool) list, (*user qualifier*) |
|
38 |
name: bstring, (*base name*) |
|
39 |
pos: Position.T}; (*source position*) |
|
28941 | 40 |
|
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
41 |
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
|
42 |
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
|
43 |
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
44 |
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
|
45 |
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
|
46 |
|
30276 | 47 |
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
|
48 |
|
30222
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 str_of (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 |
let |
30335
b3ef64cadcad
Binding.str_of: removed verbose feature, include qualifier in output;
wenzelm
parents:
30276
diff
changeset
|
51 |
val text = space_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
|
52 |
val props = Position.properties_of pos; |
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
53 |
in Markup.markup (Markup.properties props (Markup.binding name)) text end; |
28965 | 54 |
|
30222
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 |
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
57 |
(** 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
|
58 |
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
59 |
(* 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
|
60 |
|
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 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
|
62 |
fun name name = make (name, Position.none); |
28965 | 63 |
|
30222
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 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
|
65 |
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
|
66 |
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
67 |
fun map_name f = map_binding (fn (prefix, qualifier, name, pos) => (prefix, qualifier, f name, pos)); |
28941 | 68 |
|
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
69 |
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
|
70 |
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
|
71 |
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
72 |
|
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
73 |
(* user qualifier *) |
28941 | 74 |
|
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
75 |
fun qualify _ "" = I |
30335
b3ef64cadcad
Binding.str_of: removed verbose feature, include qualifier in output;
wenzelm
parents:
30276
diff
changeset
|
76 |
| qualify strict qual = map_binding (fn (prefix, qualifier, name, pos) => |
b3ef64cadcad
Binding.str_of: removed verbose feature, include qualifier in output;
wenzelm
parents:
30276
diff
changeset
|
77 |
(prefix, (qual, strict) :: qualifier, name, pos)); |
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
78 |
|
28965 | 79 |
|
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
80 |
(* 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
|
81 |
|
30276 | 82 |
fun prefix_of (Binding {prefix, ...}) = prefix; |
83 |
||
30222
4102bbf2af21
moved type bstring from name_space.ML to binding.ML -- it is the primitive concept behind bindings;
wenzelm
parents:
30217
diff
changeset
|
84 |
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
|
85 |
(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
|
86 |
|
30335
b3ef64cadcad
Binding.str_of: removed verbose feature, include qualifier in output;
wenzelm
parents:
30276
diff
changeset
|
87 |
fun prefix _ "" = I |
b3ef64cadcad
Binding.str_of: removed verbose feature, include qualifier in output;
wenzelm
parents:
30276
diff
changeset
|
88 |
| prefix strict prfx = map_prefix (cons (prfx, strict)); |
28941 | 89 |
|
90 |
end; |
|
91 |
||
30214
f84c9f10292a
moved name space externalization flags back to name_space.ML;
wenzelm
parents:
29617
diff
changeset
|
92 |
type binding = Binding.binding; |
f84c9f10292a
moved name space externalization flags back to name_space.ML;
wenzelm
parents:
29617
diff
changeset
|
93 |