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,9 @@
(executable
(name print_cookie_driver)
(libraries ppxlib)
(preprocess
(pps ppxlib.metaquot)))
(cram
(package ppxlib)
(deps print_cookie_driver.exe))

View file

@ -0,0 +1,33 @@
open Ppxlib
let value_x = ref ""
let f = function
| Some value_of_x ->
value_x := Printf.sprintf "Value of cookie x: %i" value_of_x
| None -> value_x := "Cookie x isn't set."
let () = Ppxlib.Driver.Cookies.(add_simple_handler ~f "x" Ast_pattern.(eint __))
let print_cookie_x =
object
inherit Ast_traverse.map as super
method! structure str =
let new_str =
List.fold_left
(fun acc str_item ->
match str_item with
| [%stri [@@@print_cookie_x]] ->
let _ = print_endline !value_x in
acc
| _ -> str_item :: acc)
[] str
in
super#structure (List.rev new_str)
end
let () =
Driver.register_transformation ~impl:print_cookie_x#structure "test_cookies"
let () = Ppxlib.Driver.standalone ()

View file

@ -0,0 +1,10 @@
The cookie flag is taken into account, both by the main standalone
$ echo "[@@@print_cookie_x]" > impl.ml
$ ./print_cookie_driver.exe -cookie x=1 impl.ml
Value of cookie x: 1
...and by the `-as-ppx` standalone
$ ocaml -ppx './print_cookie_driver.exe --as-ppx -cookie x=1' impl.ml
Value of cookie x: 1