src/Pure/Thy/thy_output.ML
changeset 69887 b9985133805d
parent 69886 0cb8753bdb50
child 69891 def3ec9cdb7e
equal deleted inserted replaced
69886:0cb8753bdb50 69887:b9985133805d
   200       Latex.string "%\n" :: output_document ctxt {markdown = true} source @ [Latex.string "\n"]);
   200       Latex.string "%\n" :: output_document ctxt {markdown = true} source @ [Latex.string "\n"]);
   201 
   201 
   202 
   202 
   203 (* command spans *)
   203 (* command spans *)
   204 
   204 
   205 type command = string * Position.T * string list;   (*name, position, tags*)
   205 type command = string * Position.T;   (*name, position*)
   206 type source = (token * (string * int)) list;        (*token, markup flag, meta-comment depth*)
   206 type source = (token * (string * int)) list;        (*token, markup flag, meta-comment depth*)
   207 
   207 
   208 datatype span = Span of command * (source * source * source * source) * bool;
   208 datatype span = Span of command * (source * source * source * source) * bool;
   209 
   209 
   210 fun make_span cmd src =
   210 fun make_span cmd src =
   285     val present = fold (fn (tok, (flag, 0)) =>
   285     val present = fold (fn (tok, (flag, 0)) =>
   286         fold cons (present_token ctxt' tok)
   286         fold cons (present_token ctxt' tok)
   287         #> cons (Latex.string flag)
   287         #> cons (Latex.string flag)
   288       | _ => I);
   288       | _ => I);
   289 
   289 
   290     val Span ((cmd_name, cmd_pos, cmd_tags), srcs, span_newline) = span;
   290     val Span ((cmd_name, cmd_pos), srcs, span_newline) = span;
       
   291     val cmd_tags = Document_Source.get_tags (Toplevel.presentation_context state');
   291 
   292 
   292     val (tag, tags) = tag_stack;
   293     val (tag, tags) = tag_stack;
   293     val {tag', active_tag'} =
   294     val {tag', active_tag'} =
   294       command_tag {cmd_name = cmd_name, cmd_tags = cmd_tags, tag = tag, active_tag = active_tag}
   295       command_tag {cmd_name = cmd_name, cmd_tags = cmd_tags, tag = tag, active_tag = active_tag}
   295         state state';
   296         state state';
   369 
   370 
   370     fun markup pred mk flag = Scan.peek (fn d =>
   371     fun markup pred mk flag = Scan.peek (fn d =>
   371       Document_Source.improper |--
   372       Document_Source.improper |--
   372         Parse.position (Scan.one (fn tok =>
   373         Parse.position (Scan.one (fn tok =>
   373           Token.is_command tok andalso pred keywords (Token.content_of tok))) --
   374           Token.is_command tok andalso pred keywords (Token.content_of tok))) --
   374       Scan.repeat Document_Source.tag --
   375       (Document_Source.annotation |--
   375       Parse.!!!! ((Document_Source.improper -- locale -- Document_Source.improper) |--
   376         Parse.!!!! ((Document_Source.improper -- locale -- Document_Source.improper) |--
   376         Parse.document_source --| Document_Source.improper_end)
   377           Parse.document_source --| Document_Source.improper_end))
   377           >> (fn (((tok, pos'), tags), source) =>
   378             >> (fn ((tok, pos'), source) =>
   378             let val name = Token.content_of tok
   379               let val name = Token.content_of tok
   379             in (SOME (name, pos', tags), (mk (name, source), (flag, d))) end));
   380               in (SOME (name, pos'), (mk (name, source), (flag, d))) end));
   380 
   381 
   381     val command = Scan.peek (fn d =>
   382     val command = Scan.peek (fn d =>
   382       Scan.optional (Scan.one Token.is_command_modifier ::: Document_Source.improper) [] --
   383       Scan.optional (Scan.one Token.is_command_modifier ::: Document_Source.improper) [] --
   383       Scan.one Token.is_command -- Document_Source.tags
   384       Scan.one Token.is_command --| Document_Source.annotation
   384       >> (fn ((cmd_mod, cmd), tags) =>
   385       >> (fn (cmd_mod, cmd) =>
   385         map (fn tok => (NONE, (Basic_Token tok, ("", d)))) cmd_mod @
   386         map (fn tok => (NONE, (Basic_Token tok, ("", d)))) cmd_mod @
   386           [(SOME (Token.content_of cmd, Token.pos_of cmd, tags),
   387           [(SOME (Token.content_of cmd, Token.pos_of cmd),
   387             (Basic_Token cmd, (markup_false, d)))]));
   388             (Basic_Token cmd, (markup_false, d)))]));
   388 
   389 
   389     val cmt = Scan.peek (fn d =>
   390     val cmt = Scan.peek (fn d =>
   390       Scan.one Document_Source.is_black_comment >> (fn tok => (NONE, (Basic_Token tok, ("", d)))));
   391       Scan.one Document_Source.is_black_comment >> (fn tok => (NONE, (Basic_Token tok, ("", d)))));
   391 
   392