src/Pure/General/position.ML
author wenzelm
Sun, 03 Apr 2011 21:59:33 +0200
changeset 42204 b3277168c1e7
parent 41504 f0f20a5b54df
child 42327 7c7cc7590eb3
permissions -rw-r--r--
added Position.reports convenience; modernized Syntax.trrule constructors; modernized Sign.add_trrules/del_trrules: internal arguments; modernized Isar_Cmd.translations/no_translations: external arguments; explicit syntax categories class_name/type_name, with reports via type_context; eliminated former class_name/type_name ast translations; tuned signatures;
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
    Author:     Markus Wenzel, TU Muenchen
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
     3
29307
3a0b38b7fbb4 added id;
wenzelm
parents: 28122
diff changeset
     4
Source positions: counting Isabelle symbols, starting from 1.
5010
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
     5
*)
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
signature POSITION =
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
     8
sig
41484
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
     9
  eqtype T
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    10
  val make: {line: int, column: int, offset: int, end_offset: int, props: Properties.T} -> T
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    11
  val dest: T -> {line: int, column: int, offset: int, end_offset: int, props: Properties.T}
23673
67c748e5ae54 replaced name by file (unquoted);
wenzelm
parents: 23627
diff changeset
    12
  val line_of: T -> int option
26003
7a8aee8353cf added column field;
wenzelm
parents: 25954
diff changeset
    13
  val column_of: T -> int option
27795
f67f4c677d81 count offset as well;
wenzelm
parents: 27791
diff changeset
    14
  val offset_of: T -> int option
41484
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    15
  val end_offset_of: T -> int option
23673
67c748e5ae54 replaced name by file (unquoted);
wenzelm
parents: 23627
diff changeset
    16
  val file_of: T -> string option
27796
a6da5f68e776 added distance_of (permissive version);
wenzelm
parents: 27795
diff changeset
    17
  val advance: Symbol.symbol -> T -> T
a6da5f68e776 added distance_of (permissive version);
wenzelm
parents: 27795
diff changeset
    18
  val distance_of: T -> T -> int
5010
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    19
  val none: T
27777
7a63d1b50b88 only increment column if valid;
wenzelm
parents: 27764
diff changeset
    20
  val start: T
31435
d24ef3ff34bc export file_name;
wenzelm
parents: 31424
diff changeset
    21
  val file_name: string -> Properties.T
27777
7a63d1b50b88 only increment column if valid;
wenzelm
parents: 27764
diff changeset
    22
  val file: string -> T
5010
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    23
  val line: int -> T
27777
7a63d1b50b88 only increment column if valid;
wenzelm
parents: 27764
diff changeset
    24
  val line_file: int -> string -> T
29307
3a0b38b7fbb4 added id;
wenzelm
parents: 28122
diff changeset
    25
  val id: string -> T
32573
62b5b538408d Isar.define_command: identify transaction;
wenzelm
parents: 32195
diff changeset
    26
  val id_only: string -> T
27426
c0ef698c0904 added get_id/put_id;
wenzelm
parents: 26890
diff changeset
    27
  val get_id: T -> string option
c0ef698c0904 added get_id/put_id;
wenzelm
parents: 26890
diff changeset
    28
  val put_id: string -> T -> T
28017
4919bd124a58 type Properties.T;
wenzelm
parents: 27796
diff changeset
    29
  val of_properties: Properties.T -> T
4919bd124a58 type Properties.T;
wenzelm
parents: 27796
diff changeset
    30
  val properties_of: T -> Properties.T
4919bd124a58 type Properties.T;
wenzelm
parents: 27796
diff changeset
    31
  val default_properties: T -> Properties.T -> Properties.T
39440
4c2547af5909 simplified/clarified (Context_)Position.markup/reported_text;
wenzelm
parents: 38887
diff changeset
    32
  val markup: T -> Markup.T -> Markup.T
41504
f0f20a5b54df clarified notion Position.is_reported;
wenzelm
parents: 41484
diff changeset
    33
  val is_reported: T -> bool
