package dream-html

  1. Overview
  2. Docs
HTML generator eDSL for Dream

Install

Dune Dependency

Authors

Maintainers

Sources

dream-html-3.11.0.tbz
sha256=d1ac64685188a5b41834c8e1ffc4187f8dfdbc27a972898e6bb833ca4c715811
sha512=43ae60f49d3ada8cd633e0fbe6bf892094eb46a8f8ff1c7605c33724e6f44abcb3466dc61511994a8ac63a5ccd9421c53ce6f5f703bd307d9da3de7b6dbdf85e

doc/src/ppx/ppx.ml.html

Source file ppx.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
(* Copyright 2024 Yawar Amin

   This file is part of dream-html.

   dream-html is free software: you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the Free
   Software Foundation, either version 3 of the License, or (at your option) any
   later version.

   dream-html is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
   details.

   You should have received a copy of the GNU General Public License along with
   dream-html. If not, see <https://www.gnu.org/licenses/>. *)

open Ppxlib
open Ast_builder.Default

let expansion ~loc s =
  pexp_apply ~loc
    (evar ~loc "Dream_html.path")
    [Nolabel, estring ~loc s; Nolabel, estring ~loc s]

let binding_extender =
  Extension.V3.declare "path" Extension.Context.structure_item
    Ast_pattern.(
      pstr
        (pstr_value drop (value_binding ~pat:__ ~expr:(estring __) ^:: nil)
        ^:: nil))
    (fun ~ctxt pat s ->
      let loc = Expansion_context.Extension.extension_point_loc ctxt in
      pstr_value ~loc Nonrecursive
        [value_binding ~loc ~pat ~expr:(expansion ~loc s)])

let expr_extender =
  Extension.V3.declare "path" Extension.Context.expression
    Ast_pattern.(single_expr_payload (estring __))
    (fun ~ctxt s ->
      let loc = Expansion_context.Extension.extension_point_loc ctxt in
      expansion ~loc s)

let path_binding = Context_free.Rule.extension binding_extender
let path_expr = Context_free.Rule.extension expr_extender

let () =
  Driver.register_transformation ~rules:[path_binding; path_expr]
    "dream-html.ppx"
OCaml

Innovation. Community. Security.