-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocation.ml
28 lines (21 loc) · 838 Bytes
/
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
type 'a located =
{ content : 'a ;
startpos : Lexing.position ;
endpos : Lexing.position }
let locate x startpos endpos =
{ content = x ; startpos = startpos ; endpos = endpos }
let locate_with content { startpos ; endpos ; _ } =
{ content ; startpos ; endpos }
let relocate r startpos endpos =
{ r with startpos = startpos ; endpos = endpos }
let relocate_with { content ; _ } { startpos ; endpos ; _ } =
{ content ; startpos ; endpos }
let map f r = locate_with (f r.content) r
let dummy_locate x =
let dummy = Lexing.dummy_pos in
locate x dummy dummy
let location_msg { startpos ; endpos ; _ } =
let open Lexing in
Printf.sprintf "file \"%s\", line %i, characters %i-%i"
startpos.pos_fname startpos.pos_lnum startpos.pos_cnum
(endpos.pos_cnum + (endpos.pos_bol - startpos.pos_bol))