package ppxlib

  1. Overview
  2. Docs
Standard infrastructure for ppx rewriters

Install

Dune Dependency

Authors

Maintainers

Sources

ppxlib-0.36.0.tbz
sha256=5aba1bce14c53108614130110c843d004bf93bd2cf3a0778fd7086b85390a434
sha512=1e3e8fee42fe74bffc178dbcbb2db8ec38dd23e71f6fed3c4c92618cf93892f5847787e6e9abb322f5c85d29a76afde28ce840b42e10fedc14cd82ba578ad06a

doc/src/ppxlib.metaquot_lifters/ppxlib_metaquot_lifters.ml.html

Source file ppxlib_metaquot_lifters.ml

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
open Stdppx
open Ppxlib
open Ast_builder.Default

class expression_lifters loc =
  let loc = { loc with loc_ghost = true } in
  object
    inherit [expression] Ppxlib_traverse_builtins.lift

    method record flds =
      pexp_record ~loc
        (List.map flds ~f:(fun (lab, e) -> ({ loc; txt = Lident lab }, e)))
        None

    method constr id args =
      pexp_construct ~loc { loc; txt = Lident id }
        (match args with [] -> None | l -> Some (pexp_tuple ~loc l))

    method tuple l = pexp_tuple ~loc l
    method int i = eint ~loc i
    method int32 i = eint32 ~loc i
    method int64 i = eint64 ~loc i
    method nativeint i = enativeint ~loc i
    method float f = efloat ~loc (Float.to_string f)
    method string s = estring ~loc s
    method char c = echar ~loc c
    method bool b = ebool ~loc b

    method array : 'a. ('a -> expression) -> 'a array -> expression =
      fun f a -> pexp_array ~loc (List.map (Array.to_list a) ~f)

    method unit () = eunit ~loc
    method other : 'a. 'a -> expression = fun _ -> failwith "not supported"
  end

class pattern_lifters loc =
  let loc = { loc with loc_ghost = true } in
  object
    inherit [pattern] Ppxlib_traverse_builtins.lift

    method record flds =
      ppat_record ~loc
        (List.map flds ~f:(fun (lab, e) -> ({ loc; txt = Lident lab }, e)))
        Closed

    method constr id args =
      ppat_construct ~loc { loc; txt = Lident id }
        (match args with [] -> None | l -> Some (ppat_tuple ~loc l))

    method tuple l = ppat_tuple ~loc l
    method int i = pint ~loc i
    method int32 i = pint32 ~loc i
    method int64 i = pint64 ~loc i
    method nativeint i = pnativeint ~loc i
    method float f = pfloat ~loc (Float.to_string f)
    method string s = pstring ~loc s
    method char c = pchar ~loc c
    method bool b = pbool ~loc b

    method array : 'a. ('a -> pattern) -> 'a array -> pattern =
      fun f a -> ppat_array ~loc (List.map (Array.to_list a) ~f)

    method unit () = punit ~loc
    method other : 'a. 'a -> pattern = fun _ -> failwith "not supported"
  end
OCaml

Innovation. Community. Security.