File: expansion_context.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 (71 lines) | stat: -rw-r--r-- 2,270 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
module Base : sig
  (** Type for the location independent parts of the expansion context *)
  type t

  (**/*)
  (** Undocumented section *)

  (** Build a new base context at the top level of the given file with the given
      calling tool name.
  *)
  val top_level :
    tool_name:string ->
    file_path:string ->
    t

  (** Proxy functions to update the wrapped code path. See code_path.mli for details. *)
  val enter_expr : t -> t
  val enter_module : loc:Location.t -> string -> t -> t
  val enter_value : loc:Location.t -> string -> t -> t
end

module Extension : sig
  (** Type of expansion contexts for extensions *)
  type t

  (** Return the location of the extension point being expanded *)
  val extension_point_loc : t -> Location.t

  (** Return the code path for the given context *)
  val code_path : t -> Code_path.t

  (** Can be used within a ppx preprocessor to know which tool is
      calling it ["ocamlc"], ["ocamlopt"], ["ocamldep"], ["ocaml"], ... . *)
  val tool_name : t -> string

  (** Wrap a [fun ~loc ~path] into a [fun ~ctxt] *)
  val with_loc_and_path : (loc:Location.t -> path:string -> 'a) -> (ctxt:t -> 'a)

  (**/**)
  (** Undocumented section *)

  (** Build a new expansion context with the given extension point location and base context *)
  val make : extension_point_loc:Location.t -> base:Base.t -> unit -> t
end

module Deriver : sig
  (** Type of expansion contexts for derivers *)
  type t

  (** Return the location of the item to which the deriver is being applied *)
  val derived_item_loc : t -> Location.t

  (** Return the code path for the given context *)
  val code_path : t -> Code_path.t

  (** Can be used within a ppx preprocessor to know which tool is
      calling it ["ocamlc"], ["ocamlopt"], ["ocamldep"], ["ocaml"], ... . *)
  val tool_name : t -> string

  (** Wrap a [fun ~loc ~path] into a [fun ~ctxt] *)
  val with_loc_and_path : (loc:Location.t -> path:string -> 'a) -> (ctxt:t -> 'a)

  (** Whether the derived code is going to be inlined in the source *)
  val inline : t -> bool

  (**/**)
  (** Undocumented section *)

  (** Build a new expansion context with the given item location and code path *)
  val make : derived_item_loc:Location.t -> inline:bool -> base:Base.t -> unit -> t
end