1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162openPpxlibmoduleExtension_name=structtypet=Debug|Info|Warn|Error|Trace|Smtletto_string=function|Debug->"l.debug"|Info->"l.info"|Warn->"l.warn"|Error->"l.error"|Trace->"l.trace"|Smt->"l.smt"endletassociated_fn~loc=function|Extension_name.Debug->[%exprL.debug]|Info->[%exprL.info]|Warn->[%exprL.warn]|Error->[%exprL.error]|Trace->[%exprL.trace]|Smt->[%exprL.smt]letsplit_applyexpr=letrecauxaccexpr=matchexpr.pexp_descwith|Pexp_apply(fn,args)->aux(args@acc)fn|_->(expr,acc)inaux[]exprletvalidate_payload~extfmtargs=letstring_of_arg_label=function|Nolabel->""|Labelledl->"~"^l|Optionall->"?"^linlethas_labelled_arg=functionNolabel,_->false|_->trueinmatchList.find_opthas_labelled_argargswith|Some(label,_)->Location.raise_errorf~loc:fmt.pexp_loc"%%%s does not support labelled or optional arguments (found %s)"(Extension_name.to_stringext)(string_of_arg_labellabel)|None->(matchfmt.pexp_descwith|Pexp_constant(Pconst_string_)->()|_->Location.raise_errorf~loc:fmt.pexp_loc"%%%s expects a string literal format as first argument"(Extension_name.to_stringext))letexpand~extexpr=letloc={expr.pexp_locwithloc_ghost=true}inletfn=associated_fn~locextinletfmt,args=split_applyexprinlet()=validate_payload~extfmtargsin(* we use "m__" as the name of the argument to the function passed to [fn] to
avoid potential name clashes with variables in the original expression *)letm_call=Ast_builder.Default.pexp_apply~loc[%exprm__]((Nolabel,fmt)::args)in[%expr[%efn](funm__->[%em_call])]