123456789101112131415161718192021222324252627282930313233343536373839404142openImporttypet={mutablenext_id:int;mutablebindings:Parsetree.value_bindinglist;}letcreate()={next_id=0;bindings=[]}letsanitizete=matcht.bindingswith|[]->e|bindings->let(moduleAst)=Ast_builder.makee.pexp_locinAst.pexp_letNonrecursivebindingseletquotet(e:expression)=letloc=e.pexp_locinlet(moduleAst)=Ast_builder.makelocinletname="__"^Int.to_stringt.next_idinletbinding_expr,quoted_expr=matchewith(* Optimize identifier quoting by avoiding closure.
See https://github.com/ocaml-ppx/ppx_deriving/pull/252. *)|{pexp_desc=Pexp_ident_;_}->(e,Ast.evarname)|_->letbinding_expr=Ast.pexp_funNolabelNone(letunit=Ast_builder.Default.Located.lident~loc"()"inAst.ppat_constructunitNone)einletquoted_expr=Ast.eapply(Ast.evarname)[Ast.eunit]in(binding_expr,quoted_expr)inletbinding=letpat=Ast.pvarnameinAst.value_binding~pat~expr:binding_exprint.bindings<-binding::t.bindings;t.next_id<-t.next_id+1;quoted_expr