src/Pure/pure_syn.ML
author nipkow
Fri, 11 Dec 2020 17:58:01 +0100
changeset 72884 50f18a822ee9
parent 69965 da5e7278286b
child 73751 fefb5ccb1e5e
permissions -rw-r--r--
merged
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48879
cb5cdbb645cd clarified bootstrapping of Pure;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/pure_syn.ML
cb5cdbb645cd clarified bootstrapping of Pure;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
cb5cdbb645cd clarified bootstrapping of Pure;
wenzelm
parents:
diff changeset
     3
60096
7b98dbc1d13e tuned comment;
wenzelm
parents: 60095
diff changeset
     4
Outer syntax for bootstrapping: commands that are accessible outside a
7b98dbc1d13e tuned comment;
wenzelm
parents: 60095
diff changeset
     5
regular theory context.
48879
cb5cdbb645cd clarified bootstrapping of Pure;
wenzelm
parents:
diff changeset
     6
*)
cb5cdbb645cd clarified bootstrapping of Pure;
wenzelm
parents:
diff changeset
     7
60095
35f626b11422 more explicit bootstrap_thy;
wenzelm
parents: 58999
diff changeset
     8
signature PURE_SYN =
35f626b11422 more explicit bootstrap_thy;
wenzelm
parents: 58999
diff changeset
     9
sig
67381
146757999c8d theory Pure is default presentation context;
wenzelm
parents: 64556
diff changeset
    10
  val document_command: {markdown: bool} -> (xstring * Position.T) option * Input.source ->
146757999c8d theory Pure is default presentation context;
wenzelm
parents: 64556
diff changeset
    11
    Toplevel.transition -> Toplevel.transition
60095
35f626b11422 more explicit bootstrap_thy;
wenzelm
parents: 58999
diff changeset
    12
  val bootstrap_thy: theory
35f626b11422 more explicit bootstrap_thy;
wenzelm
parents: 58999
diff changeset
    13
end;
35f626b11422 more explicit bootstrap_thy;
wenzelm
parents: 58999
diff changeset
    14
35f626b11422 more explicit bootstrap_thy;
wenzelm
parents: 58999
diff changeset
    15
structure Pure_Syn: PURE_SYN =
48879
cb5cdbb645cd clarified bootstrapping of Pure;
wenzelm
parents:
diff changeset
    16
struct
cb5cdbb645cd clarified bootstrapping of Pure;
wenzelm
parents:
diff changeset
    17
62912
745d31e63c21 section headings for ROOT.ML;
wenzelm
parents: 62876
diff changeset
    18
val semi = Scan.option (Parse.$$$ ";");
745d31e63c21 section headings for ROOT.ML;
wenzelm
parents: 62876
diff changeset
    19
67569
5d71b114e7a3 avoid proliferation of language_document reports;
wenzelm
parents: 67381
diff changeset
    20
fun output_document state markdown txt =
5d71b114e7a3 avoid proliferation of language_document reports;
wenzelm
parents: 67381
diff changeset
    21
  let
5d71b114e7a3 avoid proliferation of language_document reports;
wenzelm
parents: 67381
diff changeset
    22
    val ctxt = Toplevel.presentation_context state;
69965
da5e7278286b more markup for various text kinds, notably for nested formal comments;
wenzelm
parents: 67569
diff changeset
    23
    val pos = Input.pos_of txt;
67569
5d71b114e7a3 avoid proliferation of language_document reports;
wenzelm
parents: 67381
diff changeset
    24
    val _ =
69965
da5e7278286b more markup for various text kinds, notably for nested formal comments;
wenzelm
parents: 67569
diff changeset
    25
      Context_Position.reports ctxt
da5e7278286b more markup for various text kinds, notably for nested formal comments;
wenzelm
parents: 67569
diff changeset
    26
        [(pos, Markup.language_document (Input.is_delimited txt)),
da5e7278286b more markup for various text kinds, notably for nested formal comments;
wenzelm
parents: 67569
diff changeset
    27
         (pos, Markup.plain_text)];
