package hegel

  1. Overview
  2. Docs

Source file hegel_template.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
# 1 "template/hegel_template.fallback.ml"
(* Upstream OCaml has no [ppx_template]. This rewriter keeps each
   [let%template] and [val%template] item and removes the marker. The compiler
   ignores the [[@mode]] attributes that remain. *)

open Ppxlib

let structure_item =
  Extension.V3.declare
    "template"
    Extension.Context.structure_item
    Ast_pattern.(pstr (__ ^:: nil))
    (fun ~ctxt:_ item -> item)
;;

let signature_item =
  Extension.V3.declare
    "template"
    Extension.Context.signature_item
    Ast_pattern.(psig (__ ^:: nil))
    (fun ~ctxt:_ item -> item)
;;

let () =
  Driver.register_transformation
    "hegel_template"
    ~rules:
      [ Context_free.Rule.extension structure_item
      ; Context_free.Rule.extension signature_item
      ]
;;