ident.mli 3.82 KB
Newer Older
1 2 3
(**************************************************************************)
(*                                                                        *)
(*  Copyright (C) 2010-                                                   *)
MARCHE Claude's avatar
MARCHE Claude committed
4 5 6
(*    François Bobot                                                     *)
(*    Jean-Christophe Filliâtre                                          *)
(*    Claude Marché                                                      *)
7 8 9 10 11 12 13 14 15 16 17 18 19
(*    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.                  *)
(*                                                                        *)
(**************************************************************************)

François Bobot's avatar
François Bobot committed
20 21
open Stdlib

MARCHE Claude's avatar
MARCHE Claude committed
22 23
(** Identifiers *)

MARCHE Claude's avatar
MARCHE Claude committed
24 25 26 27 28 29 30
(** {2 Labels} *)

type label = string * Loc.position option

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

(** {2 Identifiers} *)
31 32

type ident = private {
33 34
  id_string : string;       (* non-unique name *)
  id_origin : origin;       (* origin of the ident *)
Andrei Paskevich's avatar
Andrei Paskevich committed
35
  id_label  : label list;   (* identifier labels *)
Andrei Paskevich's avatar
Andrei Paskevich committed
36
  id_tag    : Hashweak.tag; (* unique magical tag *)
37 38 39 40 41 42 43 44
}

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

module Mid : Map.S with type key = ident
45
module Sid : Mid.Set
46 47
module Hid : Hashtbl.S with type key = ident

48 49
val id_equal : ident -> ident -> bool

Andrei Paskevich's avatar
Andrei Paskevich committed
50 51
val id_hash : ident -> int

52 53
(* a user-created type of unregistered identifiers *)
type preid
54

55 56
(* register a pre-ident (never use this function) *)
val id_register : preid -> ident
57

58
(* create a fresh pre-ident *)
Andrei Paskevich's avatar
Andrei Paskevich committed
59
val id_fresh : ?labels:(label list) -> string -> preid
60

61
(* create a localized pre-ident *)
Andrei Paskevich's avatar
Andrei Paskevich committed
62
val id_user : ?labels:(label list) -> string -> Loc.position -> preid
63 64

(* create a derived pre-ident *)
Andrei Paskevich's avatar
Andrei Paskevich committed
65
val id_derive : ?labels:(label list) -> string -> ident -> preid
66

Andrei Paskevich's avatar
Andrei Paskevich committed
67 68
(* create a derived pre-ident with the same name and labels *)
val id_clone : ?labels:(label list) -> ident -> preid
69 70

(* create a duplicate pre-ident *)
Andrei Paskevich's avatar
Andrei Paskevich committed
71
val id_dup : ?labels:(label list) -> ident -> preid
72

73 74
(* id_derived_from i1 i2 <=> i1 is derived from i2 *)
val id_derived_from : ident -> ident -> bool
75

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

79 80
(** Unique persistent names for pretty printing *)

81
type ident_printer
82

83 84
val create_ident_printer :
  ?sanitizer : (string -> string) -> string list -> ident_printer
MARCHE Claude's avatar
MARCHE Claude committed
85
(** start a new printer with a sanitizing function and a blacklist *)
86

87 88
val id_unique :
  ident_printer -> ?sanitizer : (string -> string) -> ident -> string
89
(** use ident_printer to generate a unique name for ident
MARCHE Claude's avatar
MARCHE Claude committed
90
    an optional sanitizer is applied over the printer's sanitizer *)
91

92
val string_unique : ident_printer -> string -> string
MARCHE Claude's avatar
MARCHE Claude committed
93
(** Uniquify string *)
94

95
val forget_id : ident_printer -> ident -> unit
MARCHE Claude's avatar
MARCHE Claude committed
96
(** forget an ident *)
97

98
val forget_all : ident_printer -> unit
MARCHE Claude's avatar
MARCHE Claude committed
99
(** forget all idents *)
100 101

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

(** various character encoders *)
105 106 107 108 109 110

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
111