src/Pure/Thy/thy_output.ML
changeset 59924 801b979ec0c2
parent 59917 9830c944670f
child 59939 7d46aa03696e
equal deleted inserted replaced
59923:b21c82422d65 59924:801b979ec0c2
   201 
   201 
   202 
   202 
   203 
   203 
   204 (** present theory source **)
   204 (** present theory source **)
   205 
   205 
   206 (*NB: arranging white space around command spans is a black art.*)
   206 (*NB: arranging white space around command spans is a black art*)
   207 
   207 
   208 (* presentation tokens *)
   208 (* presentation tokens *)
   209 
   209 
   210 datatype token =
   210 datatype token =
   211     No_Token
   211     No_Token
   382       >> (fn (((tok, pos'), tags), source) =>
   382       >> (fn (((tok, pos'), tags), source) =>
   383         let val name = Token.content_of tok
   383         let val name = Token.content_of tok
   384         in (SOME (name, pos', tags), (mk (name, source), (flag, d))) end));
   384         in (SOME (name, pos', tags), (mk (name, source), (flag, d))) end));
   385 
   385 
   386     val command = Scan.peek (fn d =>
   386     val command = Scan.peek (fn d =>
   387       Parse.position (Scan.one (Token.is_command)) --
   387       Scan.optional (Scan.one Token.is_private -- improper >> op ::) [] --
   388       Scan.repeat tag
   388       Scan.one Token.is_command -- Scan.repeat tag
   389       >> (fn ((tok, pos), tags) =>
   389       >> (fn ((private, cmd), tags) =>
   390         let val name = Token.content_of tok
   390         map (fn tok => (NONE, (Basic_Token tok, ("", d)))) private @
   391         in (SOME (name, pos, tags), (Basic_Token tok, (Latex.markup_false, d))) end));
   391           [(SOME (Token.content_of cmd, Token.pos_of cmd, tags),
       
   392             (Basic_Token cmd, (Latex.markup_false, d)))]));
   392 
   393 
   393     val cmt = Scan.peek (fn d =>
   394     val cmt = Scan.peek (fn d =>
   394       Parse.$$$ "--" |-- Parse.!!!! (improper |-- Parse.document_source) >>
   395       Parse.$$$ "--" |-- Parse.!!!! (improper |-- Parse.document_source) >>
   395         (fn source => (NONE, (Markup_Token ("cmt", source), ("", d)))));
   396         (fn source => (NONE, (Markup_Token ("cmt", source), ("", d)))));
   396 
   397 
   397     val other = Scan.peek (fn d =>
   398     val other = Scan.peek (fn d =>
   398        Parse.not_eof >> (fn tok => (NONE, (Basic_Token tok, ("", d)))));
   399        Parse.not_eof >> (fn tok => (NONE, (Basic_Token tok, ("", d)))));
   399 
   400 
   400     val token =
   401     val tokens =
   401       ignored ||
   402       (ignored ||
   402       markup Keyword.is_document_heading Markup_Token Latex.markup_true ||
   403         markup Keyword.is_document_heading Markup_Token Latex.markup_true ||
   403       markup Keyword.is_document_body Markup_Env_Token Latex.markup_true ||
   404         markup Keyword.is_document_body Markup_Env_Token Latex.markup_true ||
   404       markup Keyword.is_document_raw (Verbatim_Token o #2) "" ||
   405         markup Keyword.is_document_raw (Verbatim_Token o #2) "") >> single ||
   405       command || cmt || other;
   406       command ||
       
   407       (cmt || other) >> single;
   406 
   408 
   407 
   409 
   408     (* spans *)
   410     (* spans *)
   409 
   411 
   410     val is_eof = fn (_, (Basic_Token x, _)) => Token.is_eof x | _ => false;
   412     val is_eof = fn (_, (Basic_Token x, _)) => Token.is_eof x | _ => false;
   429           make_span (the cmd) (toks1 @ (tok2 :: (toks3 @ the_default [] tok4))));
   431           make_span (the cmd) (toks1 @ (tok2 :: (toks3 @ the_default [] tok4))));
   430 
   432 
   431     val spans = toks
   433     val spans = toks
   432       |> take_suffix Token.is_space |> #1
   434       |> take_suffix Token.is_space |> #1
   433       |> Source.of_list
   435       |> Source.of_list
   434       |> Source.source' 0 Token.stopper (Scan.error (Scan.bulk token))
   436       |> Source.source' 0 Token.stopper (Scan.error (Scan.bulk tokens >> flat))
   435       |> Source.source stopper (Scan.error (Scan.bulk span))
   437       |> Source.source stopper (Scan.error (Scan.bulk span))
   436       |> Source.exhaust;
   438       |> Source.exhaust;
   437 
   439 
   438 
   440 
   439     (* present commands *)
   441     (* present commands *)