Commits

camlspotter  committed 7f963c1

position.mli

  • Participants
  • Parent commits 41841ff

Comments (0)

Files changed (2)

File lib/position.ml

   let none = ()
 end
 
-module type File = sig
-  type t = {
-    fname : string; (* file name *) 
-    byte : int; (* in bytes from 0 *)
-    line : int; (* from 1 *)
-    column : int; (* in bytes from 0 *)
-  } with sexp
-
-  include Mtypes.Printable with type t := t
-
-  val top : string (* file name *) -> t
-  val add_newlines : t -> int -> t
-  val add_columns : t -> int -> t
-  val none : t
-  val format_detailed : Format.formatter -> t -> unit
-end
-
-module File : File = struct
+module File = struct
   type t = {
     fname : string;
     byte : int; (* in bytes from 0 *)
 
   let top fname = { start = File.top fname; end_ = File.top fname }
   let none = { start = File.none; end_ = File.none }
+  let show t = 
+    if t.start.File.byte < 0 then Printf.sprintf "<no location>"
+    else 
+      let diff = t.end_.File.byte - t.start.File.byte in
+      Printf.sprintf "line %d, character %d-%d" t.start.File.line t.start.File.column (t.start.File.column + diff)
+
   let format ppf t = 
     if t.start.File.byte < 0 then Format.fprintf ppf "<no location>"
     else 

File lib/position.mli

+module type S = sig
+  type t
+  include Mtypes.Printable with type t := t
+  val top : string -> t
+  val none : t
+end
+
+module None : S with type t = unit
+
+module File : sig
+  type t = {
+    fname : string; (* file name *) 
+    byte : int;     (* in bytes from 0 *)
+    line : int;     (* from 1 *)
+    column : int;   (* in bytes from 0 *)
+  } with sexp
+
+  include S with type t := t
+
+  val add_newlines : t -> int -> t
+  val add_columns : t -> int -> t
+  val format_detailed : Format.formatter -> t -> unit
+end
+
+module Region : sig
+  type t = { start : File.t; end_ : File.t; } with sexp
+  include S with type t := t
+end