| author | Fabian Huch <huch@in.tum.de> | 
| Fri, 15 Mar 2024 17:57:03 +0100 | |
| changeset 79899 | c73a36081b1c | 
| parent 78811 | d3328c562307 | 
| child 80868 | 0ed02f473cf9 | 
| permissions | -rw-r--r-- | 
| 6118 | 1 | (* Title: Pure/General/position.ML | 
| 74165 | 2 | Author: Makarius | 
| 5010 | 3 | |
| 74165 | 4 | Source positions starting from 1; values <= 0 mean "absent". Count Isabelle | 
| 5 | symbols, not UTF8 bytes nor UTF16 characters. Position range specifies a | |
| 6 | right-open interval offset .. end_offset (exclusive). | |
| 5010 | 7 | *) | 
| 8 | ||
| 9 | signature POSITION = | |
| 10 | sig | |
| 41484 | 11 | eqtype T | 
| 71465 
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
 wenzelm parents: 
70498diff
changeset | 12 | val ord: T ord | 
| 78811 | 13 | val make0: int -> int -> int -> string -> string -> string -> T | 
| 62940 | 14 | val make: Thread_Position.T -> T | 
| 15 | val dest: T -> Thread_Position.T | |
| 23673 | 16 | val line_of: T -> int option | 
| 27795 | 17 | val offset_of: T -> int option | 
| 41484 | 18 | val end_offset_of: T -> int option | 
| 78021 | 19 | val label_of: T -> string option | 
| 23673 | 20 | val file_of: T -> string option | 
| 74166 | 21 | val id_of: T -> string option | 
| 74174 | 22 | val symbol: Symbol.symbol -> T -> T | 
| 23 | val symbol_explode: string -> T -> T | |
| 68177 | 24 | val distance_of: T * T -> int option | 
| 5010 | 25 | val none: T | 
| 27777 | 26 | val start: T | 
| 78021 | 27 | val label: string -> T -> T | 
| 44200 | 28 | val file_only: string -> T | 
| 27777 | 29 | val file: string -> T | 
| 56437 | 30 | val line_file_only: int -> string -> T | 
| 31 | val line_file: int -> string -> T | |
| 5010 | 32 | val line: int -> T | 
| 29307 | 33 | val id: string -> T | 
| 32573 | 34 | val id_only: string -> T | 
| 27426 | 35 | val put_id: string -> T -> T | 
| 68858 | 36 | val copy_id: T -> T -> T | 
| 50911 
ee7fe4230642
more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
 wenzelm parents: 
50254diff
changeset | 37 | val parse_id: T -> int option | 
| 77771 | 38 |   val shift_offsets: {remove_id: bool} -> int -> T -> T
 | 
| 68183 
6560324b1e4d
adjust position according to offset of command/exec id;
 wenzelm parents: 
68177diff
changeset | 39 | val adjust_offsets: (int -> int option) -> T -> T | 
| 77776 | 40 |   val of_props: {line: int, offset: int, end_offset: int, props: Properties.T} -> T
 | 
| 28017 | 41 | val of_properties: Properties.T -> T | 
| 42 | val properties_of: T -> Properties.T | |
| 42327 
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
 wenzelm parents: 
42204diff
changeset | 43 | val def_properties_of: T -> Properties.T | 
| 71910 | 44 | val entity_markup: string -> string * T -> Markup.T | 
| 74262 | 45 |   val make_entity_markup: {def: bool} -> serial -> string -> string * T -> Markup.T
 | 
| 39440 
4c2547af5909
simplified/clarified (Context_)Position.markup/reported_text;
 wenzelm parents: 
38887diff
changeset | 46 | val markup: T -> Markup.T -> Markup.T | 
| 41504 | 47 | val is_reported: T -> bool | 
| 56459 
38d0b2099743
no report for position singularity, notably for aux. file, especially empty one;
 wenzelm parents: 
56437diff
changeset | 48 | val is_reported_range: T -> bool | 
| 39507 
839873937ddd
tuned signature of (Context_)Position.report variants;
 wenzelm parents: 
39440diff
changeset | 49 | val reported_text: T -> Markup.T -> string -> string | 
| 
839873937ddd
tuned signature of (Context_)Position.report variants;
 wenzelm parents: 
39440diff
changeset | 50 | val report_text: T -> Markup.T -> string -> unit | 
| 
839873937ddd
tuned signature of (Context_)Position.report variants;
 wenzelm parents: 
