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