-
Notifications
You must be signed in to change notification settings - Fork 108
/
SourcePos.ML
69 lines (52 loc) · 1.5 KB
/
SourcePos.ML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
(* SPDX-License-Identifier: HPND *)
(* Copyright (C) 1999-2002 Henry Cejtin, Matthew Fluet, Suresh
* Jagannathan, and Stephen Weeks.
* Copyright (C) 1997-1999 NEC Research Institute.
*
* Please see the file MLton-LICENSE for license information.
* Slightly adjusted by Michael Norrish (2006)
*)
signature SOURCE_POS =
sig
type t
val bogus: t
val column: t -> int
val compare: t * t -> order
val equals: t * t -> bool
val file: t -> string
val line: t -> int
val make: {column: int, file: string, line: int} -> t
val toString: t -> string
val posToString : t -> string
end
structure SourcePos : SOURCE_POS =
struct
datatype t = T of {column: int, file: string, line: int}
local
fun f g (T r) = g r
in
val column = f #column
val line = f #line
end
fun compare (T {column = c, file = f, line = l},
T {column = c', file = f', line = l'}) =
case String.compare (f, f') of
EQUAL =>
(case Int.compare (l, l') of
EQUAL => Int.compare (c, c')
| r => r)
| r => r
fun equals (T r, T r') = r = r'
fun make {column, file, line} =
T {column = column,
file = file,
line = line}
fun file (T {file, ...}) = file
val bogus = T {column = ~1,
file = "<bogus>",
line = ~1}
fun toString (p as T {column, line, ...}) =
String.concat [file p, " ", Int.toString line, ".", Int.toString column]
fun posToString (T {column,line,...}) =
String.concat [Int.toString line, ".", Int.toString column]
end