author | immler@in.tum.de |
Thu, 27 Aug 2009 10:51:09 +0200 | |
changeset 34674 | f9b71bcf2eb7 |
parent 34662 | ab54955c9eea |
child 34675 | 5427df0f6bcb |
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 |
|
34674 | 11 |
import scala.actors.Actor |
12 |
import scala.actors.Actor._ |
|
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 |
|
34662 | 16 |
import isabelle.proofdocument.{Token, ProofDocument} |
34451 | 17 |
import isabelle.jedit.{Isabelle, Plugin} |
34476 | 18 |
import isabelle.XML |
34451 | 19 |
|
20 |
import sidekick.{SideKickParsedData, IAsset} |
|
21 |
||
22 |
||
34637 | 23 |
object Command |
24 |
{ |
|
25 |
object Status extends Enumeration |
|
26 |
{ |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
27 |
val UNPROCESSED = Value("UNPROCESSED") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
28 |
val FINISHED = Value("FINISHED") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
29 |
val FAILED = Value("FAILED") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
30 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
31 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
32 |
|
34451 | 33 |
|
34674 | 34 |
class Command(val tokens: List[Token], val starts: Map[Token, Int], chg_rec: Actor) |
34451 | 35 |
{ |
34637 | 36 |
require(!tokens.isEmpty) |
37 |
||
34603
83a37e3b8c9c
produce ids via Isabelle.system (http://isabelle.in.tum.de/repos/isabelle/rev/c23663825e23);
wenzelm
parents:
34597
diff
changeset
|
38 |
val id = Isabelle.system.id() |
34653 | 39 |
override def hashCode = id.hashCode |
34637 | 40 |
|
34674 | 41 |
def changed() = chg_rec ! this |
42 |
||
43 |
||
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
44 |
/* content */ |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
45 |
|
34495 | 46 |
override def toString = name |
47 |
||
34526 | 48 |
val name = tokens.head.content |
34582 | 49 |
val content: String = Token.string_from_tokens(tokens, starts) |
34637 | 50 |
val symbol_index = new Symbol.Index(content) |
34451 | 51 |
|
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34539
diff
changeset
|
52 |
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
|
53 |
def stop(doc: ProofDocument) = doc.token_start(tokens.last) + tokens.last.length |
34451 | 54 |
|
34593 | 55 |
def contains(p: Token) = tokens.contains(p) |
56 |
||
34653 | 57 |
/* states */ |
58 |
val states = mutable.Map[IsarDocument.State_ID, Command_State]() |
|
59 |
private def state(doc: ProofDocument) = doc.states.get(this) |
|
60 |
||
61 |
/* command status */ |
|
34508 | 62 |
|
34653 | 63 |
def set_status(state: IsarDocument.State_ID, status: Command.Status.Value) = { |
64 |
if (state != null) |
|
65 |
states.getOrElseUpdate(state, new Command_State(this)).status = status |
|
34500
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 |
|
34653 | 68 |
def status(doc: ProofDocument) = |
69 |
state(doc) match { |
|
70 |
case Some(s) => states.getOrElseUpdate(s, new Command_State(this)).status |
|
71 |
case _ => Command.Status.UNPROCESSED |
|
72 |
} |
|
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
73 |
|
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
74 |
/* results */ |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
75 |
|
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
76 |
private val results = new mutable.ListBuffer[XML.Tree] |
34653 | 77 |
def add_result(state: IsarDocument.State_ID, tree: XML.Tree) = synchronized { |
78 |
(if (state == null) results else states(state).results) += tree |
|
34508 | 79 |
} |
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
80 |
|
34653 | 81 |
def result_document(doc: ProofDocument) = { |
82 |
val state_results = state(doc) match { |
|
83 |
case Some(s) => |
|
84 |
states.getOrElseUpdate(s, new Command_State(this)).results |
|
85 |
case _ => Nil} |
|
86 |
XML.document( |
|
87 |
results.toList ::: state_results.toList match { |
|
88 |
case Nil => XML.Elem("message", Nil, Nil) |
|
89 |
case List(elem) => elem |
|
90 |
case elems => XML.Elem("messages", Nil, elems) |
|
91 |
}, "style") |
|
92 |
} |
|
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
93 |
|
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
94 |
|
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
95 |
/* markup */ |
34451 | 96 |
|
34557 | 97 |
val empty_root_node = |
34582 | 98 |
new MarkupNode(this, 0, starts(tokens.last) - starts(tokens.first) + tokens.last.length, |
99 |
Nil, id, content, RootInfo()) |
|
34653 | 100 |
private var _markup_root = empty_root_node |
34656 | 101 |
def add_markup(state: IsarDocument.State_ID, raw_node: MarkupNode) = { |
102 |
// decode node |
|
103 |
val node = raw_node transform symbol_index.decode |
|
34658 | 104 |
if (state == null) _markup_root += node |
34653 | 105 |
else { |
106 |
val cmd_state = states.getOrElseUpdate(state, new Command_State(this)) |
|
107 |
cmd_state.markup_root += node |
|
108 |
} |
|
109 |
} |
|
34557 | 110 |
|
34653 | 111 |
def markup_root(doc: ProofDocument): MarkupNode = { |
112 |
state(doc) match { |
|
113 |
case Some(s) => |
|
114 |
(_markup_root /: states(s).markup_root.children) (_ + _) |
|
115 |
case _ => _markup_root |
|
116 |
} |
|
117 |
} |
|
34451 | 118 |
|
34653 | 119 |
def highlight_node(doc: ProofDocument): MarkupNode = |
34637 | 120 |
{ |
34560 | 121 |
import MarkupNode._ |
34653 | 122 |
markup_root(doc).filter(_.info match { |
34564
850dc36d4926
let MarkupNode carry arbitrary information
immler@in.tum.de
parents:
34562
diff
changeset
|
123 |
case RootInfo() | OuterInfo(_) | HighlightInfo(_) => true |
34560 | 124 |
case _ => false |
125 |
}).head |
|
126 |
} |
|
34556 | 127 |
|
34564
850dc36d4926
let MarkupNode carry arbitrary information
immler@in.tum.de
parents:
34562
diff
changeset
|
128 |
def markup_node(begin: Int, end: Int, info: MarkupInfo) = |
34557 | 129 |
new MarkupNode(this, begin, end, Nil, id, |
34582 | 130 |
if (end <= content.length && begin >= 0) content.substring(begin, end) |
131 |
else "wrong indices??", |
|
132 |
info) |
|
34556 | 133 |
|
34653 | 134 |
def type_at(doc: ProofDocument, pos: Int) = |
135 |
state(doc).map(states(_).type_at(pos)).getOrElse(null) |
|
136 |
||
137 |
def ref_at(doc: ProofDocument, pos: Int) = |
|
138 |
state(doc).flatMap(states(_).ref_at(pos)) |
|
139 |
||
140 |
} |
|
141 |
||
142 |
class Command_State(val cmd: Command) { |
|
143 |
||
144 |
var status = Command.Status.UNPROCESSED |
|
145 |
||
146 |
/* results */ |
|
147 |
val results = new mutable.ListBuffer[XML.Tree] |
|
148 |
||
149 |
/* markup */ |
|
150 |
val empty_root_node = cmd.empty_root_node |
|
151 |
var markup_root = empty_root_node |
|
152 |
||
34637 | 153 |
def type_at(pos: Int): String = |
154 |
{ |
|
34582 | 155 |
val types = markup_root.filter(_.info match { case TypeInfo(_) => true case _ => false }) |
34562 | 156 |
types.flatten(_.flatten). |
157 |
find(t => t.start <= pos && t.stop > pos). |
|
34586 | 158 |
map(t => t.content + ": " + (t.info match { case TypeInfo(i) => i case _ => "" })). |
34562 | 159 |
getOrElse(null) |
160 |
} |
|
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
34564
diff
changeset
|
161 |
|
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
34564
diff
changeset
|
162 |
def ref_at(pos: Int): Option[MarkupNode] = |
34582 | 163 |
markup_root.filter(_.info match { case RefInfo(_, _, _, _) => true case _ => false }). |
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
34564
diff
changeset
|
164 |
flatten(_.flatten). |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
34564
diff
changeset
|
165 |
find(t => t.start <= pos && t.stop > pos) |
34451 | 166 |
} |