| author | traytel | 
| Thu, 25 Jul 2013 16:46:53 +0200 | |
| changeset 52731 | dacd47a0633f | 
| parent 52642 | 84eb792224a8 | 
| child 52849 | 199e9fa5a5c2 | 
| 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  | 
{
 | 
|
| 38361 | 17  | 
/** accumulated results from prover **/  | 
18  | 
||
| 50507 | 19  | 
/* results */  | 
20  | 
||
21  | 
object Results  | 
|
22  | 
  {
 | 
|
| 
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
 | 
23  | 
type Entry = (Long, XML.Tree)  | 
| 50507 | 24  | 
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
 | 
25  | 
def make(es: Iterable[Results.Entry]): Results = (empty /: es.iterator)(_ + _)  | 
| 50507 | 26  | 
def merge(rs: Iterable[Results]): Results = (empty /: rs.iterator)(_ ++ _)  | 
27  | 
}  | 
|
28  | 
||
| 51494 | 29  | 
final class Results private(private val rep: SortedMap[Long, XML.Tree])  | 
| 50507 | 30  | 
  {
 | 
31  | 
def defined(serial: Long): Boolean = rep.isDefinedAt(serial)  | 
|
32  | 
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
 | 
33  | 
def entries: Iterator[Results.Entry] = rep.iterator  | 
| 
50508
 
5b7150395568
tuned implementation according to Library.insert/merge in ML;
 
wenzelm 
parents: 
50507 
diff
changeset
 | 
34  | 
|
| 
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
 | 
35  | 
def + (entry: Results.Entry): Results =  | 
| 
50508
 
5b7150395568
tuned implementation according to Library.insert/merge in ML;
 
wenzelm 
parents: 
50507 
diff
changeset
 | 
36  | 
if (defined(entry._1)) this  | 
| 
 
5b7150395568
tuned implementation according to Library.insert/merge in ML;
 
wenzelm 
parents: 
50507 
diff
changeset
 | 
37  | 
else new Results(rep + entry)  | 
| 
 
5b7150395568
tuned implementation according to Library.insert/merge in ML;
 
wenzelm 
parents: 
50507 
diff
changeset
 | 
38  | 
|
| 
 
5b7150395568
tuned implementation according to Library.insert/merge in ML;
 
wenzelm 
parents: 
50507 
diff
changeset
 | 
39  | 
def ++ (other: Results): Results =  | 
| 
 
5b7150395568
tuned implementation according to Library.insert/merge in ML;
 
wenzelm 
parents: 
50507 
diff
changeset
 | 
40  | 
if (this eq other) this  | 
| 
 
5b7150395568
tuned implementation according to Library.insert/merge in ML;
 
wenzelm 
parents: 
50507 
diff
changeset
 | 
41  | 
else if (rep.isEmpty) other  | 
| 
 
5b7150395568
tuned implementation according to Library.insert/merge in ML;
 
wenzelm 
parents: 
50507 
diff
changeset
 | 
42  | 
else (this /: other.entries)(_ + _)  | 
| 50540 | 43  | 
|
| 51494 | 44  | 
override def hashCode: Int = rep.hashCode  | 
45  | 
override def equals(that: Any): Boolean =  | 
|
46  | 
      that match {
 | 
|
47  | 
case other: Results => rep == other.rep  | 
|
48  | 
case _ => false  | 
|
49  | 
}  | 
|
| 50540 | 50  | 
    override def toString: String = entries.mkString("Results(", ", ", ")")
 | 
| 50507 | 51  | 
}  | 
52  | 
||
53  | 
||
54  | 
/* state */  | 
|
| 
50501
 
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
 
wenzelm 
parents: 
50500 
diff
changeset
 | 
55  | 
|
| 43714 | 56  | 
sealed case class State(  | 
| 
50501
 
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
 
wenzelm 
parents: 
50500 
diff
changeset
 | 
57  | 
command: Command,  | 
| 
 
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
 
wenzelm 
parents: 
50500 
diff
changeset
 | 
58  | 
status: List[Markup] = Nil,  | 
| 50507 | 59  | 
results: Results = Results.empty,  | 
| 
50501
 
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
 
wenzelm 
parents: 
50500 
diff
changeset
 | 
60  | 
markup: Markup_Tree = Markup_Tree.empty)  | 
| 38361 | 61  | 
  {
 | 
| 49645 | 62  | 
def markup_to_XML(filter: XML.Elem => Boolean): XML.Body =  | 
63  | 
markup.to_XML(command.range, command.source, filter)  | 
|
| 49614 | 64  | 
|
65  | 
||
| 51494 | 66  | 
/* content */  | 
67  | 
||
68  | 
def eq_content(other: State): Boolean =  | 
|
69  | 
command.source == other.command.source &&  | 
|
70  | 
status == other.status &&  | 
|
71  | 
results == other.results &&  | 
|
72  | 
markup == other.markup  | 
|
| 38361 | 73  | 
|
| 
46152
 
793cecd4ffc0
accumulate status as regular markup for command range;
 
wenzelm 
parents: 
45709 
diff
changeset
 | 
74  | 
private def add_status(st: Markup): State = copy(status = st :: status)  | 
| 
 
793cecd4ffc0
accumulate status as regular markup for command range;
 
wenzelm 
parents: 
45709 
diff
changeset
 | 
75  | 
private def add_markup(m: Text.Markup): State = copy(markup = markup + m)  | 
| 38361 | 76  | 
|
| 52531 | 77  | 
def + (alt_id: Document_ID.Generic, message: XML.Elem): State =  | 
| 38361 | 78  | 
      message match {
 | 
| 
50201
 
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
 
wenzelm 
parents: 
50163 
diff
changeset
 | 
79  | 
case XML.Elem(Markup(Markup.STATUS, _), msgs) =>  | 
| 38714 | 80  | 
(this /: msgs)((state, msg) =>  | 
81  | 
            msg match {
 | 
|
| 
46152
 
793cecd4ffc0
accumulate status as regular markup for command range;
 
wenzelm 
parents: 
45709 
diff
changeset
 | 
82  | 
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
 | 
83  | 
state.add_status(markup)  | 
| 
 
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
 | 
84  | 
.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
 | 
85  | 
|
| 52536 | 86  | 
case _ =>  | 
87  | 
                java.lang.System.err.println("Ignored status message: " + msg)
 | 
|
88  | 
state  | 
|
| 38714 | 89  | 
})  | 
| 
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
 | 
90  | 
|
| 
50201
 
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
 
wenzelm 
parents: 
50163 
diff
changeset
 | 
91  | 
case XML.Elem(Markup(Markup.REPORT, _), msgs) =>  | 
| 
38572
 
0fe2c01ef7da
Command.State: accumulate markup reports uniformly;
 
wenzelm 
parents: 
38564 
diff
changeset
 | 
92  | 
(this /: msgs)((state, msg) =>  | 
| 
 
0fe2c01ef7da
Command.State: accumulate markup reports uniformly;
 
wenzelm 
parents: 
38564 
diff
changeset
 | 
93  | 
            msg match {
 | 
| 
39173
 
ed3946086358
Command.State.accumulate: check actual source range;
 
wenzelm 
parents: 
39172 
diff
changeset
 | 
94  | 
case XML.Elem(Markup(name, atts @ Position.Id_Range(id, raw_range)), args)  | 
| 49527 | 95  | 
if (id == command.id || id == alt_id) &&  | 
96  | 
command.range.contains(command.decode(raw_range)) =>  | 
|
| 
39173
 
ed3946086358
Command.State.accumulate: check actual source range;
 
wenzelm 
parents: 
39172 
diff
changeset
 | 
97  | 
val range = command.decode(raw_range)  | 
| 38872 | 98  | 
val props = Position.purge(atts)  | 
| 45455 | 99  | 
val info: Text.Markup = Text.Info(range, XML.Elem(Markup(name, props), args))  | 
| 38723 | 100  | 
state.add_markup(info)  | 
| 
49526
 
6d1465c00f2e
more restrictive pattern, to avoid malformed positions intruding the command range (cf. d7a1973b063c);
 
wenzelm 
parents: 
49493 
diff
changeset
 | 
101  | 
case XML.Elem(Markup(name, atts), args)  | 
| 
50201
 
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
 
wenzelm 
parents: 
50163 
diff
changeset
 | 
102  | 
              if !atts.exists({ case (a, _) => Markup.POSITION_PROPERTIES(a) }) =>
 | 
| 
49037
 
d7a1973b063c
more markup for failed goal forks, reusing "bad";
 
wenzelm 
parents: 
48922 
diff
changeset
 | 
103  | 
val range = command.proper_range  | 
| 
 
d7a1973b063c
more markup for failed goal forks, reusing "bad";
 
wenzelm 
parents: 
48922 
diff
changeset
 | 
104  | 
val props = Position.purge(atts)  | 
| 
 
d7a1973b063c
more markup for failed goal forks, reusing "bad";
 
wenzelm 
parents: 
48922 
diff
changeset
 | 
105  | 
val info: Text.Markup = Text.Info(range, XML.Elem(Markup(name, props), args))  | 
| 
 
d7a1973b063c
more markup for failed goal forks, reusing "bad";
 
wenzelm 
parents: 
48922 
diff
changeset
 | 
106  | 
state.add_markup(info)  | 
| 40572 | 107  | 
case _ =>  | 
| 52536 | 108  | 
                // FIXME java.lang.System.err.println("Ignored report message: " + msg)
 | 
| 40572 | 109  | 
state  | 
| 38361 | 110  | 
})  | 
| 38872 | 111  | 
case XML.Elem(Markup(name, atts), body) =>  | 
112  | 
          atts match {
 | 
|
| 
50201
 
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
 
wenzelm 
parents: 
50163 
diff
changeset
 | 
113  | 
case Markup.Serial(i) =>  | 
| 
50163
 
c62ce309dc26
more abstract Sendback operations, with explicit id/exec_id properties;
 
wenzelm 
parents: 
50158 
diff
changeset
 | 
114  | 
val props = Position.purge(atts)  | 
| 
50201
 
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
 
wenzelm 
parents: 
50163 
diff
changeset
 | 
115  | 
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
 | 
116  | 
val message2 = XML.Elem(Markup(name, props), body)  | 
| 
 
c62ce309dc26
more abstract Sendback operations, with explicit id/exec_id properties;
 
wenzelm 
parents: 
50158 
diff
changeset
 | 
117  | 
|
| 
 
c62ce309dc26
more abstract Sendback operations, with explicit id/exec_id properties;
 
wenzelm 
parents: 
50158 
diff
changeset
 | 
118  | 
val st0 = copy(results = results + (i -> message1))  | 
| 
39441
 
4110cc1b8f9f
allow embedded reports in regular prover messages, to avoid side-effects for errors for example;
 
wenzelm 
parents: 
39173 
diff
changeset
 | 
119  | 
val st1 =  | 
| 
50500
 
c94bba7906d2
identify dialogs via official serial and maintain as result message;
 
wenzelm 
parents: 
50499 
diff
changeset
 | 
120  | 
if (Protocol.is_inlined(message))  | 
| 
45709
 
87017fcbad83
clarified modules (again) -- NB: both Document and Protocol are specific to this particular prover;
 
wenzelm 
parents: 
45672 
diff
changeset
 | 
121  | 
(st0 /: Protocol.message_positions(command, message))(  | 
| 
50163
 
c62ce309dc26
more abstract Sendback operations, with explicit id/exec_id properties;
 
wenzelm 
parents: 
50158 
diff
changeset
 | 
122  | 
(st, range) => st.add_markup(Text.Info(range, message2)))  | 
| 
50500
 
c94bba7906d2
identify dialogs via official serial and maintain as result message;
 
wenzelm 
parents: 
50499 
diff
changeset
 | 
123  | 
else st0  | 
| 
49445
 
638cefe3ee99
earlier treatment of embedded report/no_report messages (see also 4110cc1b8f9f);
 
wenzelm 
parents: 
49418 
diff
changeset
 | 
124  | 
|
| 
 
638cefe3ee99
earlier treatment of embedded report/no_report messages (see also 4110cc1b8f9f);
 
wenzelm 
parents: 
49418 
diff
changeset
 | 
125  | 
st1  | 
| 52536 | 126  | 
case _ =>  | 
127  | 
              java.lang.System.err.println("Ignored message without serial number: " + message)
 | 
|
128  | 
this  | 
|
| 38872 | 129  | 
}  | 
| 38361 | 130  | 
}  | 
| 
52527
 
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
 
wenzelm 
parents: 
52524 
diff
changeset
 | 
131  | 
|
| 
 
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
 
wenzelm 
parents: 
52524 
diff
changeset
 | 
132  | 
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
 | 
133  | 
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
 | 
134  | 
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
 | 
135  | 
results = results ++ other.results,  | 
| 
 
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
 | 
136  | 
markup = markup ++ other.markup)  | 
| 38361 | 137  | 
}  | 
| 38367 | 138  | 
|
139  | 
||
| 45644 | 140  | 
/* make commands */  | 
141  | 
||
| 48745 | 142  | 
type Span = List[Token]  | 
143  | 
||
| 52524 | 144  | 
def apply(  | 
| 
52530
 
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
 
wenzelm 
parents: 
52527 
diff
changeset
 | 
145  | 
id: Document_ID.Command,  | 
| 52524 | 146  | 
node_name: Document.Node.Name,  | 
147  | 
span: Span,  | 
|
148  | 
results: Results = Results.empty,  | 
|
149  | 
markup: Markup_Tree = Markup_Tree.empty): Command =  | 
|
| 45644 | 150  | 
  {
 | 
151  | 
val source: String =  | 
|
| 48745 | 152  | 
      span match {
 | 
| 45644 | 153  | 
case List(tok) => tok.source  | 
| 48745 | 154  | 
case _ => span.map(_.source).mkString  | 
| 45644 | 155  | 
}  | 
156  | 
||
| 48745 | 157  | 
val span1 = new mutable.ListBuffer[Token]  | 
| 45644 | 158  | 
var i = 0  | 
| 48745 | 159  | 
    for (Token(kind, s) <- span) {
 | 
| 45644 | 160  | 
val n = s.length  | 
161  | 
val s1 = source.substring(i, i + n)  | 
|
| 48745 | 162  | 
span1 += Token(kind, s1)  | 
| 45644 | 163  | 
i += n  | 
164  | 
}  | 
|
165  | 
||
| 
50501
 
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
 
wenzelm 
parents: 
50500 
diff
changeset
 | 
166  | 
new Command(id, node_name, span1.toList, source, results, markup)  | 
| 45644 | 167  | 
}  | 
168  | 
||
| 
52530
 
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
 
