69876
|
1 |
(* Title: Pure/Thy/document_source.ML
|
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
Document source for presentation.
|
|
5 |
*)
|
|
6 |
|
|
7 |
signature DOCUMENT_SOURCE =
|
|
8 |
sig
|
|
9 |
val is_white: Token.T -> bool
|
|
10 |
val is_black: Token.T -> bool
|
|
11 |
val is_white_comment: Token.T -> bool
|
|
12 |
val is_black_comment: Token.T -> bool
|
|
13 |
val is_improper: Token.T -> bool
|
|
14 |
val improper: Token.T list parser
|
|
15 |
val improper_end: Token.T list parser
|
|
16 |
val blank_end: Token.T list parser
|
|
17 |
val tag: string parser
|
|
18 |
val tags: string list parser
|
|
19 |
end;
|
|
20 |
|
|
21 |
structure Document_Source: DOCUMENT_SOURCE =
|
|
22 |
struct
|
|
23 |
|
|
24 |
(* white space and comments *)
|
|
25 |
|
|
26 |
(*NB: arranging white space around command spans is a black art*)
|
|
27 |
|
|
28 |
val is_white = Token.is_space orf Token.is_informal_comment;
|
|
29 |
val is_black = not o is_white;
|
|
30 |
|
|
31 |
val is_white_comment = Token.is_informal_comment;
|
|
32 |
val is_black_comment = Token.is_formal_comment;
|
|
33 |
|
|
34 |
|
|
35 |
val space_proper =
|
|
36 |
Scan.one Token.is_blank -- Scan.many is_white_comment -- Scan.one is_black;
|
|
37 |
|
|
38 |
val is_improper = not o (is_black orf Token.is_begin_ignore orf Token.is_end_ignore);
|
|
39 |
val improper = Scan.many is_improper;
|
|
40 |
val improper_end = Scan.repeat (Scan.unless space_proper (Scan.one is_improper));
|
|
41 |
val blank_end = Scan.repeat (Scan.unless space_proper (Scan.one Token.is_blank));
|
|
42 |
|
|
43 |
|
|
44 |
(* tags *)
|
|
45 |
|
|
46 |
val tag_name = Parse.group (fn () => "document tag name") (Parse.short_ident || Parse.string);
|
|
47 |
|
|
48 |
val tag = (improper -- Parse.$$$ "%" -- improper) |-- Parse.!!! (tag_name --| blank_end);
|
|
49 |
val tags = Scan.repeat tag;
|
|
50 |
|
|
51 |
end;
|