From 2e4d37e3ca6bf5e655d900af570d65d681f486dd Mon Sep 17 00:00:00 2001 From: Makarius Date: Sun, 19 Dec 2021 15:23:33 +0100 Subject: [PATCH] More on Document preparation in Isabelle/ML. --- NOTES.thy | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/NOTES.thy b/NOTES.thy index 8f3463c3..4fbb6773 100644 --- a/NOTES.thy +++ b/NOTES.thy @@ -78,7 +78,55 @@ text \ \ -section \Isabelle/ML\ +section \Document preparation in Isabelle/ML\ + +subsection \Theory presentation hook\ + +text \ + \<^ML>\Thy_Info.add_presentation\ installs a hook to be invoked at the + end of successful loading of theories; the provided context + \<^ML_type>\Thy_Info.presentation_context\ provides access to + \<^ML_type>\Options.T\ and \<^ML_type>\Document_Output.segment\ with + command-spans and semantic states. + + An example is regular Latex output in + \<^file>\$ISABELLE_HOME/src/Pure/Thy/thy_info.ML\ where \<^ML>\Export.export\ + is used to produce export artifacts in the session build database, for + retrieval via Isabelle/Scala. +\ + + +subsection \Document commands\ + +text \ + Isar toplevel commands now support a uniform concept for + \<^ML_type>\Toplevel.presentation\, but the exported interfaces are + limited to commands that do not change the semantic state: see + \<^ML>\Toplevel.present\ and \<^ML>\Toplevel.present_local_theory\. + + There is an adhoc change to support \<^verbatim>\Toplevel.present_theory\ in + \<^file>\$ISABELLE_DOF_HOME/src/patches/present_theory\. + + An alternative, without patching Isabelle2021-1 in production, is to use + the presentation hook together with a function like this: +\ + +ML \ + fun present_segment pr (segment: Document_Output.segment) = + (case #span segment of + Command_Span.Span (Command_Span.Command_Span (name, _), toks) => + let + val {span, command = tr, prev_state = st, state = st'} = segment; + val tr' = + Toplevel.empty + |> Toplevel.name (Toplevel.name_of tr) + |> Toplevel.position (Toplevel.pos_of tr) + |> Toplevel.present (pr name toks); + val st'' = Toplevel.command_exception false tr' st' + handle Runtime.EXCURSION_FAIL (exn, _) => Exn.reraise exn; + in {span = span, command = tr, prev_state = st, state = st''} end + | _ => segment); +\ section \Isabelle/Scala\