summaryrefslogtreecommitdiffstats
path: root/camlp4/ocaml_src/lib/stdpp.ml
blob: 0830e6842dbbec4733248c189e2687aaa4439a0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
(* camlp4r *)
(***********************************************************************)
(*                                                                     *)
(*                             Camlp4                                  *)
(*                                                                     *)
(*        Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt     *)
(*                                                                     *)
(*  Copyright 2002 Institut National de Recherche en Informatique et   *)
(*  Automatique.  Distributed only by permission.                      *)
(*                                                                     *)
(***********************************************************************)

(* This file has been generated by program: do not edit! *)

exception Exc_located of (int * int) * exn;;

let raise_with_loc loc exc =
  match exc with
    Exc_located (_, _) -> raise exc
  | _ -> raise (Exc_located (loc, exc))
;;

let line_of_loc fname (bp, ep) =
  try
    let ic = open_in_bin fname in
    let rec loop lin col cnt =
      if cnt < bp then
        let (lin, col) =
          match input_char ic with
            '\n' -> lin + 1, 0
          | _ -> lin, col + 1
        in
        loop lin col (cnt + 1)
      else lin, col, col + ep - bp
    in
    let r =
      try loop 1 0 0 with
        End_of_file -> 1, bp, ep
    in
    close_in ic; r
  with
    Sys_error _ -> 1, bp, ep
;;

let loc_name = ref "loc";;