29 |
29 |
30 class Prover(isabelle_system: IsabelleSystem, logic: String) extends Actor |
30 class Prover(isabelle_system: IsabelleSystem, logic: String) extends Actor |
31 { |
31 { |
32 /* prover process */ |
32 /* prover process */ |
33 |
33 |
34 |
|
35 private val process = |
34 private val process = |
36 { |
35 { |
37 val results = new EventBus[IsabelleProcess.Result] + handle_result |
36 val results = new EventBus[IsabelleProcess.Result] + handle_result |
38 results.logger = Log.log(Log.ERROR, null, _) |
37 results.logger = Log.log(Log.ERROR, null, _) |
39 new IsabelleProcess(isabelle_system, results, "-m", "xsymbols", logic) with IsarDocument |
38 new IsabelleProcess(isabelle_system, results, "-m", "xsymbols", logic) with IsarDocument |
98 var change_receiver: Actor = null |
97 var change_receiver: Actor = null |
99 |
98 |
100 private def handle_result(result: IsabelleProcess.Result) |
99 private def handle_result(result: IsabelleProcess.Result) |
101 { |
100 { |
102 // helper-function (move to XML?) |
101 // helper-function (move to XML?) |
103 def get_attr(attributes: List[(String, String)], attr: String): Option[String] = |
102 def get_attr(attrs: List[(String, String)], name: String): Option[String] = |
104 attributes.find(p => p._1 == attr).map(_._2) |
103 attrs.find(p => p._1 == name).map(_._2) |
|
104 |
|
105 def get_offsets(attrs: List[(String, String)]): (Option[Int], Option[Int]) = |
|
106 { |
|
107 val begin = get_attr(attrs, Markup.OFFSET).map(_.toInt - 1) |
|
108 val end = get_attr(attrs, Markup.END_OFFSET).map(_.toInt - 1) |
|
109 (begin, if (end.isDefined) end else begin.map(_ + 1)) |
|
110 } |
105 |
111 |
106 def command_change(c: Command) = this ! c |
112 def command_change(c: Command) = this ! c |
107 val (running, command) = |
113 val (running, command) = |
108 result.props.find(p => p._1 == Markup.ID) match { |
114 result.props.find(p => p._1 == Markup.ID) match { |
109 case None => (false, null) |
115 case None => (false, null) |
186 output_info.event(result.toString) |
192 output_info.event(result.toString) |
187 command.status = Command.Status.FAILED |
193 command.status = Command.Status.FAILED |
188 command_change(command) |
194 command_change(command) |
189 case XML.Elem(kind, attr, body) |
195 case XML.Elem(kind, attr, body) |
190 if command != null => |
196 if command != null => |
191 val begin = get_attr(attr, Markup.OFFSET).map(_.toInt - 1) |
197 val (begin, end) = get_offsets(attr) |
192 val end = get_attr(attr, Markup.END_OFFSET).map(_.toInt - 1) |
|
193 if (begin.isDefined && end.isDefined) { |
198 if (begin.isDefined && end.isDefined) { |
194 if (kind == Markup.ML_TYPING) { |
199 if (kind == Markup.ML_TYPING) { |
195 val info = body.first.asInstanceOf[XML.Text].content |
200 val info = body.first.asInstanceOf[XML.Text].content |
196 command.markup_root += command.markup_node(begin.get, end.get, TypeInfo(info)) |
201 command.markup_root += command.markup_node(begin.get, end.get, TypeInfo(info)) |
197 } else if (kind == Markup.ML_REF) { |
202 } else if (kind == Markup.ML_REF) { |
211 command_change(command) |
216 command_change(command) |
212 case XML.Elem(kind, attr, body) |
217 case XML.Elem(kind, attr, body) |
213 if command == null => |
218 if command == null => |
214 // TODO: This is mostly irrelevant information on removed commands, but it can |
219 // TODO: This is mostly irrelevant information on removed commands, but it can |
215 // also be outer-syntax-markup since there is no id in props (fix that?) |
220 // also be outer-syntax-markup since there is no id in props (fix that?) |
216 val begin = get_attr(attr, Markup.OFFSET).map(_.toInt - 1) |
221 val (begin, end) = get_offsets(attr) |
217 val end = get_attr(attr, Markup.END_OFFSET).map(_.toInt - 1) |
|
218 val markup_id = get_attr(attr, Markup.ID) |
222 val markup_id = get_attr(attr, Markup.ID) |
219 val outer = isabelle.jedit.DynamicTokenMarker.is_outer(kind) |
223 val outer = isabelle.jedit.DynamicTokenMarker.is_outer(kind) |
220 if (outer && !running && begin.isDefined && end.isDefined && markup_id.isDefined) |
224 if (outer && !running && begin.isDefined && end.isDefined && markup_id.isDefined) |
221 commands.get(markup_id.get).map (cmd => { |
225 commands.get(markup_id.get).map (cmd => { |
222 cmd.markup_root += cmd.markup_node(begin.get, end.get, OuterInfo(kind)) |
226 cmd.markup_root += cmd.markup_node(begin.get, end.get, OuterInfo(kind)) |
266 } |
270 } |
267 |
271 |
268 def set_document(change_receiver: Actor, path: String) { |
272 def set_document(change_receiver: Actor, path: String) { |
269 this.change_receiver = change_receiver |
273 this.change_receiver = change_receiver |
270 this ! ProverEvents.SetIsCommandKeyword(command_decls.contains) |
274 this ! ProverEvents.SetIsCommandKeyword(command_decls.contains) |
271 process.ML("()") // FIXME force initial writeln |
|
272 process.begin_document(document_id0, path) |
275 process.begin_document(document_id0, path) |
273 } |
276 } |
274 |
277 |
275 private def edit_document(old_id: String, document_id: String, changes: StructureChange) = Swing.now |
278 private def edit_document(old_id: String, document_id: String, changes: StructureChange) = Swing.now |
276 { |
279 { |