author | immler@in.tum.de |
Mon, 06 Apr 2009 19:04:38 +0200 | |
changeset 34544 | 56217d219e27 |
parent 34540 | 50ae42f01d45 |
child 34554 | 7dc6c231da40 |
permissions | -rw-r--r-- |
34407 | 1 |
/* |
34501 | 2 |
* Higher-level prover communication: interactive document model |
34407 | 3 |
* |
4 |
* @author Johannes Hölzl, TU Munich |
|
5 |
* @author Fabian Immler, TU Munich |
|
34453 | 6 |
* @author Makarius |
34407 | 7 |
*/ |
8 |
||
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
9 |
package isabelle.prover |
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 |
|
34497 | 12 |
import scala.collection.mutable |
34475
f963335dbc6b
implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents:
34471
diff
changeset
|
13 |
import scala.collection.immutable.{TreeSet} |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
14 |
|
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
15 |
import scala.actors.Actor |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
16 |
import scala.actors.Actor._ |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
17 |
|
34456 | 18 |
import org.gjt.sp.util.Log |
19 |
||
34501 | 20 |
import isabelle.jedit.Isabelle |
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
21 |
import isabelle.proofdocument.{StructureChange, ProofDocument, Text, Token} |
34489
7b7ccf0ff629
replaced java.util.Property by plain association list;
wenzelm
parents:
34485
diff
changeset
|
22 |
import isabelle.IsarDocument |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
23 |
|
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
24 |
object ProverEvents { |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
25 |
case class Activate |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
26 |
case class SetEventBus(bus: EventBus[StructureChange]) |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
27 |
case class SetIsCommandKeyword(is_command_keyword: String => Boolean) |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
28 |
} |
34453 | 29 |
|
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
30 |
class Prover(isabelle_system: IsabelleSystem, logic: String) extends Actor |
34453 | 31 |
{ |
34504
4bd676662792
eliminated Prover.start -- part of main constructor;
wenzelm
parents:
34503
diff
changeset
|
32 |
/* prover process */ |
4bd676662792
eliminated Prover.start -- part of main constructor;
wenzelm
parents:
34503
diff
changeset
|
33 |
|
4bd676662792
eliminated Prover.start -- part of main constructor;
wenzelm
parents:
34503
diff
changeset
|
34 |
|
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
35 |
private val process = |
34504
4bd676662792
eliminated Prover.start -- part of main constructor;
wenzelm
parents:
34503
diff
changeset
|
36 |
{ |
4bd676662792
eliminated Prover.start -- part of main constructor;
wenzelm
parents:
34503
diff
changeset
|
37 |
val results = new EventBus[IsabelleProcess.Result] + handle_result |
4bd676662792
eliminated Prover.start -- part of main constructor;
wenzelm
parents:
34503
diff
changeset
|
38 |
results.logger = Log.log(Log.ERROR, null, _) |
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
39 |
new IsabelleProcess(isabelle_system, results, "-m", "xsymbols", logic) with IsarDocument |
34504
4bd676662792
eliminated Prover.start -- part of main constructor;
wenzelm
parents:
34503
diff
changeset
|
40 |
} |
4bd676662792
eliminated Prover.start -- part of main constructor;
wenzelm
parents:
34503
diff
changeset
|
41 |
|
4bd676662792
eliminated Prover.start -- part of main constructor;
wenzelm
parents:
34503
diff
changeset
|
42 |
def stop() { process.kill } |
4bd676662792
eliminated Prover.start -- part of main constructor;
wenzelm
parents:
34503
diff
changeset
|
43 |
|
4bd676662792
eliminated Prover.start -- part of main constructor;
wenzelm
parents:
34503
diff
changeset
|
44 |
|
34509 | 45 |
/* document state information */ |
46 |
||
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
47 |
private val states = new mutable.HashMap[IsarDocument.State_ID, Command] with |
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
48 |
mutable.SynchronizedMap[IsarDocument.State_ID, Command] |
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
49 |
private val commands = new mutable.HashMap[IsarDocument.Command_ID, Command] with |
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
50 |
mutable.SynchronizedMap[IsarDocument.Command_ID, Command] |
34544
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
51 |
private var document_versions = List(ProofDocument.empty) |
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
52 |
private val document_id0 = ProofDocument.empty.id |
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
53 |
|
34544
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
54 |
def document = document_versions.head |
34509 | 55 |
|
56 |
private var initialized = false |
|
57 |
||
58 |
||
34485 | 59 |
/* outer syntax keywords */ |
60 |
||
34465
ccadbf63e320
added EventBus for new command- or keyword-declarations
immler@in.tum.de
parents:
34462
diff
changeset
|
61 |
val decl_info = new EventBus[(String, String)] |
34489
7b7ccf0ff629
replaced java.util.Property by plain association list;
wenzelm
parents:
34485
diff
changeset
|
62 |
|
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
63 |
private val keyword_decls = |
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
64 |
new mutable.HashSet[String] with mutable.SynchronizedSet[String] { |
34489
7b7ccf0ff629
replaced java.util.Property by plain association list;
wenzelm
parents:
34485
diff
changeset
|
65 |
override def +=(name: String) = { |
7b7ccf0ff629
replaced java.util.Property by plain association list;
wenzelm
parents:
34485
diff
changeset
|
66 |
decl_info.event(name, OuterKeyword.MINOR) |
7b7ccf0ff629
replaced java.util.Property by plain association list;
wenzelm
parents:
34485
diff
changeset
|
67 |
super.+=(name) |
7b7ccf0ff629
replaced java.util.Property by plain association list;
wenzelm
parents:
34485
diff
changeset
|
68 |
} |
7b7ccf0ff629
replaced java.util.Property by plain association list;
wenzelm
parents:
34485
diff
changeset
|
69 |
} |
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
70 |
private val command_decls = |
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
71 |
new mutable.HashMap[String, String] with mutable.SynchronizedMap[String, String] { |
34471
1dac47492863
decl_info: cover both commands and keywords, with kind;
wenzelm
parents:
34466
diff
changeset
|
72 |
override def +=(entry: (String, String)) = { |
1dac47492863
decl_info: cover both commands and keywords, with kind;
wenzelm
parents:
34466
diff
changeset
|
73 |
decl_info.event(entry) |
1dac47492863
decl_info: cover both commands and keywords, with kind;
wenzelm
parents:
34466
diff
changeset
|
74 |
super.+=(entry) |
34465
ccadbf63e320
added EventBus for new command- or keyword-declarations
immler@in.tum.de
parents:
34462
diff
changeset
|
75 |
} |
ccadbf63e320
added EventBus for new command- or keyword-declarations
immler@in.tum.de
parents:
34462
diff
changeset
|
76 |
} |
34485 | 77 |
|
78 |
||
34489
7b7ccf0ff629
replaced java.util.Property by plain association list;
wenzelm
parents:
34485
diff
changeset
|
79 |
/* completions */ |
7b7ccf0ff629
replaced java.util.Property by plain association list;
wenzelm
parents:
34485
diff
changeset
|
80 |
|
34475
f963335dbc6b
implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents:
34471
diff
changeset
|
81 |
var _completions = new TreeSet[String] |
f963335dbc6b
implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents:
34471
diff
changeset
|
82 |
def completions = _completions |
f963335dbc6b
implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents:
34471
diff
changeset
|
83 |
/* // TODO: ask Makarius to make Interpretation.symbols public (here: read-only as 'symbol_map') |
f963335dbc6b
implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents:
34471
diff
changeset
|
84 |
val map = isabelle.jedit.Isabelle.symbols.symbol_map |
34503 | 85 |
for (xsymb <- map.keys) { |
34475
f963335dbc6b
implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents:
34471
diff
changeset
|
86 |
_completions += xsymb |
34503 | 87 |
if (map(xsymb).get("abbrev").isDefined) _completions += map(xsymb)("abbrev") |
34475
f963335dbc6b
implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents:
34471
diff
changeset
|
88 |
} |
f963335dbc6b
implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents:
34471
diff
changeset
|
89 |
*/ |
f963335dbc6b
implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents:
34471
diff
changeset
|
90 |
decl_info += (k_v => _completions += k_v._1) |
34489
7b7ccf0ff629
replaced java.util.Property by plain association list;
wenzelm
parents:
34485
diff
changeset
|
91 |
|
7b7ccf0ff629
replaced java.util.Property by plain association list;
wenzelm
parents:
34485
diff
changeset
|
92 |
|
7b7ccf0ff629
replaced java.util.Property by plain association list;
wenzelm
parents:
34485
diff
changeset
|
93 |
/* event handling */ |
7b7ccf0ff629
replaced java.util.Property by plain association list;
wenzelm
parents:
34485
diff
changeset
|
94 |
|
34456 | 95 |
val activated = new EventBus[Unit] |
96 |
val output_info = new EventBus[String] |
|
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
97 |
var change_receiver = null: Actor |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
98 |
|
34509 | 99 |
private def handle_result(result: IsabelleProcess.Result) |
34489
7b7ccf0ff629
replaced java.util.Property by plain association list;
wenzelm
parents:
34485
diff
changeset
|
100 |
{ |
34539 | 101 |
def command_change(c: Command) = this ! c |
34509 | 102 |
val (running, command) = |
103 |
result.props.find(p => p._1 == Markup.ID) match { |
|
104 |
case None => (false, null) |
|
105 |
case Some((_, id)) => |
|
106 |
if (commands.contains(id)) (false, commands(id)) |
|
107 |
else if (states.contains(id)) (true, states(id)) |
|
108 |
else (false, null) |
|
109 |
} |
|
34453 | 110 |
|
34509 | 111 |
if (result.kind == IsabelleProcess.Kind.STDOUT || result.kind == IsabelleProcess.Kind.STDIN) |
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
112 |
output_info.event(result.toString) |
34509 | 113 |
else if (result.kind == IsabelleProcess.Kind.WRITELN && !initialized) { // FIXME !? |
34453 | 114 |
initialized = true |
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
115 |
Swing.now { this ! ProverEvents.Activate } |
34453 | 116 |
} |
117 |
else { |
|
34509 | 118 |
result.kind match { |
119 |
||
120 |
case IsabelleProcess.Kind.WRITELN | IsabelleProcess.Kind.PRIORITY |
|
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
121 |
| IsabelleProcess.Kind.WARNING | IsabelleProcess.Kind.ERROR => |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
122 |
if (command != null) { |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
123 |
if (result.kind == IsabelleProcess.Kind.ERROR) |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
124 |
command.status = Command.Status.FAILED |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
125 |
command.add_result(running, process.parse_message(result)) |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
126 |
command_change(command) |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
127 |
} else { |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
128 |
output_info.event(result.toString) |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
129 |
} |
34404
98155c35d252
delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents:
34401
diff
changeset
|
130 |
|
34509 | 131 |
case IsabelleProcess.Kind.STATUS => |
132 |
//{{{ handle all kinds of status messages here |
|
133 |
process.parse_message(result) match { |
|
134 |
case XML.Elem(Markup.MESSAGE, _, elems) => |
|
135 |
for (elem <- elems) { |
|
136 |
elem match { |
|
137 |
//{{{ |
|
138 |
// command and keyword declarations |
|
139 |
case XML.Elem(Markup.COMMAND_DECL, |
|
140 |
(Markup.NAME, name) :: (Markup.KIND, kind) :: _, _) => |
|
141 |
command_decls += (name -> kind) |
|
142 |
case XML.Elem(Markup.KEYWORD_DECL, (Markup.NAME, name) :: _, _) => |
|
143 |
keyword_decls += name |
|
34404
98155c35d252
delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents:
34401
diff
changeset
|
144 |
|
34509 | 145 |
// document edits |
146 |
case XML.Elem(Markup.EDITS, (Markup.ID, doc_id) :: _, edits) |
|
34544
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
147 |
if document_versions.exists(dv => doc_id == dv.id) => |
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
148 |
output_info.event(result.toString) |
34509 | 149 |
for { |
150 |
XML.Elem(Markup.EDIT, (Markup.ID, cmd_id) :: (Markup.STATE, state_id) :: _, _) |
|
151 |
<- edits |
|
152 |
} { |
|
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
153 |
if (commands.contains(cmd_id)) { |
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
154 |
val cmd = commands(cmd_id) |
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
155 |
if (cmd.state_id != null) states -= cmd.state_id |
34540 | 156 |
states(state_id) = cmd |
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
157 |
cmd.state_id = state_id |
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
158 |
cmd.status = Command.Status.UNPROCESSED |
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
159 |
command_change(cmd) |
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
160 |
} |
34453 | 161 |
|
34509 | 162 |
} |
163 |
// command status |
|
164 |
case XML.Elem(Markup.UNPROCESSED, _, _) |
|
165 |
if command != null => |
|
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
166 |
output_info.event(result.toString) |
34509 | 167 |
command.status = Command.Status.UNPROCESSED |
168 |
command_change(command) |
|
169 |
case XML.Elem(Markup.FINISHED, _, _) |
|
170 |
if command != null => |
|
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
171 |
output_info.event(result.toString) |
34509 | 172 |
command.status = Command.Status.FINISHED |
173 |
command_change(command) |
|
174 |
case XML.Elem(Markup.FAILED, _, _) |
|
175 |
if command != null => |
|
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
176 |
output_info.event(result.toString) |
34509 | 177 |
command.status = Command.Status.FAILED |
178 |
command_change(command) |
|
34453 | 179 |
|
34509 | 180 |
// other markup |
181 |
case XML.Elem(kind, |
|
182 |
(Markup.OFFSET, offset) :: (Markup.END_OFFSET, end_offset) :: |
|
183 |
(Markup.ID, markup_id) :: _, _) => |
|
184 |
val begin = offset.toInt - 1 |
|
185 |
val end = end_offset.toInt - 1 |
|
186 |
||
187 |
val cmd = // FIXME proper command version!? running!? |
|
188 |
// outer syntax: no id in props |
|
189 |
if (command == null) commands.getOrElse(markup_id, null) |
|
190 |
// inner syntax: id from props |
|
191 |
else command |
|
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
192 |
if (cmd != null) { |
34509 | 193 |
cmd.root_node.insert(cmd.node_from(kind, begin, end)) |
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
194 |
command_change(cmd) |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
195 |
} |
34509 | 196 |
case _ => |
197 |
//}}} |
|
34453 | 198 |
} |
34509 | 199 |
} |
200 |
case _ => |
|
201 |
} |
|
202 |
//}}} |
|
34453 | 203 |
|
34509 | 204 |
case _ => |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
205 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
206 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
207 |
} |
34453 | 208 |
|
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
209 |
def act() { |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
210 |
import ProverEvents._ |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
211 |
loop { |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
212 |
react { |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
213 |
case Activate => { |
34544
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
214 |
val old = document |
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
215 |
val (doc, structure_change) = old.activate |
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
216 |
document_versions ::= doc |
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
217 |
edit_document(old.id, doc.id, structure_change) |
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
218 |
} |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
219 |
case SetIsCommandKeyword(f) => { |
34544
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
220 |
val old = document |
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
221 |
val doc = old.set_command_keyword(f) |
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
222 |
document_versions ::= doc |
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
223 |
edit_document(old.id, doc.id, StructureChange(None, Nil, Nil)) |
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
224 |
} |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
225 |
case change: Text.Change => { |
34544
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
226 |
val old = document |
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
227 |
val (doc, structure_change) = old.text_changed(change) |
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
228 |
document_versions ::= doc |
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
229 |
edit_document(old.id, doc.id, structure_change) |
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
230 |
} |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
231 |
case command: Command => { |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
232 |
//state of command has changed |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
233 |
change_receiver ! command |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
234 |
} |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
235 |
} |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
236 |
} |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
237 |
} |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
238 |
|
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
239 |
def set_document(change_receiver: Actor, path: String) { |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
240 |
this.change_receiver = change_receiver |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
241 |
this ! ProverEvents.SetIsCommandKeyword(command_decls.contains) |
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
242 |
process.ML("()") // FIXME force initial writeln |
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
243 |
process.begin_document(document_id0, path) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
244 |
} |
34453 | 245 |
|
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
246 |
private def edit_document(old_id: String, document_id: String, changes: StructureChange) = Swing.now |
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
247 |
{ |
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
248 |
val removes = |
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
249 |
for (cmd <- changes.removed_commands) yield { |
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
250 |
commands -= cmd.id |
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
251 |
if (cmd.state_id != null) states -= cmd.state_id |
34539 | 252 |
(document.commands.prev(cmd).map(_.id).getOrElse(document_id0)) -> None |
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
253 |
} |
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
254 |
val inserts = |
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
255 |
for (cmd <- changes.added_commands) yield { |
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
256 |
commands += (cmd.id -> cmd) |
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
257 |
process.define_command(cmd.id, isabelle_system.symbols.encode(cmd.content)) |
34539 | 258 |
(document.commands.prev(cmd).map(_.id).getOrElse(document_id0)) -> Some(cmd.id) |
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
259 |
} |
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
260 |
process.edit_document(old_id, document_id, removes.reverse ++ inserts) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
261 |
} |
34453 | 262 |
} |