src/Pure/General/position.ML
author wenzelm
Thu, 27 Apr 2006 15:06:40 +0200
changeset 19484 89484a62184a
parent 15531 08c8dad8e399
child 22158 ff4fc4ee9eb0
permissions -rw-r--r--
added map_filter;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6118
caa439435666 fixed titles;
wenzelm
parents: 5010
diff changeset
     1
(*  Title:      Pure/General/position.ML
5010
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
     4
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
     5
Input positions.
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
     6
*)
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
     7
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
     8
signature POSITION =
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
     9
sig
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    10
  type T
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    11
  val none: T
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    12
  val line: int -> T
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    13
  val name: string -> T
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    14
  val line_name: int -> string -> T
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    15
  val inc: T -> T
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    16
  val str_of: T -> string
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    17
end;
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    18
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    19
structure Position: POSITION =
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    20
struct
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    21
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    22
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    23
(* datatype position *)
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    24
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    25
datatype T =
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    26
  Pos of int option * string option;
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    27
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
    28
val none = Pos (NONE, NONE);
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
    29
fun line n = Pos (SOME n, NONE);
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
    30
fun name s = Pos (NONE, SOME s);
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
    31
fun line_name n s = Pos (SOME n, SOME s);
5010
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    32
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    33
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    34
(* increment *)
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    35
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
    36
fun inc (pos as Pos (NONE, _)) = pos
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
    37
  | inc (Pos (SOME n, opt_s)) = Pos (SOME (n + 1), opt_s);
5010
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    38
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    39
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    40
(* str_of *)
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    41
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
    42
fun str_of (Pos (NONE, NONE)) = ""
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
    43
  | str_of (Pos (SOME n, NONE)) = " (line " ^ string_of_int n ^ ")"
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
    44
  | str_of (Pos (NONE, SOME s)) = " (" ^ s ^ ")"
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
    45
  | str_of (Pos (SOME n, SOME s)) = " (line " ^ string_of_int n ^ " of " ^ s ^ ")";
5010
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    46
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    47
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    48
end;