wenzelm 
parents: 
52527 
diff
changeset
 | 
169  | 
val empty = Command(Document_ID.none, Document.Node.Name.empty, Nil)  | 
| 49414 | 170  | 
|
| 
52530
 
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
 
wenzelm 
parents: 
52527 
diff
changeset
 | 
171  | 
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
 | 
172  | 
: Command =  | 
| 
 
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
 
wenzelm 
parents: 
50500 
diff
changeset
 | 
173  | 
Command(id, Document.Node.Name.empty, List(Token(Token.Kind.UNPARSED, source)), results, markup)  | 
| 49414 | 174  | 
|
| 
50501
 
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
 
wenzelm 
parents: 
50500 
diff
changeset
 | 
175  | 
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
 | 
176  | 
unparsed(Document_ID.none, source, Results.empty, Markup_Tree.empty)  | 
| 44384 | 177  | 
|
| 
52530
 
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
 
wenzelm 
parents: 
52527 
diff
changeset
 | 
178  | 
def rich_text(id: Document_ID.Command, results: Results, body: XML.Body): Command =  | 
| 49414 | 179  | 
  {
 | 
| 49466 | 180  | 
val text = XML.content(body)  | 
181  | 
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
 | 
182  | 
unparsed(id, text, results, markup)  | 
| 49414 | 183  | 
}  | 
| 
49359
 
