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