src/Pure/General/position.ML
author wenzelm
Sat, 07 Jul 2007 00:14:52 +0200
changeset 23613 3f2a6c66e089
parent 22158 ff4fc4ee9eb0
child 23627 f543538866a2
permissions -rw-r--r--
added General/markup.ML; moved General/xml.ML to Tools/xml.ML;
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
22158
ff4fc4ee9eb0 Add line_of, name_of destructors.
aspinall
parents: 15531
diff changeset
    17
  val line_of: T -> int option
ff4fc4ee9eb0 Add line_of, name_of destructors.
aspinall
parents: 15531
diff changeset
    18
  val name_of: T -> string option
5010
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    19
end;
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    20
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    21
structure Position: POSITION =
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    22
struct
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    23
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 position *)
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    26
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    27
datatype T =
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    28
  Pos of int option * string option;
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    29
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
    30
val none = Pos (NONE, NONE);
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
    31
fun line n = Pos (SOME n, NONE);
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
    32
fun name s = Pos (NONE, SOME s);
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
    33
fun line_name n s = Pos (SOME n, SOME s);
5010
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    34
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    35
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    36
(* increment *)
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    37
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
    38
fun inc (pos as Pos (NONE, _)) = pos
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
    39
  | 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
    40
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    41
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    42
(* str_of *)
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    43
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
    44
fun str_of (Pos (NONE, NONE)) = ""
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
    45
  | str_of (Pos (SOME n, NONE)) = " (line " ^ string_of_int n ^ ")"
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
    46
  | str_of (Pos (NONE, SOME s)) = " (" ^ s ^ ")"
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
    47
  | 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
    48
22158
ff4fc4ee9eb0 Add line_of, name_of destructors.
aspinall
parents: 15531
diff changeset
    49
fun line_of (Pos (SOME n,_)) = SOME n
ff4fc4ee9eb0 Add line_of, name_of destructors.
aspinall
parents: 15531
diff changeset
    50
  | line_of _ = NONE
ff4fc4ee9eb0 Add line_of, name_of destructors.
aspinall
parents: 15531
diff changeset
    51
ff4fc4ee9eb0 Add line_of, name_of destructors.
aspinall
parents: 15531
diff changeset
    52
fun name_of (Pos (_,SOME s)) = SOME s
ff4fc4ee9eb0 Add line_of, name_of destructors.
aspinall
parents: 15531
diff changeset
    53
  | name_of _ = NONE
5010
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    54
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    55
end;