author | immler@in.tum.de |
Wed, 29 Apr 2009 16:08:22 +0200 | |
changeset 34557 | 647a2430d1cd |
parent 34556 | 09a5984250a2 |
child 34560 | 08f0d81c6833 |
permissions | -rw-r--r-- |
34407 | 1 |
/* |
2 |
* Prover commands with semantic state |
|
3 |
* |
|
4 |
* @author Johannes Hölzl, TU Munich |
|
5 |
* @author Fabian Immler, TU Munich |
|
6 |
*/ |
|
7 |
||
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
8 |
package isabelle.prover |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
9 |
|
34451 | 10 |
|
34393 | 11 |
import javax.swing.text.Position |
12 |
import javax.swing.tree.DefaultMutableTreeNode |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
13 |
|
34497 | 14 |
import scala.collection.mutable |
34486 | 15 |
|
34491 | 16 |
import isabelle.proofdocument.{Text, Token, ProofDocument} |
34451 | 17 |
import isabelle.jedit.{Isabelle, Plugin} |
34476 | 18 |
import isabelle.XML |
34451 | 19 |
|
20 |
import sidekick.{SideKickParsedData, IAsset} |
|
21 |
||
22 |
||
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
23 |
object Command { |
34458
e2aa32bb73c0
- renamed Command.Phase to Command.Status (cf. src/Pure/Isar/isar.ML);
wenzelm
parents:
34451
diff
changeset
|
24 |
object Status extends Enumeration { |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
25 |
val UNPROCESSED = Value("UNPROCESSED") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
26 |
val FINISHED = Value("FINISHED") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
27 |
val FAILED = Value("FAILED") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
28 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
29 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
30 |
|
34451 | 31 |
|
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34539
diff
changeset
|
32 |
class Command(val tokens: List[Token], val starts: Map[Token, Int]) |
34451 | 33 |
{ |
34 |
val id = Isabelle.plugin.id() |
|
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
35 |
|
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
36 |
/* content */ |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
37 |
|
34495 | 38 |
override def toString = name |
39 |
||
34526 | 40 |
val name = tokens.head.content |
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34539
diff
changeset
|
41 |
val content:String = Token.string_from_tokens(tokens.takeWhile(_.kind != Token.Kind.COMMENT), starts) |
34451 | 42 |
|
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34539
diff
changeset
|
43 |
def start(doc: ProofDocument) = doc.token_start(tokens.first) |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34539
diff
changeset
|
44 |
def stop(doc: ProofDocument) = doc.token_start(tokens.last) + tokens.last.length |
34451 | 45 |
|
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
46 |
/* command status */ |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
47 |
|
34508 | 48 |
var state_id: IsarDocument.State_ID = null |
49 |
||
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
50 |
private var _status = Command.Status.UNPROCESSED |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
51 |
def status = _status |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
52 |
def status_=(st: Command.Status.Value) { |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
53 |
if (st == Command.Status.UNPROCESSED) { |
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34508
diff
changeset
|
54 |
state_results.clear |
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
55 |
// delete markup |
34557 | 56 |
state_markup = empty_root_node |
57 |
highlight_markup = empty_root_node |
|
58 |
types_markup = empty_root_node |
|
59 |
refs_markup = empty_root_node |
|
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
60 |
} |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
61 |
_status = st |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
62 |
} |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
63 |
|
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
64 |
|
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
65 |
/* results */ |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
66 |
|
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
67 |
private val results = new mutable.ListBuffer[XML.Tree] |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
68 |
private val state_results = new mutable.ListBuffer[XML.Tree] |
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34508
diff
changeset
|
69 |
def add_result(running: Boolean, tree: XML.Tree) = synchronized { |
34508 | 70 |
(if (running) state_results else results) += tree |
71 |
} |
|
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
72 |
|
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
73 |
def result_document = XML.document( |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
74 |
results.toList ::: state_results.toList match { |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
75 |
case Nil => XML.Elem("message", Nil, Nil) |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
76 |
case List(elem) => elem |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
77 |
case elems => XML.Elem("messages", Nil, elems) |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
78 |
}, "style") |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
79 |
|
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
80 |
|
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
81 |
/* markup */ |
34451 | 82 |
|
34557 | 83 |
val empty_root_node = |
84 |
new MarkupNode(this, 0, starts(tokens.last) - starts(tokens.first) + tokens.last.length, Nil, id, content, Markup.COMMAND_SPAN) |
|
85 |
||
86 |
var command_markup = empty_root_node |
|
34451 | 87 |
|
34557 | 88 |
var state_markup = empty_root_node |
89 |
var highlight_markup = empty_root_node |
|
90 |
var types_markup = empty_root_node |
|
91 |
var refs_markup = empty_root_node |
|
92 |
var state_markups = List(state_markup, highlight_markup, types_markup, refs_markup) |
|
34556 | 93 |
|
34557 | 94 |
def highlight_node = (command_markup /: highlight_markup.children) (_ + _) |
95 |
||
96 |
def root_node = (command_markup /: state_markup.children) (_ + _) |
|
34556 | 97 |
|
34557 | 98 |
def markup_node(desc: String, begin: Int, end: Int) = |
99 |
new MarkupNode(this, begin, end, Nil, id, |
|
100 |
if (end <= content.length && begin >= 0) content.substring(begin, end) else "wrong indices??", |
|
101 |
desc) |
|
34556 | 102 |
|
34451 | 103 |
} |