author | wenzelm |
Thu, 06 Dec 2018 16:40:56 +0100 | |
changeset 69414 | eab0d3108b46 |
parent 68758 | a110e7e24e55 |
child 69846 | e02e3763e7a4 |
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 |
|
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
9 |
|
45709
87017fcbad83
clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
wenzelm
parents:
45672
diff
changeset
|
10 |
object Protocol |
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
11 |
{ |
38567
b670faa807c9
concentrate protocol message formats in Isar_Document;
wenzelm
parents:
38483
diff
changeset
|
12 |
/* document editing */ |
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
13 |
|
52563 | 14 |
object Assign_Update |
44476
e8a87398f35d
propagate information about last command with exec state assignment through document model;
wenzelm
parents:
44474
diff
changeset
|
15 |
{ |
52563 | 16 |
def unapply(text: String): Option[(Document_ID.Version, Document.Assign_Update)] = |
44661
383c9d758a56
raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents:
44644
diff
changeset
|
17 |
try { |
383c9d758a56
raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents:
44644
diff
changeset
|
18 |
import XML.Decode._ |
65345
2fdd4431b30e
clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents:
65313
diff
changeset
|
19 |
Some(pair(long, list(pair(long, list(long))))(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
|
20 |
} |
383c9d758a56
raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents:
44644
diff
changeset
|
21 |
catch { |
383c9d758a56
raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents:
44644
diff
changeset
|
22 |
case ERROR(_) => None |
51987 | 23 |
case _: XML.Error => None |
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
24 |
} |
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
25 |
} |
38567
b670faa807c9
concentrate protocol message formats in Isar_Document;
wenzelm
parents:
38483
diff
changeset
|
26 |
|
44676 | 27 |
object Removed |
28 |
{ |
|
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
29 |
def unapply(text: String): Option[List[Document_ID.Version]] = |
44676 | 30 |
try { |
31 |
import XML.Decode._ |
|
65345
2fdd4431b30e
clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents:
65313
diff
changeset
|
32 |
Some(list(long)(Symbol.decode_yxml(text))) |
44676 | 33 |
} |
34 |
catch { |
|
35 |
case ERROR(_) => None |
|
51987 | 36 |
case _: XML.Error => None |
44676 | 37 |
} |
38 |
} |
|
39 |
||
38567
b670faa807c9
concentrate protocol message formats in Isar_Document;
wenzelm
parents:
38483
diff
changeset
|
40 |
|
51818
517f232e867d
clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents:
51533
diff
changeset
|
41 |
/* command timing */ |
517f232e867d
clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents:
51533
diff
changeset
|
42 |
|
517f232e867d
clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents:
51533
diff
changeset
|
43 |
object Command_Timing |
517f232e867d
clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents:
51533
diff
changeset
|
44 |
{ |
52531 | 45 |
def unapply(props: Properties.T): Option[(Document_ID.Generic, isabelle.Timing)] = |
51818
517f232e867d
clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents:
51533
diff
changeset
|
46 |
props match { |
66873
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66717
diff
changeset
|
47 |
case Markup.COMMAND_TIMING :: args => |
51818
517f232e867d
clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents:
51533
diff
changeset
|
48 |
(args, args) match { |
517f232e867d
clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents:
51533
diff
changeset
|
49 |
case (Position.Id(id), Markup.Timing_Properties(timing)) => Some((id, timing)) |
517f232e867d
clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents:
51533
diff
changeset
|
50 |
case _ => None |
517f232e867d
clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents:
51533
diff
changeset
|
51 |
} |
517f232e867d
clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents:
51533
diff
changeset
|
52 |
case _ => None |
517f232e867d
clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents:
51533
diff
changeset
|
53 |
} |
517f232e867d
clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents:
51533
diff
changeset
|
54 |
} |
517f232e867d
clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents:
51533
diff
changeset
|
55 |
|
517f232e867d
clarified module dependencies: avoid Properties and Document introding minimal "PIDE";
wenzelm
parents:
51533
diff
changeset
|
56 |
|
66873
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66717
diff
changeset
|
57 |
/* theory timing */ |
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66717
diff
changeset
|
58 |
|
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66717
diff
changeset
|
59 |
object Theory_Timing |
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66717
diff
changeset
|
60 |
{ |
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66717
diff
changeset
|
61 |
def unapply(props: Properties.T): Option[(String, isabelle.Timing)] = |
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66717
diff
changeset
|
62 |
props match { |
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66717
diff
changeset
|
63 |
case Markup.THEORY_TIMING :: args => |
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66717
diff
changeset
|
64 |
(args, args) match { |
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66717
diff
changeset
|
65 |
case (Markup.Name(name), Markup.Timing_Properties(timing)) => Some((name, timing)) |
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66717
diff
changeset
|
66 |
case _ => None |
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66717
diff
changeset
|
67 |
} |
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66717
diff
changeset
|
68 |
case _ => None |
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66717
diff
changeset
|
69 |
} |
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66717
diff
changeset
|
70 |
} |
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66717
diff
changeset
|
71 |
|
9953ae603a23
provide theory timing information, similar to command timing but always considered relevant;
wenzelm
parents:
66717
diff
changeset
|
72 |
|
39441
4110cc1b8f9f
allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
wenzelm
parents:
39439
diff
changeset
|
73 |
/* 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
|
74 |
|
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
75 |
def is_result(msg: XML.Tree): Boolean = |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
76 |
msg match { |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
77 |
case XML.Elem(Markup(Markup.RESULT, _), _) => true |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
78 |
case _ => false |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
79 |
} |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
80 |
|
50157 | 81 |
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
|
82 |
msg match { |
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
50157
diff
changeset
|
83 |
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
|
84 |
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
|
85 |
case _ => false |
53365ba766ac
Command.accumulate: refrain from adding tracing messages to markup tree -- potential scalability problem;
wenzelm
parents:
39511
diff
changeset
|
86 |
} |
53365ba766ac
Command.accumulate: refrain from adding tracing messages to markup tree -- potential scalability problem;
wenzelm
parents:
39511
diff
changeset
|
87 |
|
59184
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
59085
diff
changeset
|
88 |
def is_state(msg: XML.Tree): Boolean = |
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
89 |
msg match { |
59184
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
59085
diff
changeset
|
90 |
case XML.Elem(Markup(Markup.STATE, _), _) => true |
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
59085
diff
changeset
|
91 |
case XML.Elem(Markup(Markup.STATE_MESSAGE, _), _) => true |
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
59085
diff
changeset
|
92 |
case _ => false |
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
59085
diff
changeset
|
93 |
} |
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
59085
diff
changeset
|
94 |
|
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
59085
diff
changeset
|
95 |
def is_information(msg: XML.Tree): Boolean = |
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
59085
diff
changeset
|
96 |
msg match { |
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
59085
diff
changeset
|
97 |
case XML.Elem(Markup(Markup.INFORMATION, _), _) => true |
830bb7ddb3ab
explicit message channels for "state", "information";
wenzelm
parents:
59085
diff
changeset
|
98 |
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
|
99 |
case _ => false |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
100 |
} |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
101 |
|
67923
3e072441c96a
clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents:
67915
diff
changeset
|
102 |
def is_writeln(msg: XML.Tree): Boolean = |
3e072441c96a
clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents:
67915
diff
changeset
|
103 |
msg match { |
3e072441c96a
clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents:
67915
diff
changeset
|
104 |
case XML.Elem(Markup(Markup.WRITELN, _), _) => true |
3e072441c96a
clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents:
67915
diff
changeset
|
105 |
case XML.Elem(Markup(Markup.WRITELN_MESSAGE, _), _) => true |
3e072441c96a
clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents:
67915
diff
changeset
|
106 |
case _ => false |
3e072441c96a
clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents:
67915
diff
changeset
|
107 |
} |
3e072441c96a
clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents:
67915
diff
changeset
|
108 |
|
39511 | 109 |
def is_warning(msg: XML.Tree): Boolean = |
110 |
msg match { |
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
50157
diff
changeset
|
111 |
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
|
112 |
case XML.Elem(Markup(Markup.WARNING_MESSAGE, _), _) => true |
39511 | 113 |
case _ => false |
114 |
} |
|
115 |
||
59203
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents:
59184
diff
changeset
|
116 |
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
|
117 |
msg match { |
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents:
59184
diff
changeset
|
118 |
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
|
119 |
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
|
120 |
case _ => false |
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents:
59184
diff
changeset
|
121 |
} |
5f0bd5afc16d
explicit message channel for "legacy", which is nonetheless a variant of "warning";
wenzelm
parents:
59184
diff
changeset
|
122 |
|
39511 | 123 |
def is_error(msg: XML.Tree): Boolean = |
124 |
msg match { |
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
50157
diff
changeset
|
125 |
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
|
126 |
case XML.Elem(Markup(Markup.ERROR_MESSAGE, _), _) => true |
39511 | 127 |
case _ => false |
128 |
} |
|
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
|
129 |
|
56495 | 130 |
def is_inlined(msg: XML.Tree): Boolean = |
131 |
!(is_result(msg) || is_tracing(msg) || is_state(msg)) |
|
132 |
||
67923
3e072441c96a
clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents:
67915
diff
changeset
|
133 |
def is_exported(msg: XML.Tree): Boolean = |
3e072441c96a
clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents:
67915
diff
changeset
|
134 |
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
|
135 |
|
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
136 |
|
60882 | 137 |
/* breakpoints */ |
138 |
||
139 |
object ML_Breakpoint |
|
140 |
{ |
|
141 |
def unapply(tree: XML.Tree): Option[Long] = |
|
142 |
tree match { |
|
143 |
case XML.Elem(Markup(Markup.ML_BREAKPOINT, Markup.Serial(breakpoint)), _) => Some(breakpoint) |
|
144 |
case _ => None |
|
145 |
} |
|
146 |
} |
|
147 |
||
148 |
||
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
149 |
/* dialogs */ |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
150 |
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
151 |
object Dialog_Args |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
152 |
{ |
52531 | 153 |
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
|
154 |
(props, props, props) match { |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
155 |
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
|
156 |
Some((id, serial, result)) |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
157 |
case _ => None |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
158 |
} |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
159 |
} |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
160 |
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
161 |
object Dialog |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
162 |
{ |
52531 | 163 |
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
|
164 |
tree match { |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
165 |
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
|
166 |
Some((id, serial, result)) |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
167 |
case _ => None |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
168 |
} |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
169 |
} |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
170 |
|
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
171 |
object Dialog_Result |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
172 |
{ |
52531 | 173 |
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
|
174 |
{ |
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50500
diff
changeset
|
175 |
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
|
176 |
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
|
177 |
} |
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
178 |
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50500
diff
changeset
|
179 |
def unapply(tree: XML.Tree): Option[String] = |
50500
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
180 |
tree match { |
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50500
diff
changeset
|
181 |
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
|
182 |
case _ => None |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
183 |
} |
c94bba7906d2
identify dialogs via official serial and maintain as result message;
wenzelm
parents:
50498
diff
changeset
|
184 |
} |
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
185 |
} |
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
186 |
|
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
187 |
|
57916 | 188 |
trait Protocol |
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
189 |
{ |
57916 | 190 |
/* protocol commands */ |
191 |
||
192 |
def protocol_command_bytes(name: String, args: Bytes*): Unit |
|
193 |
def protocol_command(name: String, args: String*): Unit |
|
194 |
||
195 |
||
56387 | 196 |
/* options */ |
197 |
||
198 |
def options(opts: Options): Unit = |
|
65345
2fdd4431b30e
clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents:
65313
diff
changeset
|
199 |
protocol_command("Prover.options", Symbol.encode_yxml(opts.encode)) |
56387 | 200 |
|
201 |
||
65470 | 202 |
/* session base */ |
203 |
||
204 |
private def encode_table(table: List[(String, String)]): String = |
|
205 |
{ |
|
206 |
import XML.Encode._ |
|
207 |
Symbol.encode_yxml(list(pair(string, string))(table)) |
|
208 |
} |
|
209 |
||
66712 | 210 |
private def encode_list(lst: List[String]): String = |
211 |
{ |
|
212 |
import XML.Encode._ |
|
213 |
Symbol.encode_yxml(list(string)(lst)) |
|
214 |
} |
|
215 |
||
67493
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67471
diff
changeset
|
216 |
private def encode_sessions(lst: List[(String, Position.T)]): String = |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67471
diff
changeset
|
217 |
{ |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67471
diff
changeset
|
218 |
import XML.Encode._ |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67471
diff
changeset
|
219 |
Symbol.encode_yxml(list(pair(string, properties))(lst)) |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67471
diff
changeset
|
220 |
} |
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67471
diff
changeset
|
221 |
|
66668
6019cfb8256c
proper standard_path to revert platform_path in JEdit_Sessions.session_base;
wenzelm
parents:
66411
diff
changeset
|
222 |
def session_base(resources: Resources) |
6019cfb8256c
proper standard_path to revert platform_path in JEdit_Sessions.session_base;
wenzelm
parents:
66411
diff
changeset
|
223 |
{ |
6019cfb8256c
proper standard_path to revert platform_path in JEdit_Sessions.session_base;
wenzelm
parents:
66411
diff
changeset
|
224 |
val base = resources.session_base.standard_path |
67219 | 225 |
protocol_command("Prover.init_session_base", |
67493
c4e9e0c50487
treat sessions as entities with defining position;
wenzelm
parents:
67471
diff
changeset
|
226 |
encode_sessions(base.known.sessions.toList), |
67471 | 227 |
encode_list(base.doc_names), |
66668
6019cfb8256c
proper standard_path to revert platform_path in JEdit_Sessions.session_base;
wenzelm
parents:
66411
diff
changeset
|
228 |
encode_table(base.global_theories.toList), |
66717
67dbf5cdc056
more informative loaded_theories: dependencies and syntax;
wenzelm
parents:
66712
diff
changeset
|
229 |
encode_list(base.loaded_theories.keys), |
66668
6019cfb8256c
proper standard_path to revert platform_path in JEdit_Sessions.session_base;
wenzelm
parents:
66411
diff
changeset
|
230 |
encode_table(base.dest_known_theories)) |
6019cfb8256c
proper standard_path to revert platform_path in JEdit_Sessions.session_base;
wenzelm
parents:
66411
diff
changeset
|
231 |
} |
65470 | 232 |
|
233 |
||
56387 | 234 |
/* interned items */ |
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
235 |
|
56335
8953d4cc060a
store blob content within document node: aux. files that were once open are made persistent;
wenzelm
parents:
56306
diff
changeset
|
236 |
def define_blob(digest: SHA1.Digest, bytes: Bytes): Unit = |
56387 | 237 |
protocol_command_bytes("Document.define_blob", Bytes(digest.toString), bytes) |
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
238 |
|
59671
9715eb8e9408
more precise position information in Isabelle/Scala, with YXML markup as in Isabelle/ML;
wenzelm
parents:
59364
diff
changeset
|
239 |
def define_command(command: Command) |
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
240 |
{ |
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
241 |
val blobs_yxml = |
61376
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
60992
diff
changeset
|
242 |
{ |
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
60992
diff
changeset
|
243 |
import XML.Encode._ |
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
244 |
val encode_blob: T[Command.Blob] = |
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
245 |
variant(List( |
54526 | 246 |
{ case Exn.Res((a, b)) => |
65345
2fdd4431b30e
clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents:
65313
diff
changeset
|
247 |
(Nil, pair(string, option(string))((a.node, b.map(p => p._1.toString)))) }, |
2fdd4431b30e
clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents:
65313
diff
changeset
|
248 |
{ 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
|
249 |
|
65345
2fdd4431b30e
clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents:
65313
diff
changeset
|
250 |
Symbol.encode_yxml(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
|
251 |
} |
59085
08a6901eb035
clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents:
58015
diff
changeset
|
252 |
|
08a6901eb035
clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents:
58015
diff
changeset
|
253 |
val toks = command.span.content |
08a6901eb035
clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents:
58015
diff
changeset
|
254 |
val toks_yxml = |
61376
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
60992
diff
changeset
|
255 |
{ |
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
60992
diff
changeset
|
256 |
import XML.Encode._ |
64616 | 257 |
val encode_tok: T[Token] = (tok => pair(int, int)((tok.kind.id, Symbol.length(tok.source)))) |
65345
2fdd4431b30e
clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents:
65313
diff
changeset
|
258 |
Symbol.encode_yxml(list(encode_tok)(toks)) |
59085
08a6901eb035
clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents:
58015
diff
changeset
|
259 |
} |
08a6901eb035
clarified define_command: send tokens more directly, without requiring keywords in ML;
wenzelm
parents:
58015
diff
changeset
|
260 |
|
52582 | 261 |
protocol_command("Document.define_command", |
65345
2fdd4431b30e
clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents:
65313
diff
changeset
|
262 |
(Document_ID(command.id) :: Symbol.encode(command.span.name) :: blobs_yxml :: toks_yxml :: |
2fdd4431b30e
clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents:
65313
diff
changeset
|
263 |
toks.map(tok => Symbol.encode(tok.source))): _*) |
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54515
diff
changeset
|
264 |
} |
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
265 |
|
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
266 |
|
52931
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52862
diff
changeset
|
267 |
/* execution */ |
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52862
diff
changeset
|
268 |
|
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52862
diff
changeset
|
269 |
def discontinue_execution(): Unit = |
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52862
diff
changeset
|
270 |
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
|
271 |
|
52931
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52862
diff
changeset
|
272 |
def cancel_exec(id: Document_ID.Exec): Unit = |
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52862
diff
changeset
|
273 |
protocol_command("Document.cancel_exec", Document_ID(id)) |
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52862
diff
changeset
|
274 |
|
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52862
diff
changeset
|
275 |
|
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52862
diff
changeset
|
276 |
/* 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
|
277 |
|
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
278 |
def update(old_id: Document_ID.Version, new_id: Document_ID.Version, |
68381
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68336
diff
changeset
|
279 |
edits: List[Document.Edit_Command], consolidate: List[Document.Node.Name]) |
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
280 |
{ |
44157
a21d3e1e64fd
uniform treatment of header edits as document edits;
wenzelm
parents:
44156
diff
changeset
|
281 |
val edits_yxml = |
61376
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
60992
diff
changeset
|
282 |
{ |
93224745477f
output HTML text according to Isabelle/Scala Symbol.Interpretation;
wenzelm
parents:
60992
diff
changeset
|
283 |
import XML.Encode._ |
44383 | 284 |
def id: T[Command] = (cmd => long(cmd.id)) |
46737 | 285 |
def encode_edit(name: Document.Node.Name) |
52849 | 286 |
: 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
|
287 |
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
|
288 |
{ 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
|
289 |
{ case Document.Node.Deps(header) => |
60992 | 290 |
val master_dir = File.standard_url(name.master_dir) |
59695 | 291 |
val imports = header.imports.map({ case (a, _) => a.node }) |
65384 | 292 |
val keywords = |
293 |
header.keywords.map({ case (a, Keyword.Spec(b, c, d)) => (a, ((b, c), d)) }) |
|
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
|
294 |
(Nil, |
65345
2fdd4431b30e
clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents:
65313
diff
changeset
|
295 |
pair(string, pair(string, pair(list(string), pair(list(pair(string, |
2fdd4431b30e
clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents:
65313
diff
changeset
|
296 |
pair(pair(string, list(string)), list(string)))), list(string)))))( |
65445
e9e7f5f5794c
more qualifier treatment, but in the end it is still ignored;
wenzelm
parents:
65439
diff
changeset
|
297 |
(master_dir, (name.theory, (imports, (keywords, header.errors)))))) }, |
52849 | 298 |
{ case Document.Node.Perspective(a, b, c) => |
299 |
(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
|
300 |
list(pair(id, pair(string, list(string))))(c.dest)) })) |
48705
dd32321d6eef
tuned signature -- slightly more abstract text representation of prover process;
wenzelm
parents:
47542
diff
changeset
|
301 |
def encode_edits: T[List[Document.Edit_Command]] = list((node_edit: Document.Edit_Command) => |
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
|
302 |
{ |
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
|
303 |
val (name, edit) = node_edit |
65345
2fdd4431b30e
clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents:
65313
diff
changeset
|
304 |
pair(string, encode_edit(name))(name.node, edit) |
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
|
305 |
}) |
68381
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68336
diff
changeset
|
306 |
Symbol.encode_yxml(encode_edits(edits)) |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68336
diff
changeset
|
307 |
} |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68336
diff
changeset
|
308 |
|
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68336
diff
changeset
|
309 |
val consolidate_yxml = |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68336
diff
changeset
|
310 |
{ |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68336
diff
changeset
|
311 |
import XML.Encode._ |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68336
diff
changeset
|
312 |
Symbol.encode_yxml(list(string)(consolidate.map(_.node))) |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68336
diff
changeset
|
313 |
} |
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68336
diff
changeset
|
314 |
|
68336
09ac56914b29
Document.update includes node consolidation / presentation as regular print operation: avoid user operations on protocol thread;
wenzelm
parents:
68323
diff
changeset
|
315 |
protocol_command( |
68381
2fd3a6d6ba2e
less wasteful consolidation, based on PIDE front-end state and recent changes;
wenzelm
parents:
68336
diff
changeset
|
316 |
"Document.update", Document_ID(old_id), Document_ID(new_id), edits_yxml, consolidate_yxml) |
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
317 |
} |
43748 | 318 |
|
44673 | 319 |
def remove_versions(versions: List[Document.Version]) |
320 |
{ |
|
321 |
val versions_yxml = |
|
59364 | 322 |
{ import XML.Encode._ |
65345
2fdd4431b30e
clarified YXML vs. symbol encoding: operate on whole message;
wenzelm
parents:
65313
diff
changeset
|
323 |
Symbol.encode_yxml(list(long)(versions.map(_.id))) } |
52582 | 324 |
protocol_command("Document.remove_versions", versions_yxml) |
44673 | 325 |
} |
326 |
||
43748 | 327 |
|
50498 | 328 |
/* dialog via document content */ |
329 |
||
52931
ac6648c0c0fb
cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents:
52862
diff
changeset
|
330 |
def dialog_result(serial: Long, result: String): Unit = |
63805 | 331 |
protocol_command("Document.dialog_result", Value.Long(serial), result) |
38412
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
wenzelm
parents:
diff
changeset
|
332 |
} |