author | wenzelm |
Sun, 17 Mar 2019 20:03:55 +0100 | |
changeset 69916 | 3235ecdcd884 |
parent 69891 | def3ec9cdb7e |
child 69962 | 82e945d472d5 |
permissions | -rw-r--r-- |
69887 | 1 |
(* Title: Pure/Thy/document_marker.ML |
2 |
Author: Makarius |
|
3 |
||
4 |
Document markers: declarations on the presentation context. |
|
5 |
*) |
|
6 |
||
7 |
signature DOCUMENT_MARKER = |
|
8 |
sig |
|
9 |
type marker = Proof.context -> Proof.context |
|
10 |
val setup: binding -> 'a context_parser -> ('a -> marker) -> theory -> theory |
|
69889
be04e9a053a7
markup and document markers for some meta data from "Dublin Core Metadata Element Set";
wenzelm
parents:
69887
diff
changeset
|
11 |
val setup0: binding -> 'a parser -> ('a -> marker) -> theory -> theory |
69887 | 12 |
val evaluate: Input.source -> marker |
69891
def3ec9cdb7e
document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents:
69890
diff
changeset
|
13 |
val legacy_tag: string -> Input.source |
69887 | 14 |
end; |
15 |
||
16 |
structure Document_Marker: DOCUMENT_MARKER = |
|
17 |
struct |
|
18 |
||
19 |
(* theory data *) |
|
20 |
||
21 |
type marker = Proof.context -> Proof.context; |
|
22 |
||
23 |
structure Markers = Theory_Data |
|
24 |
( |
|
25 |
type T = (Token.src -> Proof.context -> Proof.context) Name_Space.table; |
|
26 |
val empty : T = Name_Space.empty_table "document_marker"; |
|
27 |
val extend = I; |
|
28 |
val merge = Name_Space.merge_tables; |
|
29 |
); |
|
30 |
||
31 |
val get_markers = Markers.get o Proof_Context.theory_of; |
|
32 |
||
33 |
fun check ctxt = Name_Space.check (Context.Proof ctxt) (get_markers ctxt); |
|
34 |
||
35 |
fun setup name scan body thy = |
|
36 |
let |
|
37 |
fun marker src ctxt = |
|
38 |
let val (x, ctxt') = Token.syntax scan src ctxt |
|
39 |
in body x ctxt' end; |
|
40 |
in thy |> Markers.map (Name_Space.define (Context.Theory thy) true (name, marker) #> #2) end; |
|
41 |
||
69889
be04e9a053a7
markup and document markers for some meta data from "Dublin Core Metadata Element Set";
wenzelm
parents:
69887
diff
changeset
|
42 |
fun setup0 name scan = setup name (Scan.lift scan); |
be04e9a053a7
markup and document markers for some meta data from "Dublin Core Metadata Element Set";
wenzelm
parents:
69887
diff
changeset
|
43 |
|
69887 | 44 |
|
45 |
(* evaluate inner syntax *) |
|
46 |
||
47 |
val parse_marker = Parse.token Parse.liberal_name ::: Parse.!!! Parse.args; |
|
48 |
||
49 |
fun evaluate input ctxt = |
|
50 |
let |
|
69891
def3ec9cdb7e
document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents:
69890
diff
changeset
|
51 |
val body = |
def3ec9cdb7e
document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents:
69890
diff
changeset
|
52 |
Input.source_explode input |
def3ec9cdb7e
document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents:
69890
diff
changeset
|
53 |
|> drop_prefix (fn (s, _) => s = Symbol.marker) |
def3ec9cdb7e
document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents:
69890
diff
changeset
|
54 |
|> Symbol_Pos.cartouche_content; |
69887 | 55 |
val markers = |
69891
def3ec9cdb7e
document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents:
69890
diff
changeset
|
56 |
(case Token.read_body (Thy_Header.get_keywords' ctxt) (Parse.list parse_marker) body of |
69887 | 57 |
SOME res => res |
69891
def3ec9cdb7e
document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents:
69890
diff
changeset
|
58 |
| NONE => error ("Bad input" ^ Position.here (Input.pos_of input))); |
69887 | 59 |
in fold (fn src => #2 (check ctxt (Token.name_of_src src)) src) markers ctxt end; |
60 |
||
61 |
||
62 |
(* concrete markers *) |
|
63 |
||
69889
be04e9a053a7
markup and document markers for some meta data from "Dublin Core Metadata Element Set";
wenzelm
parents:
69887
diff
changeset
|
64 |
fun meta_data markup arg ctxt = |
be04e9a053a7
markup and document markers for some meta data from "Dublin Core Metadata Element Set";
wenzelm
parents:
69887
diff
changeset
|
65 |
(Context_Position.report_text ctxt (Position.thread_data ()) markup arg; ctxt); |
be04e9a053a7
markup and document markers for some meta data from "Dublin Core Metadata Element Set";
wenzelm
parents:
69887
diff
changeset
|
66 |
|
69887 | 67 |
val _ = |
68 |
Theory.setup |
|
69889
be04e9a053a7
markup and document markers for some meta data from "Dublin Core Metadata Element Set";
wenzelm
parents:
69887
diff
changeset
|
69 |
(setup0 (Binding.make ("tag", \<^here>)) Parse.name Document_Source.update_tags #> |
be04e9a053a7
markup and document markers for some meta data from "Dublin Core Metadata Element Set";
wenzelm
parents:
69887
diff
changeset
|
70 |
setup0 (Binding.make ("title", \<^here>)) Parse.embedded (meta_data Markup.meta_title) #> |
be04e9a053a7
markup and document markers for some meta data from "Dublin Core Metadata Element Set";
wenzelm
parents:
69887
diff
changeset
|
71 |
setup0 (Binding.make ("creator", \<^here>)) Parse.embedded (meta_data Markup.meta_creator) #> |
be04e9a053a7
markup and document markers for some meta data from "Dublin Core Metadata Element Set";
wenzelm
parents:
69887
diff
changeset
|
72 |
setup0 (Binding.make ("contributor", \<^here>)) Parse.embedded (meta_data Markup.meta_contributor) #> |
be04e9a053a7
markup and document markers for some meta data from "Dublin Core Metadata Element Set";
wenzelm
parents:
69887
diff
changeset
|
73 |
setup0 (Binding.make ("date", \<^here>)) Parse.embedded (meta_data Markup.meta_date) #> |
69890 | 74 |
setup0 (Binding.make ("description", \<^here>)) (Parse.input Parse.embedded) |
75 |
(fn source => fn ctxt => |
|
76 |
let |
|
77 |
val (arg, pos) = Input.source_content source; |
|
78 |
val _ = Context_Position.report ctxt pos Markup.words; |
|
69916
3235ecdcd884
more meta data from "dcterms" (superset of "dc");
wenzelm
parents:
69891
diff
changeset
|
79 |
in meta_data Markup.meta_description arg ctxt end) #> |
3235ecdcd884
more meta data from "dcterms" (superset of "dc");
wenzelm
parents:
69891
diff
changeset
|
80 |
setup0 (Binding.make ("license", \<^here>)) Parse.embedded (meta_data Markup.meta_license)); |
69887 | 81 |
|
69891
def3ec9cdb7e
document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents:
69890
diff
changeset
|
82 |
fun legacy_tag name = |
def3ec9cdb7e
document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents:
69890
diff
changeset
|
83 |
Input.string (cartouche ("tag " ^ Symbol_Pos.quote_string_qq name)); |
def3ec9cdb7e
document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents:
69890
diff
changeset
|
84 |
|
69887 | 85 |
end; |