c1262d7389fb
refined output panel: more value-oriented approach to update and caret focus;
 
wenzelm 
parents: 
49037 
diff
changeset
 | 
184  | 
|
| 44384 | 185  | 
|
186  | 
/* perspective */  | 
|
187  | 
||
| 44474 | 188  | 
object Perspective  | 
189  | 
  {
 | 
|
190  | 
val empty: Perspective = Perspective(Nil)  | 
|
191  | 
}  | 
|
| 
44385
 
e7fdb008aa7d
propagate editor perspective through document model;
 
wenzelm 
parents: 
44384 
diff
changeset
 | 
192  | 
|
| 44474 | 193  | 
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
 | 
194  | 
  {
 | 
| 44474 | 195  | 
def same(that: Perspective): Boolean =  | 
196  | 
    {
 | 
|
197  | 
val cmds1 = this.commands  | 
|
198  | 
val cmds2 = that.commands  | 
|
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48745 
diff
changeset
 | 
199  | 
require(!cmds1.exists(_.is_undefined))  | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48745 
diff
changeset
 | 
200  | 
require(!cmds2.exists(_.is_undefined))  | 
| 44474 | 201  | 
cmds1.length == cmds2.length &&  | 
202  | 
        (cmds1.iterator zip cmds2.iterator).forall({ case (c1, c2) => c1.id == c2.id })
 | 
|
203  | 
}  | 
|
| 
44385
 
e7fdb008aa7d
propagate editor perspective through document model;
 
wenzelm 
parents: 
44384 
diff
changeset
 | 
204  | 
}  | 
| 
34318
 
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
 
