-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocation.ml
66 lines (59 loc) · 2.08 KB
/
location.ml
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
(* ----------------------------------------------------------------------------
* SchedMCore - A MultiCore Scheduling Framework
* Copyright (C) 2009-2011, ONERA, Toulouse, FRANCE - LIFL, Lille, FRANCE
*
* This file is part of Mince
*
* Mince is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation ; either version 2 of
* the License, or (at your option) any later version.
*
* Mince is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program ; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*---------------------------------------------------------------------------- *)
type t = { loc_start: Lexing.position; loc_end: Lexing.position }
let input_name = ref ""
let curr lexbuf = {
loc_start = lexbuf.Lexing.lex_start_p;
loc_end = lexbuf.Lexing.lex_curr_p
}
let init lexbuf fname =
lexbuf.Lexing.lex_curr_p <- {
Lexing.pos_fname = fname;
Lexing.pos_lnum = 1;
Lexing.pos_bol = 0;
Lexing.pos_cnum = 0;
}
let symbol_rloc () = {
loc_start = Parsing.symbol_start_pos ();
loc_end = Parsing.symbol_end_pos ()
}
open Format
let print loc =
let filename = loc.loc_start.Lexing.pos_fname in
let line = loc.loc_start.Lexing.pos_lnum in
let start_char =
loc.loc_start.Lexing.pos_cnum - loc.loc_start.Lexing.pos_bol
in
let end_char =
loc.loc_end.Lexing.pos_cnum - loc.loc_start.Lexing.pos_cnum + start_char
in
let (start_char, end_char) =
if start_char < 0 then (0,1) else (start_char, end_char)
in
print_string ("File \""^filename^"\", line ");
print_int line;
print_string ", characters ";
print_int start_char;
print_string "-";
print_int end_char;
print_string ":";
print_newline ()