| author | nipkow | 
| Mon, 26 Aug 2024 22:52:27 +0200 | |
| changeset 80776 | 3a9e570c916d | 
| parent 79743 | 3648e9c88d0c | 
| child 81166 | 26ecbac09941 | 
| permissions | -rw-r--r-- | 
| 5823 | 1 | (* Title: Pure/Isar/attrib.ML | 
| 2 | Author: Markus Wenzel, TU Muenchen | |
| 3 | ||
| 18734 | 4 | Symbolic representation of attributes -- with name and syntax. | 
| 5823 | 5 | *) | 
| 6 | ||
| 7 | signature ATTRIB = | |
| 8 | sig | |
| 67652 | 9 | type thms = Attrib.thms | 
| 10 | type fact = Attrib.fact | |
| 59917 
9830c944670f
more uniform "verbose" option to print name space;
 wenzelm parents: 
59064diff
changeset | 11 | val print_attributes: bool -> Proof.context -> unit | 
| 74261 
d28a51dd9da6
export other entities, e.g. relevant for formal document output;
 wenzelm parents: 
74156diff
changeset | 12 | val attribute_space: Context.generic -> Name_Space.T | 
| 63336 | 13 | val define_global: binding -> (Token.src -> attribute) -> string -> theory -> string * theory | 
| 14 | val define: binding -> (Token.src -> attribute) -> string -> local_theory -> string * local_theory | |
| 55997 
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
 wenzelm parents: 
55914diff
changeset | 15 | val check_name_generic: Context.generic -> xstring * Position.T -> string | 
| 
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
 wenzelm parents: 
55914diff
changeset | 16 | val check_name: Proof.context -> xstring * Position.T -> string | 
| 58011 
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
 wenzelm parents: 
57942diff
changeset | 17 | val check_src: Proof.context -> Token.src -> Token.src | 
| 61814 
1ca1142e1711
clarified type Token.src: plain token list, with usual implicit value assignment;
 wenzelm parents: 
61527diff
changeset | 18 | val attribs: Token.src list context_parser | 
| 
1ca1142e1711
clarified type Token.src: plain token list, with usual implicit value assignment;
 wenzelm parents: 
61527diff
changeset | 19 | val opt_attribs: Token.src list context_parser | 
| 58011 
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
 wenzelm parents: 
57942diff
changeset | 20 | val pretty_attribs: Proof.context -> Token.src list -> Pretty.T list | 
| 63336 | 21 | val pretty_binding: Proof.context -> Attrib.binding -> string -> Pretty.T list | 
| 58011 
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
 wenzelm parents: 
57942diff
changeset | 22 | val attribute: Proof.context -> Token.src -> attribute | 
| 
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
 wenzelm parents: 
57942diff
changeset | 23 | val attribute_global: theory -> Token.src -> attribute | 
| 
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
 wenzelm parents: 
57942diff
changeset | 24 | val attribute_cmd: Proof.context -> Token.src -> attribute | 
| 
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
 wenzelm parents: 
57942diff
changeset | 25 | val attribute_cmd_global: theory -> Token.src -> attribute | 
| 45390 
e29521ef9059
tuned signature -- avoid spurious Thm.mixed_attribute;
 wenzelm parents: 
45375diff
changeset | 26 |   val map_specs: ('a list -> 'att list) ->
 | 
| 30759 | 27 |     (('c * 'a list) * 'b) list -> (('c * 'att list) * 'b) list
 | 
| 45390 
e29521ef9059
tuned signature -- avoid spurious Thm.mixed_attribute;
 wenzelm parents: 
45375diff
changeset | 28 |   val map_facts: ('a list -> 'att list) ->
 | 
| 17105 
1b07a176a880
added map_specs/facts operators (from locale.ML);
 wenzelm parents: 
16934diff
changeset | 29 |     (('c * 'a list) * ('d * 'a list) list) list ->
 | 
| 18905 | 30 |     (('c * 'att list) * ('d * 'att list) list) list
 | 
| 45390 
e29521ef9059
tuned signature -- avoid spurious Thm.mixed_attribute;
 wenzelm parents: 
45375diff
changeset | 31 |   val map_facts_refs: ('a list -> 'att list) -> ('b -> 'fact) ->
 | 
| 30759 | 32 |     (('c * 'a list) * ('b * 'a list) list) list ->
 | 
| 33 |     (('c * 'att list) * ('fact * 'att list) list) list
 | |
| 79347 | 34 |   val map_thms: ('a -> 'b) ->
 | 
