Newer
Older
(** Time-stamp: <modified the 05/02/2008 (at 11:44) by Erwan Jahier> *)
(** Common to lus2lic and lic2loc *)
(* pour calculer line/col *)
let line_num = ref 1
let line_start_pos = ref 0
let new_line ( lexbuf ) = (
line_start_pos := Lexing.lexeme_end lexbuf;
incr line_num;
()
)
(* le type ``lexeme'', string + info source *)
type t = {
_str : string ;
_line : int ;
_cstart : int ;
_cend : int
}
let str x = (x._str)
let id x = (Ident.of_string x._str)
let line x = (x._line)
let cstart x = (x._cstart)
let cend x = (x._cend)
(* affichage standard: *)
let details lxm = (
Printf.sprintf "'%s' (file:%s, line:%d, col:%d to %d)"
lxm._str lxm._file lxm._line lxm._cstart lxm._cend
)
let position lxm = (
Printf.sprintf "line:%d, col:%d to %d"
lxm._line lxm._cstart lxm._cend
)
(* constructeur de type flaggé avec un lexeme *)
type 'a srcflaged = {
src : t ;
it : 'a
}
(* flagage d'une valeur quelconque *)
let (flagit : 'a -> t -> 'a srcflaged) =
function x -> function lxm ->
{ it = x; src = lxm }
let dummy = { _str = "dummy" ; _file = "dummy" ; _line = 0 ; _cstart = 0 ; _cend = 0 }
let make ( lexbuf ) = (
let s = (Lexing.lexeme lexbuf) in
let l = !line_num in
let c1 = (Lexing.lexeme_start lexbuf - !line_start_pos + 1) in
let c2 = (Lexing.lexeme_end lexbuf - !line_start_pos) in
last_lexeme :=
{ _str = s ;
_file = _lus2lic_ARGS.infile;
_line = l;
_cstart = c1 ;
_cend = c2
};
!last_lexeme