123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2022 Nomadic Labs. <contact@nomadic-labs.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. *)(* *)(*****************************************************************************)(* The head of the list is the root of the namespace *)typet=stringlisttypecons=string->tletsep='/'letroot_name="."letempty=[]letis_empty=List.is_emptyletis_singleton=function[_]->true|_->falseletto_stringt=matchtwith[]->root_name|_->String.concat(Char.escapedsep)tletbasename=function[]->root_name|t->Stdlib.List.(revt|>hd)letppfmtt=Format.pp_print_stringfmt(to_stringt)letpp_shortfmtt=Format.pp_print_stringfmt(basenamet)letequal=List.equalString.equalletcompare=List.compareString.comparelethash=Stdlib.Hashtbl.hashletof_strings=(ifString.equalsroot_namethen[]elseString.split_on_charseps)|>List.rev|>(function|h::tasl->ifString.(equalhempty)thentelsel|[]->[])|>List.revletappend:t->t->t=List.appendlet(@)=appendletcons(l:t)(a:string):t=l@matchof_stringawith|[_]->[a]|_->Format.eprintf"Namespace.cons error: string contains %c: %s@."sepa;assertfalseletencoding=Data_encoding.(liststring)letto_listl=root_name::lletof_listl=letl=matchlwithx::xswhenx=root_name->xs|_->linmatchList.find(funs->String.containsssep)lwith|None->l|Somea->Format.eprintf"Namespace.of_list error: list contains \"%s\" that contains '%c'@."asep;assertfalseletname_match(pattern:t)(name:t)=letl,leftovers=List.combine_with_leftoverspatternnameinmatchleftoverswith|None|Some(Right_)->List.for_all(fun(a,b)->String.equalab)l|_->falseletto_filenamens=String.concat"__"@@matchto_listnswith|hd::nswhenString.equalhdroot_name->ns|ns->nsmoduleHashtbl=Hashtbl.MakeSeeded(structtypenonrect=tletequal=equal(* See [src/lib_base/tzPervasives.ml] for an explanation *)[@@@ocaml.warning"-32"]lethash=Hashtbl.seeded_hashletseeded_hash=Hashtbl.seeded_hash[@@@ocaml.warning"+32"]end)moduleSet=Set.Make(structtypenonrect=tletcompare=compareend)moduleMap=Map.Make(structtypenonrect=tletcompare=compareend)letroot=cons[]letmakensstr=cons(nsstr)