Skip to content

Commit

Permalink
[ppx] Update ppx_tester to accept less arguments
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitrii.Kosarev a.k.a. Kakadu <[email protected]>
  • Loading branch information
Kakadu authored and Dmitrii.Kosarev a.k.a. Kakadu committed Dec 17, 2024
1 parent e67ebd7 commit 962312e
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions ppx/tester/ppx_tester.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ open Ppxlib
let string_of_expression e =
Format.set_margin 1000;
Format.set_max_indent 0;
let ans = Format.asprintf "%a" Pprintast.expression e in
ans
Format.asprintf "%a" Pprintast.expression e
;;

let name = "tester"
Expand All @@ -42,23 +41,25 @@ let () =
(pstr_eval
(pexp_apply
__
((nolabel ** __) ^:: (nolabel ** __) ^:: (nolabel ** __) ^:: (nolabel ** __) ^:: nil))
((nolabel ** __) ^:: (nolabel ** __) ^:: (nolabel ** __) ^:: (nolabel ** __) ^:: nil
|> map2 ~f:(fun a b -> [ a; b ])
||| ((nolabel ** __) ^:: (nolabel ** __) ^:: nil |> map0 ~f:[])))
nil
^:: nil)
in
[ Extension.declare
name
Extension.Context.Expression
pattern
(fun ~loc ~path:_ runner reifier shower n realtion ->
(fun ~loc ~path:_ runner reifier_shower n relation ->
let open Ppxlib.Ast_builder.Default in
let count =
let rec helper acc e =
match e.pexp_desc with
| Pexp_fun (_, _, _, body) -> helper (1 + acc) body
| _ -> acc
in
helper 0 realtion
helper 0 relation
in
let middle =
match count with
Expand All @@ -70,13 +71,13 @@ let () =
| _ -> failwith (Printf.sprintf "5 and more arguments are not supported")
in
let last =
let s = string_of_expression @@ realtion in
let s = string_of_expression relation in
let open Ppxlib.Ast_builder.Default in
[%expr [%e pexp_constant ~loc (Pconst_string (s, loc, None))], [%e realtion]]
[%expr [%e pexp_constant ~loc (Pconst_string (s, loc, None))], [%e relation]]
in
pexp_apply ~loc runner
@@ List.map (fun e -> Nolabel, e)
@@ List.concat [ [ reifier; shower; n ]; middle; [ last ] ])
@@ List.concat [ reifier_shower @ [ n ]; middle; [ last ] ])
]
in
Ppxlib.Driver.register_transformation ~extensions name
Expand Down

0 comments on commit 962312e

Please sign in to comment.