author | wenzelm |
Mon, 25 Mar 2019 17:21:26 +0100 | |
changeset 69981 | 3dced198b9ec |
parent 69891 | def3ec9cdb7e |
child 70134 | e69f00f4b897 |
permissions | -rw-r--r-- |
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 |
|
69887 | 17 |
val get_tags: Proof.context -> string list |
18 |
val update_tags: string -> Proof.context -> Proof.context |
|
69876 | 19 |
val tags: string list parser |
69891
def3ec9cdb7e
document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents:
69887
diff
changeset
|
20 |
val annotation: unit parser |
69876 | 21 |
end; |
22 |
||
23 |
structure Document_Source: DOCUMENT_SOURCE = |
|
24 |
struct |
|
25 |
||
26 |
(* white space and comments *) |
|
27 |
||
28 |
(*NB: arranging white space around command spans is a black art*) |
|
29 |
||
30 |
val is_white = Token.is_space orf Token.is_informal_comment; |
|
31 |
val is_black = not o is_white; |
|
32 |
||
33 |
val is_white_comment = Token.is_informal_comment; |
|
34 |
val is_black_comment = Token.is_formal_comment; |
|
35 |
||
36 |
||
37 |
val space_proper = |
|
38 |
Scan.one Token.is_blank -- Scan.many is_white_comment -- Scan.one is_black; |
|
39 |
||
40 |
val is_improper = not o (is_black orf Token.is_begin_ignore orf Token.is_end_ignore); |
|
41 |
val improper = Scan.many is_improper; |
|
42 |
val improper_end = Scan.repeat (Scan.unless space_proper (Scan.one is_improper)); |
|
43 |
val blank_end = Scan.repeat (Scan.unless space_proper (Scan.one Token.is_blank)); |
|
44 |
||
45 |
||
69887 | 46 |
(* syntactic tags (old-style) *) |
47 |
||
48 |
structure Tags = Proof_Data |
|
49 |
( |
|
50 |
type T = string list; |
|
51 |
fun init _ = []; |
|
52 |
); |
|
53 |
||
54 |
val get_tags = Tags.get; |
|
55 |
val update_tags = Tags.map o update (op =); |
|
69876 | 56 |
|
57 |
val tag_name = Parse.group (fn () => "document tag name") (Parse.short_ident || Parse.string); |
|
58 |
||
59 |
val tag = (improper -- Parse.$$$ "%" -- improper) |-- Parse.!!! (tag_name --| blank_end); |
|
60 |
val tags = Scan.repeat tag; |
|
61 |
||
69887 | 62 |
|
63 |
(* semantic markers (operation on presentation context) *) |
|
64 |
||
69891
def3ec9cdb7e
document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents:
69887
diff
changeset
|
65 |
val marker = improper |-- Parse.document_marker --| blank_end; |
69887 | 66 |
|
69891
def3ec9cdb7e
document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents:
69887
diff
changeset
|
67 |
val annotation = Scan.repeat (tag >> K () || marker >> K ()) >> K (); |
69887 | 68 |
|
69876 | 69 |
end; |