39440diff
changeset | 51 | val report: T -> Markup.T -> unit | 
| 44736 | 52 | type report = T * Markup.T | 
| 48767 | 53 | type report_text = report * string | 
| 54 | val reports_text: report_text list -> unit | |
| 44736 | 55 | val reports: report list -> unit | 
| 55922 
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
 wenzelm parents: 
55624diff
changeset | 56 | val store_reports: report_text list Unsynchronized.ref -> | 
| 
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
 wenzelm parents: 
55624diff
changeset | 57 |     T list -> ('a -> Markup.T list) -> 'a -> unit
 | 
| 55959 
c3b458435f4f
more decisive commitment to get_free vs. the_const;
 wenzelm parents: 
55922diff
changeset | 58 | val append_reports: report_text list Unsynchronized.ref -> report list -> unit | 
| 71465 
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
 wenzelm parents: 
70498diff
changeset | 59 | val here_strs: T -> string * string | 
| 48992 | 60 | val here: T -> string | 
| 49691 | 61 | val here_list: T list -> string | 
| 27764 | 62 | type range = T * T | 
| 27796 | 63 | val no_range: range | 
| 62800 | 64 | val no_range_position: T -> T | 
| 62797 | 65 | val range_position: range -> T | 
| 66 | val range: T * T -> range | |
| 58978 
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
 wenzelm parents: 
58854diff
changeset | 67 | val range_of_properties: Properties.T -> range | 
| 
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
 wenzelm parents: 
58854diff
changeset | 68 | val properties_of_range: range -> Properties.T | 
| 25817 | 69 | val thread_data: unit -> T | 
| 70 |   val setmp_thread_data: T -> ('a -> 'b) -> 'a -> 'b
 | |
| 78023 | 71 |   val setmp_thread_data_label: string -> ('a -> 'b) -> 'a -> 'b
 | 
| 49528 
789b73fcca72
report proper binding positions only -- avoid swamping document model with unspecific information;
 wenzelm parents: 
48992diff
changeset | 72 | val default: T -> bool * T | 
| 5010 | 73 | end; | 
| 74 | ||
| 75 | structure Position: POSITION = | |
| 76 | struct | |
| 77 | ||
| 78 | (* datatype position *) | |
| 79 | ||
| 77776 | 80 | datatype T = Pos of Thread_Position.T; | 
| 71465 
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
 wenzelm parents: 
70498diff
changeset | 81 | |
| 78811 | 82 | fun make0 line offset end_offset label file id = | 
| 83 |   Pos {line = line, offset = offset, end_offset = end_offset,
 | |
| 84 |     props = {label = label, file = file, id = id}};
 | |
| 85 | ||
| 77776 | 86 | val make = Pos; | 
| 77769 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 87 | fun dest (Pos args) = args; | 
| 27777 | 88 | |
| 77769 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 89 | val ord = | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 90 | pointer_eq_ord | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 91 | (int_ord o apply2 (#line o dest) ||| | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 92 | int_ord o apply2 (#offset o dest) ||| | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 93 | int_ord o apply2 (#end_offset o dest) ||| | 
| 78021 | 94 | fast_string_ord o apply2 (#label o #props o dest) ||| | 
| 77776 | 95 | fast_string_ord o apply2 (#file o #props o dest) ||| | 
| 96 | fast_string_ord o apply2 (#id o #props o dest)); | |
| 27795 | 97 | |
| 27777 | 98 | |
| 27796 | 99 | (* fields *) | 
| 100 | ||
| 77769 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 101 | fun valid (i: int) = i > 0; | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 102 | fun maybe_valid i = if valid i then SOME i else NONE; | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 103 | |
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 104 | val invalid = not o valid; | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 105 | fun invalid_pos (Pos {line, offset, ...}) = invalid line andalso invalid offset;
 | 
| 27796 | 106 | |
| 77769 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 107 | val line_of = maybe_valid o #line o dest; | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 108 | val offset_of = maybe_valid o #offset o dest; | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 109 | val end_offset_of = maybe_valid o #end_offset o dest; | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 110 | |
| 78021 | 111 | fun label_of (Pos {props = {label, ...}, ...}) = if label = "" then NONE else SOME label;
 | 
| 77776 | 112 | fun file_of (Pos {props = {file, ...}, ...}) = if file = "" then NONE else SOME file;
 | 
| 113 | fun id_of (Pos {props = {id, ...}, ...}) = if id = "" then NONE else SOME id;
 | |
| 27796 | 114 | |
| 115 | ||
| 77769 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 116 | (* symbol positions *) | 
| 5010 | 117 | |
| 77769 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 118 | fun symbols [] pos = pos | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 119 |   | symbols ss (pos as Pos {line, offset, end_offset, props}) =
 | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 120 | let | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 121 | val line' = if valid line then fold (fn s => s = "\n" ? Integer.add 1) ss line else line; | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 122 | val offset' = | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 123 | if valid offset then fold (fn s => Symbol.not_eof s ? Integer.add 1) ss offset else offset; | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 124 | in | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 125 | if line = line' andalso offset = offset' then pos | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 126 |         else Pos {line = line', offset = offset', end_offset = end_offset, props = props}
 | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 127 | end; | 
| 27795 | 128 | |
| 77769 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 129 | val symbol = symbols o single; | 
| 27777 | 130 | |
| 77769 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 131 | fun symbol_explode str pos = | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 132 | if str = "" orelse invalid_pos pos then pos | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 133 | else fold symbol (Symbol.explode str) pos; | 
| 74171 | 134 | |
| 74176 | 135 | |
| 27796 | 136 | (* distance of adjacent positions *) | 
| 27777 | 137 | |
| 77769 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 138 | fun distance_of (Pos {offset, ...}, Pos {offset = offset', ...}) =
 | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 139 | if valid offset andalso valid offset' then SOME (offset' - offset) else NONE; | 
| 26882 | 140 | |
| 5010 | 141 | |
| 27777 | 142 | (* make position *) | 
| 143 | ||
| 78021 | 144 | type props = {label: string, file: string, id: string};
 | 
| 77776 | 145 | |
| 78021 | 146 | val no_props: props = {label = "", file = "", id = ""};
 | 
| 77776 | 147 | |
| 148 | fun file_props name : props = | |
| 78021 | 149 |   if name = "" then no_props else {label = "", file = name, id = ""};
 | 
| 77776 | 150 | |
| 151 | fun id_props id : props = | |
| 78021 | 152 |   if id = "" then no_props else {label = "", file = "", id = id};
 | 
| 27744 | 153 | |
| 29307 | 154 | |
| 77776 | 155 | val none = Pos {line = 0, offset = 0, end_offset = 0, props = no_props};
 | 
| 156 | val start = Pos {line = 1, offset = 1, end_offset = 0, props = no_props};
 | |
| 157 | ||
| 78021 | 158 | fun label label (Pos {line, offset, end_offset, props = {label = _, file, id}}) =
 | 
| 159 |   Pos {line = line, offset = offset, end_offset = end_offset,
 | |
| 160 |     props = {label = label, file = file, id = id}};
 | |
| 27796 | 161 | |
| 77776 | 162 | fun file_only name = Pos {line = 0, offset = 0, end_offset = 0, props = file_props name};
 | 
| 163 | fun file name = Pos {line = 1, offset = 1, end_offset = 0, props = file_props name};
 | |
| 27744 | 164 | |
| 77776 | 165 | fun line_file_only line name = Pos {line = line, offset = 0, end_offset = 0, props = file_props name};
 | 
| 166 | fun line_file line name = Pos {line = line, offset = 1, end_offset = 0, props = file_props name};
 | |
| 77769 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 167 | fun line line = line_file line ""; | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 168 | |
| 77776 | 169 | fun id id = Pos {line = 0, offset = 1, end_offset = 0, props = id_props id};
 | 
| 170 | fun id_only id = Pos {line = 0, offset = 0, end_offset = 0, props = id_props id};
 | |
| 67280 
dfc5a1503916
clarified default position for empty message pos;
 wenzelm parents: 
64556diff
changeset | 171 | |
| 78021 | 172 | fun put_id id' (pos as Pos {line, offset, end_offset, props = {label, file, id}}) =
 | 
| 77776 | 173 | if id = id' then pos | 
| 78021 | 174 |   else Pos {line = line, offset = offset, end_offset = end_offset,
 | 
| 175 |     props = {label = label, file = file, id = id'}};
 | |
| 22158 | 176 | |
| 74166 | 177 | fun copy_id pos = (case id_of pos of NONE => I | SOME id => put_id id); | 
| 27426 | 178 | |
| 74166 | 179 | fun parse_id pos = Option.map Value.parse_int (id_of pos); | 
| 50911 
ee7fe4230642
more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
 wenzelm parents: 
50254diff
changeset | 180 | |
| 74180 | 181 | |
| 182 | (* adjust offsets *) | |
| 183 | ||
| 77769 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 184 | fun shift_offsets {remove_id} shift (pos as Pos {line, offset, end_offset, props}) =
 | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 185 | if shift < 0 then raise Fail "Illegal offset shift" | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 186 | else if shift > 0 andalso valid line then raise Fail "Illegal line position" | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 187 | else | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 188 | let | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 189 | val offset' = if valid offset then offset + shift else offset; | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 190 | val end_offset' = if valid end_offset then end_offset + shift else end_offset; | 
| 77776 | 191 | val props' = if remove_id then file_props (#file props) else props; | 
| 77769 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 192 | in | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 193 | if offset = offset' andalso end_offset = end_offset' andalso props = props' then pos | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 194 |       else Pos {line = line, offset = offset', end_offset = end_offset', props = props'}
 | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 195 | end; | 
| 74180 | 196 | |
| 77769 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 197 | fun adjust_offsets adjust pos = | 
| 68858 | 198 | if is_none (file_of pos) then | 
| 199 | (case parse_id pos of | |
| 200 | SOME id => | |
| 201 | (case adjust id of | |
| 77769 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 202 |           SOME shift => shift_offsets {remove_id = true} shift pos
 | 
| 68858 | 203 | | NONE => pos) | 
| 204 | | NONE => pos) | |
| 205 | else pos; | |
| 68183 
6560324b1e4d
adjust position according to offset of command/exec id;
 wenzelm parents: 
68177diff
changeset | 206 | |
| 
6560324b1e4d
adjust position according to offset of command/exec id;
 wenzelm parents: 
68177diff
changeset | 207 | |
| 29307 | 208 | (* markup properties *) | 
| 209 | ||
| 77776 | 210 | fun of_props {line, offset, end_offset, props} =
 | 
| 211 |   Pos {line = line, offset = offset, end_offset = end_offset,
 | |
| 212 | props = | |
| 78021 | 213 |      {label = Properties.get_string props Markup.labelN,
 | 
| 214 | file = Properties.get_string props Markup.fileN, | |
| 77776 | 215 | id = Properties.get_string props Markup.idN}}; | 
| 216 | ||
| 25817 | 217 | fun of_properties props = | 
| 77776 | 218 |   of_props {
 | 
| 77772 | 219 | line = Properties.get_int props Markup.lineN, | 
| 220 | offset = Properties.get_int props Markup.offsetN, | |
| 221 | end_offset = Properties.get_int props Markup.end_offsetN, | |
| 58978 
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
 wenzelm parents: 
58854diff
changeset | 222 | props = props}; | 
| 26003 | 223 | |
| 78021 | 224 | fun properties_of (Pos {line, offset, end_offset, props = {label, file, id}}) =
 | 
| 77777 | 225 | Properties.make_int Markup.lineN line @ | 
| 226 | Properties.make_int Markup.offsetN offset @ | |
| 227 | Properties.make_int Markup.end_offsetN end_offset @ | |
| 78021 | 228 | Properties.make_string Markup.labelN label @ | 
| 77777 | 229 | Properties.make_string Markup.fileN file @ | 
| 230 | Properties.make_string Markup.idN id; | |
| 26003 | 231 | |
| 74182 | 232 | val def_properties_of = properties_of #> map (apfst Markup.def_name); | 
| 42327 
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
 wenzelm parents: 
42204diff
changeset | 233 | |
| 71910 | 234 | fun entity_markup kind (name, pos) = | 
| 235 | Markup.entity kind name |> Markup.properties (def_properties_of pos); | |
| 236 | ||
| 74262 | 237 | fun make_entity_markup {def} serial kind (name, pos) =
 | 
| 74183 | 238 | let | 
| 239 | val props = | |
| 240 | if def then (Markup.defN, Value.print_int serial) :: properties_of pos | |
| 241 | else (Markup.refN, Value.print_int serial) :: def_properties_of pos; | |
| 242 | in Markup.entity kind name |> Markup.properties props end; | |
| 45412 | 243 | |
| 39440 
4c2547af5909
simplified/clarified (Context_)Position.markup/reported_text;
 wenzelm parents: 
38887diff
changeset | 244 | val markup = Markup.properties o properties_of; | 
| 
4c2547af5909
simplified/clarified (Context_)Position.markup/reported_text;
 wenzelm parents: 
38887diff
changeset | 245 | |
| 
4c2547af5909
simplified/clarified (Context_)Position.markup/reported_text;
 wenzelm parents: 
38887diff
changeset | 246 | |
| 
4c2547af5909
simplified/clarified (Context_)Position.markup/reported_text;
 wenzelm parents: 
38887diff
changeset | 247 | (* 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: 
38236diff
changeset | 248 | |
| 74166 | 249 | fun is_reported pos = is_some (offset_of pos) andalso is_some (id_of pos); | 
| 56459 
38d0b2099743
no report for position singularity, notably for aux. file, especially empty one;
 wenzelm parents: 
56437diff
changeset | 250 | fun is_reported_range pos = is_reported pos andalso is_some (end_offset_of pos); | 
| 30669 
6de7ef888aa3
added report_text -- status messages with text body;
 wenzelm parents: 
29307diff
changeset | 251 | |
| 41504 | 252 | fun reported_text pos m txt = if is_reported pos then Markup.markup (markup pos m) txt else ""; | 
| 56333 
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
 wenzelm parents: 
55959diff
changeset | 253 | fun report_text pos markup txt = Output.report [reported_text pos markup txt]; | 
| 39507 
839873937ddd
tuned signature of (Context_)Position.report variants;
 wenzelm parents: 
39440diff
changeset | 254 | fun report pos markup = report_text pos markup ""; | 
| 27764 | 255 | |
| 44736 | 256 | type report = T * Markup.T; | 
| 48767 | 257 | type report_text = report * string; | 
| 44736 | 258 | |
| 48767 | 259 | val reports_text = | 
| 260 | map (fn ((pos, m), txt) => if is_reported pos then Markup.markup (markup pos m) txt else "") | |
| 56333 
38f1422ef473
support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
 wenzelm parents: 
55959diff
changeset | 261 | #> Output.report; | 
| 42204 | 262 | |
| 48767 | 263 | val reports = map (rpair "") #> reports_text; | 
| 264 | ||
| 44735 | 265 | fun store_reports _ [] _ _ = () | 
| 55922 
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
 wenzelm parents: 
55624diff
changeset | 266 | | store_reports (r: report_text list Unsynchronized.ref) ps markup x = | 
| 42204 | 267 | let val ms = markup x | 
| 55922 
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
 wenzelm parents: 
55624diff
changeset | 268 | in Unsynchronized.change r (fold (fn p => fold (fn m => cons ((p, m), "")) ms) ps) end; | 
| 42204 | 269 | |
| 55959 
c3b458435f4f
more decisive commitment to get_free vs. the_const;
 wenzelm parents: 
55922diff
changeset | 270 | fun append_reports (r: report_text list Unsynchronized.ref) reports = | 
| 
c3b458435f4f
more decisive commitment to get_free vs. the_const;
 wenzelm parents: 
55922diff
changeset | 271 | Unsynchronized.change r (append (map (rpair "") reports)); | 
| 
c3b458435f4f
more decisive commitment to get_free vs. the_const;
 wenzelm parents: 
55922diff
changeset | 272 | |
| 25817 | 273 | |
| 56532 
3da244bc02bd
tuned message, to accommodate extra brackets produced by Scala parsers;
 wenzelm parents: 
56459diff
changeset | 274 | (* here: user output *) | 
| 26003 | 275 | |
| 71465 
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
 wenzelm parents: 
70498diff
changeset | 276 | fun here_strs pos = | 
| 
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
 wenzelm parents: 
70498diff
changeset | 277 | (case (line_of pos, file_of pos) of | 
| 
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
 wenzelm parents: 
70498diff
changeset | 278 |     (SOME i, NONE) => (" ", "(line " ^ Value.print_int i ^ ")")
 | 
| 
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
 wenzelm parents: 
70498diff
changeset | 279 |   | (SOME i, SOME name) => (" ", "(line " ^ Value.print_int i ^ " of " ^ quote name ^ ")")
 | 
| 
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
 wenzelm parents: 
70498diff
changeset | 280 |   | (NONE, SOME name) => (" ", "(file " ^ quote name ^ ")")
 | 
| 
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
 wenzelm parents: 
70498diff
changeset | 281 |   | _ => if is_reported pos then ("", "\092<^here>") else ("", ""));
 | 
| 
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
 wenzelm parents: 
70498diff
changeset | 282 | |
| 48992 | 283 | fun here pos = | 
| 26003 | 284 | let | 
| 285 | val props = properties_of pos; | |
| 71465 
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
 wenzelm parents: 
70498diff
changeset | 286 | val (s1, s2) = here_strs pos; | 
| 26003 | 287 | in | 
| 69348 | 288 | if s2 = "" then "" | 
| 55624 | 289 | else s1 ^ Markup.markup (Markup.properties props Markup.position) s2 | 
| 26003 | 290 | end; | 
| 25817 | 291 | |
| 70498 | 292 | val here_list = map here #> distinct (op =) #> implode; | 
| 49691 | 293 | |
| 23627 | 294 | |
| 27736 | 295 | (* range *) | 
| 296 | ||
| 297 | type range = T * T; | |
| 298 | ||
| 27796 | 299 | val no_range = (none, none); | 
| 300 | ||
| 77769 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 301 | fun no_range_position (Pos {line, offset, end_offset = _, props}) =
 | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 302 |   Pos {line = line, offset = offset, end_offset = 0, props = props};
 | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 303 | |
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 304 | fun range_position (Pos {line, offset, end_offset = _, props}, Pos {offset = offset', ...}) =
 | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 305 |   Pos {line = line, offset = offset, end_offset = offset', props = props};
 | 
| 
17391f298cf5
misc tuning and clarification: more tight representation;
 wenzelm parents: 
74262diff
changeset | 306 | |
| 62800 | 307 | fun range (pos, pos') = (range_position (pos, pos'), no_range_position pos'); | 
| 27777 | 308 | |
| 58978 
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
 wenzelm parents: 
58854diff
changeset | 309 | fun range_of_properties props = | 
| 
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
 wenzelm parents: 
58854diff
changeset | 310 | let | 
| 
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
 wenzelm parents: 
58854diff
changeset | 311 | val pos = of_properties props; | 
| 
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
 wenzelm parents: 
58854diff
changeset | 312 | val pos' = | 
| 77776 | 313 |       of_props {line = Properties.get_int props Markup.end_lineN,
 | 
| 77772 | 314 | offset = Properties.get_int props Markup.end_offsetN, | 
| 58978 
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
 wenzelm parents: 
58854diff
changeset | 315 | end_offset = 0, | 
| 
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
 wenzelm parents: 
58854diff
changeset | 316 | props = props}; | 
| 
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
 wenzelm parents: 
58854diff
changeset | 317 | in (pos, pos') end; | 
| 
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
 wenzelm parents: 
58854diff
changeset | 318 | |
| 
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
 wenzelm parents: 
58854diff
changeset | 319 | fun properties_of_range (pos, pos') = | 
| 77777 | 320 | properties_of pos @ Properties.make_int Markup.end_lineN (the_default 0 (line_of pos')); | 
| 58978 
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
 wenzelm parents: 
58854diff
changeset | 321 | |
| 27764 | 322 | |
| 323 | (* thread data *) | |
| 324 | ||
| 77776 | 325 | val thread_data = Pos o Thread_Position.get; | 
| 62940 | 326 | fun setmp_thread_data pos = Thread_Position.setmp (dest pos); | 
| 27764 | 327 | |
| 78023 | 328 | fun setmp_thread_data_label a f x = | 
| 329 | if a = "" then f x | |
| 330 | else setmp_thread_data (label a (thread_data ())) f x; | |
| 331 | ||
| 33097 
9d501e11084a
maintain position of formal entities via name space;
 wenzelm parents: 
32573diff
changeset | 332 | fun default pos = | 
| 49528 
789b73fcca72
report proper binding positions only -- avoid swamping document model with unspecific information;
 wenzelm parents: 
48992diff
changeset | 333 | if pos = none then (false, thread_data ()) | 
| 
789b73fcca72
report proper binding positions only -- avoid swamping document model with unspecific information;
 wenzelm parents: 
48992diff
changeset | 334 | else (true, pos); | 
| 33097 
9d501e11084a
maintain position of formal entities via name space;
 wenzelm parents: 
32573diff
changeset | 335 | |
| 27764 | 336 | end; |