| author | hoelzl |
| Mon, 14 Mar 2011 14:37:41 +0100 | |
| changeset 41975 | d47eabd80e59 |
| parent 39502 | cffceed8e7fa |
| child 42102 | fcfd07f122d4 |
| permissions | -rw-r--r-- |
| 39348 | 1 |
(* ========================================================================= *) |
2 |
(* NAMES *) |
|
| 39502 | 3 |
(* Copyright (c) 2004 Joe Hurd, distributed under the BSD License *) |
| 39348 | 4 |
(* ========================================================================= *) |
5 |
||
6 |
structure Name :> Name = |
|
7 |
struct |
|
8 |
||
9 |
open Useful; |
|
10 |
||
11 |
(* ------------------------------------------------------------------------- *) |
|
12 |
(* A type of names. *) |
|
13 |
(* ------------------------------------------------------------------------- *) |
|
14 |
||
15 |
type name = string; |
|
16 |
||
17 |
(* ------------------------------------------------------------------------- *) |
|
18 |
(* A total ordering. *) |
|
19 |
(* ------------------------------------------------------------------------- *) |
|
20 |
||
21 |
val compare = String.compare; |
|
22 |
||
23 |
fun equal n1 n2 = n1 = n2; |
|
24 |
||
25 |
(* ------------------------------------------------------------------------- *) |
|
26 |
(* Fresh variables. *) |
|
27 |
(* ------------------------------------------------------------------------- *) |
|
28 |
||
29 |
local |
|
30 |
val prefix = "_"; |
|
31 |
||
32 |
fun numName i = mkPrefix prefix (Int.toString i); |
|
33 |
in |
|
34 |
fun newName () = numName (newInt ()); |
|
35 |
||
36 |
fun newNames n = map numName (newInts n); |
|
37 |
end; |
|
38 |
||
39 |
fun variantPrime acceptable = |
|
40 |
let |
|
41 |
fun variant n = if acceptable n then n else variant (n ^ "'") |
|
42 |
in |
|
43 |
variant |
|
44 |
end; |
|
45 |
||
46 |
local |
|
47 |
fun isDigitOrPrime #"'" = true |
|
48 |
| isDigitOrPrime c = Char.isDigit c; |
|
49 |
in |
|
50 |
fun variantNum acceptable n = |
|
51 |
if acceptable n then n |
|
52 |
else |
|
53 |
let |
|
54 |
val n = stripSuffix isDigitOrPrime n |
|
55 |
||
56 |
fun variant i = |
|
57 |
let |
|
58 |
val n_i = n ^ Int.toString i |
|
59 |
in |
|
60 |
if acceptable n_i then n_i else variant (i + 1) |
|
61 |
end |
|
62 |
in |
|
63 |
variant 0 |
|
64 |
end; |
|
65 |
end; |
|
66 |
||
67 |
(* ------------------------------------------------------------------------- *) |
|
68 |
(* Parsing and pretty printing. *) |
|
69 |
(* ------------------------------------------------------------------------- *) |
|
70 |
||
71 |
val pp = Print.ppString; |
|
72 |
||
73 |
fun toString s : string = s; |
|
74 |
||
75 |
fun fromString s : name = s; |
|
76 |
||
77 |
end |
|
78 |
||
79 |
structure NameOrdered = |
|
80 |
struct type t = Name.name val compare = Name.compare end |
|
81 |
||
82 |
structure NameMap = KeyMap (NameOrdered); |
|
83 |
||
84 |
structure NameSet = |
|
85 |
struct |
|
86 |
||
|
39443
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39353
diff
changeset
|
87 |
local |
|
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39353
diff
changeset
|
88 |
structure S = ElementSet (NameMap); |
|
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39353
diff
changeset
|
89 |
in |
|
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39353
diff
changeset
|
90 |
open S; |
|
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39353
diff
changeset
|
91 |
end; |
| 39348 | 92 |
|
|
39443
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39353
diff
changeset
|
93 |
val pp = |
|
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39353
diff
changeset
|
94 |
Print.ppMap |
|
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39353
diff
changeset
|
95 |
toList |
|
e330437cd22a
copied the unmodified official Metis 2.3 (15 Sept. 2010) sources into Isabelle
blanchet
parents:
39353
diff
changeset
|
96 |
(Print.ppBracket "{" "}" (Print.ppOpList "," Name.pp));
|
| 39348 | 97 |
|
98 |
end |