The API should be straitforward after some meditaion Use many for lists, and double asterisk for pairs.
#use "topfind";;
#require "ppxlib";;
#require "ppxlib.metaquot";;
open Ppxlib.Ast_builder.Default
open Format
let loc = Location.none;;
let record = [%expr {x with foo=bar; baz=fooz}];;
let pp_expr ppf e =
Format.fprintf ppf "%a" (Ocaml_common.Pprintast.expression) e
let () = Ppxlib.Ast_pattern.(
let pfield = (__ ** __) |> map2 ~f:(fun a b -> (a,b)) in
parse (pexp_record (many pfield) __)
)
loc
record
(fun fields b ->
List.iter (fun (fname,b) ->
let _ : Ppxlib__.Import.longident_loc = fname in
printf "? = %a\n" (pp_expr) b)fields;
printf "%a\n%!" (pp_print_option pp_expr) b)