heptagon/global/names.ml

45 lines
973 B
OCaml
Raw Normal View History

(** Define qualified names "Module.name" (longname)
[shortname] longname -> name
[fullname] longname -> Module.name *)
2010-06-15 10:49:03 +02:00
type name = string
type longname =
| Name of name
| Modname of qualident
and qualident = { qual: string; id: string }
module NamesM = struct
type t = name
let compare = compare
end
module NamesEnv =
struct
include (Map.Make(NamesM))
let append env0 env =
fold (fun key v env -> add key v env) env0 env
end
module S = Set.Make (struct type t = string let compare = compare end)
2010-06-15 10:49:03 +02:00
let shortname = function
| Name s -> s
| Modname { id = id; } -> id
let fullname = function
| Name s -> s
| Modname { qual = qual; id = id; } -> qual ^ "." ^ id
let mk_longname s =
try
let ind = String.index s '.' in
let id = String.sub s (ind + 1) (String.length s - ind - 1) in
Modname { qual = String.sub s 0 ind; id = id; }
with Not_found -> Name s
let print_longname ff id = Format.fprintf ff "%s" (fullname id)