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

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

MARCHE Claude's avatar
MARCHE Claude committed
25 26
(** {2 Labels} *)

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

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

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

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

(** {2 Identifiers} *)
41 42

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

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

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

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

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

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

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

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

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

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

Francois Bobot's avatar
Francois Bobot committed
75

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

78
type ident_printer
79

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

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

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

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

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

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

(** various character encoders *)
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
107
val char_to_lalnum : char -> string
108
val char_to_alnumus : char -> string
109
val char_to_lalnumus : char -> string
110