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_______________________________________________________________ *)
16 type graph = string * (int -> int)
19 let sort = H.create sorts
21 let default_graph = "Z1"
23 (* Internal functions *******************************************************)
26 H.add sort h s; succ h
28 let graph_of_string err f s =
30 let x = S.sscanf s "Z%u" C.start in
31 if x > 0 then f (s, fun h -> x + h) else err ()
33 S.Scan_failure _ | Failure _ | End_of_file -> err ()
35 let graph = ref (graph_of_string C.err C.start default_graph)
37 (* Interface functions ******************************************************)
40 List.fold_left set_sort i ss
42 let string_of_sort err f h =
43 try f (H.find sort h) with Not_found -> err ()
45 let sort_of_string err f s =
46 let map h n = function
47 | None when n = s -> Some h
50 match H.fold map sort None with
54 let string_of_graph () = fst !graph
56 let apply h = snd !graph h
60 let f g = graph := g; true in
61 graph_of_string err f s