dtlc

dependently-typed lambda calculus toy
git clone git://git.rr3.xyz/dtlc
Log | Files | Refs | README | LICENSE

loc.ml (828B)


      1 open Lexing
      2 
      3 type loc =
      4 | Nowhere
      5 | Loc of {
      6 	beg_row: int;
      7 	beg_col: int;
      8 	end_row: int;
      9 	end_col: int;
     10 }
     11 type t = loc
     12 
     13 let of_positions
     14 : position -> position -> loc
     15 = fun beg_pos end_pos ->
     16 	Loc {
     17 		beg_row = beg_pos.pos_lnum;
     18 		beg_col = beg_pos.pos_cnum - beg_pos.pos_bol;
     19 		end_row = end_pos.pos_lnum;
     20 		end_col = end_pos.pos_cnum - end_pos.pos_bol;
     21 	}
     22 
     23 let of_locs
     24 : loc -> loc -> loc
     25 = fun beg_loc end_loc -> match beg_loc, end_loc with
     26 | Loc b, Loc e ->
     27 	Loc {
     28 		beg_row = b.beg_row;
     29 		beg_col = b.beg_col;
     30 		end_row = e.end_row;
     31 		end_col = e.end_col;
     32 	}
     33 | Nowhere, _ | _, Nowhere -> Nowhere
     34 
     35 let pp_print
     36 : Format.formatter -> loc -> unit
     37 = fun ppf -> function
     38 | Nowhere -> Format.pp_print_string ppf "?"
     39 | Loc {beg_row; beg_col; end_row; end_col} ->
     40 	Format.fprintf ppf "%d:%d-%d:%d" beg_row beg_col end_row end_col