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 | 4747b0022a0b9d8b4a631428c4a157f056af823c (patch) | |
tree | 3b86aa94b962fcc4872a7813d7eb1042e38dca47 /perl_checker.src/info.ml | |
parent | a94569f90f13d5636542ff0da7ce3bbd141c0928 (diff) | |
download | perl_checker-4747b0022a0b9d8b4a631428c4a157f056af823c.tar perl_checker-4747b0022a0b9d8b4a631428c4a157f056af823c.tar.gz perl_checker-4747b0022a0b9d8b4a631428c4a157f056af823c.tar.bz2 perl_checker-4747b0022a0b9d8b4a631428c4a157f056af823c.tar.xz perl_checker-4747b0022a0b9d8b4a631428c4a157f056af823c.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) |