1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950(**************************************************************************)(* *)(* 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*tletrecflataccu=functionLidents->s::accu|Ldot(lid,s)->flat(s::accu)lid|Lapply(_,_)->Misc.fatal_error"Longident.flat"letflattenlid=flat[]lidletlast=functionLidents->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