author | wenzelm |
Tue, 30 Jun 2009 21:22:50 +0200 | |
changeset 34634 | 4b797391859a |
parent 34615 | 5e61055bf35b |
child 34649 | 70759ca6bb87 |
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 |
|
34615 | 30 |
class Prover(isabelle_system: Isabelle_System, 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 |
|
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
34 |
private val process = |
34504
4bd676662792
eliminated Prover.start -- part of main constructor;
wenzelm
parents:
34503
diff
changeset
|
35 |
{ |
34615 | 36 |
val results = new EventBus[Isabelle_Process.Result] + handle_result |
34504
4bd676662792
eliminated Prover.start -- part of main constructor;
wenzelm
parents:
34503
diff
changeset
|
37 |
results.logger = Log.log(Log.ERROR, null, _) |
34615 | 38 |
new Isabelle_Process(isabelle_system, results, "-m", "xsymbols", logic) with IsarDocument |
34504
4bd676662792
eliminated Prover.start -- part of main constructor;
wenzelm
parents:
34503
diff
changeset
|
39 |
} |
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 |
def stop() { process.kill } |
4bd676662792
eliminated Prover.start -- part of main constructor;
wenzelm
parents:
34503
diff
changeset
|
42 |
|
4bd676662792
eliminated Prover.start -- part of main constructor;
wenzelm
parents:
34503
diff
changeset
|
43 |
|
34509 | 44 |
/* document state information */ |
45 |
||
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
46 |
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
|
47 |
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
|
48 |
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
|
49 |
mutable.SynchronizedMap[IsarDocument.Command_ID, Command] |
34544
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
50 |
private var document_versions = List(ProofDocument.empty) |
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
51 |
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
|
52 |
|
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
34564
diff
changeset
|
53 |
def command(id: IsarDocument.Command_ID): Option[Command] = commands.get(id) |
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 |
||
34611 | 79 |
/* completions */ |
34489
7b7ccf0ff629
replaced java.util.Property by plain association list;
wenzelm
parents:
34485
diff
changeset
|
80 |
|
34612
5a03dc7a19e1
fall back on Isabelle system completion (symbols only);
wenzelm
parents:
34611
diff
changeset
|
81 |
private var _completion = Isabelle.completion |
5a03dc7a19e1
fall back on Isabelle system completion (symbols only);
wenzelm
parents:
34611
diff
changeset
|
82 |
def completion = _completion |
5a03dc7a19e1
fall back on Isabelle system completion (symbols only);
wenzelm
parents:
34611
diff
changeset
|
83 |
decl_info += (p => _completion += p._1) |
34489
7b7ccf0ff629
replaced java.util.Property by plain association list;
wenzelm
parents:
34485
diff
changeset
|
84 |
|
7b7ccf0ff629
replaced java.util.Property by plain association list;
wenzelm
parents:
34485
diff
changeset
|
85 |
|
7b7ccf0ff629
replaced java.util.Property by plain association list;
wenzelm
parents:
34485
diff
changeset
|
86 |
/* event handling */ |
7b7ccf0ff629
replaced java.util.Property by plain association list;
wenzelm
parents:
34485
diff
changeset
|
87 |
|
34456 | 88 |
val activated = new EventBus[Unit] |
89 |
val output_info = new EventBus[String] |
|
34582 | 90 |
var change_receiver: Actor = null |
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
91 |
|
34615 | 92 |
private def handle_result(result: Isabelle_Process.Result) |
34489
7b7ccf0ff629
replaced java.util.Property by plain association list;
wenzelm
parents:
34485
diff
changeset
|
93 |
{ |
34539 | 94 |
def command_change(c: Command) = this ! c |
34509 | 95 |
val (running, command) = |
96 |
result.props.find(p => p._1 == Markup.ID) match { |
|
97 |
case None => (false, null) |
|
98 |
case Some((_, id)) => |
|
99 |
if (commands.contains(id)) (false, commands(id)) |
|
100 |
else if (states.contains(id)) (true, states(id)) |
|
101 |
else (false, null) |
|
102 |
} |
|
34453 | 103 |
|
34615 | 104 |
if (result.kind == Isabelle_Process.Kind.STDOUT || |
105 |
result.kind == Isabelle_Process.Kind.STDIN) |
|
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
106 |
output_info.event(result.toString) |
34453 | 107 |
else { |
34509 | 108 |
result.kind match { |
109 |
||
34615 | 110 |
case Isabelle_Process.Kind.WRITELN |
111 |
| Isabelle_Process.Kind.PRIORITY |
|
112 |
| Isabelle_Process.Kind.WARNING |
|
113 |
| Isabelle_Process.Kind.ERROR => |
|
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
114 |
if (command != null) { |
34615 | 115 |
if (result.kind == Isabelle_Process.Kind.ERROR) |
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
116 |
command.status = Command.Status.FAILED |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
117 |
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
|
118 |
command_change(command) |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
119 |
} else { |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
120 |
output_info.event(result.toString) |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
121 |
} |
34404
98155c35d252
delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents:
34401
diff
changeset
|
122 |
|
34615 | 123 |
case Isabelle_Process.Kind.STATUS => |
34509 | 124 |
//{{{ handle all kinds of status messages here |
125 |
process.parse_message(result) match { |
|
126 |
case XML.Elem(Markup.MESSAGE, _, elems) => |
|
127 |
for (elem <- elems) { |
|
128 |
elem match { |
|
129 |
//{{{ |
|
130 |
// command and keyword declarations |
|
131 |
case XML.Elem(Markup.COMMAND_DECL, |
|
132 |
(Markup.NAME, name) :: (Markup.KIND, kind) :: _, _) => |
|
133 |
command_decls += (name -> kind) |
|
134 |
case XML.Elem(Markup.KEYWORD_DECL, (Markup.NAME, name) :: _, _) => |
|
135 |
keyword_decls += name |
|
34404
98155c35d252
delayed repainting new phase in buffer and overview;
immler@in.tum.de
parents:
34401
diff
changeset
|
136 |
|
34589
d461e5506d02
handle_result: activate via explicit status "ready" (cf. http://isabelle.in.tum.de/repos/isabelle/rev/ce169bd37fc0);
wenzelm
parents:
34582
diff
changeset
|
137 |
// process ready (after initialization) |
d461e5506d02
handle_result: activate via explicit status "ready" (cf. http://isabelle.in.tum.de/repos/isabelle/rev/ce169bd37fc0);
wenzelm
parents:
34582
diff
changeset
|
138 |
case XML.Elem(Markup.READY, _, _) |
d461e5506d02
handle_result: activate via explicit status "ready" (cf. http://isabelle.in.tum.de/repos/isabelle/rev/ce169bd37fc0);
wenzelm
parents:
34582
diff
changeset
|
139 |
if !initialized => |
d461e5506d02
handle_result: activate via explicit status "ready" (cf. http://isabelle.in.tum.de/repos/isabelle/rev/ce169bd37fc0);
wenzelm
parents:
34582
diff
changeset
|
140 |
initialized = true |
34634
4b797391859a
renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents:
34615
diff
changeset
|
141 |
Swing_Thread.now { this ! ProverEvents.Activate } |
34589
d461e5506d02
handle_result: activate via explicit status "ready" (cf. http://isabelle.in.tum.de/repos/isabelle/rev/ce169bd37fc0);
wenzelm
parents:
34582
diff
changeset
|
142 |
|
34509 | 143 |
// document edits |
144 |
case XML.Elem(Markup.EDITS, (Markup.ID, doc_id) :: _, edits) |
|
34582 | 145 |
if document_versions.exists(_.id == doc_id) => |
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
146 |
output_info.event(result.toString) |
34509 | 147 |
for { |
148 |
XML.Elem(Markup.EDIT, (Markup.ID, cmd_id) :: (Markup.STATE, state_id) :: _, _) |
|
149 |
<- edits |
|
150 |
} { |
|
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
151 |
if (commands.contains(cmd_id)) { |
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
152 |
val cmd = commands(cmd_id) |
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
153 |
if (cmd.state_id != null) states -= cmd.state_id |
34540 | 154 |
states(state_id) = cmd |
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
155 |
cmd.state_id = state_id |
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
156 |
cmd.status = Command.Status.UNPROCESSED |
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
157 |
command_change(cmd) |
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
158 |
} |
34453 | 159 |
|
34509 | 160 |
} |
161 |
// command status |
|
162 |
case XML.Elem(Markup.UNPROCESSED, _, _) |
|
163 |
if command != null => |
|
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
164 |
output_info.event(result.toString) |
34509 | 165 |
command.status = Command.Status.UNPROCESSED |
166 |
command_change(command) |
|
167 |
case XML.Elem(Markup.FINISHED, _, _) |
|
168 |
if command != null => |
|
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
169 |
output_info.event(result.toString) |
34509 | 170 |
command.status = Command.Status.FINISHED |
171 |
command_change(command) |
|
172 |
case XML.Elem(Markup.FAILED, _, _) |
|
173 |
if command != null => |
|
34533
35308320713a
preliminary/failed attempt to use the new IsarDocument access model to the prover;
wenzelm
parents:
34509
diff
changeset
|
174 |
output_info.event(result.toString) |
34509 | 175 |
command.status = Command.Status.FAILED |
176 |
command_change(command) |
|
34570
c3bdaea2dd6a
improved handling of markup-information with command=null
immler@in.tum.de
parents:
34568
diff
changeset
|
177 |
case XML.Elem(kind, attr, body) |
c3bdaea2dd6a
improved handling of markup-information with command=null
immler@in.tum.de
parents:
34568
diff
changeset
|
178 |
if command != null => |
34610 | 179 |
val (begin, end) = Position.offsets_of(attr) |
34576
b86c54be2fe0
check presence of begin, end in attributes
immler@in.tum.de
parents:
34570
diff
changeset
|
180 |
if (begin.isDefined && end.isDefined) { |
b86c54be2fe0
check presence of begin, end in attributes
immler@in.tum.de
parents:
34570
diff
changeset
|
181 |
if (kind == Markup.ML_TYPING) { |
b86c54be2fe0
check presence of begin, end in attributes
immler@in.tum.de
parents:
34570
diff
changeset
|
182 |
val info = body.first.asInstanceOf[XML.Text].content |
34610 | 183 |
command.markup_root += |
184 |
command.markup_node(begin.get - 1, end.get - 1, TypeInfo(info)) |
|
34576
b86c54be2fe0
check presence of begin, end in attributes
immler@in.tum.de
parents:
34570
diff
changeset
|
185 |
} else if (kind == Markup.ML_REF) { |
b86c54be2fe0
check presence of begin, end in attributes
immler@in.tum.de
parents:
34570
diff
changeset
|
186 |
body match { |
b86c54be2fe0
check presence of begin, end in attributes
immler@in.tum.de
parents:
34570
diff
changeset
|
187 |
case List(XML.Elem(Markup.ML_DEF, attr, _)) => |
34610 | 188 |
command.markup_root += command.markup_node( |
189 |
begin.get - 1, end.get - 1, |
|
190 |
RefInfo( |
|
191 |
Position.file_of(attr), |
|
192 |
Position.line_of(attr), |
|
193 |
Position.id_of(attr), |
|
194 |
Position.offset_of(attr))) |
|
34576
b86c54be2fe0
check presence of begin, end in attributes
immler@in.tum.de
parents:
34570
diff
changeset
|
195 |
case _ => |
b86c54be2fe0
check presence of begin, end in attributes
immler@in.tum.de
parents:
34570
diff
changeset
|
196 |
} |
b86c54be2fe0
check presence of begin, end in attributes
immler@in.tum.de
parents:
34570
diff
changeset
|
197 |
} else { |
34610 | 198 |
command.markup_root += |
199 |
command.markup_node(begin.get - 1, end.get - 1, HighlightInfo(kind)) |
|
34570
c3bdaea2dd6a
improved handling of markup-information with command=null
immler@in.tum.de
parents:
34568
diff
changeset
|
200 |
} |
34557 | 201 |
} |
34555
7c001369956a
included information on ML status messages in Sidekick's status-window
immler@in.tum.de
parents:
34554
diff
changeset
|
202 |
command_change(command) |
34570
c3bdaea2dd6a
improved handling of markup-information with command=null
immler@in.tum.de
parents:
34568
diff
changeset
|
203 |
case XML.Elem(kind, attr, body) |
c3bdaea2dd6a
improved handling of markup-information with command=null
immler@in.tum.de
parents:
34568
diff
changeset
|
204 |
if command == null => |
c3bdaea2dd6a
improved handling of markup-information with command=null
immler@in.tum.de
parents:
34568
diff
changeset
|
205 |
// TODO: This is mostly irrelevant information on removed commands, but it can |
c3bdaea2dd6a
improved handling of markup-information with command=null
immler@in.tum.de
parents:
34568
diff
changeset
|
206 |
// also be outer-syntax-markup since there is no id in props (fix that?) |
34610 | 207 |
val (begin, end) = Position.offsets_of(attr) |
208 |
val markup_id = Position.id_of(attr) |
|
34579
f5c3ad245539
outer syntax could clash with status on removed commands
immler@in.tum.de
parents:
34578
diff
changeset
|
209 |
val outer = isabelle.jedit.DynamicTokenMarker.is_outer(kind) |
f5c3ad245539
outer syntax could clash with status on removed commands
immler@in.tum.de
parents:
34578
diff
changeset
|
210 |
if (outer && !running && begin.isDefined && end.isDefined && markup_id.isDefined) |
34570
c3bdaea2dd6a
improved handling of markup-information with command=null
immler@in.tum.de
parents:
34568
diff
changeset
|
211 |
commands.get(markup_id.get).map (cmd => { |
34610 | 212 |
cmd.markup_root += |
213 |
cmd.markup_node(begin.get - 1, end.get - 1, OuterInfo(kind)) |
|
34570
c3bdaea2dd6a
improved handling of markup-information with command=null
immler@in.tum.de
parents:
34568
diff
changeset
|
214 |
command_change(cmd) |
c3bdaea2dd6a
improved handling of markup-information with command=null
immler@in.tum.de
parents:
34568
diff
changeset
|
215 |
}) |
34509 | 216 |
case _ => |
217 |
//}}} |
|
34453 | 218 |
} |
34509 | 219 |
} |
220 |
case _ => |
|
221 |
} |
|
222 |
//}}} |
|
34453 | 223 |
|
34509 | 224 |
case _ => |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
225 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
226 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
227 |
} |
34453 | 228 |
|
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
229 |
def act() { |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
230 |
import ProverEvents._ |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
231 |
loop { |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
232 |
react { |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
233 |
case Activate => { |
34544
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
234 |
val old = document |
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
235 |
val (doc, structure_change) = old.activate |
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
236 |
document_versions ::= doc |
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
237 |
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
|
238 |
} |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
239 |
case SetIsCommandKeyword(f) => { |
34544
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
240 |
val old = document |
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
241 |
val doc = old.set_command_keyword(f) |
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
242 |
document_versions ::= doc |
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
243 |
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
|
244 |
} |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
245 |
case change: Text.Change => { |
34544
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
246 |
val old = document |
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
247 |
val (doc, structure_change) = old.text_changed(change) |
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
248 |
document_versions ::= doc |
56217d219e27
proofdocument-versions get id from changes
immler@in.tum.de
parents:
34540
diff
changeset
|
249 |
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
|
250 |
} |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
251 |
case command: Command => { |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
252 |
//state of command has changed |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
253 |
change_receiver ! command |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
254 |
} |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
255 |
} |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
256 |
} |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
257 |
} |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
258 |
|
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
259 |
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
|
260 |
this.change_receiver = change_receiver |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
261 |
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
|
262 |
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
|
263 |
} |
34453 | 264 |
|
34634
4b797391859a
renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents:
34615
diff
changeset
|
265 |
private def edit_document(old_id: String, document_id: String, changes: StructureChange) = |
4b797391859a
renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents:
34615
diff
changeset
|
266 |
Swing_Thread.now { |
4b797391859a
renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents:
34615
diff
changeset
|
267 |
val removes = |
4b797391859a
renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents:
34615
diff
changeset
|
268 |
for (cmd <- changes.removed_commands) yield { |
4b797391859a
renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents:
34615
diff
changeset
|
269 |
commands -= cmd.id |
4b797391859a
renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents:
34615
diff
changeset
|
270 |
if (cmd.state_id != null) states -= cmd.state_id |
4b797391859a
renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents:
34615
diff
changeset
|
271 |
changes.before_change.map(_.id).getOrElse(document_id0) -> None |
4b797391859a
renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents:
34615
diff
changeset
|
272 |
} |
4b797391859a
renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents:
34615
diff
changeset
|
273 |
val inserts = |
4b797391859a
renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents:
34615
diff
changeset
|
274 |
for (cmd <- changes.added_commands) yield { |
4b797391859a
renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents:
34615
diff
changeset
|
275 |
commands += (cmd.id -> cmd) |
4b797391859a
renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents:
34615
diff
changeset
|
276 |
process.define_command(cmd.id, isabelle_system.symbols.encode(cmd.content)) |
4b797391859a
renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents:
34615
diff
changeset
|
277 |
(document.commands.prev(cmd).map(_.id).getOrElse(document_id0)) -> Some(cmd.id) |
4b797391859a
renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents:
34615
diff
changeset
|
278 |
} |
4b797391859a
renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents:
34615
diff
changeset
|
279 |
process.edit_document(old_id, document_id, removes.reverse ++ inserts) |
4b797391859a
renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents:
34615
diff
changeset
|
280 |
} |
34453 | 281 |
} |