6118
|
1 |
(* Title: Pure/General/position.ML
|
5010
|
2 |
ID: $Id$
|
|
3 |
Author: Markus Wenzel, TU Muenchen
|
8806
|
4 |
License: GPL (GNU GENERAL PUBLIC LICENSE)
|
5010
|
5 |
|
|
6 |
Input positions.
|
|
7 |
*)
|
|
8 |
|
|
9 |
signature POSITION =
|
|
10 |
sig
|
|
11 |
type T
|
|
12 |
val none: T
|
|
13 |
val line: int -> T
|
|
14 |
val name: string -> T
|
|
15 |
val line_name: int -> string -> T
|
|
16 |
val inc: T -> T
|
|
17 |
val str_of: T -> string
|
|
18 |
end;
|
|
19 |
|
|
20 |
structure Position: POSITION =
|
|
21 |
struct
|
|
22 |
|
|
23 |
|
|
24 |
(* datatype position *)
|
|
25 |
|
|
26 |
datatype T =
|
|
27 |
Pos of int option * string option;
|
|
28 |
|
|
29 |
val none = Pos (None, None);
|
|
30 |
fun line n = Pos (Some n, None);
|
|
31 |
fun name s = Pos (None, Some s);
|
|
32 |
fun line_name n s = Pos (Some n, Some s);
|
|
33 |
|
|
34 |
|
|
35 |
(* increment *)
|
|
36 |
|
|
37 |
fun inc (pos as Pos (None, _)) = pos
|
|
38 |
| inc (Pos (Some n, opt_s)) = Pos (Some (n + 1), opt_s);
|
|
39 |
|
|
40 |
|
|
41 |
(* str_of *)
|
|
42 |
|
|
43 |
fun str_of (Pos (None, None)) = ""
|
|
44 |
| str_of (Pos (Some n, None)) = " (line " ^ string_of_int n ^ ")"
|
|
45 |
| str_of (Pos (None, Some s)) = " (" ^ s ^ ")"
|
|
46 |
| str_of (Pos (Some n, Some s)) = " (line " ^ string_of_int n ^ " of " ^ s ^ ")";
|
|
47 |
|
|
48 |
|
|
49 |
end;
|