1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980(**************************************************************************)(* *)(* 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[]lidletrechead=functionLidents->s|Ldot(lid,_)->headlid|Lapply(_,_)->assertfalseletlast=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->vletkeep_suffix=letrecaux=function|Lidentstr->ifString.uncapitalize_asciistr<>strthenSome(Lidentstr,false)elseNone|Ldot(t,str)->ifString.uncapitalize_asciistr<>strthenmatchauxtwith|None->Some(Lidentstr,true)|Some(t,is_label)->Some(Ldot(t,str),is_label)elseNone|t->Some(t,false)(* Can be improved... *)infunction|Lidents->Lidents,false|Ldot(t,s)->beginmatchauxtwith|None->Lidents,true|Some(t,is_label)->Ldot(t,s),is_labelend|otherwise->otherwise,false