summaryrefslogtreecommitdiffstats
path: root/perl_checker.src/info.ml
diff options
context:
space:
mode:
Diffstat (limited to 'perl_checker.src/info.ml')
-rw-r--r--perl_checker.src/info.ml25
1 files changed, 25 insertions, 0 deletions
diff --git a/perl_checker.src/info.ml b/perl_checker.src/info.ml
new file mode 100644
index 0000000..5c002ae
--- /dev/null
+++ b/perl_checker.src/info.ml
@@ -0,0 +1,25 @@
+open List
+open Printf
+open Common
+
+let (lines_starts : (string * int list ref) list ref) = ref []
+let current_file_lines_starts = ref []
+let current_file = ref ""
+
+let start_a_new_file file =
+ current_file := file ;
+ current_file_lines_starts := [0] ;
+ lines_starts := (file, current_file_lines_starts) :: !lines_starts
+
+let pos2line (file, a, b) =
+ let starts = map_index (fun a b -> a,b) (rev !(assoc file !lines_starts)) in
+ let ((offset, line), _) = find (fun (_,(e,_)) -> e > a) (combine starts (tl starts @ [99999, 99999])) in
+ file, line, a - offset, b - offset
+
+let pos2sfull pos =
+ try
+ let (file, line, n1,n2) = pos2line pos in
+ sprintf "File \"%s\", line %d, character %d-%d\n" file (line + 1) n1 n2
+ with Not_found -> ""
+
+let pos2sfull_current a b = pos2sfull (!current_file, a, b)