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