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