2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
17 type graph = string * (int -> int)
20 let sort = KH.create sorts
22 let default_graph = "Z1"
24 (* Internal functions *******************************************************)
27 KH.add sort h s; succ h
29 let graph_of_string err f s =
31 let x = KS.sscanf s "Z%u" C.start in
32 if x > 0 then f (s, fun h -> x + h) else err ()
34 KS.Scan_failure _ | Failure _ | End_of_file -> err ()
36 let graph = ref (graph_of_string C.err C.start default_graph)
38 (* Interface functions ******************************************************)
41 List.fold_left set_sort i ss
43 let string_of_sort err f h =
44 try f (KH.find sort h) with Not_found -> err ()
46 let sort_of_string err f s =
47 let map h n = function
48 | None when n = s -> Some h
51 match KH.fold map sort None with
55 let string_of_graph () = fst !graph
57 let apply h = snd !graph h
61 let f g = graph := g; true in
62 graph_of_string err f s
65 KH.clear sort; graph := graph_of_string C.err C.start default_graph