wenzelm 
parents:  
diff
changeset
 | 
205  | 
}  | 
| 
 
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
 
wenzelm 
parents:  
diff
changeset
 | 
206  | 
|
| 38361 | 207  | 
|
| 46712 | 208  | 
final class Command private(  | 
| 
52530
 
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
 
wenzelm 
parents: 
52527 
diff
changeset
 | 
209  | 
val id: Document_ID.Command,  | 
| 44615 | 210  | 
val node_name: Document.Node.Name,  | 
| 
52535
 
b7badd371e4d
tuned signature -- eliminated pointless type synonym;
 
wenzelm 
parents: 
52531 
diff
changeset
 | 
211  | 
val span: List[Token],  | 
| 49414 | 212  | 
val source: String,  | 
| 
50501
 
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
 
wenzelm 
parents: 
50500 
diff
changeset
 | 
213  | 
val init_results: Command.Results,  | 
| 49414 | 214  | 
val init_markup: Markup_Tree)  | 
| 34451 | 215  | 
{
 | 
| 34859 | 216  | 
/* classification */  | 
| 
34500
 
384427c750c8
state_results: separate buffer for messages from running command;
 
wenzelm 
parents: 
34497 
diff
changeset
 | 
217  | 
|
| 
52530
 
99dd8b4ef3fe
explicit module Document_ID as source of globally unique identifiers across ML/Scala;
 
wenzelm 
parents: 
52527 
diff
changeset
 | 
218  | 
def is_undefined: Boolean = id == Document_ID.none  | 
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48745 
diff
changeset
 | 
219  | 
val is_unparsed: Boolean = span.exists(_.is_unparsed)  | 
| 
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48745 
diff
changeset
 | 
220  | 
val is_unfinished: Boolean = span.exists(_.is_unfinished)  | 
| 
44385
 
e7fdb008aa7d
propagate editor perspective through document model;
 
wenzelm 
parents: 
44384 
diff
changeset
 | 
221  | 
|
| 48599 | 222  | 
val is_ignored: Boolean = !span.exists(_.is_proper)  | 
| 
48754
 
c2c1e5944536
clarified undefined, unparsed, unfinished command spans;
 
wenzelm 
parents: 
48745 
diff
changeset
 | 
223  | 
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
 | 
224  | 
def is_command: Boolean = !is_ignored && !is_malformed  | 
| 34859 | 225  | 
|
| 
47012
 
0e246130486b
clarified command span classification: strict Command.is_command, permissive Command.name;
 
wenzelm 
parents: 
46910 
diff
changeset
 | 
226  | 
def name: String =  | 
| 48718 | 227  | 
    span.find(_.is_command) match { case Some(tok) => tok.source case _ => "" }
 | 
| 
47012
 
0e246130486b
clarified command span classification: strict Command.is_command, permissive Command.name;
 
wenzelm 
parents: 
46910 
diff
changeset
 | 
228  | 
|
| 37129 | 229  | 
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
 | 
230  | 
id + "/" + (if (is_command) name else if (is_ignored) "IGNORED" else "MALFORMED")  | 
| 34495 | 231  | 
|
| 34859 | 232  | 
|
| 52509 | 233  | 
/* source */  | 
| 34451 | 234  | 
|
| 46813 | 235  | 
def length: Int = source.length  | 
236  | 
val range: Text.Range = Text.Range(0, length)  | 
|
237  | 
||
238  | 
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
 | 
239  | 
Text.Range(0, (length /: span.reverse.iterator.takeWhile(_.is_improper))(_ - _.source.length))  | 
| 46813 | 240  | 
|
| 38426 | 241  | 
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
 | 
242  | 
|
| 52507 | 243  | 
lazy val symbol_index = Symbol.Index(source)  | 
| 38579 | 244  | 
def decode(i: Text.Offset): Text.Offset = symbol_index.decode(i)  | 
245  | 
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
 | 
246  | 
|
| 
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
247  | 
|
| 
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
248  | 
/* accumulated results */  | 
| 
 
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
 
wenzelm 
parents: 
38367 
diff
changeset
 | 
249  | 
|
| 
50501
 
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
 
wenzelm 
parents: 
50500 
diff
changeset
 | 
250  | 
val init_state: Command.State =  | 
| 
 
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
 
wenzelm 
parents: 
50500 
diff
changeset
 | 
251  | 
Command.State(this, results = init_results, markup = init_markup)  | 
| 
52527
 
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
 
wenzelm 
parents: 
52524 
diff
changeset
 | 
252  | 
|
| 
 
dbac84eab3bc
separate exec_id assignment for Command.print states, without affecting result of eval;
 
wenzelm 
parents: 
52524 
diff
changeset
 | 
253  | 
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
 | 
254  | 
}  |