File: name.mli

package info (click to toggle)
ppxlib 0.15.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 1,284 kB
  • sloc: ml: 17,184; sh: 149; makefile: 36; python: 36
file content (91 lines) | stat: -rw-r--r-- 2,559 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
open! Import

module Pattern : sig
  type t

  (** Uses the rules described in [Attribute] *)
  val make : string -> t

  val name : t -> string

  (** [matches ~pattern name] returns [true] iff [name] matches [pattern].

      For instance, the exact set of names such that
      [matches (make "foo.bar.@blah.x") name] is:
      - "foo.bar.blah.x"
      -     "bar.blah.x"
      -         "blah.x"
  *)
  val matches : t -> string -> bool
end

(** Split the path part of a name:

    [split_path "a.b.C.D" = "a.b", Some "C.D"]
*)
val split_path : string -> string * string option

(** [fold_dot_suffixes "foo.@bar.blah" ~init ~f] is

    {[
      ["bar.blah"; "foo.bar.blah"]
    ]}
*)
val dot_suffixes : string -> string list

module Registrar : sig
  (** Names are organized by context. For instance contexts can be: expressions, patterns,
      types, ... *)
  type 'context t

  (** - [kind] is a description of the things registered. For instance: "extension",
      "attribute", ...

      - [current_file] is where this function is called. Must be [__FILE__].

      - [string_of_context]: human readable description of a context
  *)
  val create
    :  kind:string
    -> current_file:string (* must be [__FILE__] *)
    -> string_of_context:('context -> string option)
    -> 'context t

  val register : kind:[ `Attribute | `Extension ] -> 'context t -> 'context -> string -> unit

  val spellcheck :
    'context t -> 'context -> ?white_list:string list -> string -> string option

  val raise_errorf
    :  'context t
    -> 'context
    -> ?white_list:string list
    -> (string -> 'a, unit, string, 'c) format4
    -> string Loc.t
    -> 'a
end

module Whitelisted : sig
  val get_attribute_list : unit -> string list
  val get_extension_list : unit -> string list

  val is_whitelisted : kind:[ `Attribute | `Extension ] -> string -> bool
end

module Reserved_namespaces : sig
  (** [reserve "foo"] has two implications:
        - one can't then declare an attribute inside this namespace
        - attributes within this namespace won't be reported by [check_unused]

      This is here to insure that the rewriter cohabits well with other rewriter
      or tools (e.g. merlin) which might leave attribute on the AST.

      N.B. the "merlin" namespace is reserved by default. *)
  val reserve : string -> unit

  val is_in_reserved_namespaces : string -> bool
end

(** Returns [true] if checks should be ignored for the following name,
    for instance if it is reserved or starts with an underscore. *)
val ignore_checks : string -> bool