This commit is contained in:
swrup 2025-11-11 02:07:51 +01:00
parent aa2ff7b2f0
commit 2f3113f55d
11742 changed files with 1223940 additions and 0 deletions

View file

@ -0,0 +1,14 @@
(rule
(package ppxlib)
(alias runtest)
(enabled_if
(>= %{ocaml_version} "4.08.0"))
(deps
(:test test.ml)
(package ppxlib))
(action
(chdir
%{project_root}
(progn
(run expect-test %{test})
(diff? %{test} %{test}.corrected)))))

View file

@ -0,0 +1,36 @@
open Ppxlib
let extend_list_by name = object
inherit Ast_traverse.map as super
method! expression e =
match e.pexp_desc with
| Pexp_construct ({txt = Lident "[]"; _}, None) -> Ast_builder.Default.elist ~loc:e.pexp_loc [Ast_builder.Default.estring ~loc:e.pexp_loc name]
| _ -> super#expression e
end
[%%expect{|
val extend_list_by : string -> Ast_traverse.map = <fun>
|}]
let () =
let name = "a: instr pos=Before" in
let transform = extend_list_by name in
Driver.(register_transformation ~instrument:(Instrument.make ~position:Before transform#structure) name)
let () =
let name = "b: instr pos=After" in
let transform = extend_list_by name in
Driver.(register_transformation ~instrument:(Instrument.make ~position:After transform#structure) name)
let () =
let name = "c: impl" in
let transform = extend_list_by name in
Driver.register_transformation ~impl:transform#structure name
(* The order of the list should only depend on how the rewriters got registered,
not on the alphabetic order of the names they got registered with. *)
let x = []
[%%expect{|
val x : string list =
["a: instr pos=Before"; "c: impl"; "b: instr pos=After"]
|}]