package ppxlib

  1. Overview
  2. Docs
Standard infrastructure for ppx rewriters

Install

dune-project
 Dependency

Authors

Maintainers

Sources

ppxlib-0.38.0.tbz
sha256=89e049b3102f6670a213d34d802ea3ab0fc530a8959d2f1a1e8db830063429a3
sha512=2fbbf124fc61e1f22242d13505e9af39d4a3c7cf03def1c33ee8bd915195be9b817636667302e9c6ceddc74a9a4a54926340e21c96fd770a2bc6752400315cfd

doc/src/ppxlib.astlib/encoding_502.ml.html

Source file encoding_502.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
module Ext_name = struct
  let ptyp_open = "ppxlib.migration.ptyp_open_502"
end

let invalid_encoding ~loc name =
  Location.raise_errorf ~loc "Invalid %s encoding" name

module To_501 = struct
  open Ast_501.Asttypes
  open Ast_501.Parsetree

  let encode_ptyp_open ~loc ((name, typ) : Longident.t Location.loc * core_type)
      : extension =
    let typ = Ptyp_constr (name, [ typ ]) in
    let ctyp =
      {
        ptyp_desc = typ;
        ptyp_loc = loc;
        ptyp_attributes = [];
        ptyp_loc_stack = [];
      }
    in
    let payload = PTyp ctyp in
    let ext = { txt = Ext_name.ptyp_open; loc } in
    (ext, payload)

  let decode_ptyp_open ~loc = function
    | PTyp { ptyp_desc = Ptyp_constr (name, [ typ ]); _ } -> (name, typ)
    | _ -> invalid_encoding ~loc Ext_name.ptyp_open
end