diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2002-11-09 12:02:04 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2002-11-09 12:02:04 +0000 |
commit | 566dc80134a61ef7909315ddc902da511741e5f1 (patch) | |
tree | dda5abfbf25a7828b8119229ff62c0d8735a8890 /perl_checker.src/info.ml | |
parent | f77da0ea13e278254462c123518881e1dc19085a (diff) | |
download | perl-MDK-Common-566dc80134a61ef7909315ddc902da511741e5f1.tar perl-MDK-Common-566dc80134a61ef7909315ddc902da511741e5f1.tar.gz perl-MDK-Common-566dc80134a61ef7909315ddc902da511741e5f1.tar.bz2 perl-MDK-Common-566dc80134a61ef7909315ddc902da511741e5f1.tar.xz perl-MDK-Common-566dc80134a61ef7909315ddc902da511741e5f1.zip |
*** empty log message ***
Diffstat (limited to 'perl_checker.src/info.ml')
-rw-r--r-- | perl_checker.src/info.ml | 25 |
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) |