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