1995-09-28 03:41:50 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Objective Caml *)
|
1995-09-28 03:41:50 -07:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
1995-09-28 03:41:50 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
|
|
|
type t =
|
|
|
|
Lident of string
|
|
|
|
| Ldot of t * string
|
|
|
|
| Lapply of t * t
|
|
|
|
|
|
|
|
let rec flat accu = function
|
|
|
|
Lident s -> s :: accu
|
|
|
|
| Ldot(lid, s) -> flat (s :: accu) lid
|
|
|
|
| Lapply(l1, l2) -> Misc.fatal_error "Longident.flat"
|
|
|
|
|
|
|
|
let flatten lid = flat [] lid
|
2000-03-25 10:55:45 -08:00
|
|
|
|
|
|
|
let rec split_at_dots s pos =
|
|
|
|
try
|
|
|
|
let dot = String.index_from s pos '.' in
|
|
|
|
String.sub s pos (dot - pos) :: split_at_dots s (dot + 1)
|
|
|
|
with Not_found ->
|
|
|
|
[String.sub s pos (String.length s - pos)]
|
|
|
|
|
|
|
|
let parse s =
|
|
|
|
match split_at_dots s 0 with
|
|
|
|
[] -> Lident "" (* should not happen, but don't put assert false
|
|
|
|
so as not to crash the toplevel (see Genprintval) *)
|
|
|
|
| hd :: tl -> List.fold_left (fun p s -> Ldot(p, s)) (Lident hd) tl
|