67569
5d71b114e7a3 avoid proliferation of language_document reports;
wenzelm
parents: 67381
diff changeset
    28
  in Thy_Output.output_document ctxt markdown txt end;
5d71b114e7a3 avoid proliferation of language_document reports;
wenzelm
parents: 67381
diff changeset
    29
5d71b114e7a3 avoid proliferation of language_document reports;
wenzelm
parents: 67381
diff changeset
    30
fun document_command markdown (loc, txt) =
67381
146757999c8d theory Pure is default presentation context;
wenzelm
parents: 64556
diff changeset
    31
  Toplevel.keep (fn state =>
146757999c8d theory Pure is default presentation context;
wenzelm
parents: 64556
diff changeset
    32
    (case loc of
67569
5d71b114e7a3 avoid proliferation of language_document reports;
wenzelm
parents: 67381
diff changeset
    33
      NONE => ignore (output_document state markdown txt)
67381
146757999c8d theory Pure is default presentation context;
wenzelm
parents: 64556
diff changeset
    34
    | SOME (_, pos) =>
146757999c8d theory Pure is default presentation context;
wenzelm
parents: 64556
diff changeset
    35
        error ("Illegal target specification -- not a theory context" ^ Position.here pos))) o
146757999c8d theory Pure is default presentation context;
wenzelm
parents: 64556
diff changeset
    36
  Toplevel.present_local_theory loc (fn state =>
67569
5d71b114e7a3 avoid proliferation of language_document reports;
wenzelm
parents: 67381
diff changeset
    37
    ignore (output_document state markdown txt));
67381
146757999c8d theory Pure is default presentation context;
wenzelm
parents: 64556
diff changeset
    38
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58918
diff changeset
    39
val _ =
64556
851ae0e7b09c more symbols;
wenzelm
parents: 62912
diff changeset
    40
  Outer_Syntax.command ("chapter", \<^here>) "chapter heading"
67381
146757999c8d theory Pure is default presentation context;
wenzelm
parents: 64556
diff changeset
    41
    (Parse.opt_target -- Parse.document_source --| semi >> document_command {markdown = false});
58999
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58928
diff changeset
    42
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58928
diff changeset
    43
val _ =
64556
851ae0e7b09c more symbols;
wenzelm
parents: 62912
diff changeset
    44
  Outer_Syntax.command ("section", \<^here>) "section heading"
67381
146757999c8d theory Pure is default presentation context;
wenzelm
parents: 64556
diff changeset
    45
    (Parse.opt_target -- Parse.document_source --| semi >> document_command {markdown = false});
58918
8d36bc5eaed3 simplified keyword kinds;
wenzelm
parents: 58852
diff changeset
    46
48879
cb5cdbb645cd clarified bootstrapping of Pure;
wenzelm
parents:
diff changeset
    47
val _ =
64556
851ae0e7b09c more symbols;
wenzelm
parents: 62912
diff changeset
    48
  Outer_Syntax.command ("subsection", \<^here>) "subsection heading"
67381
146757999c8d theory Pure is default presentation context;
wenzelm
parents: 64556
diff changeset
    49
    (Parse.opt_target -- Parse.document_source --| semi >> document_command {markdown = false});
58999
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58928
diff changeset
    50
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58928
diff changeset
    51
val _ =
64556
851ae0e7b09c more symbols;
wenzelm
parents: 62912
diff changeset
    52
  Outer_Syntax.command ("subsubsection", \<^here>) "subsubsection heading"
67381
146757999c8d theory Pure is default presentation context;
wenzelm
parents: 64556
diff changeset
    53
    (Parse.opt_target -- Parse.document_source --| semi >> document_command {markdown = false});
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58918
diff changeset
    54
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58918
diff changeset
    55
val _ =
64556
851ae0e7b09c more symbols;
wenzelm
parents: 62912
diff changeset
    56
  Outer_Syntax.command ("paragraph", \<^here>) "paragraph heading"
