src/Pure/Thy/thy_output.ML
changeset 27874 f0364f1c0ecf
parent 27809 a1e409db516b
child 27882 eaa9fef9f4c1
equal deleted inserted replaced
27873:34d61938e27a 27874:f0364f1c0ecf
    20   val integer: string -> int
    20   val integer: string -> int
    21   val args: (Context.generic * Args.T list -> 'a * (Context.generic * Args.T list)) ->
    21   val args: (Context.generic * Args.T list -> 'a * (Context.generic * Args.T list)) ->
    22     (Args.src -> Proof.context -> 'a -> string) -> Args.src -> Toplevel.node option -> string
    22     (Args.src -> Proof.context -> 'a -> string) -> Args.src -> Toplevel.node option -> string
    23   datatype markup = Markup | MarkupEnv | Verbatim
    23   datatype markup = Markup | MarkupEnv | Verbatim
    24   val modes: string list ref
    24   val modes: string list ref
    25   val eval_antiquote: Scan.lexicon -> Toplevel.node option -> string * Position.T -> string
    25   val eval_antiquote: Scan.lexicon -> Toplevel.node option -> SymbolPos.text * Position.T -> string
    26   val process_thy: Scan.lexicon -> (string -> string list) -> (markup -> string -> bool) ->
    26   val process_thy: Scan.lexicon -> (string -> string list) -> (markup -> string -> bool) ->
    27     Toplevel.transition list -> (OuterLex.token, 'a) Source.source -> Buffer.T
    27     Toplevel.transition list -> (OuterLex.token, 'a) Source.source -> Buffer.T
    28   val output_list: (Proof.context -> 'a -> Pretty.T) -> Args.src ->
    28   val output_list: (Proof.context -> 'a -> Pretty.T) -> Args.src ->
    29     Proof.context -> 'a list -> string
    29     Proof.context -> 'a list -> string
    30   val output: (Proof.context -> 'a -> Pretty.T) -> Args.src -> Proof.context -> 'a -> string
    30   val output: (Proof.context -> 'a -> Pretty.T) -> Args.src -> Proof.context -> 'a -> string
   143 
   143 
   144 (* eval_antiquote *)
   144 (* eval_antiquote *)
   145 
   145 
   146 val modes = ref ([]: string list);
   146 val modes = ref ([]: string list);
   147 
   147 
   148 fun eval_antiquote lex node (str, pos) =
   148 fun eval_antiquote lex node (txt, pos) =
   149   let
   149   let
   150     fun expand (Antiquote.Text s) = s
   150     fun expand (Antiquote.Text s) = s
   151       | expand (Antiquote.Antiq x) =
   151       | expand (Antiquote.Antiq x) =
   152           let val (opts, src) = Antiquote.read_antiq lex antiq x in
   152           let val (opts, src) = Antiquote.read_antiq lex antiq x in
   153             options opts (fn () => command src node) ();  (*preview errors!*)
   153             options opts (fn () => command src node) ();  (*preview errors!*)
   154             PrintMode.with_modes (! modes @ Latex.modes)
   154             PrintMode.with_modes (! modes @ Latex.modes)
   155               (Output.no_warnings (options opts (fn () => command src node))) ()
   155               (Output.no_warnings (options opts (fn () => command src node))) ()
   156           end
   156           end
   157       | expand (Antiquote.Open _) = ""
   157       | expand (Antiquote.Open _) = ""
   158       | expand (Antiquote.Close _) = "";
   158       | expand (Antiquote.Close _) = "";
   159     val ants = Antiquote.read (str, pos);
   159     val ants = Antiquote.read (SymbolPos.explode (txt, pos), pos);
   160   in
   160   in
   161     if is_none node andalso exists Antiquote.is_antiq ants then
   161     if is_none node andalso exists Antiquote.is_antiq ants then
   162       error ("Unknown context -- cannot expand text antiquotations" ^ Position.str_of pos)
   162       error ("Unknown context -- cannot expand text antiquotations" ^ Position.str_of pos)
   163     else implode (map expand ants)
   163     else implode (map expand ants)
   164   end;
   164   end;
   332       >> (fn d => (NONE, (NoToken, ("", d))));
   332       >> (fn d => (NONE, (NoToken, ("", d))));
   333 
   333 
   334     fun markup mark mk flag = Scan.peek (fn d =>
   334     fun markup mark mk flag = Scan.peek (fn d =>
   335       improper |-- P.position (Scan.one (T.is_kind T.Command andf is_markup mark o T.content_of)) --
   335       improper |-- P.position (Scan.one (T.is_kind T.Command andf is_markup mark o T.content_of)) --
   336       Scan.repeat tag --
   336       Scan.repeat tag --
   337       P.!!!! ((improper -- locale -- improper) |-- P.position P.text --| improper_end)
   337       P.!!!! ((improper -- locale -- improper) |-- P.doc_source --| improper_end)
   338       >> (fn (((tok, pos), tags), txt) =>
   338       >> (fn (((tok, pos), tags), txt) =>
   339         let val name = T.content_of tok
   339         let val name = T.content_of tok
   340         in (SOME (name, pos, tags), (mk (name, txt), (flag, d))) end));
   340         in (SOME (name, pos, tags), (mk (name, txt), (flag, d))) end));
   341 
   341 
   342     val command = Scan.peek (fn d =>
   342     val command = Scan.peek (fn d =>
   345       >> (fn ((tok, pos), tags) =>
   345       >> (fn ((tok, pos), tags) =>
   346         let val name = T.content_of tok
   346         let val name = T.content_of tok
   347         in (SOME (name, pos, tags), (BasicToken tok, (Latex.markup_false, d))) end));
   347         in (SOME (name, pos, tags), (BasicToken tok, (Latex.markup_false, d))) end));
   348 
   348 
   349     val cmt = Scan.peek (fn d =>
   349     val cmt = Scan.peek (fn d =>
   350       P.$$$ "--" |-- P.!!!! (improper |-- P.position P.text)
   350       P.$$$ "--" |-- P.!!!! (improper |-- P.doc_source)
   351       >> (fn txt => (NONE, (MarkupToken ("cmt", txt), ("", d)))));
   351       >> (fn txt => (NONE, (MarkupToken ("cmt", txt), ("", d)))));
   352 
   352 
   353     val other = Scan.peek (fn d =>
   353     val other = Scan.peek (fn d =>
   354        P.not_eof >> (fn tok => (NONE, (BasicToken tok, ("", d)))));
   354        P.not_eof >> (fn tok => (NONE, (BasicToken tok, ("", d)))));
   355 
   355