123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869openPpxlibletcount=ref0letexpand~loc~path(msg:string)(e:expression)=incrcount;(* Printf.printf "GOT: %s -> %s/%d\n" path msg !count; *)[%expr[%eAst_builder.Default.(pexp_apply~loc(pexp_ident~loc(Located.mk~loc(Longident.parse"Genprint.print")))[Nolabel,estring~locmsg;Nolabel,pexp_tuple~loc[e;(eint~loc!count);(estring~loc@@Filename.basenamepath)]])]]letgenprint=Extension.declare"prs"Extension.Context.expression(* pattern appearing in [%pr "..." v] is the application of the string to the value *)Ast_pattern.(pstr((pstr_eval(pexp_apply(estring__)(no_label__^::nil))nil)^::nil))expandlet()=Driver.register_transformation"genprint"~extensions:[genprint]letexpand_ff~loc~path(lid:longident)(el:(arg_label*expression)list)=incrcount;matchList.revelwith|[]->assertfalse|(_,e)::tl->letfirst_word=Longident.namelidinletmsg=List.fold_left(funmsg(_,word)->matchword.pexp_descwith|Pexp_identid->letword'=Longident.nameid.txtin(" "^word'^msg)|_->Location.raise_errorf~loc:word.pexp_loc"this should be a word")""tlin[%expr[%eAst_builder.Default.(pexp_apply~loc(pexp_ident~loc(Located.mk~loc(Longident.parse"Genprint.print")))[Nolabel,estring~loc(first_word^msg);Nolabel,pexp_tuple~loc[e;(eint~loc!count);(estring~loc@@Filename.basenamepath)]])]]letgenprint_freeform=Extension.declare"pr"Extension.Context.expression(* pattern appearing in [%pr "..." v] is the application of the string to the value *)Ast_pattern.(pstr((pstr_eval(pexp_apply(pexp_ident__)(__))nil)^::nil))expand_fflet()=Driver.register_transformation"genprint-freeform"~extensions:[genprint_freeform]