| 35 |     ('c * ('a list * 'd) list) list ->
 | |
| 36 |     ('c * ('b list * 'd) list) list
 | |
| 67652 | 37 | val trim_context_binding: Attrib.binding -> Attrib.binding | 
| 38 | val trim_context_thms: thms -> thms | |
| 39 | val trim_context_fact: fact -> fact | |
| 40 | val global_notes: string -> fact list -> theory -> | |
| 41 | (string * thm list) list * theory | |
| 42 | val local_notes: string -> fact list -> Proof.context -> | |
| 43 | (string * thm list) list * Proof.context | |
| 44 | val generic_notes: string -> fact list -> Context.generic -> | |
| 45 | (string * thm list) list * Context.generic | |
| 67671 
857da80611ab
support for lazy notes in global/local context and Element.Lazy_Notes: name binding and fact without attributes;
 wenzelm parents: 
67652diff
changeset | 46 | val lazy_notes: string -> binding * thm list lazy -> Context.generic -> Context.generic | 
| 58011 
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
 wenzelm parents: 
57942diff
changeset | 47 | val eval_thms: Proof.context -> (Facts.ref * Token.src list) list -> thm list | 
| 
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
 wenzelm parents: 
57942diff
changeset | 48 | val attribute_syntax: attribute context_parser -> Token.src -> attribute | 
| 63336 | 49 | val setup: binding -> attribute context_parser -> string -> theory -> theory | 
| 50 | val local_setup: binding -> attribute context_parser -> string -> | |
| 57927 | 51 | local_theory -> local_theory | 
| 59064 | 52 | val attribute_setup: bstring * Position.T -> Input.source -> string -> | 
| 57941 
57200bdc2aa7
localized command 'method_setup' and 'attribute_setup';
 wenzelm parents: 
57938diff
changeset | 53 | local_theory -> local_theory | 
| 78095 | 54 | val internal: Position.T -> (morphism -> attribute) -> Token.src | 
| 55 | val internal_declaration: Position.T -> Morphism.declaration_entity -> thms | |
| 30525 
8a5a0aa30e1c
added setup and attribute_setup -- expect plain parser instead of syntax function;
 wenzelm parents: 
30513diff
changeset | 56 | val add_del: attribute -> attribute -> attribute context_parser | 
| 30513 | 57 | val thm: thm context_parser | 
| 58 | val thms: thm list context_parser | |
| 59 | val multi_thm: thm list context_parser | |
| 67652 | 60 | val transform_facts: morphism -> fact list -> fact list | 
| 61 | val partial_evaluation: Proof.context -> fact list -> fact list | |
| 59917 
9830c944670f
more uniform "verbose" option to print name space;
 wenzelm parents: 
59064diff
changeset | 62 | val print_options: bool -> Proof.context -> unit | 
| 63336 | 63 | val config_bool: binding -> (Context.generic -> bool) -> bool Config.T * (theory -> theory) | 
| 64 | val config_int: binding -> (Context.generic -> int) -> int Config.T * (theory -> theory) | |
| 65 | val config_real: binding -> (Context.generic -> real) -> real Config.T * (theory -> theory) | |
| 66 | val config_string: binding -> (Context.generic -> string) -> string Config.T * (theory -> theory) | |
| 67 | val setup_config_bool: binding -> (Context.generic -> bool) -> bool Config.T | |
| 68 | val setup_config_int: binding -> (Context.generic -> int) -> int Config.T | |
| 69 | val setup_config_real: binding -> (Context.generic -> real) -> real Config.T | |
| 70 | val setup_config_string: binding -> (Context.generic -> string) -> string Config.T | |
| 56438 | 71 | val option_bool: string * Position.T -> bool Config.T * (theory -> theory) | 
| 72 | val option_int: string * Position.T -> int Config.T * (theory -> theory) | |
| 73 | val option_real: string * Position.T -> real Config.T * (theory -> theory) | |
| 74 | val option_string: string * Position.T -> string Config.T * (theory -> theory) | |
| 75 | val setup_option_bool: string * Position.T -> bool Config.T | |
| 76 | val setup_option_int: string * Position.T -> int Config.T | |
| 77 | val setup_option_real: string * Position.T -> real Config.T | |
| 78 | val setup_option_string: string * Position.T -> string Config.T | |
| 63019 | 79 | val consumes: int -> Token.src | 
| 80 | val constraints: int -> Token.src | |
| 81 | val cases_open: Token.src | |
| 82 | val case_names: string list -> Token.src | |
| 83 | val case_conclusion: string * string list -> Token.src | |
| 5823 | 84 | end; | 
| 85 | ||
| 63336 | 86 | structure Attrib: sig type binding = Attrib.binding include ATTRIB end = | 
| 5823 | 87 | struct | 
| 88 | ||
| 67652 | 89 | open Attrib; | 
| 45584 
41a768a431a6
do not store vacuous theorem specifications -- relevant for frugal local theory content;
 wenzelm parents: 
45537diff
changeset | 90 | |
| 28084 
a05ca48ef263
type Attrib.binding abbreviates Name.binding without attributes;
 wenzelm parents: 
28083diff
changeset | 91 | |
| 27729 | 92 | |
| 18734 | 93 | (** named attributes **) | 
| 18636 | 94 | |
| 18734 | 95 | (* theory data *) | 
| 5823 | 96 | |
| 57927 | 97 | structure Attributes = Generic_Data | 
| 22846 | 98 | ( | 
| 58011 
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
 wenzelm parents: 
57942diff
changeset | 99 | type T = ((Token.src -> attribute) * string) Name_Space.table; | 
| 74112 | 100 | val empty : T = Name_Space.empty_table Markup.attributeN; | 
| 33522 | 101 | fun merge data : T = Name_Space.merge_tables data; | 
| 22846 | 102 | ); | 
| 5823 | 103 | |
| 63090 
7aa9ac5165e4
common entity definitions within a global or local theory context;
 wenzelm parents: 
63068diff
changeset | 104 | val ops_attributes = {get_data = Attributes.get, put_data = Attributes.put};
 | 
| 57927 | 105 | |
| 63090 
7aa9ac5165e4
common entity definitions within a global or local theory context;
 wenzelm parents: 
63068diff
changeset | 106 | val get_attributes = Attributes.get o Context.Proof; | 
| 55997 
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
 wenzelm parents: 
55914diff
changeset | 107 | |
| 59917 
9830c944670f
more uniform "verbose" option to print name space;
 wenzelm parents: 
59064diff
changeset | 108 | fun print_attributes verbose ctxt = | 
| 22846 | 109 | let | 
| 57927 | 110 | val attribs = get_attributes ctxt; | 
| 50301 | 111 | fun prt_attr (name, (_, "")) = Pretty.mark_str name | 
| 42813 
6c841fa92fa2
optional description for 'attribute_setup' and 'method_setup';
 wenzelm parents: 
42808diff
changeset | 112 | | prt_attr (name, (_, comment)) = | 
| 50301 | 113 | Pretty.block | 
| 114 | (Pretty.mark_str name :: Pretty.str ":" :: Pretty.brk 2 :: Pretty.text comment); | |
| 22846 | 115 | in | 
| 59917 
9830c944670f
more uniform "verbose" option to print name space;
 wenzelm parents: 
59064diff
changeset | 116 | [Pretty.big_list "attributes:" (map prt_attr (Name_Space.markup_table verbose ctxt attribs))] | 
| 56334 
6b3739fee456
some shortcuts for chunks, which sometimes avoid bulky string output;
 wenzelm parents: 
56303diff
changeset | 117 | |> Pretty.writeln_chunks | 
| 22846 | 118 | end; | 
| 7611 | 119 | |
| 74261 
d28a51dd9da6
export other entities, e.g. relevant for formal document output;
 wenzelm parents: 
74156diff
changeset | 120 | val attribute_space = Name_Space.space_of_table o Attributes.get; | 
| 57927 | 121 | |
| 122 | ||
| 123 | (* define *) | |
| 124 | ||
| 63090 
7aa9ac5165e4
common entity definitions within a global or local theory context;
 wenzelm parents: 
63068diff
changeset | 125 | fun define_global binding att comment = | 
| 
7aa9ac5165e4
common entity definitions within a global or local theory context;
 wenzelm parents: 
63068diff
changeset | 126 | Entity.define_global ops_attributes binding (att, comment); | 
| 56027 
25889f5c39a8
prefer Name_Space.pretty with its builtin markup;
 wenzelm parents: 
56026diff
changeset | 127 | |
| 57941 
57200bdc2aa7
localized command 'method_setup' and 'attribute_setup';
 wenzelm parents: 
57938diff
changeset | 128 | fun define binding att comment = | 
| 63090 
7aa9ac5165e4
common entity definitions within a global or local theory context;
 wenzelm parents: 
63068diff
changeset | 129 | Entity.define ops_attributes binding (att, comment); | 
| 31306 
a74ee84288a0
eliminated old Attrib.add_attributes (and Attrib.syntax);
 wenzelm parents: 
31305diff
changeset | 130 | |
| 5823 | 131 | |
| 55997 
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
 wenzelm parents: 
55914diff
changeset | 132 | (* check *) | 
| 15703 | 133 | |
| 57927 | 134 | fun check_name_generic context = #1 o Name_Space.check context (Attributes.get context); | 
| 56032 
b034b9f0fa2a
clarified Args.check_src: retain name space information for error output;
 wenzelm parents: 
56029diff
changeset | 135 | val check_name = check_name_generic o Context.Proof; | 
| 15703 | 136 | |
| 56033 | 137 | fun check_src ctxt src = | 
| 61814 
1ca1142e1711
clarified type Token.src: plain token list, with usual implicit value assignment;
 wenzelm parents: 
61527diff
changeset | 138 | let | 
| 
1ca1142e1711
clarified type Token.src: plain token list, with usual implicit value assignment;
 wenzelm parents: 
61527diff
changeset | 139 | val _ = | 
| 
1ca1142e1711
clarified type Token.src: plain token list, with usual implicit value assignment;
 wenzelm parents: 
61527diff
changeset | 140 | if Token.checked_src src then () | 
| 62795 
063d2f23cdf6
removed redundant Position.set_range -- already done in Position.range;
 wenzelm parents: 
62498diff
changeset | 141 | else Context_Position.report ctxt (#1 (Token.range_of src)) Markup.language_attribute; | 
| 61814 
1ca1142e1711
clarified type Token.src: plain token list, with usual implicit value assignment;
 wenzelm parents: 
61527diff
changeset | 142 | in #1 (Token.check_src ctxt get_attributes src) end; | 
| 
1ca1142e1711
clarified type Token.src: plain token list, with usual implicit value assignment;
 wenzelm parents: 
61527diff
changeset | 143 | |
| 
1ca1142e1711
clarified type Token.src: plain token list, with usual implicit value assignment;
 wenzelm parents: 
61527diff
changeset | 144 | val attribs = | 
| 
1ca1142e1711
clarified type Token.src: plain token list, with usual implicit value assignment;
 wenzelm parents: 
61527diff
changeset | 145 | Args.context -- Scan.lift Parse.attribs | 
| 
1ca1142e1711
clarified type Token.src: plain token list, with usual implicit value assignment;
 wenzelm parents: 
61527diff
changeset | 146 | >> (fn (ctxt, srcs) => map (check_src ctxt) srcs); | 
| 
1ca1142e1711
clarified type Token.src: plain token list, with usual implicit value assignment;
 wenzelm parents: 
61527diff
changeset | 147 | |
| 
1ca1142e1711
clarified type Token.src: plain token list, with usual implicit value assignment;
 wenzelm parents: 
61527diff
changeset | 148 | val opt_attribs = Scan.optional attribs []; | 
| 21031 | 149 | |
| 150 | ||
| 151 | (* pretty printing *) | |
| 152 | ||
| 153 | fun pretty_attribs _ [] = [] | |
| 58011 
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
 wenzelm parents: 
57942diff
changeset | 154 | | pretty_attribs ctxt srcs = [Pretty.enum "," "[" "]" (map (Token.pretty_src ctxt) srcs)]; | 
| 21031 | 155 | |
| 60242 
3a8501876dba
tuned output -- avoid empty quites and extra breaks;
 wenzelm parents: 
59917diff
changeset | 156 | fun pretty_binding ctxt (b, atts) sep = | 
| 60243 | 157 | (case (Binding.is_empty b, null atts) of | 
| 158 | (true, true) => [] | |
| 159 | | (false, true) => [Pretty.block [Binding.pretty b, Pretty.str sep]] | |
| 160 | | (true, false) => [Pretty.block (pretty_attribs ctxt atts @ [Pretty.str sep])] | |
| 161 | | (false, false) => | |
| 162 | [Pretty.block | |
| 163 | (Binding.pretty b :: Pretty.brk 1 :: pretty_attribs ctxt atts @ [Pretty.str sep])]); | |
| 60242 
3a8501876dba
tuned output -- avoid empty quites and extra breaks;
 wenzelm parents: 
59917diff
changeset | 164 | |
| 15703 | 165 | |
| 18734 | 166 | (* get attributes *) | 
| 5823 | 167 | |
| 47816 
cd0dfb06b0c8
prefer Context_Position.report_generic, which observes is_visible flag and thus reduces number of echos;
 wenzelm parents: 
47815diff
changeset | 168 | fun attribute_generic context = | 
| 78023 | 169 | let val table = Attributes.get context in | 
| 170 | fn src => | |
| 171 | let | |
| 172 | val name = #1 (Token.name_of_src src); | |
| 173 | val label = Long_Name.qualify Markup.attributeN name; | |
| 174 | val att = #1 (Name_Space.get table name) src; | |
| 78091 | 175 | in Position.setmp_thread_data_label label att : attribute end | 
| 78023 | 176 | end; | 
| 5823 | 177 | |
| 47816 
cd0dfb06b0c8
prefer Context_Position.report_generic, which observes is_visible flag and thus reduces number of echos;
 wenzelm parents: 
47815diff
changeset | 178 | val attribute = attribute_generic o Context.Proof; | 
| 
cd0dfb06b0c8
prefer Context_Position.report_generic, which observes is_visible flag and thus reduces number of echos;
 wenzelm parents: 
47815diff
changeset | 179 | val attribute_global = attribute_generic o Context.Theory; | 
| 47815 | 180 | |
| 55997 
9dc5ce83202c
modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
 wenzelm parents: 
55914diff
changeset | 181 | fun attribute_cmd ctxt = attribute ctxt o check_src ctxt; | 
| 56032 
b034b9f0fa2a
clarified Args.check_src: retain name space information for error output;
 wenzelm parents: 
56029diff
changeset | 182 | fun attribute_cmd_global thy = attribute_global thy o check_src (Proof_Context.init_global thy); | 
| 18636 | 183 | |
| 5823 | 184 | |
| 17105 
1b07a176a880
added map_specs/facts operators (from locale.ML);
 wenzelm parents: 
16934diff
changeset | 185 | (* attributed declarations *) | 
| 
1b07a176a880
added map_specs/facts operators (from locale.ML);
 wenzelm parents: 
16934diff
changeset | 186 | |
| 79346 | 187 | fun map_specs f = (map o apfst o apsnd) f; | 
| 30759 | 188 | |
| 79346 | 189 | fun map_facts f = map (fn (a, b) => (apsnd f a, (map o apsnd) f b)); | 
| 190 | fun map_facts_refs f g = map_facts f #> (map o apsnd o map o apfst) g; | |
| 17105 
1b07a176a880
added map_specs/facts operators (from locale.ML);
 wenzelm parents: 
16934diff
changeset | 191 | |
| 79347 | 192 | fun map_thms f = (map o apsnd o map o apfst o map) f; | 
| 193 | ||
| 17105 
1b07a176a880
added map_specs/facts operators (from locale.ML);
 wenzelm parents: 
16934diff
changeset | 194 | |
| 78064 
4e865c45458b
clarified transfer / trim_context on persistent Token.source (e.g. attribute expressions): actually set/reset implicit context;
 wenzelm parents: 
78023diff
changeset | 195 | (* implicit context *) | 
| 
4e865c45458b
clarified transfer / trim_context on persistent Token.source (e.g. attribute expressions): actually set/reset implicit context;
 wenzelm parents: 
78023diff
changeset | 196 | |
| 
4e865c45458b
clarified transfer / trim_context on persistent Token.source (e.g. attribute expressions): actually set/reset implicit context;
 wenzelm parents: 
78023diff
changeset | 197 | val trim_context_binding: Attrib.binding -> Attrib.binding = | 
| 
4e865c45458b
clarified transfer / trim_context on persistent Token.source (e.g. attribute expressions): actually set/reset implicit context;
 wenzelm parents: 
78023diff
changeset | 198 | apsnd ((map o map) Token.trim_context); | 
| 38330 | 199 | |
| 78064 
4e865c45458b
clarified transfer / trim_context on persistent Token.source (e.g. attribute expressions): actually set/reset implicit context;
 wenzelm parents: 
78023diff
changeset | 200 | val trim_context_thms: thms -> thms = | 
| 
4e865c45458b
clarified transfer / trim_context on persistent Token.source (e.g. attribute expressions): actually set/reset implicit context;
 wenzelm parents: 
78023diff
changeset | 201 | map (fn (thms, atts) => (map Thm.trim_context thms, (map o map) Token.trim_context atts)); | 
| 
4e865c45458b
clarified transfer / trim_context on persistent Token.source (e.g. attribute expressions): actually set/reset implicit context;
 wenzelm parents: 
78023diff
changeset | 202 | |
| 67652 | 203 | fun trim_context_fact (binding, thms) = (trim_context_binding binding, trim_context_thms thms); | 
| 67624 | 204 | |
| 78064 
4e865c45458b
clarified transfer / trim_context on persistent Token.source (e.g. attribute expressions): actually set/reset implicit context;
 wenzelm parents: 
78023diff
changeset | 205 | |
| 
4e865c45458b
clarified transfer / trim_context on persistent Token.source (e.g. attribute expressions): actually set/reset implicit context;
 wenzelm parents: 
78023diff
changeset | 206 | (* fact expressions *) | 
| 
4e865c45458b
clarified transfer / trim_context on persistent Token.source (e.g. attribute expressions): actually set/reset implicit context;
 wenzelm parents: 
78023diff
changeset | 207 | |
| 47249 
c0481c3c2a6c
added Attrib.global_notes/local_notes/generic_notes convenience;
 wenzelm parents: 
47005diff
changeset | 208 | fun global_notes kind facts thy = thy |> | 
| 79369 
ecfba958ef16
clarified Global_Theory.store_proofs vs. Generic_Target.thm_definition / Attrib.global_notes;
 wenzelm parents: 
79347diff
changeset | 209 | Global_Theory.note_thmss_foundation kind (map_facts (map (attribute_global thy)) facts); | 
| 47249 
c0481c3c2a6c
added Attrib.global_notes/local_notes/generic_notes convenience;
 wenzelm parents: 
47005diff
changeset | 210 | |
| 
c0481c3c2a6c
added Attrib.global_notes/local_notes/generic_notes convenience;
 wenzelm parents: 
47005diff
changeset | 211 | fun local_notes kind facts ctxt = ctxt |> | 
| 47815 | 212 | Proof_Context.note_thmss kind (map_facts (map (attribute ctxt)) facts); | 
| 47249 
c0481c3c2a6c
added Attrib.global_notes/local_notes/generic_notes convenience;
 wenzelm parents: 
47005diff
changeset | 213 | |
| 
c0481c3c2a6c
added Attrib.global_notes/local_notes/generic_notes convenience;
 wenzelm parents: 
47005diff
changeset | 214 | fun generic_notes kind facts context = context |> | 
| 
c0481c3c2a6c
added Attrib.global_notes/local_notes/generic_notes convenience;
 wenzelm parents: 
47005diff
changeset | 215 | Context.mapping_result (global_notes kind facts) (local_notes kind facts); | 
| 
c0481c3c2a6c
added Attrib.global_notes/local_notes/generic_notes convenience;
 wenzelm parents: 
47005diff
changeset | 216 | |
| 67671 
857da80611ab
support for lazy notes in global/local context and Element.Lazy_Notes: name binding and fact without attributes;
 wenzelm parents: 
67652diff
changeset | 217 | fun lazy_notes kind arg = | 
| 
857da80611ab
support for lazy notes in global/local context and Element.Lazy_Notes: name binding and fact without attributes;
 wenzelm parents: 
67652diff
changeset | 218 | Context.mapping (Global_Theory.add_thms_lazy kind arg) (Proof_Context.add_thms_lazy kind arg); | 
| 
857da80611ab
support for lazy notes in global/local context and Element.Lazy_Notes: name binding and fact without attributes;
 wenzelm parents: 
67652diff
changeset | 219 | |
| 38330 | 220 | fun eval_thms ctxt srcs = ctxt | 
| 42360 | 221 | |> Proof_Context.note_thmss "" | 
| 63352 | 222 | (map_facts_refs | 
| 223 | (map (attribute_cmd ctxt)) (Proof_Context.get_fact ctxt) [(Binding.empty_atts, srcs)]) | |
| 38330 | 224 | |> fst |> maps snd; | 
| 225 | ||
| 226 | ||
| 30525 
8a5a0aa30e1c
added setup and attribute_setup -- expect plain parser instead of syntax function;
 wenzelm parents: 
30513diff
changeset | 227 | (* attribute setup *) | 
| 
8a5a0aa30e1c
added setup and attribute_setup -- expect plain parser instead of syntax function;
 wenzelm parents: 
30513diff
changeset | 228 | |
| 57927 | 229 | fun attribute_syntax scan src (context, th) = | 
| 58011 
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
 wenzelm parents: 
57942diff
changeset | 230 | let val (a, context') = Token.syntax_generic scan src context in a (context', th) end; | 
| 57927 | 231 | |
| 232 | fun setup binding scan comment = define_global binding (attribute_syntax scan) comment #> snd; | |
| 233 | fun local_setup binding scan comment = define binding (attribute_syntax scan) comment #> snd; | |
| 5879 | 234 | |
| 69216 
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
 wenzelm parents: 
69187diff
changeset | 235 | fun attribute_setup binding source comment = | 
| 
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
 wenzelm parents: 
69187diff
changeset | 236 | ML_Context.expression (Input.pos_of source) | 
| 
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
 wenzelm parents: 
69187diff
changeset | 237 | (ML_Lex.read | 
| 
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
 wenzelm parents: 
69187diff
changeset | 238 |       ("Theory.local_setup (Attrib.local_setup (" ^ ML_Syntax.make_binding binding ^ ") (") @
 | 
| 
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
 wenzelm parents: 
69187diff
changeset | 239 |      ML_Lex.read_source source @ ML_Lex.read (") " ^ ML_Syntax.print_string comment ^ ")"))
 | 
| 57941 
57200bdc2aa7
localized command 'method_setup' and 'attribute_setup';
 wenzelm parents: 
57938diff
changeset | 240 | |> Context.proof_map; | 
| 30525 
8a5a0aa30e1c
added setup and attribute_setup -- expect plain parser instead of syntax function;
 wenzelm parents: 
30513diff
changeset | 241 | |
| 
8a5a0aa30e1c
added setup and attribute_setup -- expect plain parser instead of syntax function;
 wenzelm parents: 
30513diff
changeset | 242 | |
| 55140 
7eb0c04e4c40
define basic attributes in user-space Pure.thy -- which provides better hyperlinks and may serve as example;
 wenzelm parents: 
53171diff
changeset | 243 | (* internal attribute *) | 
| 
7eb0c04e4c40
define basic attributes in user-space Pure.thy -- which provides better hyperlinks and may serve as example;
 wenzelm parents: 
53171diff
changeset | 244 | |
| 78091 | 245 | fun make_name ctxt name = | 
| 78070 
dbc67f6c501c
proper Token.Declaration for internal_declaration;
 wenzelm parents: 
78064diff
changeset | 246 | Token.make_src (name, Position.none) [] |> check_src ctxt |> hd; | 
| 
dbc67f6c501c
proper Token.Declaration for internal_declaration;
 wenzelm parents: 
78064diff
changeset | 247 | |
| 
dbc67f6c501c
proper Token.Declaration for internal_declaration;
 wenzelm parents: 
78064diff
changeset | 248 | local | 
| 
dbc67f6c501c
proper Token.Declaration for internal_declaration;
 wenzelm parents: 
78064diff
changeset | 249 | |
| 78091 | 250 | val internal_binding = Binding.make ("attribute", \<^here>);
 | 
| 251 | ||
| 55140 
7eb0c04e4c40
define basic attributes in user-space Pure.thy -- which provides better hyperlinks and may serve as example;
 wenzelm parents: 
53171diff
changeset | 252 | val _ = Theory.setup | 
| 78091 | 253 | (setup internal_binding | 
| 78070 
dbc67f6c501c
proper Token.Declaration for internal_declaration;
 wenzelm parents: 
78064diff
changeset | 254 | (Scan.lift Args.internal_attribute >> Morphism.form || | 
| 
dbc67f6c501c
proper Token.Declaration for internal_declaration;
 wenzelm parents: 
78064diff
changeset | 255 | Scan.lift Args.internal_declaration >> (Thm.declaration_attribute o K o Morphism.form)) | 
| 55140 
7eb0c04e4c40
define basic attributes in user-space Pure.thy -- which provides better hyperlinks and may serve as example;
 wenzelm parents: 
53171diff
changeset | 256 | "internal attribute"); | 
| 
7eb0c04e4c40
define basic attributes in user-space Pure.thy -- which provides better hyperlinks and may serve as example;
 wenzelm parents: 
53171diff
changeset | 257 | |
| 78091 | 258 | val internal_name = make_name (Context.the_local_context ()) (Binding.name_of internal_binding); | 
| 78095 | 259 | fun internal_source name value = [internal_name, Token.assign (SOME value) (Token.make_string name)]; | 
| 78070 
dbc67f6c501c
proper Token.Declaration for internal_declaration;
 wenzelm parents: 
78064diff
changeset | 260 | |
| 
dbc67f6c501c
proper Token.Declaration for internal_declaration;
 wenzelm parents: 
78064diff
changeset | 261 | in | 
| 
dbc67f6c501c
proper Token.Declaration for internal_declaration;
 wenzelm parents: 
78064diff
changeset | 262 | |
| 78095 | 263 | fun internal pos arg = | 
| 78098 
2cd7e5518d0d
clarified output of embedded values, e.g. for 'print_locale';
 wenzelm parents: 
78095diff
changeset | 264 |   internal_source ("internal", pos) (Token.Attribute (Morphism.entity arg));
 | 
| 78095 | 265 | |
| 266 | fun internal_declaration pos arg = | |
| 78098 
2cd7e5518d0d
clarified output of embedded values, e.g. for 'print_locale';
 wenzelm parents: 
78095diff
changeset | 267 |   [([Drule.dummy_thm], [internal_source ("declaration", pos) (Token.Declaration arg)])];
 | 
| 78070 
dbc67f6c501c
proper Token.Declaration for internal_declaration;
 wenzelm parents: 
78064diff
changeset | 268 | |
| 
dbc67f6c501c
proper Token.Declaration for internal_declaration;
 wenzelm parents: 
78064diff
changeset | 269 | end; | 
| 63266 | 270 | |
| 55140 
7eb0c04e4c40
define basic attributes in user-space Pure.thy -- which provides better hyperlinks and may serve as example;
 wenzelm parents: 
53171diff
changeset | 271 | |
| 31305 | 272 | (* add/del syntax *) | 
| 5823 | 273 | |
| 31305 | 274 | fun add_del add del = Scan.lift (Args.add >> K add || Args.del >> K del || Scan.succeed add); | 
| 5879 | 275 | |
| 276 | ||
| 25983 | 277 | |
| 278 | (** parsing attributed theorems **) | |
| 5879 | 279 | |
| 18636 | 280 | local | 
| 281 | ||
| 69349 
7cef9e386ffe
more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
 wenzelm parents: 
69216diff
changeset | 282 | val fact_name = | 
| 
7cef9e386ffe
more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
 wenzelm parents: 
69216diff
changeset | 283 |   Parse.position Args.internal_fact >> (fn (_, pos) => ("<fact>", pos)) || Args.name_position;
 | 
| 21698 
43a842769765
thms etc.: proper treatment of internal_fact with selection;
 wenzelm parents: 
21658diff
changeset | 284 | |
| 26336 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 wenzelm parents: 
25983diff
changeset | 285 | fun gen_thm pick = Scan.depend (fn context => | 
| 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 wenzelm parents: 
25983diff
changeset | 286 | let | 
| 56140 
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
 wenzelm parents: 
56052diff
changeset | 287 | val get = Proof_Context.get_fact_generic context; | 
| 26361 | 288 | val get_fact = get o Facts.Fact; | 
| 57942 
e5bec882fdd0
more informative Token.Fact: retain name of dynamic fact (without selection);
 wenzelm parents: 
57941diff
changeset | 289 | fun get_named is_sel pos name = | 
| 
e5bec882fdd0
more informative Token.Fact: retain name of dynamic fact (without selection);
 wenzelm parents: 
57941diff
changeset | 290 | let val (a, ths) = get (Facts.Named ((name, pos), NONE)) | 
| 
e5bec882fdd0
more informative Token.Fact: retain name of dynamic fact (without selection);
 wenzelm parents: 
57941diff
changeset | 291 | in (if is_sel then NONE else a, ths) end; | 
| 26336 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 wenzelm parents: 
25983diff
changeset | 292 | in | 
| 61814 
1ca1142e1711
clarified type Token.src: plain token list, with usual implicit value assignment;
 wenzelm parents: 
61527diff
changeset | 293 | Parse.$$$ "[" |-- Scan.pass context attribs --| Parse.$$$ "]" >> (fn srcs => | 
| 24008 | 294 | let | 
| 47815 | 295 | val atts = map (attribute_generic context) srcs; | 
| 46775 
6287653e63ec
canonical argument order for attribute application;
 wenzelm parents: 
46512diff
changeset | 296 | val (th', context') = fold (uncurry o Thm.apply_attribute) atts (Drule.dummy_thm, context); | 
| 55740 | 297 |       in (context', pick ("", Position.none) [th']) end)
 | 
| 26336 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 wenzelm parents: 
25983diff
changeset | 298 | || | 
| 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 wenzelm parents: 
25983diff
changeset | 299 | (Scan.ahead Args.alt_name -- Args.named_fact get_fact | 
| 27820 | 300 |       >> (fn (s, fact) => ("", Facts.Fact s, fact)) ||
 | 
| 69349 
7cef9e386ffe
more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
 wenzelm parents: 
69216diff
changeset | 301 | Scan.ahead (fact_name -- Scan.option Parse.thm_sel) :|-- | 
| 58028 
e4250d370657
tuned signature -- define some elementary operations earlier;
 wenzelm parents: 
58025diff
changeset | 302 | (fn ((name, pos), sel) => | 
| 
e4250d370657
tuned signature -- define some elementary operations earlier;
 wenzelm parents: 
58025diff
changeset | 303 | Args.named_fact (get_named (is_some sel) pos) --| Scan.option Parse.thm_sel | 
| 
e4250d370657
tuned signature -- define some elementary operations earlier;
 wenzelm parents: 
58025diff
changeset | 304 | >> (fn fact => (name, Facts.Named ((name, pos), sel), fact)))) | 
| 61814 
1ca1142e1711
clarified type Token.src: plain token list, with usual implicit value assignment;
 wenzelm parents: 
61527diff
changeset | 305 | -- Scan.pass context opt_attribs >> (fn ((name, thmref, fact), srcs) => | 
| 26336 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 wenzelm parents: 
25983diff
changeset | 306 | let | 
| 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 wenzelm parents: 
25983diff
changeset | 307 | val ths = Facts.select thmref fact; | 
| 47815 | 308 | val atts = map (attribute_generic context) srcs; | 
| 46775 
6287653e63ec
canonical argument order for attribute application;
 wenzelm parents: 
46512diff
changeset | 309 | val (ths', context') = | 
| 
6287653e63ec
canonical argument order for attribute application;
 wenzelm parents: 
46512diff
changeset | 310 | fold_map (curry (fold (uncurry o Thm.apply_attribute) atts)) ths context; | 
| 70545 | 311 | in (context', pick (name, Facts.ref_pos thmref) ths') end) | 
| 26336 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 wenzelm parents: 
25983diff
changeset | 312 | end); | 
| 15456 
956d6acacf89
Specific theorems in a named list of theorems can now be referred to
 berghofe parents: 
15117diff
changeset | 313 | |
| 18636 | 314 | in | 
| 315 | ||
| 26336 
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
 wenzelm parents: 
25983diff
changeset | 316 | val thm = gen_thm Facts.the_single; | 
| 18998 | 317 | val multi_thm = gen_thm (K I); | 
| 61476 | 318 | val thms = Scan.repeats multi_thm; | 
| 18636 | 319 | |
| 320 | end; | |
| 321 | ||
| 5823 | 322 | |
| 58028 
e4250d370657
tuned signature -- define some elementary operations earlier;
 wenzelm parents: 
58025diff
changeset | 323 | (* transform fact expressions *) | 
| 
e4250d370657
tuned signature -- define some elementary operations earlier;
 wenzelm parents: 
58025diff
changeset | 324 | |
| 
e4250d370657
tuned signature -- define some elementary operations earlier;
 wenzelm parents: 
58025diff
changeset | 325 | fun transform_facts phi = map (fn ((a, atts), bs) => | 
| 61814 
1ca1142e1711
clarified type Token.src: plain token list, with usual implicit value assignment;
 wenzelm parents: 
61527diff
changeset | 326 | ((Morphism.binding phi a, (map o map) (Token.transform phi) atts), | 
| 
1ca1142e1711
clarified type Token.src: plain token list, with usual implicit value assignment;
 wenzelm parents: 
61527diff
changeset | 327 | bs |> map (fn (ths, btts) => (Morphism.fact phi ths, (map o map) (Token.transform phi) btts)))); | 
| 58028 
e4250d370657
tuned signature -- define some elementary operations earlier;
 wenzelm parents: 
58025diff
changeset | 328 | |
| 
e4250d370657
tuned signature -- define some elementary operations earlier;
 wenzelm parents: 
58025diff
changeset | 329 | |
| 5879 | 330 | |
| 45586 
c94f149cdf5d
refined partial evaluation of attributes: avoid duplication of facts for plain declarations;
 wenzelm parents: 
45584diff
changeset | 331 | (** partial evaluation -- observing rule/declaration/mixed attributes **) | 
| 45493 
12453fd8dcff
some support for partial evaluation of attributed facts;
 wenzelm parents: 
45491diff
changeset | 332 | |
| 56140 
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
 wenzelm parents: 
56052diff
changeset | 333 | (*NB: result length may change due to rearrangement of symbolic expression*) | 
| 
ed92ce2ac88e
just one cumulative Proof_Context.facts, with uniform retrieval (including PIDE markup, completion etc.);
 wenzelm parents: 
56052diff
changeset | 334 | |
| 45493 
12453fd8dcff
some support for partial evaluation of attributed facts;
 wenzelm parents: 
45491diff
changeset | 335 | local | 
| 45526 | 336 | |
| 45493 
12453fd8dcff
some support for partial evaluation of attributed facts;
 wenzelm parents: 
45491diff
changeset | 337 | fun apply_att src (context, th) = | 
| 45526 | 338 | let | 
| 61814 
1ca1142e1711
clarified type Token.src: plain token list, with usual implicit value assignment;
 wenzelm parents: 
61527diff
changeset | 339 | val src1 = map Token.init_assignable src; | 
| 47815 | 340 | val result = attribute_generic context src1 (context, th); | 
| 61814 
1ca1142e1711
clarified type Token.src: plain token list, with usual implicit value assignment;
 wenzelm parents: 
61527diff
changeset | 341 | val src2 = map Token.closure src1; | 
| 45526 | 342 | in (src2, result) end; | 
| 45493 
12453fd8dcff
some support for partial evaluation of attributed facts;
 wenzelm parents: 
45491diff
changeset | 343 | |
| 45527 
d2b3d16b673a
retain mixed attributes as dynamic theorem expression, but disallow subsequent static rules;
 wenzelm parents: 
45526diff
changeset | 344 | fun err msg src = | 
| 58011 
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
 wenzelm parents: 
57942diff
changeset | 345 | let val (name, pos) = Token.name_of_src src | 
| 48992 | 346 | in error (msg ^ " " ^ quote name ^ Position.here pos) end; | 
| 45527 
d2b3d16b673a
retain mixed attributes as dynamic theorem expression, but disallow subsequent static rules;
 wenzelm parents: 
45526diff
changeset | 347 | |
| 
d2b3d16b673a
retain mixed attributes as dynamic theorem expression, but disallow subsequent static rules;
 wenzelm parents: 
45526diff
changeset | 348 | fun eval src ((th, dyn), (decls, context)) = | 
| 
d2b3d16b673a
retain mixed attributes as dynamic theorem expression, but disallow subsequent static rules;
 wenzelm parents: 
45526diff
changeset | 349 | (case (apply_att src (context, th), dyn) of | 
| 
d2b3d16b673a
retain mixed attributes as dynamic theorem expression, but disallow subsequent static rules;
 wenzelm parents: 
45526diff
changeset | 350 | ((_, (NONE, SOME th')), NONE) => ((th', NONE), (decls, context)) | 
| 
d2b3d16b673a
retain mixed attributes as dynamic theorem expression, but disallow subsequent static rules;
 wenzelm parents: 
45526diff
changeset | 351 | | ((_, (NONE, SOME _)), SOME _) => err "Mixed dynamic attribute followed by static rule" src | 
| 
d2b3d16b673a
retain mixed attributes as dynamic theorem expression, but disallow subsequent static rules;
 wenzelm parents: 
45526diff
changeset | 352 | | ((src', (SOME context', NONE)), NONE) => | 
| 45493 
12453fd8dcff
some support for partial evaluation of attributed facts;
 wenzelm parents: 
45491diff
changeset | 353 | let | 
| 
12453fd8dcff
some support for partial evaluation of attributed facts;
 wenzelm parents: 
45491diff
changeset | 354 | val decls' = | 
| 
12453fd8dcff
some support for partial evaluation of attributed facts;
 wenzelm parents: 
45491diff
changeset | 355 | (case decls of | 
| 45526 | 356 | [] => [(th, [src'])] | 
| 45493 
12453fd8dcff
some support for partial evaluation of attributed facts;
 wenzelm parents: 
45491diff
changeset | 357 | | (th2, srcs2) :: rest => | 
| 52683 
fb028440473e
more official Thm.eq_thm_strict, without demanding ML equality type;
 wenzelm parents: 
52487diff
changeset | 358 | if Thm.eq_thm_strict (th, th2) | 
| 45526 | 359 | then ((th2, src' :: srcs2) :: rest) | 
| 360 | else (th, [src']) :: (th2, srcs2) :: rest); | |
| 45527 
d2b3d16b673a
retain mixed attributes as dynamic theorem expression, but disallow subsequent static rules;
 wenzelm parents: 
45526diff
changeset | 361 | in ((th, NONE), (decls', context')) end | 
| 
d2b3d16b673a
retain mixed attributes as dynamic theorem expression, but disallow subsequent static rules;
 wenzelm parents: 
45526diff
changeset | 362 | | ((src', (opt_context', opt_th')), _) => | 
| 
d2b3d16b673a
retain mixed attributes as dynamic theorem expression, but disallow subsequent static rules;
 wenzelm parents: 
45526diff
changeset | 363 | let | 
| 
d2b3d16b673a
retain mixed attributes as dynamic theorem expression, but disallow subsequent static rules;
 wenzelm parents: 
45526diff
changeset | 364 | val context' = the_default context opt_context'; | 
| 
d2b3d16b673a
retain mixed attributes as dynamic theorem expression, but disallow subsequent static rules;
 wenzelm parents: 
45526diff
changeset | 365 | val th' = the_default th opt_th'; | 
| 
d2b3d16b673a
retain mixed attributes as dynamic theorem expression, but disallow subsequent static rules;
 wenzelm parents: 
45526diff
changeset | 366 | val dyn' = | 
| 
d2b3d16b673a
retain mixed attributes as dynamic theorem expression, but disallow subsequent static rules;
 wenzelm parents: 
45526diff
changeset | 367 | (case dyn of | 
| 
d2b3d16b673a
retain mixed attributes as dynamic theorem expression, but disallow subsequent static rules;
 wenzelm parents: 
45526diff
changeset | 368 | NONE => SOME (th, [src']) | 
| 
d2b3d16b673a
retain mixed attributes as dynamic theorem expression, but disallow subsequent static rules;
 wenzelm parents: 
45526diff
changeset | 369 | | SOME (dyn_th, srcs) => SOME (dyn_th, src' :: srcs)); | 
| 
d2b3d16b673a
retain mixed attributes as dynamic theorem expression, but disallow subsequent static rules;
 wenzelm parents: 
45526diff
changeset | 370 | in ((th', dyn'), (decls, context')) end); | 
| 45493 
12453fd8dcff
some support for partial evaluation of attributed facts;
 wenzelm parents: 
45491diff
changeset | 371 | |
| 
12453fd8dcff
some support for partial evaluation of attributed facts;
 wenzelm parents: 
45491diff
changeset | 372 | in | 
| 
12453fd8dcff
some support for partial evaluation of attributed facts;
 wenzelm parents: 
45491diff
changeset | 373 | |
| 
12453fd8dcff
some support for partial evaluation of attributed facts;
 wenzelm parents: 
45491diff
changeset | 374 | fun partial_evaluation ctxt facts = | 
| 57858 
39d9c7f175e0
refined context visibility again (amending f5f9fad3321c, 8e3e004f1c31): avoid spurious warning due to global config options;
 wenzelm parents: 
56438diff
changeset | 375 | (facts, Context.Proof (Context_Position.not_really ctxt)) |-> | 
| 45586 
c94f149cdf5d
refined partial evaluation of attributes: avoid duplication of facts for plain declarations;
 wenzelm parents: 
45584diff
changeset | 376 | fold_map (fn ((b, more_atts), fact) => fn context => | 
| 
c94f149cdf5d
refined partial evaluation of attributes: avoid duplication of facts for plain declarations;
 wenzelm parents: 
45584diff
changeset | 377 | let | 
| 
c94f149cdf5d
refined partial evaluation of attributes: avoid duplication of facts for plain declarations;
 wenzelm parents: 
45584diff
changeset | 378 | val (fact', (decls, context')) = | 
| 
c94f149cdf5d
refined partial evaluation of attributes: avoid duplication of facts for plain declarations;
 wenzelm parents: 
45584diff
changeset | 379 | (fact, ([], context)) |-> fold_map (fn (ths, atts) => fn res1 => | 
| 
c94f149cdf5d
refined partial evaluation of attributes: avoid duplication of facts for plain declarations;
 wenzelm parents: 
45584diff
changeset | 380 | (ths, res1) |-> fold_map (fn th => fn res2 => | 
| 
c94f149cdf5d
refined partial evaluation of attributes: avoid duplication of facts for plain declarations;
 wenzelm parents: 
45584diff
changeset | 381 | let | 
| 
c94f149cdf5d
refined partial evaluation of attributes: avoid duplication of facts for plain declarations;
 wenzelm parents: 
45584diff
changeset | 382 | val ((th', dyn'), res3) = fold eval (atts @ more_atts) ((th, NONE), res2); | 
| 
c94f149cdf5d
refined partial evaluation of attributes: avoid duplication of facts for plain declarations;
 wenzelm parents: 
45584diff
changeset | 383 | val th_atts' = | 
| 
c94f149cdf5d
refined partial evaluation of attributes: avoid duplication of facts for plain declarations;
 wenzelm parents: 
45584diff
changeset | 384 | (case dyn' of | 
| 
c94f149cdf5d
refined partial evaluation of attributes: avoid duplication of facts for plain declarations;
 wenzelm parents: 
45584diff
changeset | 385 | NONE => (th', []) | 
| 
c94f149cdf5d
refined partial evaluation of attributes: avoid duplication of facts for plain declarations;
 wenzelm parents: 
45584diff
changeset | 386 | | SOME (dyn_th', atts') => (dyn_th', rev atts')); | 
| 
c94f149cdf5d
refined partial evaluation of attributes: avoid duplication of facts for plain declarations;
 wenzelm parents: 
45584diff
changeset | 387 | in (th_atts', res3) end)) | 
| 
c94f149cdf5d
refined partial evaluation of attributes: avoid duplication of facts for plain declarations;
 wenzelm parents: 
45584diff
changeset | 388 | |>> flat; | 
| 
c94f149cdf5d
refined partial evaluation of attributes: avoid duplication of facts for plain declarations;
 wenzelm parents: 
45584diff
changeset | 389 | val decls' = rev (map (apsnd rev) decls); | 
| 
c94f149cdf5d
refined partial evaluation of attributes: avoid duplication of facts for plain declarations;
 wenzelm parents: 
45584diff
changeset | 390 | val facts' = | 
| 52683 
fb028440473e
more official Thm.eq_thm_strict, without demanding ML equality type;
 wenzelm parents: 
52487diff
changeset | 391 | if eq_list (eq_fst Thm.eq_thm_strict) (decls', fact') then | 
| 45586 
c94f149cdf5d
refined partial evaluation of attributes: avoid duplication of facts for plain declarations;
 wenzelm parents: 
45584diff
changeset | 392 | [((b, []), map2 (fn (th, atts1) => fn (_, atts2) => (th, atts1 @ atts2)) decls' fact')] | 
| 45619 | 393 | else if null decls' then [((b, []), fact')] | 
| 63352 | 394 | else [(Binding.empty_atts, decls'), ((b, []), fact')]; | 
| 45586 
c94f149cdf5d
refined partial evaluation of attributes: avoid duplication of facts for plain declarations;
 wenzelm parents: 
45584diff
changeset | 395 | in (facts', context') end) | 
| 46906 
3c1787d46935
suppress vacous notes elements, with subtle change of semantics: 'interpret' no longer pulls-in unnamed facts "by fact";
 wenzelm parents: 
46903diff
changeset | 396 | |> fst |> flat |> map (apsnd (map (apfst single))) | 
| 63352 | 397 | |> filter_out (fn (b, fact) => Binding.is_empty_atts b andalso forall (null o #2) fact); | 
| 45493 
12453fd8dcff
some support for partial evaluation of attributed facts;
 wenzelm parents: 
45491diff
changeset | 398 | |
| 
12453fd8dcff
some support for partial evaluation of attributed facts;
 wenzelm parents: 
45491diff
changeset | 399 | end; | 
| 
12453fd8dcff
some support for partial evaluation of attributed facts;
 wenzelm parents: 
45491diff
changeset | 400 | |
| 
12453fd8dcff
some support for partial evaluation of attributed facts;
 wenzelm parents: 
45491diff
changeset | 401 | |
| 
12453fd8dcff
some support for partial evaluation of attributed facts;
 wenzelm parents: 
45491diff
changeset | 402 | |
| 24110 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24030diff
changeset | 403 | (** configuration options **) | 
| 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24030diff
changeset | 404 | |
| 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24030diff
changeset | 405 | (* naming *) | 
| 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24030diff
changeset | 406 | |
| 33522 | 407 | structure Configs = Theory_Data | 
| 24713 | 408 | ( | 
| 69575 | 409 | type T = Config.value Config.T Symtab.table; | 
| 24110 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24030diff
changeset | 410 | val empty = Symtab.empty; | 
| 33522 | 411 | fun merge data = Symtab.merge (K true) data; | 
| 24713 | 412 | ); | 
| 5823 | 413 | |
| 59917 
9830c944670f
more uniform "verbose" option to print name space;
 wenzelm parents: 
59064diff
changeset | 414 | fun print_options verbose ctxt = | 
| 24110 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24030diff
changeset | 415 | let | 
| 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24030diff
changeset | 416 | fun prt (name, config) = | 
| 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24030diff
changeset | 417 | let val value = Config.get ctxt config in | 
| 50301 | 418 |         Pretty.block [Pretty.mark_str name, Pretty.str (": " ^ Config.print_type value ^ " ="),
 | 
| 419 | Pretty.brk 1, Pretty.str (Config.print_value value)] | |
| 24110 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24030diff
changeset | 420 | end; | 
| 74261 
d28a51dd9da6
export other entities, e.g. relevant for formal document output;
 wenzelm parents: 
74156diff
changeset | 421 | val space = attribute_space (Context.Proof ctxt); | 
| 56052 | 422 | val configs = | 
| 59917 
9830c944670f
more uniform "verbose" option to print name space;
 wenzelm parents: 
59064diff
changeset | 423 | Name_Space.markup_entries verbose ctxt space | 
| 56052 | 424 | (Symtab.dest (Configs.get (Proof_Context.theory_of ctxt))); | 
| 24110 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24030diff
changeset | 425 | in Pretty.writeln (Pretty.big_list "configuration options" (map prt configs)) end; | 
| 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24030diff
changeset | 426 | |
| 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24030diff
changeset | 427 | |
| 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24030diff
changeset | 428 | (* concrete syntax *) | 
| 23988 
aa46577f4f44
added attribute "option" for setting configuration options;
 wenzelm parents: 
23937diff
changeset | 429 | |
| 24003 
da76d7e6435c
attribute "option": more elaborate syntax (with value parsing);
 wenzelm parents: 
23988diff
changeset | 430 | local | 
| 
da76d7e6435c
attribute "option": more elaborate syntax (with value parsing);
 wenzelm parents: 
23988diff
changeset | 431 | |
| 36950 | 432 | val equals = Parse.$$$ "="; | 
| 24003 
da76d7e6435c
attribute "option": more elaborate syntax (with value parsing);
 wenzelm parents: 
23988diff
changeset | 433 | |
| 24110 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24030diff
changeset | 434 | fun scan_value (Config.Bool _) = | 
| 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24030diff
changeset | 435 | equals -- Args.$$$ "false" >> K (Config.Bool false) || | 
| 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24030diff
changeset | 436 | equals -- Args.$$$ "true" >> K (Config.Bool true) || | 
| 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24030diff
changeset | 437 | Scan.succeed (Config.Bool true) | 
| 36950 | 438 | | scan_value (Config.Int _) = equals |-- Parse.int >> Config.Int | 
| 40291 | 439 | | scan_value (Config.Real _) = equals |-- Parse.real >> Config.Real | 
| 24110 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24030diff
changeset | 440 | | scan_value (Config.String _) = equals |-- Args.name >> Config.String; | 
| 24003 
da76d7e6435c
attribute "option": more elaborate syntax (with value parsing);
 wenzelm parents: 
23988diff
changeset | 441 | |
| 24110 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24030diff
changeset | 442 | fun scan_config thy config = | 
| 36787 
f60e4dd6d76f
renamed Config.get_thy to Config.get_global etc. to indicate that this is not the real thing;
 wenzelm parents: 
36002diff
changeset | 443 | let val config_type = Config.get_global thy config | 
| 24110 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24030diff
changeset | 444 | in scan_value config_type >> (K o Thm.declaration_attribute o K o Config.put_generic config) end; | 
| 24003 
da76d7e6435c
attribute "option": more elaborate syntax (with value parsing);
 wenzelm parents: 
23988diff
changeset | 445 | |
| 42616 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42380diff
changeset | 446 | fun register binding config thy = | 
| 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42380diff
changeset | 447 | let val name = Sign.full_name thy binding in | 
| 24126 
913e1fa904fb
turned simp_depth_limit into configuration option;
 wenzelm parents: 
24110diff
changeset | 448 | thy | 
| 78072 | 449 | |> setup binding (Scan.lift (scan_config thy config) >> Morphism.form_entity) | 
| 450 | "configuration option" | |
| 24126 
913e1fa904fb
turned simp_depth_limit into configuration option;
 wenzelm parents: 
24110diff
changeset | 451 | |> Configs.map (Symtab.update (name, config)) | 
| 
913e1fa904fb
turned simp_depth_limit into configuration option;
 wenzelm parents: 
24110diff
changeset | 452 | end; | 
| 24110 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24030diff
changeset | 453 | |
| 42808 
30870aee8a3f
discontinued global config options within attribute name space;
 wenzelm parents: 
42669diff
changeset | 454 | fun declare make coerce binding default = | 
| 24110 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24030diff
changeset | 455 | let | 
| 42616 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42380diff
changeset | 456 | val name = Binding.name_of binding; | 
| 56438 | 457 | val pos = Binding.pos_of binding; | 
| 458 | val config_value = Config.declare (name, pos) (make o default); | |
| 24110 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24030diff
changeset | 459 | val config = coerce config_value; | 
| 42616 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42380diff
changeset | 460 | in (config, register binding config_value) end; | 
| 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42380diff
changeset | 461 | |
| 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42380diff
changeset | 462 | in | 
| 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42380diff
changeset | 463 | |
| 56438 | 464 | fun register_config config = | 
| 465 | register (Binding.make (Config.name_of config, Config.pos_of config)) config; | |
| 52040 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 466 | |
| 69575 | 467 | val register_config_bool = register_config o Config.bool_value; | 
| 468 | val register_config_int = register_config o Config.int_value; | |
| 469 | val register_config_real = register_config o Config.real_value; | |
| 470 | val register_config_string = register_config o Config.string_value; | |
| 471 | ||
| 42808 
30870aee8a3f
discontinued global config options within attribute name space;
 wenzelm parents: 
42669diff
changeset | 472 | val config_bool = declare Config.Bool Config.bool; | 
| 
30870aee8a3f
discontinued global config options within attribute name space;
 wenzelm parents: 
42669diff
changeset | 473 | val config_int = declare Config.Int Config.int; | 
| 
30870aee8a3f
discontinued global config options within attribute name space;
 wenzelm parents: 
42669diff
changeset | 474 | val config_real = declare Config.Real Config.real; | 
| 
30870aee8a3f
discontinued global config options within attribute name space;
 wenzelm parents: 
42669diff
changeset | 475 | val config_string = declare Config.String Config.string; | 
| 42616 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42380diff
changeset | 476 | |
| 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42380diff
changeset | 477 | end; | 
| 24110 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24030diff
changeset | 478 | |
| 42616 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42380diff
changeset | 479 | |
| 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42380diff
changeset | 480 | (* implicit setup *) | 
| 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42380diff
changeset | 481 | |
| 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42380diff
changeset | 482 | local | 
| 24110 
4ab3084e311c
tuned config options: eliminated separate attribute "option";
 wenzelm parents: 
24030diff
changeset | 483 | |
| 42616 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42380diff
changeset | 484 | fun setup_config declare_config binding default = | 
| 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42380diff
changeset | 485 | let | 
| 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42380diff
changeset | 486 | val (config, setup) = declare_config binding default; | 
| 53171 | 487 | val _ = Theory.setup setup; | 
| 42616 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42380diff
changeset | 488 | in config end; | 
| 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42380diff
changeset | 489 | |
| 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42380diff
changeset | 490 | in | 
| 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42380diff
changeset | 491 | |
| 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42380diff
changeset | 492 | val setup_config_bool = setup_config config_bool; | 
| 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42380diff
changeset | 493 | val setup_config_int = setup_config config_int; | 
| 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42380diff
changeset | 494 | val setup_config_string = setup_config config_string; | 
| 
92715b528e78
added Attrib.setup_config_XXX conveniences, with implicit setup of the background theory;
 wenzelm parents: 
42380diff
changeset | 495 | val setup_config_real = setup_config config_real; | 
| 24003 
da76d7e6435c
attribute "option": more elaborate syntax (with value parsing);
 wenzelm parents: 
23988diff
changeset | 496 | |
| 
da76d7e6435c
attribute "option": more elaborate syntax (with value parsing);
 wenzelm parents: 
23988diff
changeset | 497 | end; | 
| 23988 
aa46577f4f44
added attribute "option" for setting configuration options;
 wenzelm parents: 
23937diff
changeset | 498 | |
| 
aa46577f4f44
added attribute "option" for setting configuration options;
 wenzelm parents: 
23937diff
changeset | 499 | |
| 52040 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 500 | (* system options *) | 
| 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 501 | |
| 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 502 | local | 
| 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 503 | |
| 56438 | 504 | fun declare_option coerce (name, pos) = | 
| 52040 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 505 | let | 
| 56438 | 506 | val config = Config.declare_option (name, pos); | 
| 52040 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 507 | in (coerce config, register_config config) end; | 
| 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 508 | |
| 56438 | 509 | fun setup_option coerce (name, pos) = | 
| 52040 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 510 | let | 
| 56438 | 511 | val config = Config.declare_option (name, pos); | 
| 53171 | 512 | val _ = Theory.setup (register_config config); | 
| 52040 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 513 | in coerce config end; | 
| 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 514 | |
| 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 515 | in | 
| 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 516 | |
| 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 517 | val option_bool = declare_option Config.bool; | 
| 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 518 | val option_int = declare_option Config.int; | 
| 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 519 | val option_real = declare_option Config.real; | 
| 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 520 | val option_string = declare_option Config.string; | 
| 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 521 | |
| 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 522 | val setup_option_bool = setup_option Config.bool; | 
| 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 523 | val setup_option_int = setup_option Config.int; | 
| 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 524 | val setup_option_real = setup_option Config.real; | 
| 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 525 | val setup_option_string = setup_option Config.string; | 
| 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 526 | |
| 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 527 | end; | 
| 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 528 | |
| 
852939d19216
system options as context-sensitive configuration options within the attribute name space;
 wenzelm parents: 
52039diff
changeset | 529 | |
| 18636 | 530 | (* theory setup *) | 
| 5823 | 531 | |
| 53171 | 532 | val _ = Theory.setup | 
| 67147 | 533 | (setup \<^binding>\<open>tagged\<close> (Scan.lift (Args.name -- Args.name) >> Thm.tag) "tagged theorem" #> | 
| 534 | setup \<^binding>\<open>untagged\<close> (Scan.lift Args.name >> Thm.untag) "untagged theorem" #> | |
| 535 | setup \<^binding>\<open>kind\<close> (Scan.lift Args.name >> Thm.kind) "theorem kind" #> | |
| 536 | setup \<^binding>\<open>THEN\<close> | |
| 62898 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 537 | (Scan.lift (Scan.optional (Args.bracks Parse.nat) 1) -- thm | 
| 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 538 | >> (fn (i, B) => Thm.rule_attribute [B] (fn _ => fn A => A RSN (i, B)))) | 
| 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 539 | "resolution with rule" #> | 
| 67147 | 540 | setup \<^binding>\<open>OF\<close> | 
| 62898 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 541 | (thms >> (fn Bs => Thm.rule_attribute Bs (fn _ => fn A => A OF Bs))) | 
| 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 542 | "rule resolved with facts" #> | 
| 67147 | 543 | setup \<^binding>\<open>rename_abs\<close> | 
| 62898 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 544 | (Scan.lift (Scan.repeat (Args.maybe Args.name)) >> (fn vs => | 
| 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 545 | Thm.rule_attribute [] (K (Drule.rename_bvars' vs)))) | 
| 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 546 | "rename bound variables in abstractions" #> | 
| 67147 | 547 | setup \<^binding>\<open>unfolded\<close> | 
| 62898 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 548 | (thms >> (fn ths => | 
| 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 549 | Thm.rule_attribute ths (fn context => Local_Defs.unfold (Context.proof_of context) ths))) | 
| 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 550 | "unfolded definitions" #> | 
| 67147 | 551 | setup \<^binding>\<open>folded\<close> | 
| 62898 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 552 | (thms >> (fn ths => | 
| 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 553 | Thm.rule_attribute ths (fn context => Local_Defs.fold (Context.proof_of context) ths))) | 
| 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 554 | "folded definitions" #> | 
| 67147 | 555 | setup \<^binding>\<open>consumes\<close> | 
| 62898 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 556 | (Scan.lift (Scan.optional Parse.int 1) >> Rule_Cases.consumes) | 
| 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 557 | "number of consumed facts" #> | 
| 67147 | 558 | setup \<^binding>\<open>constraints\<close> | 
| 62898 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 559 | (Scan.lift Parse.nat >> Rule_Cases.constraints) | 
| 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 560 | "number of equality constraints" #> | 
| 67147 | 561 | setup \<^binding>\<open>cases_open\<close> | 
| 63019 | 562 | (Scan.succeed Rule_Cases.cases_open) | 
| 563 | "rule with open parameters" #> | |
| 67147 | 564 | setup \<^binding>\<open>case_names\<close> | 
| 63019 | 565 | (Scan.lift (Scan.repeat (Args.name -- | 
| 62898 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 566 | Scan.optional (Parse.$$$ "[" |-- Scan.repeat1 (Args.maybe Args.name) --| Parse.$$$ "]") [])) | 
| 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 567 | >> (fn cs => | 
| 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 568 | Rule_Cases.cases_hyp_names | 
| 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 569 | (map #1 cs) | 
| 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 570 | (map (map (the_default Rule_Cases.case_hypsN) o #2) cs))) | 
| 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 571 | "named rule cases" #> | 
| 67147 | 572 | setup \<^binding>\<open>case_conclusion\<close> | 
| 62898 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 573 | (Scan.lift (Args.name -- Scan.repeat Args.name) >> Rule_Cases.case_conclusion) | 
| 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 574 | "named conclusion of rule cases" #> | 
| 67147 | 575 | setup \<^binding>\<open>params\<close> | 
| 62898 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 576 | (Scan.lift (Parse.and_list1 (Scan.repeat Args.name)) >> Rule_Cases.params) | 
| 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 577 | "named rule parameters" #> | 
| 67147 | 578 | setup \<^binding>\<open>rule_format\<close> | 
| 62898 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 579 | (Scan.lift (Args.mode "no_asm") | 
| 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 580 | >> (fn true => Object_Logic.rule_format_no_asm | false => Object_Logic.rule_format)) | 
| 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 581 | "result put into canonical rule format" #> | 
| 67147 | 582 | setup \<^binding>\<open>elim_format\<close> | 
| 62898 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 583 | (Scan.succeed (Thm.rule_attribute [] (K Tactic.make_elim))) | 
| 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 584 | "destruct rule turned into elimination rule format" #> | 
| 67147 | 585 | setup \<^binding>\<open>no_vars\<close> | 
| 70304 | 586 | (Scan.succeed (Thm.rule_attribute [] (Variable.import_vars o Context.proof_of))) | 
| 62898 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 587 | "imported schematic variables" #> | 
| 67147 | 588 | setup \<^binding>\<open>atomize\<close> | 
| 62898 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 589 | (Scan.succeed Object_Logic.declare_atomize) "declaration of atomize rule" #> | 
| 67147 | 590 | setup \<^binding>\<open>rulify\<close> | 
| 62898 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 591 | (Scan.succeed Object_Logic.declare_rulify) "declaration of rulify rule" #> | 
| 67147 | 592 | setup \<^binding>\<open>rotated\<close> | 
| 62898 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 593 | (Scan.lift (Scan.optional Parse.int 1 | 
| 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 594 | >> (fn n => Thm.rule_attribute [] (fn _ => rotate_prems n)))) "rotated theorem premises" #> | 
| 67147 | 595 | setup \<^binding>\<open>defn\<close> | 
| 62898 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 596 | (add_del Local_Defs.defn_add Local_Defs.defn_del) | 
| 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 597 | "declaration of definitional transformations" #> | 
| 67147 | 598 | setup \<^binding>\<open>abs_def\<close> | 
| 63068 
8b9401bfd9fd
unfold is subject to unfold_abs_def (still inactive);
 wenzelm parents: 
63019diff
changeset | 599 | (Scan.succeed (Thm.rule_attribute [] (Local_Defs.abs_def_rule o Context.proof_of))) | 
| 62898 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 600 | "abstract over free variables of definitional theorem" #> | 
| 
fdc290b68ecd
Pure attribute setup is back to Pure/Isar/attrib.ML, where it can be editing continuously (see also 7eb0c04e4c40);
 wenzelm parents: 
62878diff
changeset | 601 | |
| 69575 | 602 | register_config_bool Goal.quick_and_dirty #> | 
| 603 | register_config_bool Ast.trace #> | |
| 604 | register_config_bool Ast.stats #> | |
| 605 | register_config_bool Printer.show_brackets #> | |
| 606 | register_config_bool Printer.show_sorts #> | |
| 607 | register_config_bool Printer.show_types #> | |
| 608 | register_config_bool Printer.show_markup #> | |
| 609 | register_config_bool Printer.show_structs #> | |
| 610 | register_config_bool Printer.show_question_marks #> | |
| 611 | register_config_bool Syntax.ambiguity_warning #> | |
| 612 | register_config_int Syntax.ambiguity_limit #> | |
| 613 | register_config_bool Syntax_Trans.eta_contract #> | |
| 614 | register_config_bool Name_Space.names_long #> | |
| 615 | register_config_bool Name_Space.names_short #> | |
| 616 | register_config_bool Name_Space.names_unique #> | |
| 617 | register_config_int ML_Print_Depth.print_depth #> | |
| 618 | register_config_string ML_Env.ML_environment #> | |
| 619 | register_config_bool ML_Env.ML_read_global #> | |
| 620 | register_config_bool ML_Env.ML_write_global #> | |
| 78728 
72631efa3821
explicitly reject 'handle' with catch-all patterns;
 wenzelm parents: 
78098diff
changeset | 621 | register_config_bool ML_Compiler.ML_catch_all #> | 
| 69575 | 622 | register_config_bool ML_Options.source_trace #> | 
| 623 | register_config_bool ML_Options.exception_trace #> | |
| 624 | register_config_bool ML_Options.exception_debugger #> | |
| 625 | register_config_bool ML_Options.debugger #> | |
| 626 | register_config_bool Proof_Context.show_abbrevs #> | |
| 627 | register_config_int Goal_Display.goals_limit #> | |
| 628 | register_config_bool Goal_Display.show_main_goal #> | |
| 629 | register_config_bool Thm.show_consts #> | |
| 630 | register_config_bool Thm.show_hyps #> | |
| 631 | register_config_bool Thm.show_tags #> | |
| 632 | register_config_bool Pattern.unify_trace_failure #> | |
| 633 | register_config_int Unify.search_bound #> | |
| 79743 
3648e9c88d0c
add option for unify trace (now disabled by default as printing is excessive and rarely used);
 Fabian Huch <huch@in.tum.de> parents: 
79742diff
changeset | 634 | register_config_bool Unify.unify_trace #> | 
| 79742 
2e4518e8a36b
tuned unify trace option names;
 Fabian Huch <huch@in.tum.de> parents: 
79369diff
changeset | 635 | register_config_int Unify.unify_trace_bound #> | 
| 
2e4518e8a36b
tuned unify trace option names;
 Fabian Huch <huch@in.tum.de> parents: 
79369diff
changeset | 636 | register_config_bool Unify.unify_trace_simp #> | 
| 
2e4518e8a36b
tuned unify trace option names;
 Fabian Huch <huch@in.tum.de> parents: 
79369diff
changeset | 637 | register_config_bool Unify.unify_trace_types #> | 
| 69575 | 638 | register_config_int Raw_Simplifier.simp_depth_limit #> | 
| 639 | register_config_int Raw_Simplifier.simp_trace_depth_limit #> | |
| 640 | register_config_bool Raw_Simplifier.simp_debug #> | |
| 641 | register_config_bool Raw_Simplifier.simp_trace #> | |
| 642 | register_config_bool Local_Defs.unfold_abs_def); | |
| 5823 | 643 | |
| 63019 | 644 | |
| 645 | (* internal source *) | |
| 646 | ||
| 647 | local | |
| 648 | ||
| 78091 | 649 | val make_name0 = make_name (Context.the_local_context ()); | 
| 63019 | 650 | |
| 78091 | 651 | val consumes_name = make_name0 "consumes"; | 
| 652 | val constraints_name = make_name0 "constraints"; | |
| 653 | val cases_open_name = make_name0 "cases_open"; | |
| 654 | val case_names_name = make_name0 "case_names"; | |
| 655 | val case_conclusion_name = make_name0 "case_conclusion"; | |
| 63019 | 656 | |
| 657 | in | |
| 658 | ||
| 659 | fun consumes i = consumes_name :: Token.make_int i; | |
| 660 | fun constraints i = constraints_name :: Token.make_int i; | |
| 661 | val cases_open = [cases_open_name]; | |
| 78091 | 662 | fun case_names names = case_names_name :: map Token.make_string0 names; | 
| 663 | fun case_conclusion (name, names) = case_conclusion_name :: map Token.make_string0 (name :: names); | |
| 63019 | 664 | |
| 5823 | 665 | end; | 
| 63019 | 666 | |
| 667 | end; |