(* Title: Pure/Isar/attrib.ML Author: Markus Wenzel, TU Muenchen
Symbolic representation of attributes -- with name and syntax.
*)
signature ATTRIB = sig type thms = Attrib.thms type fact = Attrib.fact val print_attributes: bool -> Proof.context -> unit val attribute_space: Context.generic -> Name_Space.T val define_global: binding -> (Token.src -> attribute) -> string -> theory -> string * theory val define: binding -> (Token.src -> attribute) -> string -> local_theory -> string * local_theory val check_name_generic: Context.generic -> xstring * Position.T -> string val check_name: Proof.context -> xstring * Position.T -> string val check_src: Proof.context -> Token.src -> Token.src val attribs: Token.src list context_parser val opt_attribs: Token.src list context_parser val pretty_attribs: Proof.context -> Token.src list -> Pretty.T list val pretty_binding: Proof.context -> Attrib.binding -> string -> Pretty.T list val attribute: Proof.context -> Token.src -> attribute val attribute_global: theory -> Token.src -> attribute val attribute_cmd: Proof.context -> Token.src -> attribute val attribute_cmd_global: theory -> Token.src -> attribute val map_specs: ('a list -> 'att list) ->
(('c * 'a list) * 'b) list -> (('c * 'att list) * 'b) list val map_facts: ('a list -> 'att list) ->
(('c * 'a list) * ('d * 'a list) list) list ->
(('c * 'att list) * ('d * 'att list) list) list val map_facts_refs: ('a list -> 'att list) -> ('b -> 'fact) ->
(('c * 'a list) * ('b * 'a list) list) list ->
(('c * 'att list) * ('fact * 'att list) list) list val map_thms: ('a -> 'b) ->
('c * ('a list * 'd) list) list ->
('c * ('b list * 'd) list) list val trim_context_binding: Attrib.binding -> Attrib.binding val trim_context_thms: thms -> thms val trim_context_fact: fact -> fact val global_notes: string -> fact list -> theory ->
(string * thm list) list * theory val local_notes: string -> fact list -> Proof.context ->
(string * thm list) list * Proof.context val generic_notes: string -> fact list -> Context.generic ->
(string * thm list) list * Context.generic val lazy_notes: string -> binding * thm list lazy -> Context.generic -> Context.generic val eval_thms: Proof.context -> (Facts.ref * Token.src list) list -> thm list val attribute_syntax: attribute context_parser -> Token.src -> attribute val setup: binding -> attribute context_parser -> string -> theory -> theory val local_setup: binding -> attribute context_parser -> string ->
local_theory -> local_theory val attribute_setup: bstring * Position.T -> Input.source -> string ->
local_theory -> local_theory val internal: Position.T -> (morphism -> attribute) -> Token.src val internal_declaration: Position.T -> Morphism.declaration_entity -> thms val add_del: attribute -> attribute -> attribute context_parser val thm: thm context_parser val thms: thm list context_parser val multi_thm: thm list context_parser val transform_facts: morphism -> fact list -> fact list val partial_evaluation: Proof.context -> fact list -> fact list val print_options: bool -> Proof.context -> unit val config_bool: binding -> (Context.generic -> bool) -> bool Config.T * (theory -> theory) val config_int: binding -> (Context.generic -> int) -> int Config.T * (theory -> theory) val config_real: binding -> (Context.generic -> real) -> real Config.T * (theory -> theory) val config_string: binding -> (Context.generic -> string) -> string Config.T * (theory -> theory) val setup_config_bool: binding -> (Context.generic -> bool) -> bool Config.T val setup_config_int: binding -> (Context.generic -> int) -> int Config.T val setup_config_real: binding -> (Context.generic -> real) -> real Config.T val setup_config_string: binding -> (Context.generic -> string) -> string Config.T val option_bool: string * Position.T -> bool Config.T * (theory -> theory) val option_int: string * Position.T -> int Config.T * (theory -> theory) val option_real: string * Position.T -> real Config.T * (theory -> theory) val option_string: string * Position.T -> string Config.T * (theory -> theory) val setup_option_bool: string * Position.T -> bool Config.T val setup_option_int: string * Position.T -> int Config.T val setup_option_real: string * Position.T -> real Config.T val setup_option_string: string * Position.T -> string Config.T val consumes: int -> Token.src val constraints: int -> Token.src val cases_open: Token.src val case_names: stringlist -> Token.src val case_conclusion: string * stringlist -> Token.src end;
structure Attrib: sigtype binding = Attrib.binding include ATTRIB end = struct
open Attrib;
(** named attributes **)
(* theory data *)
structure Attributes = Generic_Data
( type T = ((Token.src -> attribute) * string) Name_Space.table; val empty : T = Name_Space.empty_table Markup.attributeN; fun merge data : T = Name_Space.merge_tables data;
);
val ops_attributes = {get_data = Attributes.get, put_data = Attributes.put};
val get_attributes = Attributes.get o Context.Proof;
fun print_attributes verbose ctxt = let val attribs = get_attributes ctxt; fun prt_attr (name, (_, "")) = Pretty.mark_str name
| prt_attr (name, (_, comment)) =
Pretty.block
(Pretty.mark_str name :: Pretty.str ":" :: Pretty.brk 2 :: Pretty.text comment); in
[Pretty.big_list "attributes:" (map prt_attr (Name_Space.markup_table verbose ctxt attribs))]
|> Pretty.chunks |> Pretty.writeln end;
val attribute_space = Name_Space.space_of_table o Attributes.get;
(* define *)
fun define_global binding att comment =
Entity.define_global ops_attributes binding (att, comment);
fun define binding att comment =
Entity.define ops_attributes binding (att, comment);
(* check *)
fun check_name_generic context = #1 o Name_Space.check context (Attributes.get context); val check_name = check_name_generic o Context.Proof;
fun check_src ctxt src = let val _ = if Token.checked_src src then () else Context_Position.report ctxt (#1 (Token.range_of src)) Markup.language_attribute; in #1 (Token.check_src ctxt get_attributes src) end;
fun attribute_generic context = letval table = Attributes.get context in
fn src => let val name = #1 (Token.name_of_src src); val label = Long_Name.qualify Markup.attributeN name; val att = #1 (Name_Space.get table name) src; in Position.setmp_thread_data_label label att : attribute end end;
val attribute = attribute_generic o Context.Proof; val attribute_global = attribute_generic o Context.Theory;
fun attribute_cmd ctxt = attribute ctxt o check_src ctxt; fun attribute_cmd_global thy = attribute_global thy o check_src (Proof_Context.init_global thy);
(* attributed declarations *)
fun map_specs f = (map o apfst o apsnd) f;
fun map_facts f = map (fn (a, b) => (apsnd f a, (map o apsnd) f b)); fun map_facts_refs f g = map_facts f #> (map o apsnd o map o apfst) g;
fun map_thms f = (map o apsnd o map o apfst o map) f;
(* implicit context *)
val trim_context_binding: Attrib.binding -> Attrib.binding =
apsnd ((map o map) Token.trim_context);
val trim_context_thms: thms -> thms = map (fn (thms, atts) => (map Thm.trim_context thms, (map o map) Token.trim_context atts));
fun trim_context_fact (binding, thms) = (trim_context_binding binding, trim_context_thms thms);
fun make_name ctxt name =
Token.make_src (name, Position.none) [] |> check_src ctxt |> hd;
local
val internal_binding = Binding.make ("attribute", \<^here>);
val _ = Theory.setup
(setup internal_binding
(Scan.lift Args.internal_attribute >> Morphism.form ||
Scan.lift Args.internal_declaration >> (Thm.declaration_attribute o K o Morphism.form)) "internal attribute");
val internal_name = make_name (Context.the_local_context ()) (Binding.name_of internal_binding); fun internal_source name value = [internal_name, Token.assign (SOME value) (Token.make_string name)];
(*NB: result length may change due to rearrangement of symbolic expression*)
local
fun apply_att src (context, th) = let val src1 = map Token.init_assignable src; val result = attribute_generic context src1 (context, th); val src2 = map Token.closure src1; in (src2, result) end;
fun err msg src = letval (name, pos) = Token.name_of_src src in error (msg ^ " " ^ quote name ^ Position.here pos) end;
fun eval src ((th, dyn), (decls, context)) =
(case (apply_att src (context, th), dyn) of
((_, (NONE, SOME th')), NONE) => ((th', NONE), (decls, context))
| ((_, (NONE, SOME _)), SOME _) => err "Mixed dynamic attribute followed by static rule" src
| ((src', (SOME context', NONE)), NONE) => let val decls' =
(case decls of
[] => [(th, [src'])]
| (th2, srcs2) :: rest => if Thm.eq_thm_strict (th, th2) then ((th2, src' :: srcs2) :: rest) else (th, [src']) :: (th2, srcs2) :: rest); in ((th, NONE), (decls', context')) end
| ((src', (opt_context', opt_th')), _) => let val context' = the_default context opt_context'; val th' = the_default th opt_th'; val dyn' =
(case dyn of
NONE => SOME (th, [src'])
| SOME (dyn_th, srcs) => SOME (dyn_th, src' :: srcs)); in ((th', dyn'), (decls, context')) end);
in
fun partial_evaluation ctxt facts =
(facts, Context.Proof (Context_Position.not_really ctxt)) |->
fold_map (fn ((b, more_atts), fact) => fn context => let val (fact', (decls, context')) =
(fact, ([], context)) |-> fold_map (fn (ths, atts) => fn res1 =>
(ths, res1) |-> fold_map (fn th => fn res2 => let val ((th', dyn'), res3) = fold eval (atts @ more_atts) ((th, NONE), res2); val th_atts' =
(case dyn' of
NONE => (th', [])
| SOME (dyn_th', atts') => (dyn_th', rev atts')); in (th_atts', res3) end))
|>> flat; val decls' = rev (map (apsnd rev) decls); val facts' = if eq_list (eq_fst Thm.eq_thm_strict) (decls', fact') then
[((b, []), map2 (fn (th, atts1) => fn (_, atts2) => (th, atts1 @ atts2)) decls' fact')] elseif null decls' then [((b, []), fact')] else [(Binding.empty_atts, decls'), ((b, []), fact')]; in (facts', context') end)
|> fst |> flat |> map (apsnd (map (apfst single)))
|> filter_out (fn (b, fact) => Binding.is_empty_atts b andalso forall (null o #2) fact);
end;
(** configuration options **)
(* naming *)
structure Configs = Theory_Data
( type T = Config.value Config.T Symtab.table; val empty = Symtab.empty; fun merge data = Symtab.merge (K true) data;
);
fun print_options verbose ctxt = let fun prt (name, config) = letval value = Config.get ctxt config in
Pretty.block [Pretty.mark_str name, Pretty.str (": " ^ Config.print_type value ^ " ="),
Pretty.brk 1, Pretty.str (Config.print_value value)] end; val space = attribute_space (Context.Proof ctxt); val configs =
Name_Space.markup_entries verbose ctxt space
(Symtab.dest (Configs.get (Proof_Context.theory_of ctxt))); in Pretty.writeln (Pretty.big_list "configuration options" (map prt configs)) end;
fun scan_config thy config = letval config_type = Config.get_global thy config in scan_value config_type >> (K o Thm.declaration_attribute o K o Config.put_generic config) end;
fun declare make coerce binding default = let val name = Binding.name_of binding; val pos = Binding.pos_of binding; val config_value = Config.declare (name, pos) (make o default); val config = coerce config_value; in (config, register binding config_value) end;
val register_config_bool = register_config o Config.bool_value; val register_config_int = register_config o Config.int_value; val register_config_real = register_config o Config.real_value; val register_config_string = register_config o Config.string_value;
val config_bool = declare Config.Bool Config.bool; val config_int = declare Config.Int Config.int; val config_real = declare Config.Real Config.real; val config_string = declare Config.String Config.string;
end;
(* implicit setup *)
local
fun setup_config declare_config binding default = let val (config, setup) = declare_config binding default; val _ = Theory.setup setup; in config end;
in
val setup_config_bool = setup_config config_bool; val setup_config_int = setup_config config_int; val setup_config_string = setup_config config_string; val setup_config_real = setup_config config_real;
end;
(* system options *)
local
fun declare_option coerce (name, pos) = let val config = Config.declare_option (name, pos); in (coerce config, register_config config) end;
fun setup_option coerce (name, pos) = let val config = Config.declare_option (name, pos); val _ = Theory.setup (register_config config); in coerce config end;
in
val option_bool = declare_option Config.bool; val option_int = declare_option Config.int; val option_real = declare_option Config.real; val option_string = declare_option Config.string;
val setup_option_bool = setup_option Config.bool; val setup_option_int = setup_option Config.int; val setup_option_real = setup_option Config.real; val setup_option_string = setup_option Config.string;
val make_name0 = make_name (Context.the_local_context ());
val consumes_name = make_name0 "consumes"; val constraints_name = make_name0 "constraints"; val cases_open_name = make_name0 "cases_open"; val case_names_name = make_name0 "case_names"; val case_conclusion_name = make_name0 "case_conclusion";
in
fun consumes i = consumes_name :: Token.make_int i; fun constraints i = constraints_name :: Token.make_int i; val cases_open = [cases_open_name]; fun case_names names = case_names_name :: map Token.make_string0 names; fun case_conclusion (name, names) = case_conclusion_name :: map Token.make_string0 (name :: names);
end;
end;
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.