39507
839873937ddd tuned signature of (Context_)Position.report variants;
wenzelm
parents: 39440
diff changeset
    34
  val reported_text: T -> Markup.T -> string -> string
839873937ddd tuned signature of (Context_)Position.report variants;
wenzelm
parents: 39440
diff changeset
    35
  val report_text: T -> Markup.T -> string -> unit
839873937ddd tuned signature of (Context_)Position.report variants;
wenzelm
parents: 39440
diff changeset
    36
  val report: T -> Markup.T -> unit
42204
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 41504
diff changeset
    37
  type reports = (T * Markup.T) list
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 41504
diff changeset
    38
  val reports: reports Unsynchronized.ref -> T list -> ('a -> Markup.T list) -> 'a -> unit
26003
7a8aee8353cf added column field;
wenzelm
parents: 25954
diff changeset
    39
  val str_of: T -> string
27764
e0ee3cc240fe advance: single argument (again);
wenzelm
parents: 27759
diff changeset
    40
  type range = T * T
27796
a6da5f68e776 added distance_of (permissive version);
wenzelm
parents: 27795
diff changeset
    41
  val no_range: range
41484
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    42
  val set_range: range -> T
27777
7a63d1b50b88 only increment column if valid;
wenzelm
parents: 27764
diff changeset
    43
  val reset_range: T -> T
27764
e0ee3cc240fe advance: single argument (again);
wenzelm
parents: 27759
diff changeset
    44
  val range: T -> T -> range
25817
d8e0190917a5 type T: based on properties, added id field;
wenzelm
parents: 25792
diff changeset
    45
  val thread_data: unit -> T
d8e0190917a5 type T: based on properties, added id field;
wenzelm
parents: 25792
diff changeset
    46
  val setmp_thread_data: T -> ('a -> 'b) -> 'a -> 'b
33097
9d501e11084a maintain position of formal entities via name space;
wenzelm
parents: 32573
diff changeset
    47
  val default: T -> T
5010
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    48
end;
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    49
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    50
structure Position: POSITION =
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    51
struct
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    52
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    53
(* datatype position *)
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    54
41484
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    55
datatype T = Pos of (int * int * int * int) * Properties.T;
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    56
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    57
fun norm_props (props: Properties.T) =
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    58
  maps (fn a => the_list (find_first (fn (b, _) => a = b) props)) Markup.position_properties';
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    59
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    60
fun make {line = i, column = j, offset = k, end_offset = l, props} =
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    61
  Pos ((i, j, k, l), norm_props props);
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    62
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    63
fun dest (Pos ((i, j, k, l), props)) =
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    64
  {line = i, column = j, offset = k, end_offset = l, props = props};
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    65
27777
7a63d1b50b88 only increment column if valid;
wenzelm
parents: 27764
diff changeset
    66
27795
f67f4c677d81 count offset as well;
wenzelm
parents: 27791
diff changeset
    67
fun valid (i: int) = i > 0;
f67f4c677d81 count offset as well;
wenzelm
parents: 27791
diff changeset
    68
fun if_valid i i' = if valid i then i' else i;
f67f4c677d81 count offset as well;
wenzelm
parents: 27791
diff changeset
    69
27777
7a63d1b50b88 only increment column if valid;
wenzelm
parents: 27764
diff changeset
    70
27796
a6da5f68e776 added distance_of (permissive version);
wenzelm
parents: 27795
diff changeset
    71
(* fields *)
a6da5f68e776 added distance_of (permissive version);
wenzelm
parents: 27795
diff changeset
    72
41484
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    73
fun line_of (Pos ((i, _, _, _), _)) = if valid i then SOME i else NONE;
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    74
fun column_of (Pos ((_, j, _, _), _)) = if valid j then SOME j else NONE;
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    75
fun offset_of (Pos ((_, _, k, _), _)) = if valid k then SOME k else NONE;
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    76
fun end_offset_of (Pos ((_, _, _, l), _)) = if valid l then SOME l else NONE;
27796
a6da5f68e776 added distance_of (permissive version);
wenzelm
parents: 27795
diff changeset
    77
28017
4919bd124a58 type Properties.T;
wenzelm
parents: 27796
diff changeset
    78
fun file_of (Pos (_, props)) = Properties.get props Markup.fileN;
27796
a6da5f68e776 added distance_of (permissive version);
wenzelm
parents: 27795
diff changeset
    79
a6da5f68e776 added distance_of (permissive version);
wenzelm
parents: 27795
diff changeset
    80
27777
7a63d1b50b88 only increment column if valid;
wenzelm
parents: 27764
diff changeset
    81
(* advance *)
26003
7a8aee8353cf added column field;
wenzelm
parents: 25954
diff changeset
    82
41484
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    83
fun advance_count "\n" (i: int, j: int, k: int, l: int) =
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    84
      (if_valid i (i + 1), if_valid j 1, if_valid k (k + 1), l)
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    85
  | advance_count s (i, j, k, l) =
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    86
      if Symbol.is_regular s then (i, if_valid j (j + 1), if_valid k (k + 1), l)
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    87
      else (i, j, k, l);
5010
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
    88
41484
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    89
fun invalid_count (i, j, k, _: int) =
27795
f67f4c677d81 count offset as well;
wenzelm
parents: 27791
diff changeset
    90
  not (valid i orelse valid j orelse valid k);
f67f4c677d81 count offset as well;
wenzelm
parents: 27791
diff changeset
    91
f67f4c677d81 count offset as well;
wenzelm
parents: 27791
diff changeset
    92
fun advance sym (pos as (Pos (count, props))) =
f67f4c677d81 count offset as well;
wenzelm
parents: 27791
diff changeset
    93
  if invalid_count count then pos else Pos (advance_count sym count, props);
27777
7a63d1b50b88 only increment column if valid;
wenzelm
parents: 27764
diff changeset
    94
7a63d1b50b88 only increment column if valid;
wenzelm
parents: 27764
diff changeset
    95
27796
a6da5f68e776 added distance_of (permissive version);
wenzelm
parents: 27795
diff changeset
    96
(* distance of adjacent positions *)
27777
7a63d1b50b88 only increment column if valid;
wenzelm
parents: 27764
diff changeset
    97
41484
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
    98
fun distance_of (Pos ((_, j, k, _), _)) (Pos ((_, j', k', _), _)) =
27796
a6da5f68e776 added distance_of (permissive version);
wenzelm
parents: 27795
diff changeset
    99
  if valid j andalso valid j' then j' - j
a6da5f68e776 added distance_of (permissive version);
wenzelm
parents: 27795
diff changeset
   100
  else if valid k andalso valid k' then k' - k
a6da5f68e776 added distance_of (permissive version);
wenzelm
parents: 27795
diff changeset
   101
  else 0;
26882
9e824d8f4512 renamed Position.path to Path.position;
wenzelm
parents: 26633
diff changeset
   102
5010
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
   103
27777
7a63d1b50b88 only increment column if valid;
wenzelm
parents: 27764
diff changeset
   104
(* make position *)
7a63d1b50b88 only increment column if valid;
wenzelm
parents: 27764
diff changeset
   105
41484
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
   106
val none = Pos ((0, 0, 0, 0), []);
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
   107
val start = Pos ((1, 1, 1, 0), []);
27744
d4c5ddf98869 advance: operate on symbol list (less overhead);
wenzelm
parents: 27741
diff changeset
   108
29307
3a0b38b7fbb4 added id;
wenzelm
parents: 28122
diff changeset
   109
27796
a6da5f68e776 added distance_of (permissive version);
wenzelm
parents: 27795
diff changeset
   110
fun file_name "" = []
a6da5f68e776 added distance_of (permissive version);
wenzelm
parents: 27795
diff changeset
   111
  | file_name name = [(Markup.fileN, name)];
a6da5f68e776 added distance_of (permissive version);
wenzelm
parents: 27795
diff changeset
   112
41484
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
   113
fun file name = Pos ((1, 1, 1, 0), file_name name);
27744
d4c5ddf98869 advance: operate on symbol list (less overhead);
wenzelm
parents: 27741
diff changeset
   114
41484
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
   115
fun line_file i name = Pos ((i, 0, 0, 0), file_name name);
27795
f67f4c677d81 count offset as well;
wenzelm
parents: 27791
diff changeset
   116
fun line i = line_file i "";
5010
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
   117
41484
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
   118
fun id id = Pos ((0, 0, 1, 0), [(Markup.idN, id)]);
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
   119
fun id_only id = Pos ((0, 0, 0, 0), [(Markup.idN, id)]);
22158
ff4fc4ee9eb0 Add line_of, name_of destructors.
aspinall
parents: 15531
diff changeset
   120
28017
4919bd124a58 type Properties.T;
wenzelm
parents: 27796
diff changeset
   121
fun get_id (Pos (_, props)) = Properties.get props Markup.idN;
4919bd124a58 type Properties.T;
wenzelm
parents: 27796
diff changeset
   122
fun put_id id (Pos (count, props)) = Pos (count, Properties.put (Markup.idN, id) props);
27426
c0ef698c0904 added get_id/put_id;
wenzelm
parents: 26890
diff changeset
   123
29307
3a0b38b7fbb4 added id;
wenzelm
parents: 28122
diff changeset
   124
3a0b38b7fbb4 added id;
wenzelm
parents: 28122
diff changeset
   125
(* markup properties *)
3a0b38b7fbb4 added id;
wenzelm
parents: 28122
diff changeset
   126
25817
d8e0190917a5 type T: based on properties, added id field;
wenzelm
parents: 25792
diff changeset
   127
fun of_properties props =
23627
f543538866a2 added property conversions;
wenzelm
parents: 22158
diff changeset
   128
  let
27795
f67f4c677d81 count offset as well;
wenzelm
parents: 27791
diff changeset
   129
    fun get name =
28017
4919bd124a58 type Properties.T;
wenzelm
parents: 27796
diff changeset
   130
      (case Properties.get props name of
27795
f67f4c677d81 count offset as well;
wenzelm
parents: 27791
diff changeset
   131
        NONE => 0
f67f4c677d81 count offset as well;
wenzelm
parents: 27791
diff changeset
   132
      | SOME s => the_default 0 (Int.fromString s));
41484
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
   133
  in
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
   134
    make {line = get Markup.lineN, column = get Markup.columnN,
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
   135
      offset = get Markup.offsetN, end_offset = get Markup.end_offsetN, props = props}
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
   136
  end;
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
   137
26003
7a8aee8353cf added column field;
wenzelm
parents: 25954
diff changeset
   138
41484
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
   139
fun value k i = if valid i then [(k, string_of_int i)] else [];
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
   140
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
   141
fun properties_of (Pos ((i, j, k, l), props)) =
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
   142
  value Markup.lineN i @ value Markup.columnN j @
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
   143
  value Markup.offsetN k @ value Markup.end_offsetN l @ props;
26003
7a8aee8353cf added column field;
wenzelm
parents: 25954
diff changeset
   144
26052
7d5b3e34a735 added default_properties;
wenzelm
parents: 26003
diff changeset
   145
fun default_properties default props =
7d5b3e34a735 added default_properties;
wenzelm
parents: 26003
diff changeset
   146
  if exists (member (op =) Markup.position_properties o #1) props then props
7d5b3e34a735 added default_properties;
wenzelm
parents: 26003
diff changeset
   147
  else properties_of default @ props;
7d5b3e34a735 added default_properties;
wenzelm
parents: 26003
diff changeset
   148
39440
4c2547af5909 simplified/clarified (Context_)Position.markup/reported_text;
wenzelm
parents: 38887
diff changeset
   149
val markup = Markup.properties o properties_of;
4c2547af5909 simplified/clarified (Context_)Position.markup/reported_text;
wenzelm
parents: 38887
diff changeset
   150
4c2547af5909 simplified/clarified (Context_)Position.markup/reported_text;
wenzelm
parents: 38887
diff changeset
   151
4c2547af5909 simplified/clarified (Context_)Position.markup/reported_text;
wenzelm
parents: 38887
diff changeset
   152
(* reports *)
38887
1261481ef5e5 Command.State: add reported positions to markup tree, according main message position or Markup.binding/entity/report occurrences in body;
wenzelm
parents: 38236
diff changeset
   153
41504
f0f20a5b54df clarified notion Position.is_reported;
wenzelm
parents: 41484
diff changeset
   154
fun is_reported pos = is_some (offset_of pos) andalso is_some (get_id pos);
30669
6de7ef888aa3 added report_text -- status messages with text body;
wenzelm
parents: 29307
diff changeset
   155
41504
f0f20a5b54df clarified notion Position.is_reported;
wenzelm
parents: 41484
diff changeset
   156
fun reported_text pos m txt = if is_reported pos then Markup.markup (markup pos m) txt else "";
39507
839873937ddd tuned signature of (Context_)Position.report variants;
wenzelm
parents: 39440
diff changeset
   157
fun report_text pos markup txt = Output.report (reported_text pos markup txt);
839873937ddd tuned signature of (Context_)Position.report variants;
wenzelm
parents: 39440
diff changeset
   158
fun report pos markup = report_text pos markup "";
27764
e0ee3cc240fe advance: single argument (again);
wenzelm
parents: 27759
diff changeset
   159
42204
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 41504
diff changeset
   160
type reports = (T * Markup.T) list;
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 41504
diff changeset
   161
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 41504
diff changeset
   162
fun reports _ [] _ _ = ()
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 41504
diff changeset
   163
  | reports (r: reports Unsynchronized.ref) ps markup x =
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 41504
diff changeset
   164
      let val ms = markup x
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 41504
diff changeset
   165
      in Unsynchronized.change r (fold (fn p => fold (fn m => cons (p, m)) ms) ps) end;
b3277168c1e7 added Position.reports convenience;
wenzelm
parents: 41504
diff changeset
   166
25817
d8e0190917a5 type T: based on properties, added id field;
wenzelm
parents: 25792
diff changeset
   167
26003
7a8aee8353cf added column field;
wenzelm
parents: 25954
diff changeset
   168
(* str_of *)
7a8aee8353cf added column field;
wenzelm
parents: 25954
diff changeset
   169
7a8aee8353cf added column field;
wenzelm
parents: 25954
diff changeset
   170
fun str_of pos =
7a8aee8353cf added column field;
wenzelm
parents: 25954
diff changeset
   171
  let
7a8aee8353cf added column field;
wenzelm
parents: 25954
diff changeset
   172
    val props = properties_of pos;
7a8aee8353cf added column field;
wenzelm
parents: 25954
diff changeset
   173
    val s =
7a8aee8353cf added column field;
wenzelm
parents: 25954
diff changeset
   174
      (case (line_of pos, file_of pos) of
27795
f67f4c677d81 count offset as well;
wenzelm
parents: 27791
diff changeset
   175
        (SOME i, NONE) => "(line " ^ string_of_int i ^ ")"
f67f4c677d81 count offset as well;
wenzelm
parents: 27791
diff changeset
   176
      | (SOME i, SOME name) => "(line " ^ string_of_int i ^ " of " ^ quote name ^ ")"
26003
7a8aee8353cf added column field;
wenzelm
parents: 25954
diff changeset
   177
      | _ => "");
7a8aee8353cf added column field;
wenzelm
parents: 25954
diff changeset
   178
  in
7a8aee8353cf added column field;
wenzelm
parents: 25954
diff changeset
   179
    if null props then ""
7a8aee8353cf added column field;
wenzelm
parents: 25954
diff changeset
   180
    else (if s = "" then "" else " ") ^ Markup.markup (Markup.properties props Markup.position) s
7a8aee8353cf added column field;
wenzelm
parents: 25954
diff changeset
   181
  end;
25817
d8e0190917a5 type T: based on properties, added id field;
wenzelm
parents: 25792
diff changeset
   182
23627
f543538866a2 added property conversions;
wenzelm
parents: 22158
diff changeset
   183
27736
3703dbd0cdea added encode_range;
wenzelm
parents: 27661
diff changeset
   184
(* range *)
3703dbd0cdea added encode_range;
wenzelm
parents: 27661
diff changeset
   185
3703dbd0cdea added encode_range;
wenzelm
parents: 27661
diff changeset
   186
type range = T * T;
3703dbd0cdea added encode_range;
wenzelm
parents: 27661
diff changeset
   187
27796
a6da5f68e776 added distance_of (permissive version);
wenzelm
parents: 27795
diff changeset
   188
val no_range = (none, none);
a6da5f68e776 added distance_of (permissive version);
wenzelm
parents: 27795
diff changeset
   189
41484
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
   190
fun set_range (Pos ((i, j, k, _), props), Pos ((_, _, k', _), _)) = Pos ((i, j, k, k'), props);
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
   191
fun reset_range (Pos ((i, j, k, _), props)) = Pos ((i, j, k, 0), props);
27777
7a63d1b50b88 only increment column if valid;
wenzelm
parents: 27764
diff changeset
   192
41484
51310e1ccd6f more direct treatment of Position.end_offset;
wenzelm
parents: 41483
diff changeset
   193
fun range pos pos' = (set_range (pos, pos'), pos');
27741
d2523b72ed44 added report;
wenzelm
parents: 27736
diff changeset
   194
27764
e0ee3cc240fe advance: single argument (again);
wenzelm
parents: 27759
diff changeset
   195
e0ee3cc240fe advance: single argument (again);
wenzelm
parents: 27759
diff changeset
   196
(* thread data *)
e0ee3cc240fe advance: single argument (again);
wenzelm
parents: 27759
diff changeset
   197
e0ee3cc240fe advance: single argument (again);
wenzelm
parents: 27759
diff changeset
   198
local val tag = Universal.tag () : T Universal.tag in
27741
d2523b72ed44 added report;
wenzelm
parents: 27736
diff changeset
   199
28122
3d099ce624e7 Thread.getLocal/setLocal;
wenzelm
parents: 28017
diff changeset
   200
fun thread_data () = the_default none (Thread.getLocal tag);
27764
e0ee3cc240fe advance: single argument (again);
wenzelm
parents: 27759
diff changeset
   201
37043
f8e24980af05 more robust Position.setmp_thread_data, independently of Output.debugging (essentially reverts f9ec18f7c0f6, which was motivated by clean exception_trace, but without transaction positions the Isabelle_Process protocol breaks down);
wenzelm
parents: 33097
diff changeset
   202
fun setmp_thread_data pos = Library.setmp_thread_data tag (thread_data ()) pos;
27764
e0ee3cc240fe advance: single argument (again);
wenzelm
parents: 27759
diff changeset
   203
5010
9101b70b696d moved Thy/position.ML to General/position.ML;
wenzelm
parents:
diff changeset
   204
end;
27764
e0ee3cc240fe advance: single argument (again);
wenzelm
parents: 27759
diff changeset
   205
33097
9d501e11084a maintain position of formal entities via name space;
wenzelm
parents: 32573
diff changeset
   206
fun default pos =
9d501e11084a maintain position of formal entities via name space;
wenzelm
parents: 32573
diff changeset
   207
  if pos = none then thread_data ()
9d501e11084a maintain position of formal entities via name space;
wenzelm
parents: 32573
diff changeset
   208
  else pos;
9d501e11084a maintain position of formal entities via name space;
wenzelm
parents: 32573
diff changeset
   209
27764
e0ee3cc240fe advance: single argument (again);
wenzelm
parents: 27759
diff changeset
   210
end;