123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)type'alazyt=unit->'atype'alazy_list_t=LConsof'a*'alazy_list_ttzresultLwt.tlazyttype'alazy_list='alazy_list_ttzresultLwt.tletrec(-->)ij=(* [i; i+1; ...; j] *)ifCompare.Int.(i>j)then[]elsei::(succi-->j)letrec(--->)ij=(* [i; i+1; ...; j] *)ifCompare.Int32.(i>j)then[]elsei::(Int32.succi--->j)letsplitdelim?(limit=max_int)path=letl=String.lengthpathinletrecdo_slashesacclimiti=ifCompare.Int.(i>=l)thenList.revaccelseifCompare.Char.(path.[i]=delim)thendo_slashesacclimit(i+1)elsedo_splitacclimitianddo_splitacclimiti=ifCompare.Int.(limit<=0)thenifCompare.Int.(i=l)thenList.revaccelseList.rev(String.subpathi(l-i)::acc)elsedo_componentacc(predlimit)iianddo_componentacclimitij=ifCompare.Int.(j>=l)thenifCompare.Int.(i=j)thenList.revaccelseList.rev(String.subpathi(j-i)::acc)elseifCompare.Char.(path.[j]=delim)thendo_slashes(String.subpathi(j-i)::acc)limitjelsedo_componentacclimiti(j+1)inifCompare.Int.(limit>0)thendo_slashes[]limit0else[path]letpp_print_paragraphppfdescription=Format.fprintfppf"@[%a@]"Format.(pp_print_list~pp_sep:pp_print_spacepp_print_string)(split' 'description)lettakenl=letrecloopaccnxs=ifCompare.Int.(n<=0)thenSome(List.revacc,xs)elsematchxswith[]->None|x::xs->loop(x::acc)(n-1)xsinloop[]nlletremove_prefix~prefixs=letx=String.lengthprefixinletn=String.lengthsinifCompare.Int.(n>=x)&&Compare.String.(String.subs0x=prefix)thenSome(String.subsx(n-x))elseNoneletrecremove_elem_from_listnb=function|[]->[]|_::_aslwhenCompare.Int.(nb<=0)->l|_::tl->remove_elem_from_list(nb-1)tlmoduleSyntax=struct(* To be upstreamed in environment v1 *)let(>|=?)=(>>|?)let(>>?=)vf=matchvwithError_ase->Lwt.returne|Okv->fvletok_unit=Ok()letok_none=OkNonelet[@inline]ok_somex=Ok(Somex)letok_nil=Ok[]leterror_unlesscondexn=ifcondthenok_unitelseerrorexnleterror_whencondexn=ifcondthenerrorexnelseok_unitletrecfilter_sfl=matchlwith|[]->return_nil|h::t->(fh>>=?function|false->filter_sft|true->filter_sft>>=?funt->return(h::t))letrecmapfl=matchlwith|[]->ok_nil|h::t->fh>>?funrh->mapft>>?funrt->Ok(rh::rt)end