author | wenzelm |
Thu, 03 Sep 2009 15:09:07 +0200 | |
changeset 34698 | 33286290e3b0 |
parent 34697 | 3d4874198e62 |
child 34699 | 9a4e5f93ccb6 |
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 |
||
34675 | 22 |
trait Accumulator extends Actor |
23 |
{ |
|
24 |
||
25 |
start() // start actor |
|
26 |
||
27 |
protected var _state: State |
|
28 |
def state = _state |
|
29 |
||
30 |
override def act() { |
|
31 |
loop { |
|
32 |
react { |
|
34697 | 33 |
case message: XML.Tree => _state += message |
34675 | 34 |
} |
35 |
} |
|
36 |
} |
|
37 |
} |
|
38 |
||
34451 | 39 |
|
34637 | 40 |
object Command |
41 |
{ |
|
42 |
object Status extends Enumeration |
|
43 |
{ |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
44 |
val UNPROCESSED = Value("UNPROCESSED") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
45 |
val FINISHED = Value("FINISHED") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
46 |
val FAILED = Value("FAILED") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
47 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
48 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
49 |
|
34451 | 50 |
|
34697 | 51 |
class Command( |
52 |
val tokens: List[Token], |
|
53 |
val starts: Map[Token, Int], |
|
54 |
change_receiver: Actor) extends Accumulator |
|
34451 | 55 |
{ |
34637 | 56 |
require(!tokens.isEmpty) |
57 |
||
34603
83a37e3b8c9c
produce ids via Isabelle.system (http://isabelle.in.tum.de/repos/isabelle/rev/c23663825e23);
wenzelm
parents:
34597
diff
changeset
|
58 |
val id = Isabelle.system.id() |
34653 | 59 |
override def hashCode = id.hashCode |
34637 | 60 |
|
34697 | 61 |
def changed() = change_receiver ! this |
34674 | 62 |
|
63 |
||
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
64 |
/* content */ |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
65 |
|
34495 | 66 |
override def toString = name |
67 |
||
34526 | 68 |
val name = tokens.head.content |
34582 | 69 |
val content: String = Token.string_from_tokens(tokens, starts) |
34637 | 70 |
val symbol_index = new Symbol.Index(content) |
34451 | 71 |
|
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34539
diff
changeset
|
72 |
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
|
73 |
def stop(doc: ProofDocument) = doc.token_start(tokens.last) + tokens.last.length |
34451 | 74 |
|
34593 | 75 |
def contains(p: Token) = tokens.contains(p) |
76 |
||
34697 | 77 |
protected override var _state = new State(this) |
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
78 |
|
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
79 |
|
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
80 |
/* markup */ |
34508 | 81 |
|
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
82 |
lazy val empty_root_node = |
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
83 |
new MarkupNode(this, 0, starts(tokens.last) - starts(tokens.first) + tokens.last.length, |
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
84 |
Nil, id, content, RootInfo()) |
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
85 |
|
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
86 |
def markup_node(begin: Int, end: Int, info: MarkupInfo) = { |
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
87 |
new MarkupNode(this, symbol_index.decode(begin), symbol_index.decode(end), Nil, id, |
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
88 |
content.substring(symbol_index.decode(begin), symbol_index.decode(end)), |
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
89 |
info) |
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
90 |
} |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
91 |
|
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
92 |
|
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
93 |
/* results, markup, ... */ |
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
94 |
|
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
95 |
private val empty_cmd_state = new Command_State(this) |
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
96 |
private def cmd_state(doc: ProofDocument) = |
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
97 |
doc.states.getOrElse(this, empty_cmd_state) |
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
98 |
|
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
99 |
def status(doc: ProofDocument) = cmd_state(doc).state.status |
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
100 |
def result_document(doc: ProofDocument) = cmd_state(doc).result_document |
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
101 |
def markup_root(doc: ProofDocument) = cmd_state(doc).markup_root |
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
102 |
def highlight_node(doc: ProofDocument) = cmd_state(doc).highlight_node |
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
103 |
def type_at(doc: ProofDocument, offset: Int) = cmd_state(doc).type_at(offset) |
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
104 |
def ref_at(doc: ProofDocument, offset: Int) = cmd_state(doc).ref_at(offset) |
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
105 |
} |
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
106 |
|
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
107 |
|
34698 | 108 |
class Command_State(val command: Command) extends Accumulator |
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
109 |
{ |
34698 | 110 |
protected override var _state = new State(command) |
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
111 |
|
34698 | 112 |
def result_document: org.w3c.dom.Document = |
34653 | 113 |
XML.document( |
34698 | 114 |
command.state.results ::: state.results match { |
34653 | 115 |
case Nil => XML.Elem("message", Nil, Nil) |
116 |
case List(elem) => elem |
|
117 |
case elems => XML.Elem("messages", Nil, elems) |
|
118 |
}, "style") |
|
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
119 |
|
34688 | 120 |
def markup_root: MarkupNode = |
34698 | 121 |
(command.state.markup_root /: state.markup_root.children) (_ + _) |
34557 | 122 |
|
34688 | 123 |
def type_at(pos: Int): String = state.type_at(pos) |
34556 | 124 |
|
34688 | 125 |
def ref_at(pos: Int): Option[MarkupNode] = state.ref_at(pos) |
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
34564
diff
changeset
|
126 |
|
34698 | 127 |
def highlight_node: MarkupNode = |
128 |
(command.state.highlight_node /: state.highlight_node.children) (_ + _) |
|
34688 | 129 |
} |