From 4e66de932b91e91e4cadd943ff8859d6f69f57e1 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 15 Jul 2014 11:35:12 +0200 Subject: Clean up & comment a bit. --- libs/util.ml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'libs') 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 *) -- cgit v1.2.3