[/] [trunk/] [src/] [lib/] [symbol.sml] - Blame information for rev 7

Line No. Rev Author Line
1 4 tbourke
(* $Id: symbol.sml 7 2007-10-31 05:39:12Z tbourke $ *)
2
 
3
structure Symbol : SYMBOL = struct
4
  infix <+ <- ++ </ =:=
5
 
6
  type symbol = Atom.atom
7
  type symbolset = AtomSet.set
8
 
9
  fun set <+ item = AtomSet.add (set, item)
10
  fun set </ item = AtomSet.difference (set, AtomSet.singleton item)
11
  fun i <- set    = AtomSet.member (set, i)
12
  val op++        = AtomSet.union
13
  val emptyset    = AtomSet.empty
14
 
15
  fun s1 =:= s2   = Atom.compare (s1, s2) = EQUAL
16
 
17
  local structure SS = Substring in
18
  fun getNewName (base, names) =
19
    (*{{{1*)
20
    if not (AtomSet.member (names, base)) then base
21
    else let
22
           fun getPrefix s = SS.string (SS.dropr Char.isDigit (SS.full s))
23
 
24
           fun getSuffix s = let
25
               val suf = SS.taker Char.isDigit (SS.full s)
26
             in
27
               if SS.isEmpty suf then 0
28
               else valOf (Int.fromString (SS.string suf))
29
             end
30
 
31
           val prefix = getPrefix (Atom.toString base)
32
 
33
           fun maxSuffix (a, m) = let val s = Atom.toString a in
34
               if String.isPrefix prefix s
35
               then Int.max (m, getSuffix s) else m
36
             end
37
 
38
           val suffix = (AtomSet.foldl maxSuffix 0 names) + 1
39
         in
40
            Atom.atom (prefix ^ Int.toString suffix)
41
         end (*}}}1*)
42
  end (*local*)
43
 
44
end
45