| author | blanchet | 
| Tue, 17 Aug 2010 13:10:58 +0200 | |
| changeset 38457 | b8760b6e7c65 | 
| parent 38420 | 7bdf6c79a2db | 
| child 38448 | 62d16c415019 | 
| permissions | -rw-r--r-- | 
| 38412 
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
 wenzelm parents: diff
changeset | 1 | (* Title: Pure/System/isar_document.ML | 
| 
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
 wenzelm parents: diff
changeset | 2 | Author: Makarius | 
| 
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
 wenzelm parents: diff
changeset | 3 | |
| 38418 
9a7af64d71bb
more explicit / functional ML version of document model;
 wenzelm parents: 
38417diff
changeset | 4 | Protocol commands for interactive Isar documents. | 
| 38412 
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
 wenzelm parents: diff
changeset | 5 | *) | 
| 
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
 wenzelm parents: diff
changeset | 6 | |
| 
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
 wenzelm parents: diff
changeset | 7 | structure Isar_Document: sig end = | 
| 
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
 wenzelm parents: diff
changeset | 8 | struct | 
| 
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
 wenzelm parents: diff
changeset | 9 | |
| 38420 
7bdf6c79a2db
use Synchronized.var and prevent global CRITICAL sections in this hot spot;
 wenzelm parents: 
38418diff
changeset | 10 | val global_state = Synchronized.var "Isar_Document" Document.init_state; | 
| 
7bdf6c79a2db
use Synchronized.var and prevent global CRITICAL sections in this hot spot;
 wenzelm parents: 
38418diff
changeset | 11 | val change_state = Synchronized.change global_state; | 
| 38412 
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
 wenzelm parents: diff
changeset | 12 | |
| 38418 
9a7af64d71bb
more explicit / functional ML version of document model;
 wenzelm parents: 
38417diff
changeset | 13 | val _ = | 
| 
9a7af64d71bb
more explicit / functional ML version of document model;
 wenzelm parents: 
38417diff
changeset | 14 | Isabelle_Process.add_command "Isar_Document.define_command" | 
| 
9a7af64d71bb
more explicit / functional ML version of document model;
 wenzelm parents: 
38417diff
changeset | 15 | (fn [id, text] => change_state (Document.define_command (Document.parse_id id) text)); | 
| 38412 
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
 wenzelm parents: diff
changeset | 16 | |
| 38418 
9a7af64d71bb
more explicit / functional ML version of document model;
 wenzelm parents: 
38417diff
changeset | 17 | val _ = | 
| 
9a7af64d71bb
more explicit / functional ML version of document model;
 wenzelm parents: 
38417diff
changeset | 18 | Isabelle_Process.add_command "Isar_Document.edit_version" | 
| 
9a7af64d71bb
more explicit / functional ML version of document model;
 wenzelm parents: 
38417diff
changeset | 19 | (fn [old_id_string, new_id_string, edits_yxml] => change_state (fn state => | 
| 
9a7af64d71bb
more explicit / functional ML version of document model;
 wenzelm parents: 
38417diff
changeset | 20 | let | 
| 
9a7af64d71bb
more explicit / functional ML version of document model;
 wenzelm parents: 
38417diff
changeset | 21 | val old_id = Document.parse_id old_id_string; | 
| 
9a7af64d71bb
more explicit / functional ML version of document model;
 wenzelm parents: 
38417diff
changeset | 22 | val new_id = Document.parse_id new_id_string; | 
| 
9a7af64d71bb
more explicit / functional ML version of document model;
 wenzelm parents: 
38417diff
changeset | 23 | val edits = | 
| 
9a7af64d71bb
more explicit / functional ML version of document model;
 wenzelm parents: 
38417diff
changeset | 24 | XML_Data.dest_list (XML_Data.dest_pair XML_Data.dest_string | 
| 
9a7af64d71bb
more explicit / functional ML version of document model;
 wenzelm parents: 
38417diff
changeset | 25 | (XML_Data.dest_option (XML_Data.dest_list | 
| 
9a7af64d71bb
more explicit / functional ML version of document model;
 wenzelm parents: 
38417diff
changeset | 26 | (XML_Data.dest_pair XML_Data.dest_int | 
| 
9a7af64d71bb
more explicit / functional ML version of document model;
 wenzelm parents: 
38417diff
changeset | 27 | (XML_Data.dest_option XML_Data.dest_int))))) (YXML.parse_body edits_yxml); | 
| 38412 
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
 wenzelm parents: diff
changeset | 28 | |
| 38418 
9a7af64d71bb
more explicit / functional ML version of document model;
 wenzelm parents: 
38417diff
changeset | 29 | val (updates, state') = Document.edit old_id new_id edits state; | 
| 
9a7af64d71bb
more explicit / functional ML version of document model;
 wenzelm parents: 
38417diff
changeset | 30 | val _ = | 
| 
9a7af64d71bb
more explicit / functional ML version of document model;
 wenzelm parents: 
38417diff
changeset | 31 | implode (map (fn (id, exec_id) => Markup.markup (Markup.edit id exec_id) "") updates) | 
| 
9a7af64d71bb
more explicit / functional ML version of document model;
 wenzelm parents: 
38417diff
changeset | 32 | |> Markup.markup (Markup.assign new_id) | 
| 
9a7af64d71bb
more explicit / functional ML version of document model;
 wenzelm parents: 
38417diff
changeset | 33 | |> Output.status; | 
| 
9a7af64d71bb
more explicit / functional ML version of document model;
 wenzelm parents: 
38417diff
changeset | 34 | val state'' = Document.execute new_id state'; | 
| 
9a7af64d71bb
more explicit / functional ML version of document model;
 wenzelm parents: 
38417diff
changeset | 35 | in state'' end)); | 
| 38412 
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
 wenzelm parents: diff
changeset | 36 | |
| 
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
 wenzelm parents: diff
changeset | 37 | end; | 
| 
c23f3abbf42d
moved isar_document.ML/scala to Pure/System/ -- side-by-side with isar.ML;
 wenzelm parents: diff
changeset | 38 |