diff options
Diffstat (limited to 'libs')
-rw-r--r-- | libs/util.ml | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/libs/util.ml b/libs/util.ml index 6e8dc59..ffeee82 100644 --- a/libs/util.ml +++ b/libs/util.ml @@ -1,4 +1,5 @@ open Unix +open Lexing (* Small things *) @@ -33,6 +34,21 @@ let position_unknown = Lexing.dummy_pos type extent = position * position let extent_unknown = (position_unknown, position_unknown) +let string_of_position p = + Printf.sprintf "%s:%i:%i" p.pos_fname p.pos_lnum (p.pos_cnum - p.pos_bol) + +let string_of_extent (p,q) = + if p.pos_fname = q.pos_fname then + if p.pos_lnum = q.pos_lnum then + if p.pos_cnum = q.pos_cnum then + Printf.sprintf "%s:%i.%i" p.pos_fname p.pos_lnum (p.pos_cnum - p.pos_bol) + else + Printf.sprintf "%s:%i.%i-%i" p.pos_fname p.pos_lnum (p.pos_cnum - p.pos_bol) (q.pos_cnum - q.pos_bol) + else + Printf.sprintf "%s:%i.%i-%i.%i" p.pos_fname p.pos_lnum (p.pos_cnum - p.pos_bol) q.pos_lnum (q.pos_cnum - q.pos_bol) + else + Printf.sprintf "%s:%i.%i-%s:%i.%i" p.pos_fname p.pos_lnum (p.pos_cnum - p.pos_bol) q.pos_fname q.pos_lnum (q.pos_cnum - q.pos_bol) + (* Exceptions *) |