author | wenzelm |
Wed, 12 Feb 2014 11:05:48 +0100 | |
changeset 55434 | aa2918d967f0 |
parent 55433 | d2960d67f163 |
child 55548 | a645277885cf |
permissions | -rw-r--r-- |
36676 | 1 |
/* Title: Pure/PIDE/command.scala |
2 |
Author: Fabian Immler, TU Munich |
|
3 |
Author: Makarius |
|
4 |
||
52536 | 5 |
Prover commands with accumulated results from execution. |
36676 | 6 |
*/ |
34407 | 7 |
|
34871
e596a0b71f3c
incorporate "proofdocument" part into main Isabelle/Pure.jar -- except for html_panel.scala, which depends on external library (Lobo/Cobra browser);
wenzelm
parents:
34865
diff
changeset
|
8 |
package isabelle |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
9 |
|
34451 | 10 |
|
45644 | 11 |
import scala.collection.mutable |
38872 | 12 |
import scala.collection.immutable.SortedMap |
13 |
||
14 |
||
34637 | 15 |
object Command |
16 |
{ |
|
52849 | 17 |
type Edit = (Option[Command], Option[Command]) |
18 |
||
19 |
||
38361 | 20 |
/** accumulated results from prover **/ |
21 |
||
50507 | 22 |
/* results */ |
23 |
||
24 |
object Results |
|
25 |
{ |
|
51496
cb677987b7e3
retain original tooltip range, to avoid repeated window popup when the mouse is moved over the same content;
wenzelm
parents:
51494
diff
changeset
|
26 |
type Entry = (Long, XML.Tree) |
50507 | 27 |
val empty = new Results(SortedMap.empty) |
51496
cb677987b7e3
retain original tooltip range, to avoid repeated window popup when the mouse is moved over the same content;
wenzelm
parents:
51494
diff
changeset
|
28 |
def make(es: Iterable[Results.Entry]): Results = (empty /: es.iterator)(_ + _) |
50507 | 29 |
def merge(rs: Iterable[Results]): Results = (empty /: rs.iterator)(_ ++ _) |
30 |
} |
|
31 |
||
51494 | 32 |
final class Results private(private val rep: SortedMap[Long, XML.Tree]) |
50507 | 33 |
{ |
34 |
def defined(serial: Long): Boolean = rep.isDefinedAt(serial) |
|
35 |
def get(serial: Long): Option[XML.Tree] = rep.get(serial) |
|
51496
cb677987b7e3
retain original tooltip range, to avoid repeated window popup when the mouse is moved over the same content;
wenzelm
parents:
51494
diff
changeset
|
36 |
def entries: Iterator[Results.Entry] = rep.iterator |
50508
5b7150395568
tuned implementation according to Library.insert/merge in ML;
wenzelm
parents:
50507
diff
changeset
|
37 |
|
51496
cb677987b7e3
retain original tooltip range, to avoid repeated window popup when the mouse is moved over the same content;
wenzelm
parents:
51494
diff
changeset
|
38 |
def + (entry: Results.Entry): Results = |
50508
5b7150395568
tuned implementation according to Library.insert/merge in ML;
wenzelm
parents:
50507
diff
changeset
|
39 |
if (defined(entry._1)) this |
5b7150395568
tuned implementation according to Library.insert/merge in ML;
wenzelm
parents:
50507
diff
changeset
|
40 |
else new Results(rep + entry) |
5b7150395568
tuned implementation according to Library.insert/merge in ML;
wenzelm
parents:
50507
diff
changeset
|
41 |
|
5b7150395568
tuned implementation according to Library.insert/merge in ML;
wenzelm
parents:
50507
diff
changeset
|
42 |
def ++ (other: Results): Results = |
5b7150395568
tuned implementation according to Library.insert/merge in ML;
wenzelm
parents:
50507
diff
changeset
|
43 |
if (this eq other) this |
5b7150395568
tuned implementation according to Library.insert/merge in ML;
wenzelm
parents:
50507
diff
changeset
|
44 |
else if (rep.isEmpty) other |
5b7150395568
tuned implementation according to Library.insert/merge in ML;
wenzelm
parents:
50507
diff
changeset
|
45 |
else (this /: other.entries)(_ + _) |
50540 | 46 |
|
51494 | 47 |
override def hashCode: Int = rep.hashCode |
48 |
override def equals(that: Any): Boolean = |
|
49 |
that match { |
|
50 |
case other: Results => rep == other.rep |
|
51 |
case _ => false |
|
52 |
} |
|
50540 | 53 |
override def toString: String = entries.mkString("Results(", ", ", ")") |
50507 | 54 |
} |
55 |
||
56 |
||
57 |
/* state */ |
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50500
diff
changeset
|
58 |
|
43714 | 59 |
sealed case class State( |
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50500
diff
changeset
|
60 |
command: Command, |
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50500
diff
changeset
|
61 |
status: List[Markup] = Nil, |
50507 | 62 |
results: Results = Results.empty, |
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
63 |
markups: Map[String, Markup_Tree] = Map.empty) |
38361 | 64 |
{ |
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
65 |
def get_markup(file_name: String): Markup_Tree = |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
66 |
markups.getOrElse(file_name, Markup_Tree.empty) |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
67 |
|
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
68 |
def markup: Markup_Tree = get_markup("") |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
69 |
|
49645 | 70 |
def markup_to_XML(filter: XML.Elem => Boolean): XML.Body = |
71 |
markup.to_XML(command.range, command.source, filter) |
|
49614 | 72 |
|
73 |
||
51494 | 74 |
/* content */ |
75 |
||
76 |
def eq_content(other: State): Boolean = |
|
77 |
command.source == other.command.source && |
|
78 |
status == other.status && |
|
79 |
results == other.results && |
|
55434 | 80 |
markups == other.markups |
38361 | 81 |
|
46152
793cecd4ffc0
accumulate status as regular markup for command range;
wenzelm
parents:
45709
diff
changeset
|
82 |
private def add_status(st: Markup): State = copy(status = st :: status) |
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
83 |
|
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
84 |
private def add_markup(file_name: String, m: Text.Markup): State = |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
85 |
copy(markups = markups + (file_name -> (get_markup(file_name) + m))) |
38361 | 86 |
|
52531 | 87 |
def + (alt_id: Document_ID.Generic, message: XML.Elem): State = |
38361 | 88 |
message match { |
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
50163
diff
changeset
|
89 |
case XML.Elem(Markup(Markup.STATUS, _), msgs) => |
38714 | 90 |
(this /: msgs)((state, msg) => |
91 |
msg match { |
|
46152
793cecd4ffc0
accumulate status as regular markup for command range;
wenzelm
parents:
45709
diff
changeset
|
92 |
case elem @ XML.Elem(markup, Nil) => |
50499
f496b2b7bafb
rendering of selected dialog_result as active_result_color, depending on dynamic command status in output panel, but not static popups etc.;
wenzelm
parents:
50201
diff
changeset
|
93 |
state.add_status(markup) |
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
94 |
.add_markup("", Text.Info(command.proper_range, elem)) // FIXME cumulation order!? |
46152
793cecd4ffc0
accumulate status as regular markup for command range;
wenzelm
parents:
45709
diff
changeset
|
95 |
|
52536 | 96 |
case _ => |
97 |
java.lang.System.err.println("Ignored status message: " + msg) |
|
98 |
state |
|
38714 | 99 |
}) |
38581
d503a0912e14
simplified Command.status again, reverting most of e5eed57913d0 (note that more complex information can be represented with full markup reports);
wenzelm
parents:
38579
diff
changeset
|
100 |
|
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
50163
diff
changeset
|
101 |
case XML.Elem(Markup(Markup.REPORT, _), msgs) => |
38572
0fe2c01ef7da
Command.State: accumulate markup reports uniformly;
wenzelm
parents:
38564
diff
changeset
|
102 |
(this /: msgs)((state, msg) => |
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
103 |
{ |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
104 |
def bad(): Unit = java.lang.System.err.println("Ignored report message: " + msg) |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
105 |
|
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
106 |
msg match { |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
107 |
case XML.Elem(Markup(name, atts @ Position.Reported(id, file_name, raw_range)), args) |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
108 |
if id == command.id || id == alt_id => |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
109 |
command.chunks.get(file_name) match { |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
110 |
case Some(chunk) => |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
111 |
val range = chunk.decode(raw_range) |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
112 |
if (chunk.range.contains(range)) { |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
113 |
val props = Position.purge(atts) |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
114 |
val info: Text.Markup = Text.Info(range, XML.Elem(Markup(name, props), args)) |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
115 |
state.add_markup(file_name, info) |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
116 |
} |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
117 |
else { |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
118 |
bad() |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
119 |
state |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
120 |
} |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
121 |
case None => |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
122 |
bad() |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
123 |
state |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
124 |
} |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
125 |
|
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
126 |
case XML.Elem(Markup(name, atts), args) |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
127 |
if !atts.exists({ case (a, _) => Markup.POSITION_PROPERTIES(a) }) => |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
128 |
val range = command.proper_range |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
129 |
val props = Position.purge(atts) |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
130 |
val info: Text.Markup = Text.Info(range, XML.Elem(Markup(name, props), args)) |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
131 |
state.add_markup("", info) |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
132 |
|
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
133 |
case _ => |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
134 |
// FIXME bad() |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
135 |
state |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
136 |
} |
38361 | 137 |
}) |
52930
5fab62ae3532
retain original messages properties, e.g. for retrieval via Command.Results;
wenzelm
parents:
52849
diff
changeset
|
138 |
case XML.Elem(Markup(name, props), body) => |
5fab62ae3532
retain original messages properties, e.g. for retrieval via Command.Results;
wenzelm
parents:
52849
diff
changeset
|
139 |
props match { |
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
50163
diff
changeset
|
140 |
case Markup.Serial(i) => |
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
50163
diff
changeset
|
141 |
val message1 = XML.Elem(Markup(Markup.message(name), props), body) |
50163
c62ce309dc26
more abstract Sendback operations, with explicit id/exec_id properties;
wenzelm
parents:
50158
diff
changeset
|
142 |
val message2 = XML.Elem(Markup(name, props), body) |
c62ce309dc26
more abstract Sendback operations, with explicit id/exec_id properties;
wenzelm
parents:
50158
diff
changeset
|
143 |
|
55433
d2960d67f163
clarified message_positions: cover alt_id as well;
wenzelm
parents:
55432
diff
changeset
|
144 |
var st = copy(results = results + (i -> message1)) |
d2960d67f163
clarified message_positions: cover alt_id as well;
wenzelm
parents:
55432
diff
changeset
|
145 |
if (Protocol.is_inlined(message)) { |
d2960d67f163
clarified message_positions: cover alt_id as well;
wenzelm
parents:
55432
diff
changeset
|
146 |
for { |
d2960d67f163
clarified message_positions: cover alt_id as well;
wenzelm
parents:
55432
diff
changeset
|
147 |
(file_name, chunk) <- command.chunks |
d2960d67f163
clarified message_positions: cover alt_id as well;
wenzelm
parents:
55432
diff
changeset
|
148 |
range <- Protocol.message_positions(command.id, alt_id, chunk, message) |
d2960d67f163
clarified message_positions: cover alt_id as well;
wenzelm
parents:
55432
diff
changeset
|
149 |
} st = st.add_markup(file_name, Text.Info(range, message2)) |
d2960d67f163
clarified message_positions: cover alt_id as well;
wenzelm
parents:
55432
diff
changeset
|
150 |
} |
d2960d67f163
clarified message_positions: cover alt_id as well;
wenzelm
parents:
55432
diff
changeset
|
151 |
st |
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
152 |
|
52536 | 153 |
case _ => |
154 |
java.lang.System.err.println("Ignored message without serial number: " + message) |
|
155 |
this |
|
38872 | 156 |
} |
38361 | 157 |
} |
52527
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52524
diff
changeset
|
158 |
|
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52524
diff
changeset
|
159 |
def ++ (other: State): State = |
52642
84eb792224a8
full merge of Command.State, which enables Command.prints to augment markup as well (assuming that these dynamic overlays are relatively few);
wenzelm
parents:
52536
diff
changeset
|
160 |
copy( |
84eb792224a8
full merge of Command.State, which enables Command.prints to augment markup as well (assuming that these dynamic overlays are relatively few);
wenzelm
parents:
52536
diff
changeset
|
161 |
status = other.status ::: status, |
84eb792224a8
full merge of Command.State, which enables Command.prints to augment markup as well (assuming that these dynamic overlays are relatively few);
wenzelm
parents:
52536
diff
changeset
|
162 |
results = results ++ other.results, |
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
163 |
markups = |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
164 |
(markups.keySet ++ other.markups.keySet) |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
165 |
.map(a => a -> (get_markup(a) ++ other.get_markup(a))).toMap |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
166 |
) |
38361 | 167 |
} |
38367 | 168 |
|
169 |
||
55431
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
170 |
|
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
171 |
/** static content **/ |
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
172 |
|
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
173 |
/* text chunks */ |
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
174 |
|
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
175 |
abstract class Chunk |
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
176 |
{ |
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
177 |
def file_name: String |
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
178 |
def length: Int |
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
179 |
def range: Text.Range |
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
180 |
def decode(r: Text.Range): Text.Range |
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
181 |
} |
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
182 |
|
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
183 |
class File(val file_name: String, text: CharSequence) extends Chunk |
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
184 |
{ |
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
185 |
val length = text.length |
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
186 |
val range = Text.Range(0, length) |
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
187 |
private val symbol_index = Symbol.Index(text) |
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
188 |
def decode(r: Text.Range): Text.Range = symbol_index.decode(r) |
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
189 |
} |
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
190 |
|
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
191 |
|
45644 | 192 |
/* make commands */ |
193 |
||
54462 | 194 |
def name(span: List[Token]): String = |
195 |
span.find(_.is_command) match { case Some(tok) => tok.source case _ => "" } |
|
48745 | 196 |
|
55431
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
197 |
type Blob = Exn.Result[(Document.Node.Name, Option[(SHA1.Digest, File)])] |
54513 | 198 |
|
52524 | 199 |
def apply( |
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
200 |
id: Document_ID.Command, |
52524 | 201 |
node_name: Document.Node.Name, |
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54517
diff
changeset
|
202 |
blobs: List[Blob], |
54462 | 203 |
span: List[Token], |
52524 | 204 |
results: Results = Results.empty, |
205 |
markup: Markup_Tree = Markup_Tree.empty): Command = |
|
45644 | 206 |
{ |
207 |
val source: String = |
|
48745 | 208 |
span match { |
45644 | 209 |
case List(tok) => tok.source |
48745 | 210 |
case _ => span.map(_.source).mkString |
45644 | 211 |
} |
212 |
||
48745 | 213 |
val span1 = new mutable.ListBuffer[Token] |
45644 | 214 |
var i = 0 |
48745 | 215 |
for (Token(kind, s) <- span) { |
45644 | 216 |
val n = s.length |
217 |
val s1 = source.substring(i, i + n) |
|
48745 | 218 |
span1 += Token(kind, s1) |
45644 | 219 |
i += n |
220 |
} |
|
221 |
||
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54517
diff
changeset
|
222 |
new Command(id, node_name, blobs, span1.toList, source, results, markup) |
45644 | 223 |
} |
224 |
||
54513 | 225 |
val empty = Command(Document_ID.none, Document.Node.Name.empty, Nil, Nil) |
49414 | 226 |
|
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
227 |
def unparsed(id: Document_ID.Command, source: String, results: Results, markup: Markup_Tree) |
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50500
diff
changeset
|
228 |
: Command = |
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54517
diff
changeset
|
229 |
Command(id, Document.Node.Name.empty, Nil, List(Token(Token.Kind.UNPARSED, source)), |
54462 | 230 |
results, markup) |
49414 | 231 |
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50500
diff
changeset
|
232 |
def unparsed(source: String): Command = |
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
233 |
unparsed(Document_ID.none, source, Results.empty, Markup_Tree.empty) |
44384 | 234 |
|
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
235 |
def rich_text(id: Document_ID.Command, results: Results, body: XML.Body): Command = |
49414 | 236 |
{ |
49466 | 237 |
val text = XML.content(body) |
238 |
val markup = Markup_Tree.from_XML(body) |
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50500
diff
changeset
|
239 |
unparsed(id, text, results, markup) |
49414 | 240 |
} |
49359
c1262d7389fb
refined output panel: more value-oriented approach to update and caret focus;
wenzelm
parents:
49037
diff
changeset
|
241 |
|
44384 | 242 |
|
243 |
/* perspective */ |
|
244 |
||
44474 | 245 |
object Perspective |
246 |
{ |
|
247 |
val empty: Perspective = Perspective(Nil) |
|
248 |
} |
|
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44384
diff
changeset
|
249 |
|
44474 | 250 |
sealed case class Perspective(commands: List[Command]) // visible commands in canonical order |
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44384
diff
changeset
|
251 |
{ |
44474 | 252 |
def same(that: Perspective): Boolean = |
253 |
{ |
|
254 |
val cmds1 = this.commands |
|
255 |
val cmds2 = that.commands |
|
48754
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
wenzelm
parents:
48745
diff
changeset
|
256 |
require(!cmds1.exists(_.is_undefined)) |
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
wenzelm
parents:
48745
diff
changeset
|
257 |
require(!cmds2.exists(_.is_undefined)) |
44474 | 258 |
cmds1.length == cmds2.length && |
259 |
(cmds1.iterator zip cmds2.iterator).forall({ case (c1, c2) => c1.id == c2.id }) |
|
260 |
} |
|
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44384
diff
changeset
|
261 |
} |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
262 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
263 |
|
38361 | 264 |
|
46712 | 265 |
final class Command private( |
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
266 |
val id: Document_ID.Command, |
44615 | 267 |
val node_name: Document.Node.Name, |
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54517
diff
changeset
|
268 |
val blobs: List[Command.Blob], |
52535
b7badd371e4d
tuned signature -- eliminated pointless type synonym;
wenzelm
parents:
52531
diff
changeset
|
269 |
val span: List[Token], |
49414 | 270 |
val source: String, |
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50500
diff
changeset
|
271 |
val init_results: Command.Results, |
49414 | 272 |
val init_markup: Markup_Tree) |
55431
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
273 |
extends Command.Chunk |
34451 | 274 |
{ |
34859 | 275 |
/* classification */ |
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
276 |
|
52530
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
wenzelm
parents:
52527
diff
changeset
|
277 |
def is_undefined: Boolean = id == Document_ID.none |
48754
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
wenzelm
parents:
48745
diff
changeset
|
278 |
val is_unparsed: Boolean = span.exists(_.is_unparsed) |
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
wenzelm
parents:
48745
diff
changeset
|
279 |
val is_unfinished: Boolean = span.exists(_.is_unfinished) |
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44384
diff
changeset
|
280 |
|
48599 | 281 |
val is_ignored: Boolean = !span.exists(_.is_proper) |
48754
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
wenzelm
parents:
48745
diff
changeset
|
282 |
val is_malformed: Boolean = !is_ignored && (!span.head.is_command || span.exists(_.is_error)) |
47012
0e246130486b
clarified command span classification: strict Command.is_command, permissive Command.name;
wenzelm
parents:
46910
diff
changeset
|
283 |
def is_command: Boolean = !is_ignored && !is_malformed |
34859 | 284 |
|
54462 | 285 |
def name: String = Command.name(span) |
47012
0e246130486b
clarified command span classification: strict Command.is_command, permissive Command.name;
wenzelm
parents:
46910
diff
changeset
|
286 |
|
37129 | 287 |
override def toString = |
37373
25078ba44436
tuned Command.toString -- preserving uniqueness allows the Scala toplevel to print Linear_Set[Command] results without crashing;
wenzelm
parents:
37197
diff
changeset
|
288 |
id + "/" + (if (is_command) name else if (is_ignored) "IGNORED" else "MALFORMED") |
34495 | 289 |
|
34859 | 290 |
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54517
diff
changeset
|
291 |
/* blobs */ |
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54517
diff
changeset
|
292 |
|
54530
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54524
diff
changeset
|
293 |
def blobs_names: List[Document.Node.Name] = |
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54524
diff
changeset
|
294 |
for (Exn.Res((name, _)) <- blobs) yield name |
2c1440f70028
ranges of thy_load commands count as visible within perspective;
wenzelm
parents:
54524
diff
changeset
|
295 |
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54517
diff
changeset
|
296 |
def blobs_digests: List[SHA1.Digest] = |
55431
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
297 |
for (Exn.Res((_, Some((digest, _)))) <- blobs) yield digest |
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54517
diff
changeset
|
298 |
|
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
299 |
val chunks: Map[String, Command.Chunk] = |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
300 |
(("" -> this) :: |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
301 |
(for (Exn.Res((name, Some((_, file)))) <- blobs) yield (name.node -> file))).toMap |
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
302 |
|
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54517
diff
changeset
|
303 |
|
52509 | 304 |
/* source */ |
34451 | 305 |
|
55431
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
306 |
def file_name: String = "" |
e0f20a44ff9d
common Command.Chunk for command source and auxiliary files (static Symbol.Index without actual String content);
wenzelm
parents:
55430
diff
changeset
|
307 |
|
46813 | 308 |
def length: Int = source.length |
309 |
val range: Text.Range = Text.Range(0, length) |
|
310 |
||
311 |
val proper_range: Text.Range = |
|
51048
123be08eed88
clarified notion of Command.proper_range (according to Token.is_proper), especially relevant for Active.try_replace_command, to avoid loosing subsequent comments accidentally;
wenzelm
parents:
50540
diff
changeset
|
312 |
Text.Range(0, (length /: span.reverse.iterator.takeWhile(_.is_improper))(_ - _.source.length)) |
46813 | 313 |
|
38426 | 314 |
def source(range: Text.Range): String = source.substring(range.start, range.stop) |
38572
0fe2c01ef7da
Command.State: accumulate markup reports uniformly;
wenzelm
parents:
38564
diff
changeset
|
315 |
|
55430 | 316 |
private lazy val symbol_index = Symbol.Index(source) |
38579 | 317 |
def decode(i: Text.Offset): Text.Offset = symbol_index.decode(i) |
318 |
def decode(r: Text.Range): Text.Range = symbol_index.decode(r) |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
319 |
|
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
320 |
|
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
321 |
/* accumulated results */ |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
322 |
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50500
diff
changeset
|
323 |
val init_state: Command.State = |
55432
9c53198dbb1c
maintain multiple command chunks and markup trees: for main chunk and loaded files;
wenzelm
parents:
55431
diff
changeset
|
324 |
Command.State(this, results = init_results, markups = Map("" -> init_markup)) |
52527
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52524
diff
changeset
|
325 |
|
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
wenzelm
parents:
52524
diff
changeset
|
326 |
val empty_state: Command.State = Command.State(this) |
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
327 |
} |