author | wenzelm |
Wed, 11 Nov 2020 21:04:22 +0100 | |
changeset 72575 | c7ab83a0c564 |
parent 71910 | f8b0271cc744 |
child 72706 | 52d0b5fcb19d |
permissions | -rw-r--r-- |
6118 | 1 |
(* Title: Pure/General/position.ML |
5010 | 2 |
Author: Markus Wenzel, TU Muenchen |
3 |
||
29307 | 4 |
Source positions: counting Isabelle symbols, starting from 1. |
5010 | 5 |
*) |
6 |
||
7 |
signature POSITION = |
|
8 |
sig |
|
41484 | 9 |
eqtype T |
71465
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
wenzelm
parents:
70498
diff
changeset
|
10 |
val ord: T ord |
62940 | 11 |
val make: Thread_Position.T -> T |
12 |
val dest: T -> Thread_Position.T |
|
23673 | 13 |
val line_of: T -> int option |
27795 | 14 |
val offset_of: T -> int option |
41484 | 15 |
val end_offset_of: T -> int option |
23673 | 16 |
val file_of: T -> string option |
27796 | 17 |
val advance: Symbol.symbol -> T -> T |
68183
6560324b1e4d
adjust position according to offset of command/exec id;
wenzelm
parents:
68177
diff
changeset
|
18 |
val advance_offsets: int -> T -> T |
68177 | 19 |
val distance_of: T * T -> int option |
5010 | 20 |
val none: T |
27777 | 21 |
val start: T |
31435 | 22 |
val file_name: string -> Properties.T |
44200 | 23 |
val file_only: string -> T |
27777 | 24 |
val file: string -> T |
56437 | 25 |
val line_file_only: int -> string -> T |
26 |
val line_file: int -> string -> T |
|
5010 | 27 |
val line: int -> T |
67280
dfc5a1503916
clarified default position for empty message pos;
wenzelm
parents:
64556
diff
changeset
|
28 |
val get_props: T -> Properties.T |
29307 | 29 |
val id: string -> T |
32573 | 30 |
val id_only: string -> T |
27426 | 31 |
val get_id: T -> string option |
32 |
val put_id: string -> T -> T |
|
68858 | 33 |
val copy_id: T -> T -> T |
68829 | 34 |
val id_properties_of: T -> Properties.T |
50911
ee7fe4230642
more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
50254
diff
changeset
|
35 |
val parse_id: T -> int option |
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 |
28017 | 37 |
val of_properties: Properties.T -> T |
38 |
val properties_of: T -> Properties.T |
|
68172 | 39 |
val offset_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 |
45412 | 42 |
val entity_properties_of: bool -> serial -> T -> Properties.T |
28017 | 43 |
val default_properties: T -> Properties.T -> Properties.T |
39440
4c2547af5909
simplified/clarified (Context_)Position.markup/reported_text;
wenzelm
parents:
38887
diff
changeset
|
44 |
val markup: T -> Markup.T -> Markup.T |
41504 | 45 |
val is_reported: T -> bool |
56459
38d0b2099743
no report for position singularity, notably for aux. file, especially empty one;
wenzelm
parents:
56437
diff
changeset
|
46 |
val is_reported_range: T -> bool |
39507
839873937ddd
tuned signature of (Context_)Position.report variants;
wenzelm
parents:
39440
diff
changeset
|
47 |
val reported_text: T -> Markup.T -> string -> string |
839873937ddd
tuned signature of (Context_)Position.report variants;
wenzelm
parents:
39440
diff
changeset
|
48 |
val report_text: T -> Markup.T -> string -> unit |
839873937ddd
tuned signature of (Context_)Position.report variants;
wenzelm
parents:
39440
diff
changeset
|
49 |
val report: T -> Markup.T -> unit |
44736 | 50 |
type report = T * Markup.T |
48767 | 51 |
type report_text = report * string |
52 |
val reports_text: report_text list -> unit |
|
44736 | 53 |
val reports: report list -> unit |
55922
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55624
diff
changeset
|
54 |
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
|
55 |
T list -> ('a -> Markup.T list) -> 'a -> unit |
55959
c3b458435f4f
more decisive commitment to get_free vs. the_const;
wenzelm
parents:
55922
diff
changeset
|
56 |
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
|
57 |
val here_strs: T -> string * string |
48992 | 58 |
val here: T -> string |
49691 | 59 |
val here_list: T list -> string |
27764 | 60 |
type range = T * T |
27796 | 61 |
val no_range: range |
62800 | 62 |
val no_range_position: T -> T |
62797 | 63 |
val range_position: range -> T |
64 |
val range: T * T -> range |
|
58978
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58854
diff
changeset
|
65 |
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
|
66 |
val properties_of_range: range -> Properties.T |
25817 | 67 |
val thread_data: unit -> T |
68 |
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
|
69 |
val default: T -> bool * T |
5010 | 70 |
end; |
71 |
||
72 |
structure Position: POSITION = |
|
73 |
struct |
|
74 |
||
75 |
(* datatype position *) |
|
76 |
||
43710
7270ae921cf2
discontinued odd Position.column -- left-over from attempts at PGIP implementation;
wenzelm
parents:
42818
diff
changeset
|
77 |
datatype T = Pos of (int * int * int) * Properties.T; |
41484 | 78 |
|
71465
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
wenzelm
parents:
70498
diff
changeset
|
79 |
fun ord (pos1 as Pos ((i, j, k), props), pos2 as Pos ((i', j', k'), props')) = |
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
wenzelm
parents:
70498
diff
changeset
|
80 |
if pointer_eq (pos1, pos2) then EQUAL |
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
wenzelm
parents:
70498
diff
changeset
|
81 |
else |
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
wenzelm
parents:
70498
diff
changeset
|
82 |
(case int_ord (i, i') of |
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
wenzelm
parents:
70498
diff
changeset
|
83 |
EQUAL => |
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
wenzelm
parents:
70498
diff
changeset
|
84 |
(case int_ord (j, j') of |
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
wenzelm
parents:
70498
diff
changeset
|
85 |
EQUAL => |
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
wenzelm
parents:
70498
diff
changeset
|
86 |
(case int_ord (k, k') of |
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
wenzelm
parents:
70498
diff
changeset
|
87 |
EQUAL => Properties.ord (props, props') |
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
wenzelm
parents:
70498
diff
changeset
|
88 |
| ord => ord) |
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
wenzelm
parents:
70498
diff
changeset
|
89 |
| ord => ord) |
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
wenzelm
parents:
70498
diff
changeset
|
90 |
| ord => ord); |
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
wenzelm
parents:
70498
diff
changeset
|
91 |
|
41484 | 92 |
fun norm_props (props: Properties.T) = |
45666 | 93 |
maps (fn a => the_list (find_first (fn (b, _) => a = b) props)) |
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49691
diff
changeset
|
94 |
Markup.position_properties'; |
41484 | 95 |
|
43710
7270ae921cf2
discontinued odd Position.column -- left-over from attempts at PGIP implementation;
wenzelm
parents:
42818
diff
changeset
|
96 |
fun make {line = i, offset = j, end_offset = k, props} = Pos ((i, j, k), norm_props props); |
7270ae921cf2
discontinued odd Position.column -- left-over from attempts at PGIP implementation;
wenzelm
parents:
42818
diff
changeset
|
97 |
fun dest (Pos ((i, j, k), props)) = {line = i, offset = j, end_offset = k, props = props}; |
27777 | 98 |
|
27795 | 99 |
fun valid (i: int) = i > 0; |
100 |
fun if_valid i i' = if valid i then i' else i; |
|
101 |
||
27777 | 102 |
|
27796 | 103 |
(* fields *) |
104 |
||
43710
7270ae921cf2
discontinued odd Position.column -- left-over from attempts at PGIP implementation;
wenzelm
parents:
42818
diff
changeset
|
105 |
fun line_of (Pos ((i, _, _), _)) = if valid i then SOME i else NONE; |
7270ae921cf2
discontinued odd Position.column -- left-over from attempts at PGIP implementation;
wenzelm
parents:
42818
diff
changeset
|
106 |
fun offset_of (Pos ((_, j, _), _)) = if valid j then SOME j else NONE; |
7270ae921cf2
discontinued odd Position.column -- left-over from attempts at PGIP implementation;
wenzelm
parents:
42818
diff
changeset
|
107 |
fun end_offset_of (Pos ((_, _, k), _)) = if valid k then SOME k else NONE; |
27796 | 108 |
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49691
diff
changeset
|
109 |
fun file_of (Pos (_, props)) = Properties.get props Markup.fileN; |
27796 | 110 |
|
111 |
||
27777 | 112 |
(* advance *) |
26003 | 113 |
|
43710
7270ae921cf2
discontinued odd Position.column -- left-over from attempts at PGIP implementation;
wenzelm
parents:
42818
diff
changeset
|
114 |
fun advance_count "\n" (i: int, j: int, k: int) = |
7270ae921cf2
discontinued odd Position.column -- left-over from attempts at PGIP implementation;
wenzelm
parents:
42818
diff
changeset
|
115 |
(if_valid i (i + 1), if_valid j (j + 1), k) |
7270ae921cf2
discontinued odd Position.column -- left-over from attempts at PGIP implementation;
wenzelm
parents:
42818
diff
changeset
|
116 |
| advance_count s (i, j, k) = |
58854 | 117 |
if Symbol.not_eof s then (i, if_valid j (j + 1), k) |
43710
7270ae921cf2
discontinued odd Position.column -- left-over from attempts at PGIP implementation;
wenzelm
parents:
42818
diff
changeset
|
118 |
else (i, j, k); |
5010 | 119 |
|
43710
7270ae921cf2
discontinued odd Position.column -- left-over from attempts at PGIP implementation;
wenzelm
parents:
42818
diff
changeset
|
120 |
fun invalid_count (i, j, _: int) = |
7270ae921cf2
discontinued odd Position.column -- left-over from attempts at PGIP implementation;
wenzelm
parents:
42818
diff
changeset
|
121 |
not (valid i orelse valid j); |
27795 | 122 |
|
123 |
fun advance sym (pos as (Pos (count, props))) = |
|
124 |
if invalid_count count then pos else Pos (advance_count sym count, props); |
|
27777 | 125 |
|
68183
6560324b1e4d
adjust position according to offset of command/exec id;
wenzelm
parents:
68177
diff
changeset
|
126 |
fun advance_offsets offset (pos as (Pos (count as (i, j, k), props))) = |
6560324b1e4d
adjust position according to offset of command/exec id;
wenzelm
parents:
68177
diff
changeset
|
127 |
if offset = 0 orelse invalid_count count then pos |
6560324b1e4d
adjust position according to offset of command/exec id;
wenzelm
parents:
68177
diff
changeset
|
128 |
else if offset < 0 then raise Fail "Illegal offset" |
59085
08a6901eb035
clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents:
58978
diff
changeset
|
129 |
else if valid i then raise Fail "Illegal line position" |
68183
6560324b1e4d
adjust position according to offset of command/exec id;
wenzelm
parents:
68177
diff
changeset
|
130 |
else Pos ((i, if_valid j (j + offset), if_valid k (k + offset)), props); |
59085
08a6901eb035
clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents:
58978
diff
changeset
|
131 |
|
27777 | 132 |
|
27796 | 133 |
(* distance of adjacent positions *) |
27777 | 134 |
|
68177 | 135 |
fun distance_of (Pos ((_, j, _), _), Pos ((_, j', _), _)) = |
136 |
if valid j andalso valid j' then SOME (j' - j) else NONE; |
|
26882 | 137 |
|
5010 | 138 |
|
27777 | 139 |
(* make position *) |
140 |
||
43710
7270ae921cf2
discontinued odd Position.column -- left-over from attempts at PGIP implementation;
wenzelm
parents:
42818
diff
changeset
|
141 |
val none = Pos ((0, 0, 0), []); |
7270ae921cf2
discontinued odd Position.column -- left-over from attempts at PGIP implementation;
wenzelm
parents:
42818
diff
changeset
|
142 |
val start = Pos ((1, 1, 0), []); |
27744 | 143 |
|
29307 | 144 |
|
27796 | 145 |
fun file_name "" = [] |
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49691
diff
changeset
|
146 |
| file_name name = [(Markup.fileN, name)]; |
27796 | 147 |
|
44200 | 148 |
fun file_only name = Pos ((0, 0, 0), file_name name); |
43710
7270ae921cf2
discontinued odd Position.column -- left-over from attempts at PGIP implementation;
wenzelm
parents:
42818
diff
changeset
|
149 |
fun file name = Pos ((1, 1, 0), file_name name); |
27744 | 150 |
|
56437 | 151 |
fun line_file_only i name = Pos ((i, 0, 0), file_name name); |
43710
7270ae921cf2
discontinued odd Position.column -- left-over from attempts at PGIP implementation;
wenzelm
parents:
42818
diff
changeset
|
152 |
fun line_file i name = Pos ((i, 1, 0), file_name name); |
27795 | 153 |
fun line i = line_file i ""; |
5010 | 154 |
|
67280
dfc5a1503916
clarified default position for empty message pos;
wenzelm
parents:
64556
diff
changeset
|
155 |
fun get_props (Pos (_, props)) = props; |
dfc5a1503916
clarified default position for empty message pos;
wenzelm
parents:
64556
diff
changeset
|
156 |
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49691
diff
changeset
|
157 |
fun id id = Pos ((0, 1, 0), [(Markup.idN, id)]); |
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49691
diff
changeset
|
158 |
fun id_only id = Pos ((0, 0, 0), [(Markup.idN, id)]); |
22158 | 159 |
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49691
diff
changeset
|
160 |
fun get_id (Pos (_, props)) = Properties.get props Markup.idN; |
62750 | 161 |
fun put_id id (Pos (count, props)) = Pos (count, norm_props (Properties.put (Markup.idN, id) props)); |
68858 | 162 |
fun copy_id pos = (case get_id pos of NONE => I | SOME id => put_id id); |
27426 | 163 |
|
63806 | 164 |
fun parse_id pos = Option.map Value.parse_int (get_id pos); |
50911
ee7fe4230642
more explicit treatment of (optional) exception properties, notably for "serial" -- avoid conflict with startPosition = offset;
wenzelm
parents:
50254
diff
changeset
|
165 |
|
68829 | 166 |
fun id_properties_of pos = |
167 |
(case get_id pos of |
|
168 |
SOME id => [(Markup.idN, id)] |
|
169 |
| NONE => []); |
|
29307 | 170 |
|
68183
6560324b1e4d
adjust position according to offset of command/exec id;
wenzelm
parents:
68177
diff
changeset
|
171 |
fun adjust_offsets adjust (pos as Pos (_, props)) = |
68858 | 172 |
if is_none (file_of pos) then |
173 |
(case parse_id pos of |
|
174 |
SOME id => |
|
175 |
(case adjust id of |
|
176 |
SOME offset => |
|
177 |
let val Pos (count, _) = advance_offsets offset pos |
|
178 |
in Pos (count, Properties.remove Markup.idN props) end |
|
179 |
| NONE => pos) |
|
180 |
| NONE => pos) |
|
181 |
else pos; |
|
68183
6560324b1e4d
adjust position according to offset of command/exec id;
wenzelm
parents:
68177
diff
changeset
|
182 |
|
6560324b1e4d
adjust position according to offset of command/exec id;
wenzelm
parents:
68177
diff
changeset
|
183 |
|
29307 | 184 |
(* markup properties *) |
185 |
||
58978
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58854
diff
changeset
|
186 |
fun get props name = |
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58854
diff
changeset
|
187 |
(case Properties.get props name of |
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58854
diff
changeset
|
188 |
NONE => 0 |
63806 | 189 |
| SOME s => Value.parse_int s); |
58978
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58854
diff
changeset
|
190 |
|
25817 | 191 |
fun of_properties props = |
58978
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58854
diff
changeset
|
192 |
make {line = get props Markup.lineN, |
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58854
diff
changeset
|
193 |
offset = get props Markup.offsetN, |
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58854
diff
changeset
|
194 |
end_offset = get props Markup.end_offsetN, |
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58854
diff
changeset
|
195 |
props = props}; |
26003 | 196 |
|
63806 | 197 |
fun value k i = if valid i then [(k, Value.print_int i)] else []; |
41484 | 198 |
|
43710
7270ae921cf2
discontinued odd Position.column -- left-over from attempts at PGIP implementation;
wenzelm
parents:
42818
diff
changeset
|
199 |
fun properties_of (Pos ((i, j, k), props)) = |
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49691
diff
changeset
|
200 |
value Markup.lineN i @ value Markup.offsetN j @ value Markup.end_offsetN k @ props; |
26003 | 201 |
|
68172 | 202 |
fun offset_properties_of (Pos ((_, j, k), _)) = |
203 |
value Markup.offsetN j @ value Markup.end_offsetN k; |
|
204 |
||
54038 | 205 |
val def_properties_of = properties_of #> map (fn (x, y) => ("def_" ^ x, y)); |
42327
7c7cc7590eb3
Name_Space.entry_markup: keep def position as separate properties;
wenzelm
parents:
42204
diff
changeset
|
206 |
|
71910 | 207 |
fun entity_markup kind (name, pos) = |
208 |
Markup.entity kind name |> Markup.properties (def_properties_of pos); |
|
209 |
||
57899
5867d1306712
clarified signature: entity serial number is not position id;
wenzelm
parents:
56532
diff
changeset
|
210 |
fun entity_properties_of def serial pos = |
63806 | 211 |
if def then (Markup.defN, Value.print_int serial) :: properties_of pos |
212 |
else (Markup.refN, Value.print_int serial) :: def_properties_of pos; |
|
45412 | 213 |
|
26052 | 214 |
fun default_properties default props = |
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
49691
diff
changeset
|
215 |
if exists (member (op =) Markup.position_properties o #1) props then props |
26052 | 216 |
else properties_of default @ props; |
217 |
||
39440
4c2547af5909
simplified/clarified (Context_)Position.markup/reported_text;
wenzelm
parents:
38887
diff
changeset
|
218 |
val markup = Markup.properties o properties_of; |
4c2547af5909
simplified/clarified (Context_)Position.markup/reported_text;
wenzelm
parents:
38887
diff
changeset
|
219 |
|
4c2547af5909
simplified/clarified (Context_)Position.markup/reported_text;
wenzelm
parents:
38887
diff
changeset
|
220 |
|
4c2547af5909
simplified/clarified (Context_)Position.markup/reported_text;
wenzelm
parents:
38887
diff
changeset
|
221 |
(* 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
|
222 |
|
41504 | 223 |
fun is_reported pos = is_some (offset_of pos) andalso is_some (get_id pos); |
56459
38d0b2099743
no report for position singularity, notably for aux. file, especially empty one;
wenzelm
parents:
56437
diff
changeset
|
224 |
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
|
225 |
|
41504 | 226 |
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
|
227 |
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
|
228 |
fun report pos markup = report_text pos markup ""; |
27764 | 229 |
|
44736 | 230 |
type report = T * Markup.T; |
48767 | 231 |
type report_text = report * string; |
44736 | 232 |
|
48767 | 233 |
val reports_text = |
234 |
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
|
235 |
#> Output.report; |
42204 | 236 |
|
48767 | 237 |
val reports = map (rpair "") #> reports_text; |
238 |
||
44735 | 239 |
fun store_reports _ [] _ _ = () |
55922
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55624
diff
changeset
|
240 |
| store_reports (r: report_text list Unsynchronized.ref) ps markup x = |
42204 | 241 |
let val ms = markup x |
55922
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55624
diff
changeset
|
242 |
in Unsynchronized.change r (fold (fn p => fold (fn m => cons ((p, m), "")) ms) ps) end; |
42204 | 243 |
|
55959
c3b458435f4f
more decisive commitment to get_free vs. the_const;
wenzelm
parents:
55922
diff
changeset
|
244 |
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
|
245 |
Unsynchronized.change r (append (map (rpair "") reports)); |
c3b458435f4f
more decisive commitment to get_free vs. the_const;
wenzelm
parents:
55922
diff
changeset
|
246 |
|
25817 | 247 |
|
56532
3da244bc02bd
tuned message, to accommodate extra brackets produced by Scala parsers;
wenzelm
parents:
56459
diff
changeset
|
248 |
(* here: user output *) |
26003 | 249 |
|
71465
910a081cca74
more position information for oracles (e.g. "skip_proof" for 'sorry'), requires Proofterm.proofs := 1;
wenzelm
parents:
70498
diff
changeset
|
250 |
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
|
251 |
(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
|
252 |
(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
|
253 |
| (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
|
254 |
| (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
|
255 |
| _ => 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
|
256 |
|
48992 | 257 |
fun here pos = |
26003 | 258 |
let |
259 |
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
|
260 |
val (s1, s2) = here_strs pos; |
26003 | 261 |
in |
69348 | 262 |
if s2 = "" then "" |
55624 | 263 |
else s1 ^ Markup.markup (Markup.properties props Markup.position) s2 |
26003 | 264 |
end; |
25817 | 265 |
|
70498 | 266 |
val here_list = map here #> distinct (op =) #> implode; |
49691 | 267 |
|
23627 | 268 |
|
27736 | 269 |
(* range *) |
270 |
||
271 |
type range = T * T; |
|
272 |
||
27796 | 273 |
val no_range = (none, none); |
274 |
||
62800 | 275 |
fun no_range_position (Pos ((i, j, _), props)) = Pos ((i, j, 0), props); |
62797 | 276 |
fun range_position (Pos ((i, j, _), props), Pos ((_, j', _), _)) = Pos ((i, j, j'), props); |
62800 | 277 |
fun range (pos, pos') = (range_position (pos, pos'), no_range_position pos'); |
27777 | 278 |
|
58978
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58854
diff
changeset
|
279 |
fun range_of_properties props = |
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58854
diff
changeset
|
280 |
let |
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58854
diff
changeset
|
281 |
val pos = of_properties props; |
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58854
diff
changeset
|
282 |
val pos' = |
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58854
diff
changeset
|
283 |
make {line = get props Markup.end_lineN, |
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58854
diff
changeset
|
284 |
offset = get props Markup.end_offsetN, |
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58854
diff
changeset
|
285 |
end_offset = 0, |
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58854
diff
changeset
|
286 |
props = props}; |
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58854
diff
changeset
|
287 |
in (pos, pos') end; |
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58854
diff
changeset
|
288 |
|
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58854
diff
changeset
|
289 |
fun properties_of_range (pos, pos') = |
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58854
diff
changeset
|
290 |
properties_of pos @ value Markup.end_lineN (the_default 0 (line_of pos')); |
e42da880c61e
more position information, e.g. relevant for errors in generated ML source;
wenzelm
parents:
58854
diff
changeset
|
291 |
|
27764 | 292 |
|
293 |
(* thread data *) |
|
294 |
||
62940 | 295 |
val thread_data = make o Thread_Position.get; |
296 |
fun setmp_thread_data pos = Thread_Position.setmp (dest pos); |
|
27764 | 297 |
|
33097
9d501e11084a
maintain position of formal entities via name space;
wenzelm
parents:
32573
diff
changeset
|
298 |
fun default pos = |
49528
789b73fcca72
report proper binding positions only -- avoid swamping document model with unspecific information;
wenzelm
parents:
48992
diff
changeset
|
299 |
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
|
300 |
else (true, pos); |
33097
9d501e11084a
maintain position of formal entities via name space;
wenzelm
parents:
32573
diff
changeset
|
301 |
|
27764 | 302 |
end; |