1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162(**************************************************************************)(* *)(* OCaml *)(* *)(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)(* *)(* Copyright 1996 Institut National de Recherche en Informatique et *)(* en Automatique. *)(* *)(* All rights reserved. This file is distributed under the terms of *)(* the GNU Lesser General Public License version 2.1, with the *)(* special exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)typet=Lidentofstring|Ldotoft*string|Lapplyoft*tletreccmp:t->t->int=funab->ifa==bthen0elsematch(a,b)with|Lidenta,Lidentb->compareab|Lident_,_->-1|_,Lident_->1|Ldot(a,b),Ldot(c,d)->(matchcmpacwith0->comparebd|n->n)|Ldot_,_->-1|_,Ldot_->1|Lapply(a,b),Lapply(c,d)->(matchcmpacwith0->cmpbd|n->n)letrecflataccu=function|Lidents->s::accu|Ldot(lid,s)->flat(s::accu)lid|Lapply(_,_)->Misc.fatal_error"Longident.flat"letflattenlid=flat[]lidletlast=function|Lidents->s|Ldot(_,s)->s|Lapply(_,_)->Misc.fatal_error"Longident.last"letrecsplit_at_dotsspos=tryletdot=String.index_fromspos'.'inString.subspos(dot-pos)::split_at_dotss(dot+1)withNot_found->[String.subspos(String.lengths-pos)]letunflattenl=matchlwith|[]->None|hd::tl->Some(List.fold_left(funps->Ldot(p,s))(Lidenthd)tl)letparses=matchunflatten(split_at_dotss0)with|None->Lident""(* should not happen, but don't put assert false
so as not to crash the toplevel (see Genprintval) *)|Somev->v