289 } |
288 } |
290 |
289 |
291 |
290 |
292 trait Protocol |
291 trait Protocol |
293 { |
292 { |
294 /* text */ |
|
295 |
|
296 def encode(s: String): String |
|
297 def decode(s: String): String |
|
298 |
|
299 object Encode |
|
300 { |
|
301 val string: XML.Encode.T[String] = (s => XML.Encode.string(encode(s))) |
|
302 } |
|
303 |
|
304 |
|
305 /* protocol commands */ |
293 /* protocol commands */ |
306 |
294 |
307 def protocol_command_bytes(name: String, args: Bytes*): Unit |
295 def protocol_command_bytes(name: String, args: Bytes*): Unit |
308 def protocol_command(name: String, args: String*): Unit |
296 def protocol_command(name: String, args: String*): Unit |
309 |
297 |
310 |
298 |
311 /* options */ |
299 /* options */ |
312 |
300 |
313 def options(opts: Options): Unit = |
301 def options(opts: Options): Unit = |
314 protocol_command("Prover.options", YXML.string_of_body(opts.encode)) |
302 protocol_command("Prover.options", Symbol.encode_yxml(opts.encode)) |
315 |
303 |
316 |
304 |
317 /* interned items */ |
305 /* interned items */ |
318 |
306 |
319 def define_blob(digest: SHA1.Digest, bytes: Bytes): Unit = |
307 def define_blob(digest: SHA1.Digest, bytes: Bytes): Unit = |
325 { |
313 { |
326 import XML.Encode._ |
314 import XML.Encode._ |
327 val encode_blob: T[Command.Blob] = |
315 val encode_blob: T[Command.Blob] = |
328 variant(List( |
316 variant(List( |
329 { case Exn.Res((a, b)) => |
317 { case Exn.Res((a, b)) => |
330 (Nil, pair(Encode.string, option(string))((a.node, b.map(p => p._1.toString)))) }, |
318 (Nil, pair(string, option(string))((a.node, b.map(p => p._1.toString)))) }, |
331 { case Exn.Exn(e) => (Nil, Encode.string(Exn.message(e))) })) |
319 { case Exn.Exn(e) => (Nil, string(Exn.message(e))) })) |
332 |
320 |
333 YXML.string_of_body(pair(list(encode_blob), int)(command.blobs, command.blobs_index)) |
321 Symbol.encode_yxml(pair(list(encode_blob), int)(command.blobs, command.blobs_index)) |
334 } |
322 } |
335 |
323 |
336 val toks = command.span.content |
324 val toks = command.span.content |
337 val toks_yxml = |
325 val toks_yxml = |
338 { |
326 { |
339 import XML.Encode._ |
327 import XML.Encode._ |
340 val encode_tok: T[Token] = (tok => pair(int, int)((tok.kind.id, Symbol.length(tok.source)))) |
328 val encode_tok: T[Token] = (tok => pair(int, int)((tok.kind.id, Symbol.length(tok.source)))) |
341 YXML.string_of_body(list(encode_tok)(toks)) |
329 Symbol.encode_yxml(list(encode_tok)(toks)) |
342 } |
330 } |
343 |
331 |
344 protocol_command("Document.define_command", |
332 protocol_command("Document.define_command", |
345 (Document_ID(command.id) :: encode(command.span.name) :: blobs_yxml :: toks_yxml :: |
333 (Document_ID(command.id) :: Symbol.encode(command.span.name) :: blobs_yxml :: toks_yxml :: |
346 toks.map(tok => encode(tok.source))): _*) |
334 toks.map(tok => Symbol.encode(tok.source))): _*) |
347 } |
335 } |
348 |
336 |
349 |
337 |
350 /* execution */ |
338 /* execution */ |
351 |
339 |
372 { case Document.Node.Deps(header) => |
360 { case Document.Node.Deps(header) => |
373 val master_dir = File.standard_url(name.master_dir) |
361 val master_dir = File.standard_url(name.master_dir) |
374 val theory = Long_Name.base_name(name.theory) |
362 val theory = Long_Name.base_name(name.theory) |
375 val imports = header.imports.map({ case (a, _) => a.node }) |
363 val imports = header.imports.map({ case (a, _) => a.node }) |
376 (Nil, |
364 (Nil, |
377 pair(Encode.string, pair(Encode.string, pair(list(Encode.string), |
365 pair(string, pair(string, pair(list(string), pair(list(pair(string, |
378 pair(list(pair(Encode.string, |
366 pair(pair(string, list(string)), list(string)))), list(string)))))( |
379 pair(pair(Encode.string, list(Encode.string)), list(Encode.string)))), |
|
380 list(Encode.string)))))( |
|
381 (master_dir, (theory, (imports, (header.keywords, header.errors)))))) }, |
367 (master_dir, (theory, (imports, (header.keywords, header.errors)))))) }, |
382 { case Document.Node.Perspective(a, b, c) => |
368 { case Document.Node.Perspective(a, b, c) => |
383 (bool_atom(a) :: b.commands.map(cmd => long_atom(cmd.id)), |
369 (bool_atom(a) :: b.commands.map(cmd => long_atom(cmd.id)), |
384 list(pair(id, pair(Encode.string, list(Encode.string))))(c.dest)) })) |
370 list(pair(id, pair(string, list(string))))(c.dest)) })) |
385 def encode_edits: T[List[Document.Edit_Command]] = list((node_edit: Document.Edit_Command) => |
371 def encode_edits: T[List[Document.Edit_Command]] = list((node_edit: Document.Edit_Command) => |
386 { |
372 { |
387 val (name, edit) = node_edit |
373 val (name, edit) = node_edit |
388 pair(Encode.string, encode_edit(name))(name.node, edit) |
374 pair(string, encode_edit(name))(name.node, edit) |
389 }) |
375 }) |
390 YXML.string_of_body(encode_edits(edits)) } |
376 Symbol.encode_yxml(encode_edits(edits)) } |
391 protocol_command("Document.update", Document_ID(old_id), Document_ID(new_id), edits_yxml) |
377 protocol_command("Document.update", Document_ID(old_id), Document_ID(new_id), edits_yxml) |
392 } |
378 } |
393 |
379 |
394 def remove_versions(versions: List[Document.Version]) |
380 def remove_versions(versions: List[Document.Version]) |
395 { |
381 { |
396 val versions_yxml = |
382 val versions_yxml = |
397 { import XML.Encode._ |
383 { import XML.Encode._ |
398 YXML.string_of_body(list(long)(versions.map(_.id))) } |
384 Symbol.encode_yxml(list(long)(versions.map(_.id))) } |
399 protocol_command("Document.remove_versions", versions_yxml) |
385 protocol_command("Document.remove_versions", versions_yxml) |
400 } |
386 } |
401 |
387 |
402 |
388 |
403 /* dialog via document content */ |
389 /* dialog via document content */ |