115 let |
115 let |
116 fun output antiq bg en = |
116 fun output antiq bg en = |
117 output_body ctxt antiq bg en (Input.source_explode (Token.input_of tok)); |
117 output_body ctxt antiq bg en (Input.source_explode (Token.input_of tok)); |
118 in |
118 in |
119 (case Token.kind_of tok of |
119 (case Token.kind_of tok of |
120 Token.Comment => [] |
120 Token.Comment NONE => [] |
121 | Token.Command => output false "\\isacommand{" "}" |
121 | Token.Command => output false "\\isacommand{" "}" |
122 | Token.Keyword => |
122 | Token.Keyword => |
123 if Symbol.is_ascii_identifier (Token.content_of tok) |
123 if Symbol.is_ascii_identifier (Token.content_of tok) |
124 then output false "\\isakeyword{" "}" |
124 then output false "\\isakeyword{" "}" |
125 else output false "" "" |
125 else output false "" "" |
149 |
149 |
150 (** present theory source **) |
150 (** present theory source **) |
151 |
151 |
152 (*NB: arranging white space around command spans is a black art*) |
152 (*NB: arranging white space around command spans is a black art*) |
153 |
153 |
|
154 val is_white = Token.is_space orf Token.is_informal_comment; |
|
155 val is_black = not o is_white; |
|
156 |
|
157 val is_white_comment = Token.is_informal_comment; |
|
158 val is_black_comment = Token.is_formal_comment; |
|
159 |
154 |
160 |
155 (* presentation tokens *) |
161 (* presentation tokens *) |
156 |
162 |
157 datatype token = |
163 datatype token = |
158 Ignore_Token |
164 Ignore_Token |
162 | Raw_Token of Input.source; |
168 | Raw_Token of Input.source; |
163 |
169 |
164 fun basic_token pred (Basic_Token tok) = pred tok |
170 fun basic_token pred (Basic_Token tok) = pred tok |
165 | basic_token _ _ = false; |
171 | basic_token _ _ = false; |
166 |
172 |
167 val improper_token = basic_token Token.is_improper; |
173 val white_token = basic_token is_white; |
168 val comment_token = basic_token Token.is_comment; |
174 val white_comment_token = basic_token is_white_comment; |
169 val blank_token = basic_token Token.is_blank; |
175 val blank_token = basic_token Token.is_blank; |
170 val newline_token = basic_token Token.is_newline; |
176 val newline_token = basic_token Token.is_newline; |
171 |
177 |
172 fun present_token ctxt tok = |
178 fun present_token ctxt tok = |
173 (case tok of |
179 (case tok of |
195 if newline_token (fst tok) then ([tok], toks, true) |
201 if newline_token (fst tok) then ([tok], toks, true) |
196 else ([], tok :: toks, false) |
202 else ([], tok :: toks, false) |
197 | take_newline [] = ([], [], false); |
203 | take_newline [] = ([], [], false); |
198 val (((src_prefix, src_main), src_suffix1), (src_suffix2, src_appendix, newline)) = |
204 val (((src_prefix, src_main), src_suffix1), (src_suffix2, src_appendix, newline)) = |
199 src |
205 src |
200 |> take_prefix (improper_token o fst) |
206 |> take_prefix (white_token o fst) |
201 ||>> take_suffix (improper_token o fst) |
207 ||>> take_suffix (white_token o fst) |
202 ||>> take_prefix (comment_token o fst) |
208 ||>> take_prefix (white_comment_token o fst) |
203 ||> take_newline; |
209 ||> take_newline; |
204 in Span (cmd, (src_prefix, src_main, src_suffix1 @ src_suffix2, src_appendix), newline) end; |
210 in Span (cmd, (src_prefix, src_main, src_suffix1 @ src_suffix2, src_appendix), newline) end; |
205 |
211 |
206 |
212 |
207 (* present spans *) |
213 (* present spans *) |
294 |
300 |
295 val markup_true = "\\isamarkuptrue%\n"; |
301 val markup_true = "\\isamarkuptrue%\n"; |
296 val markup_false = "\\isamarkupfalse%\n"; |
302 val markup_false = "\\isamarkupfalse%\n"; |
297 |
303 |
298 val space_proper = |
304 val space_proper = |
299 Scan.one Token.is_blank -- Scan.many Token.is_comment -- Scan.one Token.is_proper; |
305 Scan.one Token.is_blank -- Scan.many is_white_comment -- Scan.one is_black; |
300 |
306 |
301 val is_improper = not o (Token.is_proper orf Token.is_begin_ignore orf Token.is_end_ignore); |
307 val is_improper = not o (is_black orf Token.is_begin_ignore orf Token.is_end_ignore); |
302 val improper = Scan.many is_improper; |
308 val improper = Scan.many is_improper; |
303 val improper_end = Scan.repeat (Scan.unless space_proper (Scan.one is_improper)); |
309 val improper_end = Scan.repeat (Scan.unless space_proper (Scan.one is_improper)); |
304 val blank_end = Scan.repeat (Scan.unless space_proper (Scan.one Token.is_blank)); |
310 val blank_end = Scan.repeat (Scan.unless space_proper (Scan.one Token.is_blank)); |
305 |
311 |
306 val opt_newline = Scan.option (Scan.one Token.is_newline); |
312 val opt_newline = Scan.option (Scan.one Token.is_newline); |
347 map (fn tok => (NONE, (Basic_Token tok, ("", d)))) cmd_mod @ |
353 map (fn tok => (NONE, (Basic_Token tok, ("", d)))) cmd_mod @ |
348 [(SOME (Token.content_of cmd, Token.pos_of cmd, tags), |
354 [(SOME (Token.content_of cmd, Token.pos_of cmd, tags), |
349 (Basic_Token cmd, (markup_false, d)))])); |
355 (Basic_Token cmd, (markup_false, d)))])); |
350 |
356 |
351 val cmt = Scan.peek (fn d => |
357 val cmt = Scan.peek (fn d => |
|
358 Scan.one is_black_comment >> |
|
359 (fn tok => (NONE, (Basic_Token tok, ("", d)))) || |
352 (Parse.$$$ "--" || Parse.$$$ Symbol.comment) |-- |
360 (Parse.$$$ "--" || Parse.$$$ Symbol.comment) |-- |
353 Parse.!!!! (improper |-- Parse.document_source) >> |
361 Parse.!!!! (improper |-- Parse.document_source) >> |
354 (fn source => (NONE, (Markup_Token ("cmt", source), ("", d))))); |
362 (fn source => (NONE, (Markup_Token ("cmt", source), ("", d))))); |
355 |
363 |
356 val other = Scan.peek (fn d => |
364 val other = Scan.peek (fn d => |
371 val stopper = Scan.stopper (K (NONE, (Basic_Token Token.eof, ("", 0)))) is_eof; |
379 val stopper = Scan.stopper (K (NONE, (Basic_Token Token.eof, ("", 0)))) is_eof; |
372 |
380 |
373 val cmd = Scan.one (is_some o fst); |
381 val cmd = Scan.one (is_some o fst); |
374 val non_cmd = Scan.one (is_none o fst andf not o is_eof) >> #2; |
382 val non_cmd = Scan.one (is_none o fst andf not o is_eof) >> #2; |
375 |
383 |
376 val comments = Scan.many (comment_token o fst o snd); |
384 val white_comments = Scan.many (white_comment_token o fst o snd); |
377 val blank = Scan.one (blank_token o fst o snd); |
385 val blank = Scan.one (blank_token o fst o snd); |
378 val newline = Scan.one (newline_token o fst o snd); |
386 val newline = Scan.one (newline_token o fst o snd); |
379 val before_cmd = |
387 val before_cmd = |
380 Scan.option (newline -- comments) -- |
388 Scan.option (newline -- white_comments) -- |
381 Scan.option (newline -- comments) -- |
389 Scan.option (newline -- white_comments) -- |
382 Scan.option (blank -- comments) -- cmd; |
390 Scan.option (blank -- white_comments) -- cmd; |
383 |
391 |
384 val span = |
392 val span = |
385 Scan.repeat non_cmd -- cmd -- |
393 Scan.repeat non_cmd -- cmd -- |
386 Scan.repeat (Scan.unless before_cmd non_cmd) -- |
394 Scan.repeat (Scan.unless before_cmd non_cmd) -- |
387 Scan.option (newline >> (single o snd)) |
395 Scan.option (newline >> (single o snd)) |