ident.mli 3.65 KB
Newer Older
1 2
(**************************************************************************)
(*                                                                        *)
3
(*  Copyright (C) 2010-2011                                               *)
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
(** {2 Labels} *)

Andrei Paskevich's avatar
Andrei Paskevich committed
26 27 28 29 30
type label = private {
  lab_string : string;
  lab_tag    : int;
}

31 32 33
module Mlab : Map.S with type key = label
module Slab : Mlab.Set

Andrei Paskevich's avatar
Andrei Paskevich committed
34 35 36 37
val lab_equal : label -> label -> bool
val lab_hash  : label -> int

val create_label : string -> label
MARCHE Claude's avatar
MARCHE Claude committed
38 39

(** {2 Identifiers} *)
40 41

type ident = private {
42
  id_string : string;               (* non-unique name *)
43
  id_label  : Slab.t;               (* identifier labels *)
44 45
  id_loc    : Loc.position option;  (* optional location *)
  id_tag    : Hashweak.tag;         (* unique magical tag *)
46 47 48
}

module Mid : Map.S with type key = ident
49
module Sid : Mid.Set
50 51
module Hid : Hashtbl.S with type key = ident

52 53
val id_equal : ident -> ident -> bool

Andrei Paskevich's avatar
Andrei Paskevich committed
54 55
val id_hash : ident -> int

56 57
(* a user-created type of unregistered identifiers *)
type preid
58

59
(* register a pre-ident (you should never use this function) *)
60
val id_register : preid -> ident
61

62
(* create a fresh pre-ident *)
63
val id_fresh : ?label:Slab.t -> ?loc:Loc.position -> string -> preid
64

65
(* create a localized pre-ident *)
66
val id_user : ?label:Slab.t -> string -> Loc.position -> preid
67 68

(* create a duplicate pre-ident *)
69
val id_clone : ?label:Slab.t -> ident -> preid
70

71
(* create a derived pre-ident (inherit labels and location) *)
72
val id_derive : ?label:Slab.t -> string -> ident -> preid
73

Francois Bobot's avatar
Francois Bobot committed
74

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

77
type ident_printer
78

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

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

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

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

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

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

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

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
107