src/Pure/Thy/position.ML
author wenzelm
Tue, 19 May 1998 17:15:30 +0200
changeset 4945 d8c809afafb8
parent 4942 067533f8c419
child 4948 c53aa26ccfd2
permissions -rw-r--r--
fixed handle_error: cat_lines;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4942
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Thy/position.ML
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
     4
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
     5
Input positions.
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
     6
*)
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
     7
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
     8
signature POSITION =
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
     9
sig
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    10
  eqtype T
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    11
  val none: T
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    12
  val line: int -> T
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    13
  val name: string -> T
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    14
  val line_name: int -> string -> T
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    15
  val incr: T -> T
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    16
  val str_of: T -> string
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    17
end;
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    18
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    19
structure Position: POSITION =
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    20
struct
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    21
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    22
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    23
(* datatype position *)
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    24
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    25
datatype T =
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    26
  Pos of int option * string option;
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    27
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    28
val none = Pos (None, None);
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    29
fun line n = Pos (Some n, None);
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    30
fun name s = Pos (None, Some s);
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    31
fun line_name n s = Pos (Some n, Some s);
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    32
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    33
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    34
(* incr *)
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    35
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    36
fun incr (pos as Pos (None, _)) = pos
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    37
  | incr (Pos (Some n, opt_s)) = Pos (Some (n + 1), opt_s);
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    38
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    39
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    40
(* str_of *)
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    41
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    42
fun str_of (Pos (None, None)) = ""
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    43
  | str_of (Pos (Some n, None)) = " (line " ^ string_of_int n ^ ")"
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    44
  | str_of (Pos (None, Some s)) = " (" ^ s ^ ")"
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    45
  | str_of (Pos (Some n, Some s)) = " (line " ^ string_of_int n ^ " of " ^ s ^ ")";
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    46
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    47
067533f8c419 Input positions.
wenzelm
parents:
diff changeset
    48
end;