| author | wenzelm |
| Wed, 29 Oct 2025 17:42:25 +0100 | |
| changeset 83430 | 53c253ee5399 |
| parent 83428 | cb4f950f4fbd |
| permissions | -rw-r--r-- |
|
45709
87017fcbad83
clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
wenzelm
parents:
45672
diff
changeset
|
1 |
/* Title: Pure/PIDE/protocol.scala |
|
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
|
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
3 |
|
|
45709
87017fcbad83
clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
wenzelm
parents:
45672
diff
changeset
|
4 |
Protocol message formats for interactive proof documents. |
|
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
5 |
*/ |
|
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
6 |
|
|
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
7 |
package isabelle |
|
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
8 |
|
|
83428
cb4f950f4fbd
more accurate senback_snippets: no duplicates, no recursion into "sendback" or wrapped elements;
wenzelm
parents:
83427
diff
changeset
|
9 |
import scala.collection.mutable |
|
cb4f950f4fbd
more accurate senback_snippets: no duplicates, no recursion into "sendback" or wrapped elements;
wenzelm
parents:
83427
diff
changeset
|
10 |
import scala.annotation.tailrec |
|
cb4f950f4fbd
more accurate senback_snippets: no duplicates, no recursion into "sendback" or wrapped elements;
wenzelm
parents:
83427
diff
changeset
|
11 |
|
|
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
12 |
|
| 75393 | 13 |
object Protocol {
|
|
71630
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71624
diff
changeset
|
14 |
/* markers for inlined messages */ |
|
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71624
diff
changeset
|
15 |
|
|
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71624
diff
changeset
|
16 |
val Loading_Theory_Marker = Protocol_Message.Marker("loading_theory")
|
|
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71624
diff
changeset
|
17 |
val Meta_Info_Marker = Protocol_Message.Marker("meta_info")
|
|
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71624
diff
changeset
|
18 |
val Command_Timing_Marker = Protocol_Message.Marker("command_timing")
|
|
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71624
diff
changeset
|
19 |
val Theory_Timing_Marker = Protocol_Message.Marker("theory_timing")
|
| 72012 | 20 |
val Session_Timing_Marker = Protocol_Message.Marker("session_timing")
|
|
71630
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71624
diff
changeset
|
21 |
val ML_Statistics_Marker = Protocol_Message.Marker("ML_statistics")
|
|
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71624
diff
changeset
|
22 |
val Task_Statistics_Marker = Protocol_Message.Marker("task_statistics")
|
|
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71624
diff
changeset
|
23 |
val Error_Message_Marker = Protocol_Message.Marker("error_message")
|
|
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71624
diff
changeset
|
24 |
|
|
50425e4c3910
clarified modules: global quasi-scope for markers;
wenzelm
parents:
71624
diff
changeset
|
25 |
|
|
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72637
diff
changeset
|
26 |
/* batch build */ |
|
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72637
diff
changeset
|
27 |
|
| 75393 | 28 |
object Loading_Theory {
|
| 83226 | 29 |
def unapply(props: Properties.T): Option[(Document.Node.Name, Document_ID.Exec, Int)] = |
| 83225 | 30 |
for {
|
31 |
theory <- Markup.Name.unapply(props) |
|
| 83226 | 32 |
commands <- Markup.Commands.unapply(props) |
| 83225 | 33 |
file <- Position.File.unapply(props) if Path.is_wellformed(file) |
34 |
id <- Position.Id.unapply(props) |
|
| 83226 | 35 |
} yield (Document.Node.Name(file, theory = theory), id, commands) |
|
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72637
diff
changeset
|
36 |
} |
|
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72637
diff
changeset
|
37 |
|
|
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72637
diff
changeset
|
38 |
|
|
38567
b670faa807c9
concentrate protocol message formats in Isar_Document;
wenzelm
parents:
38483
diff
changeset
|
39 |
/* document editing */ |
|
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
40 |
|
| 75393 | 41 |
object Commands_Accepted {
|
|
70665
94442fce40a5
prefer commands_accepted: fewer protocol messages;
wenzelm
parents:
70664
diff
changeset
|
42 |
def unapply(text: String): Option[List[Document_ID.Command]] = |
|
94442fce40a5
prefer commands_accepted: fewer protocol messages;
wenzelm
parents:
70664
diff
changeset
|
43 |
try { Some(space_explode(',', text).map(Value.Long.parse)) }
|
|
94442fce40a5
prefer commands_accepted: fewer protocol messages;
wenzelm
parents:
70664
diff
changeset
|
44 |
catch { case ERROR(_) => None }
|
|
94442fce40a5
prefer commands_accepted: fewer protocol messages;
wenzelm
parents:
70664
diff
changeset
|
45 |
|
|
94442fce40a5
prefer commands_accepted: fewer protocol messages;
wenzelm
parents:
70664
diff
changeset
|
46 |
val message: XML.Elem = XML.elem(Markup.STATUS, List(XML.elem(Markup.ACCEPTED))) |
|
94442fce40a5
prefer commands_accepted: fewer protocol messages;
wenzelm
parents:
70664
diff
changeset
|
47 |
} |
|
94442fce40a5
prefer commands_accepted: fewer protocol messages;
wenzelm
parents:
70664
diff
changeset
|
48 |
|
| 75393 | 49 |
object Assign_Update {
|
50 |
def unapply( |
|
51 |
text: String |
|
52 |
) : Option[(Document_ID.Version, List[String], Document.Assign_Update)] = {
|
|
|
44661
383c9d758a56
raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents:
44644
diff
changeset
|
53 |
try {
|
|
383c9d758a56
raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents:
44644
diff
changeset
|
54 |
import XML.Decode._ |
| 69846 | 55 |
def decode_upd(body: XML.Body): (Long, List[Long]) = |
56 |
space_explode(',', string(body)).map(Value.Long.parse) match {
|
|
57 |
case a :: bs => (a, bs) |
|
58 |
case _ => throw new XML.XML_Body(body) |
|
59 |
} |
|
| 71601 | 60 |
Some(triple(long, list(string), list(decode_upd))(Symbol.decode_yxml(text))) |
|
44661
383c9d758a56
raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents:
44644
diff
changeset
|
61 |
} |
|
383c9d758a56
raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents:
44644
diff
changeset
|
62 |
catch {
|
|
383c9d758a56
raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents:
44644
diff
changeset
|
63 |
case ERROR(_) => None |
| 51987 | 64 |
case _: XML.Error => None |
|
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
65 |
} |
|
70284
3e17c3a5fd39
more thorough assignment, e.g. when "purge" removes commands that were not assigned;
wenzelm
parents:
69849
diff
changeset
|
66 |
} |
|
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
67 |
} |
|
38567
b670faa807c9
concentrate protocol message formats in Isar_Document;
wenzelm
parents:
38483
diff
changeset
|
68 |
|
| 75393 | 69 |
object Removed {
|
|
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
70 |
def unapply(text: String): Option[List[Document_ID.Version]] = |
| 44676 | 71 |
try {
|
72 |
import XML.Decode._ |
|
|
65345
2fdd4431b30e
clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents:
65313
diff
changeset
|
73 |
Some(list(long)(Symbol.decode_yxml(text))) |
| 44676 | 74 |
} |
75 |
catch {
|
|
76 |
case ERROR(_) => None |
|
| 51987 | 77 |
case _: XML.Error => None |
| 44676 | 78 |
} |
79 |
} |
|
80 |
||
|
38567
b670faa807c9
concentrate protocol message formats in Isar_Document;
wenzelm
parents:
38483
diff
changeset
|
81 |
|
|
51818
517f232e867d
clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents:
51533
diff
changeset
|
82 |
/* command timing */ |
|
517f232e867d
clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents:
51533
diff
changeset
|
83 |
|
| 75393 | 84 |
object Command_Timing {
|
|
83198
7f46426e69ab
clarified protocol: post authentic properties from Protocol.Command_Timing, which includes positions from ML;
wenzelm
parents:
83168
diff
changeset
|
85 |
def unapply(props: Properties.T): Option[(Document_ID.Generic, Properties.T)] = |
|
51818
517f232e867d
clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents:
51533
diff
changeset
|
86 |
props match {
|
|
83198
7f46426e69ab
clarified protocol: post authentic properties from Protocol.Command_Timing, which includes positions from ML;
wenzelm
parents:
83168
diff
changeset
|
87 |
case Markup.Command_Timing(args@Position.Id(id)) => Some((id, args)) |
|
51818
517f232e867d
clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents:
51533
diff
changeset
|
88 |
case _ => None |
|
517f232e867d
clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents:
51533
diff
changeset
|
89 |
} |
|
517f232e867d
clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents:
51533
diff
changeset
|
90 |
} |
|
517f232e867d
clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents:
51533
diff
changeset
|
91 |
|
|
517f232e867d
clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents:
51533
diff
changeset
|
92 |
|
|
39441
4110cc1b8f9f
allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
wenzelm
parents:
39439
diff
changeset
|
93 |
/* result messages */ |
|
39439
1c294d150ded
eliminated markup "location" in favour of more explicit "no_report", which is actually deleted from messages;
wenzelm
parents:
39181
diff
changeset
|
94 |
|
|
82316
83584916b6d7
support for writeln_urgent, which is shown in Output before state messages (reminiscent of old Output.urgent_message before 521cea5fa777);
wenzelm
parents:
81346
diff
changeset
|
95 |
def is_urgent(msg: XML.Tree): Boolean = |
|
83584916b6d7
support for writeln_urgent, which is shown in Output before state messages (reminiscent of old Output.urgent_message before 521cea5fa777);
wenzelm
parents:
81346
diff
changeset
|
96 |
msg match {
|
|
83584916b6d7
support for writeln_urgent, which is shown in Output before state messages (reminiscent of old Output.urgent_message before 521cea5fa777);
wenzelm
parents:
81346
diff
changeset
|
97 |
case XML.Elem(Markup(_, props), _) => Markup.Urgent.get(props) |
|
83584916b6d7
support for writeln_urgent, which is shown in Output before state messages (reminiscent of old Output.urgent_message before 521cea5fa777);
wenzelm
parents:
81346
diff
changeset
|
98 |
case _ => false |
|
83584916b6d7
support for writeln_urgent, which is shown in Output before state messages (reminiscent of old Output.urgent_message before 521cea5fa777);
wenzelm
parents:
81346
diff
changeset
|
99 |
} |
|
83584916b6d7
support for writeln_urgent, which is shown in Output before state messages (reminiscent of old Output.urgent_message before 521cea5fa777);
wenzelm
parents:
81346
diff
changeset
|
100 |
|
|
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
101 |
def is_result(msg: XML.Tree): Boolean = |
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
102 |
msg match {
|
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
103 |
case XML.Elem(Markup(Markup.RESULT, _), _) => true |
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
104 |
case _ => false |
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
105 |
} |
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
106 |
|
| 50157 | 107 |
def is_tracing(msg: XML.Tree): Boolean = |
|
39622
53365ba766ac
Command.accumulate: refrain from adding tracing messages to markup tree -- potential scalability problem;
wenzelm
parents:
39511
diff
changeset
|
108 |
msg match {
|
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
50157
diff
changeset
|
109 |
case XML.Elem(Markup(Markup.TRACING, _), _) => true |
|
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
50157
diff
changeset
|
110 |
case XML.Elem(Markup(Markup.TRACING_MESSAGE, _), _) => true |
|
39622
53365ba766ac
Command.accumulate: refrain from adding tracing messages to markup tree -- potential scalability problem;
wenzelm
parents:
39511
diff
changeset
|
111 |
case _ => false |
|
53365ba766ac
Command.accumulate: refrain from adding tracing messages to markup tree -- potential scalability problem;
wenzelm
parents:
39511
diff
changeset
|
112 |
} |
|
53365ba766ac
Command.accumulate: refrain from adding tracing messages to markup tree -- potential scalability problem;
wenzelm
parents:
39511
diff
changeset
|
113 |
|
|
59184
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
59085
diff
changeset
|
114 |
def is_state(msg: XML.Tree): Boolean = |
|
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
115 |
msg match {
|
|
59184
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
59085
diff
changeset
|
116 |
case XML.Elem(Markup(Markup.STATE, _), _) => true |
|
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
59085
diff
changeset
|
117 |
case XML.Elem(Markup(Markup.STATE_MESSAGE, _), _) => true |
|
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
59085
diff
changeset
|
118 |
case _ => false |
|
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
59085
diff
changeset
|
119 |
} |
|
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
59085
diff
changeset
|
120 |
|
|
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
59085
diff
changeset
|
121 |
def is_information(msg: XML.Tree): Boolean = |
|
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
59085
diff
changeset
|
122 |
msg match {
|
|
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
59085
diff
changeset
|
123 |
case XML.Elem(Markup(Markup.INFORMATION, _), _) => true |
|
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
59085
diff
changeset
|
124 |
case XML.Elem(Markup(Markup.INFORMATION_MESSAGE, _), _) => true |
|
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
125 |
case _ => false |
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
126 |
} |
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
127 |
|
|
67923
3e072441c96a
clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents:
67915
diff
changeset
|
128 |
def is_writeln(msg: XML.Tree): Boolean = |
|
3e072441c96a
clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents:
67915
diff
changeset
|
129 |
msg match {
|
|
3e072441c96a
clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents:
67915
diff
changeset
|
130 |
case XML.Elem(Markup(Markup.WRITELN, _), _) => true |
|
3e072441c96a
clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents:
67915
diff
changeset
|
131 |
case XML.Elem(Markup(Markup.WRITELN_MESSAGE, _), _) => true |
|
3e072441c96a
clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents:
67915
diff
changeset
|
132 |
case _ => false |
|
3e072441c96a
clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents:
67915
diff
changeset
|
133 |
} |
|
3e072441c96a
clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents:
67915
diff
changeset
|
134 |
|
| 39511 | 135 |
def is_warning(msg: XML.Tree): Boolean = |
136 |
msg match {
|
|
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
50157
diff
changeset
|
137 |
case XML.Elem(Markup(Markup.WARNING, _), _) => true |
|
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
50157
diff
changeset
|
138 |
case XML.Elem(Markup(Markup.WARNING_MESSAGE, _), _) => true |
| 39511 | 139 |
case _ => false |
140 |
} |
|
141 |
||
|
59203
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents:
59184
diff
changeset
|
142 |
def is_legacy(msg: XML.Tree): Boolean = |
|
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents:
59184
diff
changeset
|
143 |
msg match {
|
|
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents:
59184
diff
changeset
|
144 |
case XML.Elem(Markup(Markup.LEGACY, _), _) => true |
|
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents:
59184
diff
changeset
|
145 |
case XML.Elem(Markup(Markup.LEGACY_MESSAGE, _), _) => true |
|
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents:
59184
diff
changeset
|
146 |
case _ => false |
|
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents:
59184
diff
changeset
|
147 |
} |
|
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents:
59184
diff
changeset
|
148 |
|
| 39511 | 149 |
def is_error(msg: XML.Tree): Boolean = |
150 |
msg match {
|
|
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
50157
diff
changeset
|
151 |
case XML.Elem(Markup(Markup.ERROR, _), _) => true |
|
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
50157
diff
changeset
|
152 |
case XML.Elem(Markup(Markup.ERROR_MESSAGE, _), _) => true |
| 39511 | 153 |
case _ => false |
154 |
} |
|
|
38887
1261481ef5e5
Command.State: add reported positions to markup tree, according main message position or Markup.binding/entity/report occurrences in body;
wenzelm
parents:
38581
diff
changeset
|
155 |
|
| 83168 | 156 |
def is_warning_or_legacy(msg: XML.Tree): Boolean = |
157 |
is_warning(msg) || is_legacy(msg) |
|
158 |
||
| 56495 | 159 |
def is_inlined(msg: XML.Tree): Boolean = |
|
76070
cf13b2147c48
inline markup for Output.state (in contrast to c94bba7906d2): make messages available via Rendering.text_messages and thus "isabelle log" (see cb0c407fbc6e), while Rendering.output_messages of Isabelle/jEdit/VSCode is unaffected;
wenzelm
parents:
76022
diff
changeset
|
160 |
!(is_result(msg) || is_tracing(msg)) |
| 56495 | 161 |
|
|
67923
3e072441c96a
clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents:
67915
diff
changeset
|
162 |
def is_exported(msg: XML.Tree): Boolean = |
|
3e072441c96a
clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents:
67915
diff
changeset
|
163 |
is_writeln(msg) || is_warning(msg) || is_legacy(msg) || is_error(msg) |
|
3e072441c96a
clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents:
67915
diff
changeset
|
164 |
|
| 76087 | 165 |
def message_heading(elem: XML.Elem, pos: Position.T): String = {
|
166 |
val h = |
|
| 83168 | 167 |
if (is_warning_or_legacy(elem)) "Warning" |
| 76087 | 168 |
else if (is_error(elem)) "Error" |
169 |
else if (is_information(elem)) "Information" |
|
170 |
else if (is_tracing(elem)) "Tracing" |
|
171 |
else if (is_state(elem)) "State" |
|
172 |
else "Output" |
|
173 |
h + Position.here(pos) |
|
174 |
} |
|
175 |
||
| 72874 | 176 |
def message_text(elem: XML.Elem, |
| 72875 | 177 |
heading: Boolean = false, |
178 |
pos: Position.T = Position.none, |
|
|
82988
71ffc2c22348
explicit "isabelle process_theories -U" as in "isabelle build_log";
wenzelm
parents:
82948
diff
changeset
|
179 |
recode: String => String = identity, |
| 71649 | 180 |
margin: Double = Pretty.default_margin, |
181 |
breakgain: Double = Pretty.default_breakgain, |
|
| 81346 | 182 |
metric: Pretty.Metric = Codepoint.Metric |
| 75393 | 183 |
): String = {
|
|
82988
71ffc2c22348
explicit "isabelle process_theories -U" as in "isabelle build_log";
wenzelm
parents:
82948
diff
changeset
|
184 |
val text1 = if (heading) "\n" + recode(message_heading(elem, pos)) + ":\n" else "" |
| 72877 | 185 |
|
186 |
val body = |
|
|
82988
71ffc2c22348
explicit "isabelle process_theories -U" as in "isabelle build_log";
wenzelm
parents:
82948
diff
changeset
|
187 |
Pretty.string_of(List(elem), recode = recode, margin = margin, breakgain = breakgain, |
| 80872 | 188 |
metric = metric, pure = true) |
| 71649 | 189 |
|
| 72877 | 190 |
val text2 = |
| 83168 | 191 |
if (is_warning_or_legacy(elem)) Output.warning_prefix(body) |
| 77501 | 192 |
else if (is_error(elem)) Output.error_message_prefix(body) |
| 72877 | 193 |
else body |
194 |
||
195 |
text1 + text2 |
|
| 71165 | 196 |
} |
197 |
||
| 76680 | 198 |
def make_message(body: XML.Body, kind: String, props: Properties.T = Nil): XML.Elem = |
199 |
XML.Elem(Markup(Markup.message(kind), props), body) |
|
| 76022 | 200 |
|
| 76680 | 201 |
def writeln_message(body: XML.Body): XML.Elem = make_message(body, Markup.WRITELN) |
202 |
def warning_message(body: XML.Body): XML.Elem = make_message(body, Markup.WARNING) |
|
203 |
def error_message(body: XML.Body): XML.Elem = make_message(body, Markup.ERROR) |
|
204 |
||
205 |
def writeln_message(msg: String): XML.Elem = writeln_message(XML.string(msg)) |
|
206 |
def warning_message(msg: String): XML.Elem = warning_message(XML.string(msg)) |
|
207 |
def error_message(msg: String): XML.Elem = error_message(XML.string(msg)) |
|
| 76022 | 208 |
|
|
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
209 |
|
| 73835 | 210 |
/* ML profiling */ |
211 |
||
| 75393 | 212 |
object ML_Profiling {
|
| 73835 | 213 |
def unapply(msg: XML.Tree): Option[isabelle.ML_Profiling.Report] = |
214 |
msg match {
|
|
| 73838 | 215 |
case XML.Elem(_, List(tree)) if is_tracing(msg) => |
| 73835 | 216 |
Markup.ML_Profiling.unapply_report(tree) |
217 |
case _ => None |
|
218 |
} |
|
219 |
} |
|
220 |
||
221 |
||
| 71624 | 222 |
/* export */ |
223 |
||
| 75393 | 224 |
object Export {
|
| 71624 | 225 |
sealed case class Args( |
|
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72637
diff
changeset
|
226 |
id: Option[String] = None, |
|
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72637
diff
changeset
|
227 |
serial: Long = 0L, |
| 71624 | 228 |
theory_name: String, |
229 |
name: String, |
|
|
72692
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72637
diff
changeset
|
230 |
executable: Boolean = false, |
|
22aeec526ffd
support for PIDE markup in batch build (inactive due to pide_reports=false);
wenzelm
parents:
72637
diff
changeset
|
231 |
compress: Boolean = true, |
| 75393 | 232 |
strict: Boolean = true |
233 |
) {
|
|
| 71624 | 234 |
def compound_name: String = isabelle.Export.compound_name(theory_name, name) |
235 |
} |
|
236 |
||
237 |
def unapply(props: Properties.T): Option[Args] = |
|
238 |
props match {
|
|
239 |
case |
|
240 |
List( |
|
241 |
(Markup.FUNCTION, Markup.EXPORT), |
|
242 |
(Markup.ID, id), |
|
243 |
(Markup.SERIAL, Value.Long(serial)), |
|
244 |
(Markup.THEORY_NAME, theory_name), |
|
245 |
(Markup.NAME, name), |
|
246 |
(Markup.EXECUTABLE, Value.Boolean(executable)), |
|
247 |
(Markup.COMPRESS, Value.Boolean(compress)), |
|
248 |
(Markup.STRICT, Value.Boolean(strict))) => |
|
249 |
Some(Args(proper_string(id), serial, theory_name, name, executable, compress, strict)) |
|
250 |
case _ => None |
|
251 |
} |
|
252 |
} |
|
253 |
||
254 |
||
| 83427 | 255 |
/* sendback snippets */ |
256 |
||
| 83430 | 257 |
def sendback_snippets(xml: XML.Body): List[(String, Properties.T)] = {
|
|
83428
cb4f950f4fbd
more accurate senback_snippets: no duplicates, no recursion into "sendback" or wrapped elements;
wenzelm
parents:
83427
diff
changeset
|
258 |
var seen = Set.empty[(String, Properties.T)] |
|
cb4f950f4fbd
more accurate senback_snippets: no duplicates, no recursion into "sendback" or wrapped elements;
wenzelm
parents:
83427
diff
changeset
|
259 |
val result = new mutable.ListBuffer[(String, Properties.T)] |
|
cb4f950f4fbd
more accurate senback_snippets: no duplicates, no recursion into "sendback" or wrapped elements;
wenzelm
parents:
83427
diff
changeset
|
260 |
|
|
cb4f950f4fbd
more accurate senback_snippets: no duplicates, no recursion into "sendback" or wrapped elements;
wenzelm
parents:
83427
diff
changeset
|
261 |
@tailrec def traverse(body: XML.Body): Unit = |
|
cb4f950f4fbd
more accurate senback_snippets: no duplicates, no recursion into "sendback" or wrapped elements;
wenzelm
parents:
83427
diff
changeset
|
262 |
body match {
|
|
cb4f950f4fbd
more accurate senback_snippets: no duplicates, no recursion into "sendback" or wrapped elements;
wenzelm
parents:
83427
diff
changeset
|
263 |
case XML.Elem(Markup(Markup.SENDBACK, props), body1) :: body2 => |
|
cb4f950f4fbd
more accurate senback_snippets: no duplicates, no recursion into "sendback" or wrapped elements;
wenzelm
parents:
83427
diff
changeset
|
264 |
val entry = (XML.content(body1), props) |
|
cb4f950f4fbd
more accurate senback_snippets: no duplicates, no recursion into "sendback" or wrapped elements;
wenzelm
parents:
83427
diff
changeset
|
265 |
if (!seen(entry)) {
|
|
cb4f950f4fbd
more accurate senback_snippets: no duplicates, no recursion into "sendback" or wrapped elements;
wenzelm
parents:
83427
diff
changeset
|
266 |
seen += entry |
|
cb4f950f4fbd
more accurate senback_snippets: no duplicates, no recursion into "sendback" or wrapped elements;
wenzelm
parents:
83427
diff
changeset
|
267 |
result += entry |
|
cb4f950f4fbd
more accurate senback_snippets: no duplicates, no recursion into "sendback" or wrapped elements;
wenzelm
parents:
83427
diff
changeset
|
268 |
} |
|
cb4f950f4fbd
more accurate senback_snippets: no duplicates, no recursion into "sendback" or wrapped elements;
wenzelm
parents:
83427
diff
changeset
|
269 |
traverse(body2) |
|
cb4f950f4fbd
more accurate senback_snippets: no duplicates, no recursion into "sendback" or wrapped elements;
wenzelm
parents:
83427
diff
changeset
|
270 |
case XML.Wrapped_Elem(_, _, body1) :: body2 => traverse(body1 ::: body2) |
|
cb4f950f4fbd
more accurate senback_snippets: no duplicates, no recursion into "sendback" or wrapped elements;
wenzelm
parents:
83427
diff
changeset
|
271 |
case XML.Elem(_, body1) :: body2 => traverse(body1 ::: body2) |
|
cb4f950f4fbd
more accurate senback_snippets: no duplicates, no recursion into "sendback" or wrapped elements;
wenzelm
parents:
83427
diff
changeset
|
272 |
case XML.Text(_) :: body2 => traverse(body2) |
|
cb4f950f4fbd
more accurate senback_snippets: no duplicates, no recursion into "sendback" or wrapped elements;
wenzelm
parents:
83427
diff
changeset
|
273 |
case Nil => |
|
cb4f950f4fbd
more accurate senback_snippets: no duplicates, no recursion into "sendback" or wrapped elements;
wenzelm
parents:
83427
diff
changeset
|
274 |
} |
|
cb4f950f4fbd
more accurate senback_snippets: no duplicates, no recursion into "sendback" or wrapped elements;
wenzelm
parents:
83427
diff
changeset
|
275 |
|
|
cb4f950f4fbd
more accurate senback_snippets: no duplicates, no recursion into "sendback" or wrapped elements;
wenzelm
parents:
83427
diff
changeset
|
276 |
traverse(xml) |
|
cb4f950f4fbd
more accurate senback_snippets: no duplicates, no recursion into "sendback" or wrapped elements;
wenzelm
parents:
83427
diff
changeset
|
277 |
result.toList |
| 83427 | 278 |
} |
279 |
||
280 |
||
| 60882 | 281 |
/* breakpoints */ |
282 |
||
| 75393 | 283 |
object ML_Breakpoint {
|
| 60882 | 284 |
def unapply(tree: XML.Tree): Option[Long] = |
285 |
tree match {
|
|
286 |
case XML.Elem(Markup(Markup.ML_BREAKPOINT, Markup.Serial(breakpoint)), _) => Some(breakpoint) |
|
287 |
case _ => None |
|
288 |
} |
|
289 |
} |
|
290 |
||
291 |
||
|
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
292 |
/* dialogs */ |
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
293 |
|
| 75393 | 294 |
object Dialog_Args {
|
| 52531 | 295 |
def unapply(props: Properties.T): Option[(Document_ID.Generic, Long, String)] = |
|
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
296 |
(props, props, props) match {
|
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
297 |
case (Position.Id(id), Markup.Serial(serial), Markup.Result(result)) => |
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
298 |
Some((id, serial, result)) |
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
299 |
case _ => None |
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
300 |
} |
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
301 |
} |
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
302 |
|
| 75393 | 303 |
object Dialog {
|
| 52531 | 304 |
def unapply(tree: XML.Tree): Option[(Document_ID.Generic, Long, String)] = |
|
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
305 |
tree match {
|
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
306 |
case XML.Elem(Markup(Markup.DIALOG, Dialog_Args(id, serial, result)), _) => |
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
307 |
Some((id, serial, result)) |
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
308 |
case _ => None |
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
309 |
} |
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
310 |
} |
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
311 |
|
| 75393 | 312 |
object Dialog_Result {
|
313 |
def apply(id: Document_ID.Generic, serial: Long, result: String): XML.Elem = {
|
|
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50500
diff
changeset
|
314 |
val props = Position.Id(id) ::: Markup.Serial(serial) |
|
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50500
diff
changeset
|
315 |
XML.Elem(Markup(Markup.RESULT, props), List(XML.Text(result))) |
|
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50500
diff
changeset
|
316 |
} |
|
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
317 |
|
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50500
diff
changeset
|
318 |
def unapply(tree: XML.Tree): Option[String] = |
|
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
319 |
tree match {
|
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50500
diff
changeset
|
320 |
case XML.Elem(Markup(Markup.RESULT, _), List(XML.Text(result))) => Some(result) |
|
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
321 |
case _ => None |
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
322 |
} |
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
323 |
} |
|
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
324 |
} |
|
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
325 |
|
|
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
326 |
|
| 75393 | 327 |
trait Protocol {
|
| 57916 | 328 |
/* protocol commands */ |
329 |
||
| 70661 | 330 |
def protocol_command_raw(name: String, args: List[Bytes]): Unit |
|
80462
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
331 |
def protocol_command_args(name: String, args: List[XML.Body]): Unit |
|
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
332 |
def protocol_command(name: String, args: XML.Body*): Unit |
| 57916 | 333 |
|
334 |
||
| 56387 | 335 |
/* options */ |
336 |
||
337 |
def options(opts: Options): Unit = |
|
|
80462
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
338 |
protocol_command("Prover.options", opts.encode)
|
| 56387 | 339 |
|
340 |
||
| 72637 | 341 |
/* resources */ |
|
67493
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67471
diff
changeset
|
342 |
|
| 72637 | 343 |
def init_session(resources: Resources): Unit = |
|
80462
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
344 |
protocol_command("Prover.init_session", resources.init_session_xml)
|
| 65470 | 345 |
|
346 |
||
| 56387 | 347 |
/* interned items */ |
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
348 |
|
|
56335
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
wenzelm
parents:
56306
diff
changeset
|
349 |
def define_blob(digest: SHA1.Digest, bytes: Bytes): Unit = |
| 70661 | 350 |
protocol_command_raw("Document.define_blob", List(Bytes(digest.toString), bytes))
|
|
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
351 |
|
| 75393 | 352 |
private def encode_command( |
353 |
resources: Resources, |
|
354 |
command: Command |
|
|
80462
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
355 |
) : (XML.Body, XML.Body, XML.Body, XML.Body, XML.Body, List[XML.Body]) = {
|
|
70664
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents:
70661
diff
changeset
|
356 |
import XML.Encode._ |
|
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents:
70661
diff
changeset
|
357 |
|
| 72946 | 358 |
val parents = command.theory_parents(resources).map(name => File.standard_url(name.node)) |
|
80462
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
359 |
val parents_xml: XML.Body = list(string)(parents) |
| 72946 | 360 |
|
|
80462
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
361 |
val blobs_xml: XML.Body = {
|
| 72745 | 362 |
val encode_blob: T[Exn.Result[Command.Blob]] = |
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
363 |
variant(List( |
|
82948
e2e43992f339
more detailed export "PIDE/files": store offset of the load command, within the pro-forma loaded_theory_command --- this allows to restrict output messages for blobs;
wenzelm
parents:
82316
diff
changeset
|
364 |
{ case Exn.Res(Command.Blob(_, a, b, c)) =>
|
|
72747
5f9d66155081
clarified theory keywords: loaded_files are determined statically in Scala, but ML needs to do it semantically;
wenzelm
parents:
72745
diff
changeset
|
365 |
(Nil, triple(string, string, option(string))( |
|
5f9d66155081
clarified theory keywords: loaded_files are determined statically in Scala, but ML needs to do it semantically;
wenzelm
parents:
72745
diff
changeset
|
366 |
(a.node, b.implode, c.map(p => p._1.toString)))) }, |
|
65345
2fdd4431b30e
clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents:
65313
diff
changeset
|
367 |
{ case Exn.Exn(e) => (Nil, string(Exn.message(e))) }))
|
|
59085
08a6901eb035
clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents:
58015
diff
changeset
|
368 |
|
|
80462
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
369 |
pair(list(encode_blob), int)(command.blobs, command.blobs_index) |
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
370 |
} |
|
59085
08a6901eb035
clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents:
58015
diff
changeset
|
371 |
|
|
80462
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
372 |
val toks_xml: XML.Body = {
|
| 64616 | 373 |
val encode_tok: T[Token] = (tok => pair(int, int)((tok.kind.id, Symbol.length(tok.source)))) |
|
80462
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
374 |
list(encode_tok)(command.span.content) |
|
59085
08a6901eb035
clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents:
58015
diff
changeset
|
375 |
} |
|
80462
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
376 |
val toks_sources_xml: List[XML.Body] = command.span.content.map(tok => XML.string(tok.source)) |
|
59085
08a6901eb035
clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents:
58015
diff
changeset
|
377 |
|
|
80462
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
378 |
(Document_ID.encode(command.id), XML.string(command.span.name), |
|
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
379 |
parents_xml, blobs_xml, toks_xml, toks_sources_xml) |
|
70664
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents:
70661
diff
changeset
|
380 |
} |
|
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents:
70661
diff
changeset
|
381 |
|
| 75393 | 382 |
def define_command(resources: Resources, command: Command): Unit = {
|
|
80462
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
383 |
val (a, b, c, d, e, rest) = encode_command(resources, command) |
|
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
384 |
protocol_command_args("Document.define_command", a :: b :: c :: d :: e :: rest)
|
|
70664
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents:
70661
diff
changeset
|
385 |
} |
|
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents:
70661
diff
changeset
|
386 |
|
| 75394 | 387 |
def define_commands(resources: Resources, commands: List[Command]): Unit = |
|
70664
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents:
70661
diff
changeset
|
388 |
protocol_command_args("Document.define_commands",
|
| 75394 | 389 |
commands.map { command =>
|
|
70664
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents:
70661
diff
changeset
|
390 |
import XML.Encode._ |
|
80462
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
391 |
val (a, b, c, d, e, rest) = encode_command(resources, command) |
|
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
392 |
pair(self, pair(self, pair(self, pair(self, pair(self, list(self))))))( |
|
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
393 |
a, (b, (c, (d, (e, rest))))) |
| 75394 | 394 |
}) |
|
70664
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents:
70661
diff
changeset
|
395 |
|
| 75393 | 396 |
def define_commands_bulk(resources: Resources, commands: List[Command]): Unit = {
|
|
70664
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents:
70661
diff
changeset
|
397 |
val (irregular, regular) = commands.partition(command => YXML.detect(command.source)) |
| 72946 | 398 |
irregular.foreach(define_command(resources, _)) |
|
70664
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents:
70661
diff
changeset
|
399 |
regular match {
|
|
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents:
70661
diff
changeset
|
400 |
case Nil => |
| 72946 | 401 |
case List(command) => define_command(resources, command) |
402 |
case _ => define_commands(resources, regular) |
|
|
70664
2bd9e30183b1
prefer define_commands_bulk: fewer protocol messages;
wenzelm
parents:
70661
diff
changeset
|
403 |
} |
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
404 |
} |
|
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
405 |
|
|
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
406 |
|
|
52931
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52862
diff
changeset
|
407 |
/* execution */ |
|
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52862
diff
changeset
|
408 |
|
|
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52862
diff
changeset
|
409 |
def discontinue_execution(): Unit = |
|
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52862
diff
changeset
|
410 |
protocol_command("Document.discontinue_execution")
|
|
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
411 |
|
|
52931
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52862
diff
changeset
|
412 |
def cancel_exec(id: Document_ID.Exec): Unit = |
|
80462
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
413 |
protocol_command("Document.cancel_exec", Document_ID.encode(id))
|
|
52931
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52862
diff
changeset
|
414 |
|
|
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52862
diff
changeset
|
415 |
|
|
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52862
diff
changeset
|
416 |
/* document versions */ |
|
47343
b8aeab386414
less aggressive discontinue_execution before document update, to avoid unstable execs that need to be re-assigned;
wenzelm
parents:
46938
diff
changeset
|
417 |
|
| 75393 | 418 |
def update( |
419 |
old_id: Document_ID.Version, |
|
420 |
new_id: Document_ID.Version, |
|
421 |
edits: List[Document.Edit_Command], |
|
422 |
consolidate: List[Document.Node.Name] |
|
423 |
): Unit = {
|
|
|
80462
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
424 |
val consolidate_xml = { import XML.Encode._; list(string)(consolidate.map(_.node)) }
|
|
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
425 |
val edits_xml = {
|
| 69849 | 426 |
import XML.Encode._ |
|
80462
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
427 |
|
| 44383 | 428 |
def id: T[Command] = (cmd => long(cmd.id)) |
| 46737 | 429 |
def encode_edit(name: Document.Node.Name) |
| 52849 | 430 |
: T[Document.Node.Edit[Command.Edit, Command.Perspective]] = |
|
44979
68b990e950b1
explicit master_dir as part of header -- still required (for Cygwin) since Scala layer does not pass file content yet;
wenzelm
parents:
44866
diff
changeset
|
431 |
variant(List( |
|
68b990e950b1
explicit master_dir as part of header -- still required (for Cygwin) since Scala layer does not pass file content yet;
wenzelm
parents:
44866
diff
changeset
|
432 |
{ case Document.Node.Edits(a) => (Nil, list(pair(option(id), option(id)))(a)) },
|
|
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48705
diff
changeset
|
433 |
{ case Document.Node.Deps(header) =>
|
| 60992 | 434 |
val master_dir = File.standard_url(name.master_dir) |
|
70638
f164cec7ac22
clarified signature: prefer operations without position;
wenzelm
parents:
70284
diff
changeset
|
435 |
val imports = header.imports.map(_.node) |
| 72764 | 436 |
val keywords = header.keywords.map({ case (a, spec) => (a, (spec.kind, spec.tags)) })
|
|
44979
68b990e950b1
explicit master_dir as part of header -- still required (for Cygwin) since Scala layer does not pass file content yet;
wenzelm
parents:
44866
diff
changeset
|
437 |
(Nil, |
|
72747
5f9d66155081
clarified theory keywords: loaded_files are determined statically in Scala, but ML needs to do it semantically;
wenzelm
parents:
72745
diff
changeset
|
438 |
pair(string, pair(string, pair(list(string), |
|
5f9d66155081
clarified theory keywords: loaded_files are determined statically in Scala, but ML needs to do it semantically;
wenzelm
parents:
72745
diff
changeset
|
439 |
pair(list(pair(string, pair(string, list(string)))), list(string)))))( |
|
65445
e9e7f5f5794c
more qualifier treatment, but in the end it is still ignored;
wenzelm
parents:
65439
diff
changeset
|
440 |
(master_dir, (name.theory, (imports, (keywords, header.errors)))))) }, |
| 52849 | 441 |
{ case Document.Node.Perspective(a, b, c) =>
|
442 |
(bool_atom(a) :: b.commands.map(cmd => long_atom(cmd.id)), |
|
|
65345
2fdd4431b30e
clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents:
65313
diff
changeset
|
443 |
list(pair(id, pair(string, list(string))))(c.dest)) })) |
|
80462
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
444 |
edits.map({ case (name, edit) => pair(string, encode_edit(name))(name.node, edit) })
|
|
68381
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68336
diff
changeset
|
445 |
} |
| 70661 | 446 |
protocol_command_args("Document.update",
|
|
80462
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
447 |
Document_ID.encode(old_id) :: Document_ID.encode(new_id) :: consolidate_xml :: edits_xml) |
|
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
448 |
} |
| 43748 | 449 |
|
|
80462
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
450 |
def remove_versions(versions: List[Document.Version]): Unit = |
|
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
451 |
protocol_command("Document.remove_versions",
|
|
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
452 |
XML.Encode.list(Document_ID.encode)(versions.map(_.id))) |
| 44673 | 453 |
|
| 43748 | 454 |
|
| 50498 | 455 |
/* dialog via document content */ |
456 |
||
|
52931
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52862
diff
changeset
|
457 |
def dialog_result(serial: Long, result: String): Unit = |
|
80462
7a1f9e571046
clarified signature: more explicit XML.Body types, more uniform Symbol.encode_yxml;
wenzelm
parents:
77501
diff
changeset
|
458 |
protocol_command("Document.dialog_result", XML.Encode.long(serial), XML.string(result))
|
|
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
459 |
} |