src/Pure/Thy/thy_output.ML
author wenzelm
Mon Mar 09 21:26:13 2009 +0100 (2009-03-09)
changeset 30398 d7ac4b7aa590
parent 30394 c11a1e65a2ed
child 30513 1796b8ea88aa
permissions -rw-r--r--
simplified presentation_context_of;
     1 (*  Title:      Pure/Thy/thy_output.ML
     2     Author:     Markus Wenzel, TU Muenchen
     3 
     4 Theory document output with antiquotations.
     5 *)
     6 
     7 signature THY_OUTPUT =
     8 sig
     9   val display: bool ref
    10   val quotes: bool ref
    11   val indent: int ref
    12   val source: bool ref
    13   val break: bool ref
    14   val add_commands: (string * (Args.src -> Toplevel.state -> string)) list -> unit
    15   val add_options: (string * (string -> (unit -> string) -> unit -> string)) list -> unit
    16   val defined_command: string -> bool
    17   val defined_option: string -> bool
    18   val print_antiquotations: unit -> unit
    19   val boolean: string -> bool
    20   val integer: string -> int
    21   val antiquotation: string ->
    22     (Context.generic * Args.T list -> 'a * (Context.generic * Args.T list)) ->
    23     ({state: Toplevel.state, source: Args.src, context: Proof.context} -> 'a -> string) -> unit
    24   datatype markup = Markup | MarkupEnv | Verbatim
    25   val modes: string list ref
    26   val eval_antiquote: Scan.lexicon -> Toplevel.state -> SymbolPos.text * Position.T -> string
    27   val present_thy: Scan.lexicon -> (string -> string list) -> (markup -> string -> bool) ->
    28     (Toplevel.transition * Toplevel.state) list -> (OuterLex.token, 'a) Source.source -> Buffer.T
    29   val pretty_text: string -> Pretty.T
    30   val pretty_term: Proof.context -> term -> Pretty.T
    31   val pretty_thm: Proof.context -> thm -> Pretty.T
    32   val str_of_source: Args.src -> string
    33   val maybe_pretty_source: ('a -> Pretty.T) -> Args.src -> 'a list -> Pretty.T list
    34   val output: Pretty.T list -> string
    35 end;
    36 
    37 structure ThyOutput: THY_OUTPUT =
    38 struct
    39 
    40 structure T = OuterLex;
    41 structure P = OuterParse;
    42 
    43 
    44 (** global options **)
    45 
    46 val display = ref false;
    47 val quotes = ref false;
    48 val indent = ref 0;
    49 val source = ref false;
    50 val break = ref false;
    51 
    52 
    53 
    54 (** maintain global antiquotations **)
    55 
    56 local
    57 
    58 val global_commands =
    59   ref (Symtab.empty: (Args.src -> Toplevel.state -> string) Symtab.table);
    60 
    61 val global_options =
    62   ref (Symtab.empty: (string -> (unit -> string) -> unit -> string) Symtab.table);
    63 
    64 fun add_item kind (name, x) tab =
    65  (if not (Symtab.defined tab name) then ()
    66   else warning ("Redefined document antiquotation " ^ kind ^ ": " ^ quote name);
    67   Symtab.update (name, x) tab);
    68 
    69 in
    70 
    71 fun add_commands xs = CRITICAL (fn () => change global_commands (fold (add_item "command") xs));
    72 fun add_options xs = CRITICAL (fn () => change global_options (fold (add_item "option") xs));
    73 
    74 fun defined_command name = Symtab.defined (! global_commands) name;
    75 fun defined_option name = Symtab.defined (! global_options) name;
    76 
    77 fun command src =
    78   let val ((name, _), pos) = Args.dest_src src in
    79     (case Symtab.lookup (! global_commands) name of
    80       NONE => error ("Unknown document antiquotation: " ^ quote name ^ Position.str_of pos)
    81     | SOME f =>
    82        (Position.report (Markup.doc_antiq name) pos;
    83         (fn state => f src state handle ERROR msg =>
    84           cat_error msg ("The error(s) above occurred in document antiquotation: " ^
    85             quote name ^ Position.str_of pos))))
    86   end;
    87 
    88 fun option (name, s) f () =
    89   (case Symtab.lookup (! global_options) name of
    90     NONE => error ("Unknown document antiquotation option: " ^ quote name)
    91   | SOME opt => opt s f ());
    92 
    93 fun options [] f = f
    94   | options (opt :: opts) f = option opt (options opts f);
    95 
    96 
    97 fun print_antiquotations () =
    98  [Pretty.big_list "document antiquotation commands:"
    99     (map Pretty.str (sort_strings (Symtab.keys (! global_commands)))),
   100   Pretty.big_list "document antiquotation options:"
   101     (map Pretty.str (sort_strings (Symtab.keys (! global_options))))]
   102  |> Pretty.chunks |> Pretty.writeln;
   103 
   104 end;
   105 
   106 fun antiquotation name scan out = add_commands [(name, fn src => fn state =>
   107   let val (x, ctxt) = Args.context_syntax "document antiquotation"
   108     scan src (Toplevel.presentation_context_of state)
   109   in out {source = src, state = state, context = ctxt} x end)];
   110 
   111 
   112 
   113 (** syntax of antiquotations **)
   114 
   115 (* option values *)
   116 
   117 fun boolean "" = true
   118   | boolean "true" = true
   119   | boolean "false" = false
   120   | boolean s = error ("Bad boolean value: " ^ quote s);
   121 
   122 fun integer s =
   123   let
   124     fun int ss =
   125       (case Library.read_int ss of (i, []) => i
   126       | _ => error ("Bad integer value: " ^ quote s));
   127   in (case Symbol.explode s of "-" :: ss => ~ (int ss) | ss => int ss) end;
   128 
   129 
   130 (* outer syntax *)
   131 
   132 local
   133 
   134 val property = P.xname -- Scan.optional (P.$$$ "=" |-- P.!!! P.xname) "";
   135 val properties = Scan.optional (P.$$$ "[" |-- P.!!! (P.enum "," property --| P.$$$ "]")) [];
   136 
   137 in
   138 
   139 val antiq = P.!!! (P.position P.xname -- properties -- Args.parse --| Scan.ahead P.eof)
   140   >> (fn (((x, pos), y), z) => (y, Args.src ((x, z), pos)));
   141 
   142 end;
   143 
   144 
   145 (* eval_antiquote *)
   146 
   147 val modes = ref ([]: string list);
   148 
   149 fun eval_antiquote lex state (txt, pos) =
   150   let
   151     fun expand (Antiquote.Text s) = s
   152       | expand (Antiquote.Antiq x) =
   153           let val (opts, src) = Antiquote.read_antiq lex antiq x in
   154             options opts (fn () => command src state) ();  (*preview errors!*)
   155             PrintMode.with_modes (! modes @ Latex.modes)
   156               (Output.no_warnings (options opts (fn () => command src state))) ()
   157           end
   158       | expand (Antiquote.Open _) = ""
   159       | expand (Antiquote.Close _) = "";
   160     val ants = Antiquote.read (SymbolPos.explode (txt, pos), pos);
   161   in
   162     if Toplevel.is_toplevel state andalso exists Antiquote.is_antiq ants then
   163       error ("Unknown context -- cannot expand document antiquotations" ^ Position.str_of pos)
   164     else implode (map expand ants)
   165   end;
   166 
   167 
   168 
   169 (** present theory source **)
   170 
   171 (*NB: arranging white space around command spans is a black art.*)
   172 
   173 (* presentation tokens *)
   174 
   175 datatype token =
   176     NoToken
   177   | BasicToken of T.token
   178   | MarkupToken of string * (string * Position.T)
   179   | MarkupEnvToken of string * (string * Position.T)
   180   | VerbatimToken of string * Position.T;
   181 
   182 fun output_token lex state =
   183   let val eval = eval_antiquote lex state in
   184     fn NoToken => ""
   185      | BasicToken tok => Latex.output_basic tok
   186      | MarkupToken (cmd, txt) => Latex.output_markup cmd (eval txt)
   187      | MarkupEnvToken (cmd, txt) => Latex.output_markup_env cmd (eval txt)
   188      | VerbatimToken txt => Latex.output_verbatim (eval txt)
   189   end;
   190 
   191 fun basic_token pred (BasicToken tok) = pred tok
   192   | basic_token _ _ = false;
   193 
   194 val improper_token = basic_token (not o T.is_proper);
   195 val comment_token = basic_token T.is_comment;
   196 val blank_token = basic_token T.is_blank;
   197 val newline_token = basic_token T.is_newline;
   198 
   199 
   200 (* command spans *)
   201 
   202 type command = string * Position.T * string list;   (*name, position, tags*)
   203 type source = (token * (string * int)) list;        (*token, markup flag, meta-comment depth*)
   204 
   205 datatype span = Span of command * (source * source * source * source) * bool;
   206 
   207 fun make_span cmd src =
   208   let
   209     fun take_newline (tok :: toks) =
   210           if newline_token (fst tok) then ([tok], toks, true)
   211           else ([], tok :: toks, false)
   212       | take_newline [] = ([], [], false);
   213     val (((src_prefix, src_main), src_suffix1), (src_suffix2, src_appendix, newline)) =
   214       src
   215       |> take_prefix (improper_token o fst)
   216       ||>> take_suffix (improper_token o fst)
   217       ||>> take_prefix (comment_token o fst)
   218       ||> take_newline;
   219   in Span (cmd, (src_prefix, src_main, src_suffix1 @ src_suffix2, src_appendix), newline) end;
   220 
   221 
   222 (* present spans *)
   223 
   224 local
   225 
   226 fun err_bad_nesting pos =
   227   error ("Bad nesting of commands in presentation" ^ pos);
   228 
   229 fun edge which f (x: string option, y) =
   230   if x = y then I
   231   else (case which (x, y) of NONE => I | SOME txt => Buffer.add (f txt));
   232 
   233 val begin_tag = edge #2 Latex.begin_tag;
   234 val end_tag = edge #1 Latex.end_tag;
   235 fun open_delim delim e = edge #2 Latex.begin_delim e #> delim #> edge #2 Latex.end_delim e;
   236 fun close_delim delim e = edge #1 Latex.begin_delim e #> delim #> edge #1 Latex.end_delim e;
   237 
   238 in
   239 
   240 fun present_span lex default_tags span state state'
   241     (tag_stack, active_tag, newline, buffer, present_cont) =
   242   let
   243     val present = fold (fn (tok, (flag, 0)) =>
   244         Buffer.add (output_token lex state' tok)
   245         #> Buffer.add flag
   246       | _ => I);
   247 
   248     val Span ((cmd_name, cmd_pos, cmd_tags), srcs, span_newline) = span;
   249 
   250     val (tag, tags) = tag_stack;
   251     val tag' = try hd (fold OuterKeyword.update_tags cmd_tags (the_list tag));
   252 
   253     val active_tag' =
   254       if is_some tag' then tag'
   255       else if cmd_name = "end" andalso not (Toplevel.is_toplevel state') then NONE
   256       else try hd (default_tags cmd_name);
   257     val edge = (active_tag, active_tag');
   258 
   259     val newline' =
   260       if is_none active_tag' then span_newline else newline;
   261 
   262     val nesting = Toplevel.level state' - Toplevel.level state;
   263     val tag_stack' =
   264       if nesting = 0 andalso not (Toplevel.is_proof state) then tag_stack
   265       else if nesting >= 0 then (tag', replicate nesting tag @ tags)
   266       else
   267         (case Library.drop (~ nesting - 1, tags) of
   268           tgs :: tgss => (tgs, tgss)
   269         | [] => err_bad_nesting (Position.str_of cmd_pos));
   270 
   271     val buffer' =
   272       buffer
   273       |> end_tag edge
   274       |> close_delim (fst present_cont) edge
   275       |> snd present_cont
   276       |> open_delim (present (#1 srcs)) edge
   277       |> begin_tag edge
   278       |> present (#2 srcs);
   279     val present_cont' =
   280       if newline then (present (#3 srcs), present (#4 srcs))
   281       else (I, present (#3 srcs) #> present (#4 srcs));
   282   in (tag_stack', active_tag', newline', buffer', present_cont') end;
   283 
   284 fun present_trailer ((_, tags), active_tag, _, buffer, present_cont) =
   285   if not (null tags) then err_bad_nesting " at end of theory"
   286   else
   287     buffer
   288     |> end_tag (active_tag, NONE)
   289     |> close_delim (fst present_cont) (active_tag, NONE)
   290     |> snd present_cont;
   291 
   292 end;
   293 
   294 
   295 (* present_thy *)
   296 
   297 datatype markup = Markup | MarkupEnv | Verbatim;
   298 
   299 local
   300 
   301 val space_proper =
   302   Scan.one T.is_blank -- Scan.many T.is_comment -- Scan.one T.is_proper;
   303 
   304 val is_improper = not o (T.is_proper orf T.is_begin_ignore orf T.is_end_ignore);
   305 val improper = Scan.many is_improper;
   306 val improper_end = Scan.repeat (Scan.unless space_proper (Scan.one is_improper));
   307 val blank_end = Scan.repeat (Scan.unless space_proper (Scan.one T.is_blank));
   308 
   309 val opt_newline = Scan.option (Scan.one T.is_newline);
   310 
   311 val ignore =
   312   Scan.depend (fn d => opt_newline |-- Scan.one T.is_begin_ignore
   313     >> pair (d + 1)) ||
   314   Scan.depend (fn d => Scan.one T.is_end_ignore --|
   315     (if d = 0 then Scan.fail_with (K "Bad nesting of meta-comments") else opt_newline)
   316     >> pair (d - 1));
   317 
   318 val tag = (improper -- P.$$$ "%" -- improper) |-- P.!!! (P.tag_name --| blank_end);
   319 
   320 val locale =
   321   Scan.option ((P.$$$ "(" -- improper -- P.$$$ "in") |--
   322     P.!!! (improper |-- P.xname --| (improper -- P.$$$ ")")));
   323 
   324 in
   325 
   326 fun present_thy lex default_tags is_markup command_results src =
   327   let
   328     (* tokens *)
   329 
   330     val ignored = Scan.state --| ignore
   331       >> (fn d => (NONE, (NoToken, ("", d))));
   332 
   333     fun markup mark mk flag = Scan.peek (fn d =>
   334       improper |-- P.position (Scan.one (T.is_kind T.Command andf is_markup mark o T.content_of)) --
   335       Scan.repeat tag --
   336       P.!!!! ((improper -- locale -- improper) |-- P.doc_source --| improper_end)
   337       >> (fn (((tok, pos), tags), txt) =>
   338         let val name = T.content_of tok
   339         in (SOME (name, pos, tags), (mk (name, txt), (flag, d))) end));
   340 
   341     val command = Scan.peek (fn d =>
   342       P.position (Scan.one (T.is_kind T.Command)) --
   343       Scan.repeat tag
   344       >> (fn ((tok, pos), tags) =>
   345         let val name = T.content_of tok
   346         in (SOME (name, pos, tags), (BasicToken tok, (Latex.markup_false, d))) end));
   347 
   348     val cmt = Scan.peek (fn d =>
   349       P.$$$ "--" |-- P.!!!! (improper |-- P.doc_source)
   350       >> (fn txt => (NONE, (MarkupToken ("cmt", txt), ("", d)))));
   351 
   352     val other = Scan.peek (fn d =>
   353        P.not_eof >> (fn tok => (NONE, (BasicToken tok, ("", d)))));
   354 
   355     val token =
   356       ignored ||
   357       markup Markup MarkupToken Latex.markup_true ||
   358       markup MarkupEnv MarkupEnvToken Latex.markup_true ||
   359       markup Verbatim (VerbatimToken o #2) "" ||
   360       command || cmt || other;
   361 
   362 
   363     (* spans *)
   364 
   365     val is_eof = fn (_, (BasicToken x, _)) => T.is_eof x | _ => false;
   366     val stopper = Scan.stopper (K (NONE, (BasicToken T.eof, ("", 0)))) is_eof;
   367 
   368     val cmd = Scan.one (is_some o fst);
   369     val non_cmd = Scan.one (is_none o fst andf not o is_eof) >> #2;
   370 
   371     val comments = Scan.many (comment_token o fst o snd);
   372     val blank = Scan.one (blank_token o fst o snd);
   373     val newline = Scan.one (newline_token o fst o snd);
   374     val before_cmd =
   375       Scan.option (newline -- comments) --
   376       Scan.option (newline -- comments) --
   377       Scan.option (blank -- comments) -- cmd;
   378 
   379     val span =
   380       Scan.repeat non_cmd -- cmd --
   381         Scan.repeat (Scan.unless before_cmd non_cmd) --
   382         Scan.option (newline >> (single o snd))
   383       >> (fn (((toks1, (cmd, tok2)), toks3), tok4) =>
   384           make_span (the cmd) (toks1 @ (tok2 :: (toks3 @ the_default [] tok4))));
   385 
   386     val spans =
   387       src
   388       |> Source.filter (not o T.is_semicolon)
   389       |> Source.source' 0 T.stopper (Scan.error (Scan.bulk token)) NONE
   390       |> Source.source stopper (Scan.error (Scan.bulk span)) NONE
   391       |> Source.exhaust;
   392 
   393 
   394     (* present commands *)
   395 
   396     fun present_command tr span st st' =
   397       Toplevel.setmp_thread_position tr (present_span lex default_tags span st st');
   398 
   399     fun present _ [] = I
   400       | present st (((tr, st'), span) :: rest) = present_command tr span st st' #> present st' rest;
   401   in
   402     if length command_results = length spans then
   403       ((NONE, []), NONE, true, Buffer.empty, (I, I))
   404       |> present Toplevel.toplevel (command_results ~~ spans)
   405       |> present_trailer
   406     else error "Messed-up outer syntax for presentation"
   407   end;
   408 
   409 end;
   410 
   411 
   412 
   413 (** setup default output **)
   414 
   415 (* options *)
   416 
   417 val _ = add_options
   418  [("show_types", Library.setmp Syntax.show_types o boolean),
   419   ("show_sorts", Library.setmp Syntax.show_sorts o boolean),
   420   ("show_structs", Library.setmp show_structs o boolean),
   421   ("show_question_marks", Library.setmp show_question_marks o boolean),
   422   ("long_names", Library.setmp NameSpace.long_names o boolean),
   423   ("short_names", Library.setmp NameSpace.short_names o boolean),
   424   ("unique_names", Library.setmp NameSpace.unique_names o boolean),
   425   ("eta_contract", Library.setmp Syntax.eta_contract o boolean),
   426   ("display", Library.setmp display o boolean),
   427   ("break", Library.setmp break o boolean),
   428   ("quotes", Library.setmp quotes o boolean),
   429   ("mode", fn s => fn f => PrintMode.with_modes [s] f),
   430   ("margin", Pretty.setmp_margin o integer),
   431   ("indent", Library.setmp indent o integer),
   432   ("source", Library.setmp source o boolean),
   433   ("goals_limit", Library.setmp goals_limit o integer)];
   434 
   435 
   436 (* basic pretty printing *)
   437 
   438 fun tweak_line s =
   439   if ! display then s else Symbol.strip_blanks s;
   440 
   441 val pretty_text = Pretty.chunks o map Pretty.str o map tweak_line o Library.split_lines;
   442 
   443 fun pretty_term ctxt t = Syntax.pretty_term (Variable.auto_fixes t ctxt) t;
   444 
   445 fun pretty_term_abbrev ctxt t = ProofContext.pretty_term_abbrev (Variable.auto_fixes t ctxt) t;
   446 
   447 fun pretty_term_typ ctxt t =
   448   Syntax.pretty_term ctxt (TypeInfer.constrain (Term.fastype_of t) t);
   449 
   450 fun pretty_term_typeof ctxt = Syntax.pretty_typ ctxt o Term.fastype_of;
   451 
   452 fun pretty_const ctxt c =
   453   let
   454     val t = Const (c, Consts.type_scheme (ProofContext.consts_of ctxt) c)
   455       handle TYPE (msg, _, _) => error msg;
   456     val ([t'], _) = Variable.import_terms true [t] ctxt;
   457   in pretty_term ctxt t' end;
   458 
   459 fun pretty_abbrev ctxt s =
   460   let
   461     val t = Syntax.parse_term ctxt s |> singleton (ProofContext.standard_infer_types ctxt);
   462     fun err () = error ("Abbreviated constant expected: " ^ Syntax.string_of_term ctxt t);
   463     val (head, args) = Term.strip_comb t;
   464     val (c, T) = Term.dest_Const head handle TERM _ => err ();
   465     val (U, u) = Consts.the_abbreviation (ProofContext.consts_of ctxt) c
   466       handle TYPE _ => err ();
   467     val t' = Term.betapplys (Envir.expand_atom T (U, u), args);
   468   in pretty_term_abbrev ctxt (Logic.mk_equals (t, t')) end;
   469 
   470 fun pretty_thm ctxt = pretty_term ctxt o Thm.full_prop_of;
   471 
   472 fun pretty_term_style ctxt (name, t) =
   473   pretty_term ctxt (TermStyle.the_style (ProofContext.theory_of ctxt) name ctxt t);
   474 
   475 fun pretty_thm_style ctxt (name, th) =
   476   pretty_term_style ctxt (name, Thm.full_prop_of th);
   477 
   478 fun pretty_prf full ctxt = ProofSyntax.pretty_proof_of ctxt full;
   479 
   480 fun pretty_theory ctxt name =
   481   (Theory.requires (ProofContext.theory_of ctxt) name "presentation"; Pretty.str name);
   482 
   483 
   484 (* default output *)
   485 
   486 val str_of_source = space_implode " " o map T.unparse o #2 o #1 o Args.dest_src;
   487 
   488 fun maybe_pretty_source pretty src xs =
   489   map pretty xs  (*always pretty in order to exhibit errors!*)
   490   |> (if ! source then K [pretty_text (str_of_source src)] else I);
   491 
   492 fun output prts =
   493   prts
   494   |> (if ! quotes then map Pretty.quote else I)
   495   |> (if ! display then
   496     map (Output.output o Pretty.string_of o Pretty.indent (! indent))
   497     #> space_implode "\\isasep\\isanewline%\n"
   498     #> enclose "\\begin{isabelle}%\n" "%\n\\end{isabelle}"
   499   else
   500     map (Output.output o (if ! break then Pretty.string_of else Pretty.str_of))
   501     #> space_implode "\\isasep\\isanewline%\n"
   502     #> enclose "\\isa{" "}");
   503 
   504 
   505 
   506 (** concrete antiquotations **)
   507 
   508 (* basic entities *)
   509 
   510 local
   511 
   512 fun basic_entities name scan pretty = antiquotation name scan
   513   (fn {source, context, ...} => output o maybe_pretty_source (pretty context) source);
   514 
   515 fun basic_entity name scan = basic_entities name (scan >> single);
   516 
   517 in
   518 
   519 val _ = basic_entities "thm" Attrib.thms pretty_thm;
   520 val _ = basic_entity "thm_style" (Scan.lift Args.liberal_name -- Attrib.thm) pretty_thm_style;
   521 val _ = basic_entity "prop" Args.prop pretty_term;
   522 val _ = basic_entity "term" Args.term pretty_term;
   523 val _ = basic_entity "term_style" (Scan.lift Args.liberal_name -- Args.term) pretty_term_style;
   524 val _ = basic_entity "term_type" Args.term pretty_term_typ;
   525 val _ = basic_entity "typeof" Args.term pretty_term_typeof;
   526 val _ = basic_entity "const" Args.const_proper pretty_const;
   527 val _ = basic_entity "abbrev" (Scan.lift Args.name_source) pretty_abbrev;
   528 val _ = basic_entity "typ" Args.typ_abbrev Syntax.pretty_typ;
   529 val _ = basic_entity "text" (Scan.lift Args.name) (K pretty_text);
   530 val _ = basic_entities "prf" Attrib.thms (pretty_prf false);
   531 val _ = basic_entities "full_prf" Attrib.thms (pretty_prf true);
   532 val _ = basic_entity "theory" (Scan.lift Args.name) pretty_theory;
   533 
   534 end;
   535 
   536 
   537 (* goal state *)
   538 
   539 local
   540 
   541 fun proof_state state =
   542   (case try Toplevel.proof_of state of
   543     SOME prf => prf
   544   | _ => error "No proof state");
   545 
   546 fun goal_state name main_goal = antiquotation name (Scan.succeed ())
   547   (fn {state, ...} => fn () => output
   548     [Pretty.chunks (Proof.pretty_goals main_goal (proof_state state))]);
   549 
   550 in
   551 
   552 val _ = goal_state "goals" true;
   553 val _ = goal_state "subgoals" false;
   554 
   555 end;
   556 
   557 
   558 (* embedded lemma *)
   559 
   560 val _ = OuterKeyword.keyword "by";
   561 
   562 val _ = antiquotation "lemma"
   563   (Args.prop -- Scan.lift (Args.$$$ "by" |-- Method.parse -- Scan.option Method.parse))
   564   (fn {source, context, ...} => fn (prop, methods) =>
   565     let
   566       val prop_src =
   567         (case Args.dest_src source of ((a, arg :: _), pos) => Args.src ((a, [arg]), pos));
   568       val _ = context
   569         |> Proof.theorem_i NONE (K I) [[(prop, [])]]
   570         |> Proof.global_terminal_proof methods;
   571     in output (maybe_pretty_source (pretty_term context) prop_src [prop]) end);
   572 
   573 
   574 (* ML text *)
   575 
   576 local
   577 
   578 fun ml_text name ml = antiquotation name (Scan.lift Args.name_source_position)
   579   (fn {context, ...} => fn (txt, pos) =>
   580    (ML_Context.eval_in (SOME context) false pos (ml txt);
   581     SymbolPos.content (SymbolPos.explode (txt, pos))
   582     |> (if ! quotes then quote else I)
   583     |> (if ! display then enclose "\\begin{verbatim}\n" "\n\\end{verbatim}"
   584     else
   585       split_lines
   586       #> map (space_implode "\\verb,|," o map (enclose "\\verb|" "|") o space_explode "|")
   587       #> space_implode "\\isasep\\isanewline%\n")));
   588 
   589 in
   590 
   591 val _ = ml_text "ML" (fn txt => "fn _ => (" ^ txt ^ ");");
   592 val _ = ml_text "ML_type" (fn txt => "val _ = NONE : (" ^ txt ^ ") option;");
   593 val _ = ml_text "ML_struct" (fn txt => "functor XXX() = struct structure XX = " ^ txt ^ " end;");
   594 val _ = ml_text "ML_functor" (K "");  (*no check!*)
   595 val _ = ml_text "ML_text" (K "");
   596 
   597 end;
   598 
   599 end;