author | immler@in.tum.de |
Sun, 07 Dec 2008 15:39:50 +0100 | |
changeset 34398 | 2d40e4067c37 |
parent 34397 | 86daaf5db016 |
child 34399 | 5b8b89b7e597 |
permissions | -rw-r--r-- |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
1 |
package isabelle.prover |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
2 |
|
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
3 |
import isabelle.proofdocument.Token |
34393 | 4 |
import isabelle.jedit.Plugin |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
5 |
import isabelle.{ YXML, XML } |
34393 | 6 |
import sidekick.{SideKickParsedData} |
7 |
import sidekick.enhanced.SourceAsset |
|
8 |
import javax.swing.text.Position |
|
9 |
import javax.swing.tree.DefaultMutableTreeNode |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
10 |
|
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
11 |
object Command { |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
12 |
object Phase extends Enumeration { |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
13 |
val UNPROCESSED = Value("UNPROCESSED") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
14 |
val FINISHED = Value("FINISHED") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
15 |
val REMOVE = Value("REMOVE") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
16 |
val REMOVED = Value("REMOVED") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
17 |
val FAILED = Value("FAILED") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
18 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
19 |
|
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
20 |
private var nextId : Long = 0 |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
21 |
def generateId : Long = { |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
22 |
nextId = nextId + 1 |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
23 |
return nextId |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
24 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
25 |
|
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
26 |
def idFromString(id : String) = Long.unbox(java.lang.Long.valueOf(id, 36)) |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
27 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
28 |
|
34397 | 29 |
class Command(val document : Document, val first : Token[Command], val last : Token[Command]) { |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
30 |
import Command._ |
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 |
{ |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
33 |
var t = first |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
34 |
while(t != null) { |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
35 |
t.command = this |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
36 |
t = if (t == last) null else t.next |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
37 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
38 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
39 |
|
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
40 |
val id : Long = generateId |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
41 |
var phase = Phase.UNPROCESSED |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
42 |
|
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
43 |
var results = Nil : List[XML.Tree] |
34391 | 44 |
|
45 |
//offsets relative to first.start! |
|
46 |
class Status(val kind : String,val start : Int, val stop : Int ) { } |
|
47 |
var statuses = Nil : List[Status] |
|
34397 | 48 |
def statuses_xml = XML.Elem("statuses", List(), statuses.map (s => XML.Text(s.kind + ": " + s.start + "-" + s.stop + "\n"))) |
34391 | 49 |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
50 |
def idString = java.lang.Long.toString(id, 36) |
34397 | 51 |
def results_xml = XML.document(results match { |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
52 |
case Nil => XML.Elem("message", List(), List()) |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
53 |
case List(elem) => elem |
34391 | 54 |
case _ => |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
55 |
XML.Elem("messages", List(), List(results.first, |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
56 |
results.last)) |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
57 |
}, "style") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
58 |
def addResult(tree : XML.Tree) { |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
59 |
results = results ::: List(tree) |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
60 |
} |
34393 | 61 |
|
62 |
val root_node = { |
|
34397 | 63 |
val content = document.getContent(this) |
34393 | 64 |
val ra = new RelativeAsset(this, 0, stop - start, "command", content) |
65 |
new DefaultMutableTreeNode(ra) |
|
66 |
} |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
67 |
|
34393 | 68 |
// does cand fit into node? |
69 |
private def fitting(cand : DefaultMutableTreeNode, node : DefaultMutableTreeNode) : boolean = { |
|
70 |
val node_asset = node.getUserObject.asInstanceOf[RelativeAsset] |
|
71 |
val n_start = node_asset.rel_start |
|
72 |
val n_end = node_asset.rel_end |
|
73 |
val cand_asset = cand.getUserObject.asInstanceOf[RelativeAsset] |
|
74 |
val c_start = cand_asset.rel_start |
|
75 |
val c_end = cand_asset.rel_end |
|
76 |
return c_start >= n_start && c_end <= n_end |
|
77 |
} |
|
78 |
||
79 |
def insert_node(new_node : DefaultMutableTreeNode, node : DefaultMutableTreeNode) { |
|
80 |
assert(fitting(new_node, node)) |
|
81 |
val children = node.children |
|
82 |
while (children.hasMoreElements){ |
|
83 |
val child = children.nextElement.asInstanceOf[DefaultMutableTreeNode] |
|
84 |
if(fitting(new_node, child)) { |
|
85 |
insert_node(new_node, child) |
|
86 |
} |
|
87 |
} |
|
88 |
if(new_node.getParent == null){ |
|
89 |
while(children.hasMoreElements){ |
|
90 |
val child = children.nextElement.asInstanceOf[DefaultMutableTreeNode] |
|
91 |
if(fitting(child, new_node)) { |
|
92 |
node.remove(child.asInstanceOf[DefaultMutableTreeNode]) |
|
93 |
new_node.add(child) |
|
94 |
} |
|
95 |
} |
|
96 |
node.add(new_node) |
|
97 |
} |
|
98 |
} |
|
99 |
||
100 |
def addStatus(tree : XML.Tree) { |
|
34397 | 101 |
val (state, attr) = tree match { case XML.Elem("message", _, XML.Elem(kind, attr, _) :: _) => (kind, attr) |
34391 | 102 |
case _ => null} |
34397 | 103 |
if (phase != Phase.REMOVED && phase != Phase.REMOVE) { |
104 |
state match { |
|
105 |
case "finished" => |
|
106 |
phase = Phase.FINISHED |
|
107 |
case "unprocessed" => |
|
108 |
phase = Phase.UNPROCESSED |
|
109 |
case "failed" => |
|
110 |
phase = Phase.FAILED |
|
111 |
case "removed" => |
|
112 |
// TODO: never lose information on command + id ?? |
|
113 |
//document.prover.commands.removeKey(st.idString) |
|
114 |
phase = Phase.REMOVED |
|
115 |
case _ => |
|
116 |
//process attributes: |
|
117 |
var markup_begin = -1 |
|
118 |
var markup_end = -1 |
|
119 |
for((n, a) <- attr) { |
|
120 |
if(n.equals("offset")) markup_begin = Int.unbox(java.lang.Integer.valueOf(a)) - 1 |
|
121 |
if(n.equals("end_offset")) markup_end = Int.unbox(java.lang.Integer.valueOf(a)) - 1 |
|
122 |
} |
|
123 |
if(markup_begin > -1 && markup_end > -1){ |
|
124 |
statuses = new Status(state, markup_begin, markup_end) :: statuses |
|
125 |
val markup_content = content.substring(markup_begin, markup_end) |
|
126 |
val asset = new RelativeAsset(this, markup_begin, markup_end, state, markup_content) |
|
127 |
val new_node = new DefaultMutableTreeNode(asset) |
|
128 |
insert_node(new_node, root_node) |
|
129 |
} else { |
|
130 |
System.err.println("addStatus - ignored: " + tree) |
|
131 |
} |
|
132 |
} |
|
34391 | 133 |
} |
134 |
} |
|
135 |
||
34397 | 136 |
def content = document.getContent(this) |
34396
de809360c51d
command property: offset relative to start of command
immler@in.tum.de
parents:
34394
diff
changeset
|
137 |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
138 |
def next = if (last.next != null) last.next.command else null |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
139 |
def previous = if (first.previous != null) first.previous.command else null |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
140 |
|
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
141 |
def start = first start |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
142 |
def stop = last stop |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
143 |
|
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
144 |
def properStart = start |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
145 |
def properStop = { |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
146 |
var i = last |
34388 | 147 |
while (i != first && i.kind.equals(Token.Kind.COMMENT)) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
148 |
i = i.previous |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
149 |
i.stop |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
150 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
151 |
} |