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