67381
146757999c8d theory Pure is default presentation context;
wenzelm
parents: 64556
diff changeset
    57
    (Parse.opt_target -- Parse.document_source --| semi >> document_command {markdown = false});
61463
8e46cea6a45a added 'paragraph', 'subparagraph';
wenzelm
parents: 61457
diff changeset
    58
8e46cea6a45a added 'paragraph', 'subparagraph';
wenzelm
parents: 61457
diff changeset
    59
val _ =
64556
851ae0e7b09c more symbols;
wenzelm
parents: 62912
diff changeset
    60
  Outer_Syntax.command ("subparagraph", \<^here>) "subparagraph heading"
67381
146757999c8d theory Pure is default presentation context;
wenzelm
parents: 64556
diff changeset
    61
    (Parse.opt_target -- Parse.document_source --| semi >> document_command {markdown = false});
61463
8e46cea6a45a added 'paragraph', 'subparagraph';
wenzelm
parents: 61457
diff changeset
    62
8e46cea6a45a added 'paragraph', 'subparagraph';
wenzelm
parents: 61457
diff changeset
    63
val _ =
64556
851ae0e7b09c more symbols;
wenzelm
parents: 62912
diff changeset
    64
  Outer_Syntax.command ("text", \<^here>) "formal comment (primary style)"
67381
146757999c8d theory Pure is default presentation context;
wenzelm
parents: 64556
diff changeset
    65
    (Parse.opt_target -- Parse.document_source >> document_command {markdown = true});
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58918
diff changeset
    66
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58918
diff changeset
    67
val _ =
64556
851ae0e7b09c more symbols;
wenzelm
parents: 62912
diff changeset
    68
  Outer_Syntax.command ("txt", \<^here>) "formal comment (secondary style)"
67381
146757999c8d theory Pure is default presentation context;
wenzelm
parents: 64556
diff changeset
    69
    (Parse.opt_target -- Parse.document_source >> document_command {markdown = true});
58999
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58928
diff changeset
    70
ed09ae4ea2d8 uniform treatment of all document markup commands: 'text' and 'txt' merely differ in LaTeX style;
wenzelm
parents: 58928
diff changeset
    71
val _ =
64556
851ae0e7b09c more symbols;
wenzelm
parents: 62912
diff changeset
    72
  Outer_Syntax.command ("text_raw", \<^here>) "LaTeX text (without surrounding environment)"
67381
146757999c8d theory Pure is default presentation context;
wenzelm
parents: 64556
diff changeset
    73
    (Parse.opt_target -- Parse.document_source >> document_command {markdown = true});
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58918
diff changeset
    74
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58918
diff changeset
    75
val _ =
64556
851ae0e7b09c more symbols;
wenzelm
parents: 62912
diff changeset
    76
  Outer_Syntax.command ("theory", \<^here>) "begin theory"
58852
621c052789b4 obsolete;
wenzelm
parents: 58842
diff changeset
    77
    (Thy_Header.args >>
621c052789b4 obsolete;
wenzelm
parents: 58842
diff changeset
    78
      (fn _ => Toplevel.init_theory (fn () => error "Missing theory initialization")));
48879
cb5cdbb645cd clarified bootstrapping of Pure;
wenzelm
parents:
diff changeset
    79
60095
35f626b11422 more explicit bootstrap_thy;
wenzelm
parents: 58999
diff changeset
    80
62876
507c90523113 clarified modules -- simplified bootstrap;
wenzelm
parents: 62453
diff changeset
    81
val bootstrap_thy = Context.the_global_context ();
60095
35f626b11422 more explicit bootstrap_thy;
wenzelm
parents: 58999
diff changeset
    82
35f626b11422 more explicit bootstrap_thy;
wenzelm
parents: 58999
diff changeset
    83
val _ = Theory.setup (Config.put_global Outer_Syntax.bootstrap false);
35f626b11422 more explicit bootstrap_thy;
wenzelm
parents: 58999
diff changeset
    84
48879
cb5cdbb645cd clarified bootstrapping of Pure;
wenzelm
parents:
diff changeset
    85
end;