src/Pure/Thy/document_antiquotations.ML
author wenzelm
Fri, 19 Jan 2018 11:34:41 +0100
changeset 67468 aa8c25c528c0
parent 67463 a5ca98950a91
child 67471 bddfa23a4ea9
permissions -rw-r--r--
tuned output of plain name;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
62058
1cfd5d604937 updated headers;
wenzelm
parents: 61814
diff changeset
     1
(*  Title:      Pure/Thy/document_antiquotations.ML
61619
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
     3
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
     4
Miscellaneous document antiquotations.
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
     5
*)
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
     6
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
     7
structure Document_Antiquotations: sig end =
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
     8
struct
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
     9
67386
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    10
(* basic entities *)
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    11
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    12
local
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    13
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
    14
type style = term -> term;
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
    15
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
    16
fun pretty_term_style ctxt (style: style, t) =
67386
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    17
  Thy_Output.pretty_term ctxt (style t);
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    18
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
    19
fun pretty_thm_style ctxt (style: style, th) =
67386
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    20
  Thy_Output.pretty_term ctxt (style (Thm.full_prop_of th));
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    21
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
    22
fun pretty_term_typ ctxt (style: style, t) =
67386
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    23
  let val t' = style t
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    24
  in Thy_Output.pretty_term ctxt (Type.constraint (Term.fastype_of t') t') end;
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    25
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
    26
fun pretty_term_typeof ctxt (style: style, t) =
67386
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    27
  Syntax.pretty_typ ctxt (Term.fastype_of (style t));
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    28
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    29
fun pretty_const ctxt c =
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    30
  let
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    31
    val t = Const (c, Consts.type_scheme (Proof_Context.consts_of ctxt) c)
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    32
      handle TYPE (msg, _, _) => error msg;
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    33
    val ([t'], _) = Variable.import_terms true [t] ctxt;
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    34
  in Thy_Output.pretty_term ctxt t' end;
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    35
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    36
fun pretty_abbrev ctxt s =
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    37
  let
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    38
    val t = Syntax.read_term (Proof_Context.set_mode Proof_Context.mode_abbrev ctxt) s;
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    39
    fun err () = error ("Abbreviated constant expected: " ^ Syntax.string_of_term ctxt t);
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    40
    val (head, args) = Term.strip_comb t;
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    41
    val (c, T) = Term.dest_Const head handle TERM _ => err ();
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    42
    val (U, u) = Consts.the_abbreviation (Proof_Context.consts_of ctxt) c
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    43
      handle TYPE _ => err ();
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    44
    val t' = Term.betapplys (Envir.expand_atom T (U, u), args);
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    45
    val eq = Logic.mk_equals (t, t');
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    46
    val ctxt' = Variable.auto_fixes eq ctxt;
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    47
  in Proof_Context.pretty_term_abbrev ctxt' eq end;
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    48
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    49
fun pretty_locale ctxt (name, pos) =
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    50
  let
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    51
    val thy = Proof_Context.theory_of ctxt
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    52
  in (Pretty.str o Locale.extern thy o Locale.check thy) (name, pos) end;
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    53
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    54
fun pretty_class ctxt =
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    55
  Pretty.str o Proof_Context.extern_class ctxt o Proof_Context.read_class ctxt;
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    56
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    57
fun pretty_type ctxt s =
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    58
  let val Type (name, _) = Proof_Context.read_type_name {proper = true, strict = false} ctxt s
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    59
  in Pretty.str (Proof_Context.extern_type ctxt name) end;
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    60
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    61
fun pretty_prf full ctxt = Proof_Syntax.pretty_clean_proof_of ctxt full;
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    62
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    63
fun pretty_theory ctxt (name, pos) = (Theory.check ctxt (name, pos); Pretty.str name);
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    64
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    65
fun basic_entities name scan pretty =
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
    66
  Thy_Output.antiquotation_pretty_source name scan (map o pretty);
67386
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    67
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    68
fun basic_entities_style name scan pretty =
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
    69
  Thy_Output.antiquotation_pretty_source name scan
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
    70
    (fn ctxt => fn (style: style, xs) => map (fn x => pretty ctxt (style, x)) xs);
67386
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    71
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    72
fun basic_entity name scan = basic_entities name (scan >> single);
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    73
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    74
in
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    75
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    76
val _ = Theory.setup
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    77
 (basic_entities_style \<^binding>\<open>thm\<close> (Term_Style.parse -- Attrib.thms) pretty_thm_style #>
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    78
  basic_entity \<^binding>\<open>prop\<close> (Term_Style.parse -- Args.prop) pretty_term_style #>
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    79
  basic_entity \<^binding>\<open>term\<close> (Term_Style.parse -- Args.term) pretty_term_style #>
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    80
  basic_entity \<^binding>\<open>term_type\<close> (Term_Style.parse -- Args.term) pretty_term_typ #>
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    81
  basic_entity \<^binding>\<open>typeof\<close> (Term_Style.parse -- Args.term) pretty_term_typeof #>
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    82
  basic_entity \<^binding>\<open>const\<close> (Args.const {proper = true, strict = false}) pretty_const #>
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    83
  basic_entity \<^binding>\<open>abbrev\<close> (Scan.lift Args.embedded_inner_syntax) pretty_abbrev #>
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    84
  basic_entity \<^binding>\<open>typ\<close> Args.typ_abbrev Syntax.pretty_typ #>
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    85
  basic_entity \<^binding>\<open>locale\<close> (Scan.lift (Parse.position Args.name)) pretty_locale #>
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    86
  basic_entity \<^binding>\<open>class\<close> (Scan.lift Args.embedded_inner_syntax) pretty_class #>
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    87
  basic_entity \<^binding>\<open>type\<close> (Scan.lift Args.embedded) pretty_type #>
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    88
  basic_entities \<^binding>\<open>prf\<close> Attrib.thms (pretty_prf false) #>
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    89
  basic_entities \<^binding>\<open>full_prf\<close> Attrib.thms (pretty_prf true) #>
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    90
  basic_entity \<^binding>\<open>theory\<close> (Scan.lift (Parse.position Args.name)) pretty_theory);
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    91
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    92
end;
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    93
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
    94
62153
df566b87e269 more explicit errors for control symbols that are left-over after Markdown parsing;
wenzelm
parents: 62058
diff changeset
    95
(* Markdown errors *)
df566b87e269 more explicit errors for control symbols that are left-over after Markdown parsing;
wenzelm
parents: 62058
diff changeset
    96
df566b87e269 more explicit errors for control symbols that are left-over after Markdown parsing;
wenzelm
parents: 62058
diff changeset
    97
local
df566b87e269 more explicit errors for control symbols that are left-over after Markdown parsing;
wenzelm
parents: 62058
diff changeset
    98
df566b87e269 more explicit errors for control symbols that are left-over after Markdown parsing;
wenzelm
parents: 62058
diff changeset
    99
fun markdown_error binding =
67386
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
   100
  Document_Antiquotation.setup binding (Scan.succeed ())
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   101
    (fn {source = src, ...} =>
62153
df566b87e269 more explicit errors for control symbols that are left-over after Markdown parsing;
wenzelm
parents: 62058
diff changeset
   102
      error ("Bad Markdown structure: illegal " ^ quote (Binding.name_of binding) ^
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   103
        Position.here (Position.no_range_position (#1 (Token.range_of src)))))
62153
df566b87e269 more explicit errors for control symbols that are left-over after Markdown parsing;
wenzelm
parents: 62058
diff changeset
   104
df566b87e269 more explicit errors for control symbols that are left-over after Markdown parsing;
wenzelm
parents: 62058
diff changeset
   105
in
df566b87e269 more explicit errors for control symbols that are left-over after Markdown parsing;
wenzelm
parents: 62058
diff changeset
   106
df566b87e269 more explicit errors for control symbols that are left-over after Markdown parsing;
wenzelm
parents: 62058
diff changeset
   107
val _ =
df566b87e269 more explicit errors for control symbols that are left-over after Markdown parsing;
wenzelm
parents: 62058
diff changeset
   108
  Theory.setup
67147
dea94b1aabc3 prefer control symbol antiquotations;
wenzelm
parents: 66067
diff changeset
   109
   (markdown_error \<^binding>\<open>item\<close> #>
dea94b1aabc3 prefer control symbol antiquotations;
wenzelm
parents: 66067
diff changeset
   110
    markdown_error \<^binding>\<open>enum\<close> #>
dea94b1aabc3 prefer control symbol antiquotations;
wenzelm
parents: 66067
diff changeset
   111
    markdown_error \<^binding>\<open>descr\<close>);
62153
df566b87e269 more explicit errors for control symbols that are left-over after Markdown parsing;
wenzelm
parents: 62058
diff changeset
   112
df566b87e269 more explicit errors for control symbols that are left-over after Markdown parsing;
wenzelm
parents: 62058
diff changeset
   113
end;
df566b87e269 more explicit errors for control symbols that are left-over after Markdown parsing;
wenzelm
parents: 62058
diff changeset
   114
df566b87e269 more explicit errors for control symbols that are left-over after Markdown parsing;
wenzelm
parents: 62058
diff changeset
   115
61619
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   116
(* control spacing *)
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   117
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   118
val _ =
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   119
  Theory.setup
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   120
   (Thy_Output.antiquotation_raw \<^binding>\<open>noindent\<close> (Scan.succeed ())
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   121
      (fn _ => fn () => Latex.string "\\noindent") #>
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   122
    Thy_Output.antiquotation_raw \<^binding>\<open>smallskip\<close> (Scan.succeed ())
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   123
      (fn _ => fn () => Latex.string "\\smallskip") #>
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   124
    Thy_Output.antiquotation_raw \<^binding>\<open>medskip\<close> (Scan.succeed ())
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   125
      (fn _ => fn () => Latex.string "\\medskip") #>
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   126
    Thy_Output.antiquotation_raw \<^binding>\<open>bigskip\<close> (Scan.succeed ())
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   127
      (fn _ => fn () => Latex.string "\\bigskip"));
61619
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   128
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   129
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   130
(* control style *)
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   131
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   132
local
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   133
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   134
fun control_antiquotation name s1 s2 =
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   135
  Thy_Output.antiquotation_raw name (Scan.lift Args.cartouche_input)
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   136
    (fn ctxt => Latex.enclose_block s1 s2 o Thy_Output.output_text ctxt {markdown = false});
61619
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   137
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   138
in
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   139
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   140
val _ =
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   141
  Theory.setup
67147
dea94b1aabc3 prefer control symbol antiquotations;
wenzelm
parents: 66067
diff changeset
   142
   (control_antiquotation \<^binding>\<open>footnote\<close> "\\footnote{" "}" #>
dea94b1aabc3 prefer control symbol antiquotations;
wenzelm
parents: 66067
diff changeset
   143
    control_antiquotation \<^binding>\<open>emph\<close> "\\emph{" "}" #>
dea94b1aabc3 prefer control symbol antiquotations;
wenzelm
parents: 66067
diff changeset
   144
    control_antiquotation \<^binding>\<open>bold\<close> "\\textbf{" "}");
61619
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   145
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   146
end;
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   147
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   148
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   149
(* quasi-formal text (unchecked) *)
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   150
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   151
local
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   152
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   153
fun text_antiquotation name =
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   154
  Thy_Output.antiquotation_raw name (Scan.lift Args.text_input)
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   155
    (fn ctxt => fn text =>
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   156
      let
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   157
        val _ =
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   158
          Context_Position.report ctxt (Input.pos_of text)
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   159
            (Markup.language_text (Input.is_delimited text));
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   160
      in Thy_Output.pretty ctxt [Thy_Output.pretty_text ctxt (Input.source_content text)] end);
61619
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   161
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   162
in
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   163
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   164
val _ =
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   165
  Theory.setup
67147
dea94b1aabc3 prefer control symbol antiquotations;
wenzelm
parents: 66067
diff changeset
   166
   (text_antiquotation \<^binding>\<open>text\<close> #>
dea94b1aabc3 prefer control symbol antiquotations;
wenzelm
parents: 66067
diff changeset
   167
    text_antiquotation \<^binding>\<open>cartouche\<close>);
61619
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   168
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   169
end;
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   170
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   171
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   172
(* theory text with tokens (unchecked) *)
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   173
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   174
val _ =
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   175
  Theory.setup
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   176
    (Thy_Output.antiquotation_raw \<^binding>\<open>theory_text\<close> (Scan.lift Args.text_input)
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   177
      (fn ctxt => fn text =>
61619
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   178
        let
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   179
          val keywords = Thy_Header.get_keywords' ctxt;
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   180
61619
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   181
          val _ =
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   182
            Context_Position.report ctxt (Input.pos_of text)
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   183
              (Markup.language_Isar (Input.is_delimited text));
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   184
          val _ =
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   185
            Input.source_explode text
61705
546e6494049f trim lines for @{theory_text} similarly to @{text};
wenzelm
parents: 61704
diff changeset
   186
            |> Source.of_list
61619
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   187
            |> Token.source' true keywords
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   188
            |> Source.exhaust
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   189
            |> maps (Token.reports keywords)
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   190
            |> Context_Position.reports_text ctxt;
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   191
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   192
          val toks =
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   193
            Input.source_content text
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   194
            |> Document_Antiquotation.trim_lines ctxt
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   195
            |> Document_Antiquotation.indent_lines ctxt
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   196
            |> Token.explode keywords Position.none;
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   197
        in Thy_Output.isabelle ctxt (maps (Thy_Output.output_token ctxt) toks) end));
61619
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   198
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   199
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   200
(* goal state *)
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   201
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   202
local
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   203
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   204
fun goal_state name main =
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   205
  Thy_Output.antiquotation_pretty name (Scan.succeed ())
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   206
    (fn ctxt => fn () =>
61619
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   207
      [Goal_Display.pretty_goal
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   208
        (Config.put Goal_Display.show_main_goal main ctxt)
67381
146757999c8d theory Pure is default presentation context;
wenzelm
parents: 67356
diff changeset
   209
        (#goal (Proof.goal (Toplevel.proof_of (Toplevel.presentation_state ctxt))))]);
61619
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   210
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   211
in
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   212
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   213
val _ = Theory.setup
67147
dea94b1aabc3 prefer control symbol antiquotations;
wenzelm
parents: 66067
diff changeset
   214
 (goal_state \<^binding>\<open>goals\<close> true #>
dea94b1aabc3 prefer control symbol antiquotations;
wenzelm
parents: 66067
diff changeset
   215
  goal_state \<^binding>\<open>subgoals\<close> false);
61619
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   216
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   217
end;
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   218
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   219
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   220
(* embedded lemma *)
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   221
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   222
val _ = Theory.setup
67386
998e01d6f8fd clarified modules;
wenzelm
parents: 67381
diff changeset
   223
  (Document_Antiquotation.setup \<^binding>\<open>lemma\<close>
61619
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   224
    (Scan.lift (Scan.ahead Parse.not_eof) -- Args.prop --
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   225
      Scan.lift (Parse.position (Parse.reserved "by") -- Method.parse -- Scan.option Method.parse))
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   226
    (fn {context = ctxt, source = src, argument = ((prop_tok, prop), (((_, by_pos), m1), m2))} =>
61619
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   227
      let
66067
cdbcb417db67 more markup for HTML rendering;
wenzelm
parents: 63679
diff changeset
   228
        val reports =
cdbcb417db67 more markup for HTML rendering;
wenzelm
parents: 63679
diff changeset
   229
          (by_pos, Markup.keyword1 |> Markup.keyword_properties) ::
cdbcb417db67 more markup for HTML rendering;
wenzelm
parents: 63679
diff changeset
   230
            maps Method.reports_of (m1 :: the_list m2);
61619
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   231
        val _ = Context_Position.reports ctxt reports;
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   232
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   233
        (* FIXME check proof!? *)
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   234
        val _ = ctxt
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   235
          |> Proof.theorem NONE (K I) [[(prop, [])]]
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   236
          |> Proof.global_terminal_proof (m1, m2);
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   237
      in Thy_Output.pretty_source ctxt [hd src, prop_tok] [Thy_Output.pretty_term ctxt prop] end));
61619
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   238
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   239
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   240
(* verbatim text *)
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   241
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   242
val _ = Theory.setup
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   243
  (Thy_Output.antiquotation_verbatim \<^binding>\<open>verbatim\<close> (Scan.lift Args.text_input)
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   244
    (fn ctxt => fn text =>
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   245
      let
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   246
        val _ =
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   247
          Context_Position.report ctxt (Input.pos_of text)
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   248
            (Markup.language_verbatim (Input.is_delimited text));
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   249
      in Input.source_content text end));
61619
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   250
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   251
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   252
(* ML text *)
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   253
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   254
local
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   255
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   256
fun ml_text name ml =
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   257
  Thy_Output.antiquotation_verbatim name (Scan.lift Args.text_input)
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   258
    (fn ctxt => fn text =>
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   259
      let val _ = ML_Context.eval_in (SOME ctxt) ML_Compiler.flags (Input.pos_of text) (ml text)
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   260
      in Input.source_content text end);
61619
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   261
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   262
fun ml_enclose bg en source =
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   263
  ML_Lex.read bg @ ML_Lex.read_source false source @ ML_Lex.read en;
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   264
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   265
in
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   266
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   267
val _ = Theory.setup
67147
dea94b1aabc3 prefer control symbol antiquotations;
wenzelm
parents: 66067
diff changeset
   268
 (ml_text \<^binding>\<open>ML\<close> (ml_enclose "fn _ => (" ");") #>
dea94b1aabc3 prefer control symbol antiquotations;
wenzelm
parents: 66067
diff changeset
   269
  ml_text \<^binding>\<open>ML_op\<close> (ml_enclose "fn _ => (op " ");") #>
dea94b1aabc3 prefer control symbol antiquotations;
wenzelm
parents: 66067
diff changeset
   270
  ml_text \<^binding>\<open>ML_type\<close> (ml_enclose "val _ = NONE : (" ") option;") #>
dea94b1aabc3 prefer control symbol antiquotations;
wenzelm
parents: 66067
diff changeset
   271
  ml_text \<^binding>\<open>ML_structure\<close>
61619
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   272
    (ml_enclose "functor XXX() = struct structure XX = " " end;") #>
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   273
67147
dea94b1aabc3 prefer control symbol antiquotations;
wenzelm
parents: 66067
diff changeset
   274
  ml_text \<^binding>\<open>ML_functor\<close>   (* FIXME formal treatment of functor name (!?) *)
61619
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   275
    (fn source =>
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   276
      ML_Lex.read ("ML_Env.check_functor " ^
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   277
        ML_Syntax.print_string (Input.source_content source))) #>
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   278
67147
dea94b1aabc3 prefer control symbol antiquotations;
wenzelm
parents: 66067
diff changeset
   279
  ml_text \<^binding>\<open>ML_text\<close> (K []));
61619
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   280
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   281
end;
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   282
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   283
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   284
(* URLs *)
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   285
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   286
val _ = Theory.setup
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   287
  (Thy_Output.antiquotation_raw \<^binding>\<open>url\<close> (Scan.lift (Parse.position Parse.embedded))
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   288
    (fn ctxt => fn (url, pos) =>
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   289
      let val _ = Context_Position.reports ctxt [(pos, Markup.language_path), (pos, Markup.url url)]
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   290
      in Latex.enclose_block "\\url{" "}" [Latex.string url] end));
61619
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   291
61623
2f89f0b13e08 added @{command}, @{method}, @{attribute};
wenzelm
parents: 61619
diff changeset
   292
61660
78b371644654 added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents: 61623
diff changeset
   293
(* doc entries *)
78b371644654 added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents: 61623
diff changeset
   294
78b371644654 added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents: 61623
diff changeset
   295
val _ = Theory.setup
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   296
  (Thy_Output.antiquotation_pretty \<^binding>\<open>doc\<close> (Scan.lift (Parse.position Parse.embedded))
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   297
    (fn ctxt => fn (name, pos) =>
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   298
      let val _ = Context_Position.report ctxt pos (Markup.doc name)
67468
aa8c25c528c0 tuned output of plain name;
wenzelm
parents: 67463
diff changeset
   299
      in [Pretty.str name] end));
61660
78b371644654 added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents: 61623
diff changeset
   300
78b371644654 added antiquotation @{doc}, e.g. useful for demonstration purposes;
wenzelm
parents: 61623
diff changeset
   301
61623
2f89f0b13e08 added @{command}, @{method}, @{attribute};
wenzelm
parents: 61619
diff changeset
   302
(* formal entities *)
2f89f0b13e08 added @{command}, @{method}, @{attribute};
wenzelm
parents: 61619
diff changeset
   303
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   304
local
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   305
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   306
fun entity_antiquotation name check bg en =
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   307
  Thy_Output.antiquotation_raw name (Scan.lift (Parse.position Args.name))
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   308
    (fn ctxt => fn (name, pos) =>
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   309
      let val _ = check ctxt (name, pos)
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   310
      in Latex.enclose_block bg en [Latex.string (Output.output name)] end);
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   311
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   312
in
61623
2f89f0b13e08 added @{command}, @{method}, @{attribute};
wenzelm
parents: 61619
diff changeset
   313
2f89f0b13e08 added @{command}, @{method}, @{attribute};
wenzelm
parents: 61619
diff changeset
   314
val _ =
2f89f0b13e08 added @{command}, @{method}, @{attribute};
wenzelm
parents: 61619
diff changeset
   315
  Theory.setup
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   316
   (entity_antiquotation \<^binding>\<open>command\<close> Outer_Syntax.check_command "\\isacommand{" "}" #>
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   317
    entity_antiquotation \<^binding>\<open>method\<close> Method.check_name "\\isa{" "}" #>
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   318
    entity_antiquotation \<^binding>\<open>attribute\<close> Attrib.check_name "\\isa{" "}");
61623
2f89f0b13e08 added @{command}, @{method}, @{attribute};
wenzelm
parents: 61619
diff changeset
   319
61619
f22054b192b0 clarified modules;
wenzelm
parents:
diff changeset
   320
end;
67463
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   321
a5ca98950a91 clarified access to antiquotation options;
wenzelm
parents: 67386
diff changeset
   322
end;