|
1 /* Title: Pure/Isar/isar_document.scala |
|
2 Author: Makarius |
|
3 |
|
4 Interactive Isar documents. |
|
5 */ |
|
6 |
|
7 package isabelle |
|
8 |
|
9 |
|
10 object IsarDocument |
|
11 { |
|
12 /* unique identifiers */ |
|
13 |
|
14 type State_ID = String |
|
15 type Command_ID = String |
|
16 type Document_ID = String |
|
17 |
|
18 |
|
19 /* commands */ |
|
20 |
|
21 def define_command(proc: IsabelleProcess, id: Command_ID, text: String) { |
|
22 proc.output_sync("Isar.define_command " + IsabelleSyntax.encode_string(id) + " " + |
|
23 IsabelleSyntax.encode_string(text)) |
|
24 } |
|
25 |
|
26 |
|
27 /* documents */ |
|
28 |
|
29 def begin_document(proc: IsabelleProcess, id: Document_ID, path: String) { |
|
30 proc.output_sync("Isar.begin_document " + IsabelleSyntax.encode_string(id) + " " + |
|
31 IsabelleSyntax.encode_string(path)) |
|
32 } |
|
33 |
|
34 def end_document(proc: IsabelleProcess, id: Document_ID) { |
|
35 proc.output_sync("Isar.end_document " + IsabelleSyntax.encode_string(id)) |
|
36 } |
|
37 |
|
38 def edit_document(proc: IsabelleProcess, old_id: Document_ID, new_id: Document_ID, |
|
39 edits: List[(Command_ID, Option[Command_ID])]) |
|
40 { |
|
41 def append_edit(edit: (Command_ID, Option[Command_ID]), result: StringBuilder) |
|
42 { |
|
43 edit match { |
|
44 case (id, None) => IsabelleSyntax.append_string(id, result) |
|
45 case (id, Some(id2)) => |
|
46 IsabelleSyntax.append_string(id, result) |
|
47 result.append(" ") |
|
48 IsabelleSyntax.append_string(id2, result) |
|
49 } |
|
50 } |
|
51 |
|
52 val buf = new StringBuilder(40) |
|
53 buf.append("Isar.edit_document ") |
|
54 IsabelleSyntax.append_string(old_id, buf) |
|
55 buf.append(" ") |
|
56 IsabelleSyntax.append_string(new_id, buf) |
|
57 buf.append(" ") |
|
58 IsabelleSyntax.append_list(append_edit, edits, buf) |
|
59 proc.output_sync(buf.toString) |
|
60 } |
|
61 } |