This commit is contained in:
parent
aa2ff7b2f0
commit
2f3113f55d
11742 changed files with 1223940 additions and 0 deletions
9
unikernel/duniverse/ppxlib/test/driver/flag_cookie/dune
Normal file
9
unikernel/duniverse/ppxlib/test/driver/flag_cookie/dune
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
(executable
|
||||
(name print_cookie_driver)
|
||||
(libraries ppxlib)
|
||||
(preprocess
|
||||
(pps ppxlib.metaquot)))
|
||||
|
||||
(cram
|
||||
(package ppxlib)
|
||||
(deps print_cookie_driver.exe))
|
||||
|
|
@ -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 ()
|
||||
10
unikernel/duniverse/ppxlib/test/driver/flag_cookie/run.t
Normal file
10
unikernel/duniverse/ppxlib/test/driver/flag_cookie/run.t
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue