123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144open!Importtypet=|Atomof{loc:Positions.range;atom:string;unescaped:stringoption}|Listof{loc:Positions.range;elements:t_or_commentlist}andt_or_comment=|Sexpoft|Commentofcommentandcomment=|Plain_commentof{loc:Positions.range;comment:string}|Sexp_commentof{hash_semi_pos:Positions.pos;comments:commentlist;sexp:t}[@@deriving_inlinesexp_of]letrecsexp_of_t=(function|Atom{loc=v_loc;atom=v_atom;unescaped=v_unescaped}->letbnds=[]inletbnds=letarg=sexp_of_optionsexp_of_stringv_unescapedinPpx_sexp_conv_lib.Sexp.List[Ppx_sexp_conv_lib.Sexp.Atom"unescaped";arg]::bndsinletbnds=letarg=sexp_of_stringv_atominPpx_sexp_conv_lib.Sexp.List[Ppx_sexp_conv_lib.Sexp.Atom"atom";arg]::bndsinletbnds=letarg=Positions.sexp_of_rangev_locinPpx_sexp_conv_lib.Sexp.List[Ppx_sexp_conv_lib.Sexp.Atom"loc";arg]::bndsinPpx_sexp_conv_lib.Sexp.List(Ppx_sexp_conv_lib.Sexp.Atom"Atom"::bnds)|List{loc=v_loc;elements=v_elements}->letbnds=[]inletbnds=letarg=sexp_of_listsexp_of_t_or_commentv_elementsinPpx_sexp_conv_lib.Sexp.List[Ppx_sexp_conv_lib.Sexp.Atom"elements";arg]::bndsinletbnds=letarg=Positions.sexp_of_rangev_locinPpx_sexp_conv_lib.Sexp.List[Ppx_sexp_conv_lib.Sexp.Atom"loc";arg]::bndsinPpx_sexp_conv_lib.Sexp.List(Ppx_sexp_conv_lib.Sexp.Atom"List"::bnds):t->Ppx_sexp_conv_lib.Sexp.t)andsexp_of_t_or_comment=(function|Sexpv0->letv0=sexp_of_tv0inPpx_sexp_conv_lib.Sexp.List[Ppx_sexp_conv_lib.Sexp.Atom"Sexp";v0]|Commentv0->letv0=sexp_of_commentv0inPpx_sexp_conv_lib.Sexp.List[Ppx_sexp_conv_lib.Sexp.Atom"Comment";v0]:t_or_comment->Ppx_sexp_conv_lib.Sexp.t)andsexp_of_comment=(function|Plain_comment{loc=v_loc;comment=v_comment}->letbnds=[]inletbnds=letarg=sexp_of_stringv_commentinPpx_sexp_conv_lib.Sexp.List[Ppx_sexp_conv_lib.Sexp.Atom"comment";arg]::bndsinletbnds=letarg=Positions.sexp_of_rangev_locinPpx_sexp_conv_lib.Sexp.List[Ppx_sexp_conv_lib.Sexp.Atom"loc";arg]::bndsinPpx_sexp_conv_lib.Sexp.List(Ppx_sexp_conv_lib.Sexp.Atom"Plain_comment"::bnds)|Sexp_comment{hash_semi_pos=v_hash_semi_pos;comments=v_comments;sexp=v_sexp}->letbnds=[]inletbnds=letarg=sexp_of_tv_sexpinPpx_sexp_conv_lib.Sexp.List[Ppx_sexp_conv_lib.Sexp.Atom"sexp";arg]::bndsinletbnds=letarg=sexp_of_listsexp_of_commentv_commentsinPpx_sexp_conv_lib.Sexp.List[Ppx_sexp_conv_lib.Sexp.Atom"comments";arg]::bndsinletbnds=letarg=Positions.sexp_of_posv_hash_semi_posinPpx_sexp_conv_lib.Sexp.List[Ppx_sexp_conv_lib.Sexp.Atom"hash_semi_pos";arg]::bndsinPpx_sexp_conv_lib.Sexp.List(Ppx_sexp_conv_lib.Sexp.Atom"Sexp_comment"::bnds):comment->Ppx_sexp_conv_lib.Sexp.t);;[@@@end]letcompare=Caml.compareletcompare_t_or_comment=Caml.compareletcompare_comment=Caml.comparemoduleForget=struct(* In cps to prevent non-tail recursion.
The polymorphism in the signature ensures that each function returns
only through the continuation. *)moduleCps:sigvalforget_t:t->(Sexp.t->'r)->'rvalforget_toc:t_or_comment->(Sexp.toption->'r)->'rvalforget_tocs:t_or_commentlist->(Sexp.tlist->'r)->'rend=structletrecforget_ttk=matchtwith|Atom{atom;_}->k(Sexp.Atomatom)|List{elements;_}->forget_tocselements(funxs->k(Sexp.Listxs))andforget_tocstocsk=matchtocswith|[]->k[]|toc::tocs->forget_toctoc(function|None->forget_tocstocsk|Somex->forget_tocstocs(funxs->k(x::xs)))andforget_toctock=matchtocwith|Comment_->kNone|Sexpt->forget_tt(funx->k(Somex));;endlettx=Cps.forget_tx(funy->y)lett_or_commentx=Cps.forget_tocx(funy->y)lett_or_commentsx=Cps.forget_tocsx(funy->y)end