ident.mli 3.63 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
(**************************************************************************)
(*                                                                        *)
(*  Copyright (C) 2010-                                                   *)
(*    Francois Bobot                                                      *)
(*    Jean-Christophe Filliatre                                           *)
(*    Johannes Kanig                                                      *)
(*    Andrei Paskevich                                                    *)
(*                                                                        *)
(*  This software is free software; you can redistribute it and/or        *)
(*  modify it under the terms of the GNU Library General Public           *)
(*  License version 2.1, with the special exception on linking            *)
(*  described in file LICENSE.                                            *)
(*                                                                        *)
(*  This software is distributed in the hope that it will be useful,      *)
(*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *)
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                  *)
(*                                                                        *)
(**************************************************************************)

MARCHE Claude's avatar
MARCHE Claude committed
20 21 22 23 24 25 26
(** {2 Labels} *)

type label = string * Loc.position option

val label : ?loc:Loc.position -> string -> label

(** {2 Identifiers} *)
27 28

type ident = private {
29 30
  id_string : string;       (* non-unique name *)
  id_origin : origin;       (* origin of the ident *)
Andrei Paskevich's avatar
Andrei Paskevich committed
31
  id_tag    : Hashweak.tag; (* unique magical tag *)
32 33 34 35 36 37 38 39 40 41 42
}

and origin =
  | User of Loc.position
  | Derived of ident
  | Fresh

module Sid : Set.S with type elt = ident
module Mid : Map.S with type key = ident
module Hid : Hashtbl.S with type key = ident

43 44
val id_equal : ident -> ident -> bool

Andrei Paskevich's avatar
Andrei Paskevich committed
45 46
val id_hash : ident -> int

47 48
(* a user-created type of unregistered identifiers *)
type preid
49

50 51
(* register a pre-ident (never use this function) *)
val id_register : preid -> ident
52

53 54
(* create a fresh pre-ident *)
val id_fresh : string -> preid
55

56 57 58 59 60 61 62 63 64 65 66
(* create a localized pre-ident *)
val id_user : string -> Loc.position -> preid

(* create a derived pre-ident *)
val id_derive : string -> ident -> preid

(* create a derived pre-ident with the same name *)
val id_clone : ident -> preid

(* create a duplicate pre-ident *)
val id_dup : ident -> preid
67

68 69
(* id_derived_from i1 i2 <=> i1 is derived from i2 *)
val id_derived_from : ident -> ident -> bool
70

Francois Bobot's avatar
Francois Bobot committed
71 72 73
(* id_derived_from i1 i2 <=> i1 is derived from i2 *)
val id_from_user : ident -> Loc.position option

74 75
(** Unique persistent names for pretty printing *)

76
type ident_printer
77

78 79
val create_ident_printer :
  ?sanitizer : (string -> string) -> string list -> ident_printer
MARCHE Claude's avatar
MARCHE Claude committed
80
(** start a new printer with a sanitizing function and a blacklist *)
81

82 83
val id_unique :
  ident_printer -> ?sanitizer : (string -> string) -> ident -> string
84
(** use ident_printer to generate a unique name for ident
MARCHE Claude's avatar
MARCHE Claude committed
85
    an optional sanitizer is applied over the printer's sanitizer *)
86

87
val string_unique : ident_printer -> string -> string
MARCHE Claude's avatar
MARCHE Claude committed
88
(** Uniquify string *)
89

90
val forget_id : ident_printer -> ident -> unit
MARCHE Claude's avatar
MARCHE Claude committed
91
(** forget an ident *)
92

93
val forget_all : ident_printer -> unit
MARCHE Claude's avatar
MARCHE Claude committed
94
(** forget all idents *)
95 96

val sanitizer : (char -> string) -> (char -> string) -> string -> string
MARCHE Claude's avatar
MARCHE Claude committed
97 98 99
(** generic sanitizer taking a separate encoder for the first letter *)

(** various character encoders *)
100 101 102 103 104 105

val char_to_alpha : char -> string
val char_to_lalpha : char -> string
val char_to_ualpha : char -> string
val char_to_alnum : char -> string
val char_to_alnumus : char -> string
106