1(* Copyright (C) 1999-2002 Henry Cejtin, Matthew Fluet, Suresh
2 *    Jagannathan, and Stephen Weeks.
3 * Copyright (C) 1997-1999 NEC Research Institute.
4 *
5 * MLton is released under a BSD-style license.
6 * Please see the file MLton-LICENSE for license information.
7
8 * Slightly adjusted by Michael Norrish (2006)
9
10 *)
11
12structure SourcePos :> SourcePos =
13struct
14
15datatype t = T of {column: int, file: string, line: int}
16
17local
18   fun f g (T r) = g r
19in
20   val column = f #column
21   val line = f #line
22end
23
24fun compare (T {column = c, file = f, line = l},
25	     T {column = c', file = f', line = l'}) =
26   case String.compare (f, f') of
27      EQUAL =>
28	 (case Int.compare (l, l') of
29	     EQUAL => Int.compare (c, c')
30	   | r => r)
31    | r => r
32
33fun equals (T r, T r') = r = r'
34
35fun make {column, file, line} =
36   T {column = column,
37      file = file,
38      line = line}
39
40fun file (p as T {file, ...}) = file
41
42val bogus = T {column = ~1,
43	       file = "<bogus>",
44	       line = ~1}
45
46fun toString (p as T {column, line, ...}) =
47   String.concat [file p, " ", Int.toString line, ".", Int.toString column]
48
49fun posToString (T {column,line,...}) =
50   String.concat [Int.toString line, ".", Int.toString column]
51
52end
53