Skip to content
Snippets Groups Projects
ident.ml 2.51 KiB
(** Time-stamp: <modified the 29/01/2008 (at 09:33) by Erwan Jahier> *)

(* J'ai appele ca symbol (mais ca remplace le ident) :
c'est juste une couche qui garantit l'unicite en memoire
des strings ...
C'est tout petit, non ???

(* debut symbol.mli *)
type t
val to_string : t -> string
val of_string : string -> t

(* fin symbol.mli *)

------------------

(* debut symbol.ml *)
type t = string

module WeakStringTab = struct
  include Weak.Make(
     struct
        type t = string
        let equal = (=)
        let hash = Hashtbl.hash
     end
  )
end

let zetab = WeakStringTab.create 100 
let (to_string : t -> string) =
 fun x -> x

let (of_string : string -> t) =
 fun x -> (
     WeakStringTab.merge zetab x
 )
(* fin symbol.ml *)

 *)

(*cf  ~/dd/ocaml-3.10.0/typing/ident.ml *)

type t = string
type pack_name = t
type long = pack_name * t

let (pack_of_long : long -> pack_name) =
  fst

let (of_long : long -> t) =
  snd

let (to_string : t -> string) =
  fun x -> x

let (of_string : string -> t) =
  fun x -> x

let (pack_name_of_string : string -> pack_name) =
  fun x -> x

let (pack_name_to_string : pack_name -> string) =
  fun x -> x

let (string_of_long : long -> string) =
  fun (pn, id) -> pn ^"::"^ id
let (long_to_string : long -> string) = 
  string_of_long
let (make_long : pack_name -> t -> long) =
  fun pn id -> (pn,id)

let dft_pack_name = ref "DftPack" (* this dft value ougth to be reset *)

let (set_dft_pack_name : pack_name -> unit) =
  fun pn -> 
    dft_pack_name := pn

let (to_pack_name : t -> pack_name) =
  fun x -> x






(*  -> syntaxeTree.ml ? *)

type idref = 
    {
      id_pack : pack_name option;
      id_id  : t
    }

let (pack_of_idref : idref -> pack_name option) =
  fun ir -> ir.id_pack

let (name_of_idref : idref -> t) =
  fun ir -> ir.id_id


(* utilitaires idref *)
let idref_of_string s = (
  match (Str.split (Str.regexp "::") s) with
      [i] -> { id_pack = None; id_id = i}
    | [p;i]-> { id_pack = Some p; id_id = i}
    | _ -> raise (Failure ("idref_of_string: \""^s^"\" not a proper ident")) 
)

let (long_of_string : string -> long) =
  fun s -> 
    match (Str.split (Str.regexp "::") s) with
	[i] -> !dft_pack_name, i
      | [p;i]-> p, i
      | _ -> raise (Failure ("idref_of_string: \""^s^"\" not a proper ident")) 

let string_of_idref i = (
  match i.id_pack with
      Some p -> p^"::"^i.id_id
    | None -> i.id_id
)

let (long_of_idref : idref -> long) =
  fun idr -> 
    match pack_of_idref idr with
	Some p -> (p, name_of_idref idr)
      | None   -> (!dft_pack_name, name_of_idref idr)