src/Pure/Isar/attrib.ML
author wenzelm
Sun May 30 21:34:19 2010 +0200 (2010-05-30 ago)
changeset 37198 3af985b10550
parent 36959 f5417836dbea
child 38329 16bb1e60204b
permissions -rw-r--r--
replaced ML_Lex.read_antiq by more concise ML_Lex.read, which includes full read/report with explicit position information;
ML_Context.eval/expression expect explicit ML_Lex source, which allows surrounding further text without loosing position information;
fall back on ML_Context.eval_text if there is no position or no surrounding text;
proper Args.name_source_position for method "tactic" and "raw_tactic";
tuned;
wenzelm@5823
     1
(*  Title:      Pure/Isar/attrib.ML
wenzelm@5823
     2
    Author:     Markus Wenzel, TU Muenchen
wenzelm@5823
     3
wenzelm@18734
     4
Symbolic representation of attributes -- with name and syntax.
wenzelm@5823
     5
*)
wenzelm@5823
     6
wenzelm@5823
     7
signature ATTRIB =
wenzelm@5823
     8
sig
wenzelm@27729
     9
  type src = Args.src
haftmann@29581
    10
  type binding = binding * src list
haftmann@28965
    11
  val empty_binding: binding
wenzelm@27729
    12
  val print_attributes: theory -> unit
wenzelm@16458
    13
  val intern: theory -> xstring -> string
wenzelm@16458
    14
  val intern_src: theory -> src -> src
wenzelm@21031
    15
  val pretty_attribs: Proof.context -> src list -> Pretty.T list
wenzelm@26891
    16
  val defined: theory -> string -> bool
wenzelm@18734
    17
  val attribute: theory -> src -> attribute
wenzelm@18734
    18
  val attribute_i: theory -> src -> attribute
wenzelm@26336
    19
  val eval_thms: Proof.context -> (Facts.ref * src list) list -> thm list
wenzelm@18905
    20
  val map_specs: ('a -> 'att) ->
wenzelm@30759
    21
    (('c * 'a list) * 'b) list -> (('c * 'att list) * 'b) list
wenzelm@18905
    22
  val map_facts: ('a -> 'att) ->
wenzelm@17105
    23
    (('c * 'a list) * ('d * 'a list) list) list ->
wenzelm@18905
    24
    (('c * 'att list) * ('d * 'att list) list) list
wenzelm@30759
    25
  val map_facts_refs: ('a -> 'att) -> ('b -> 'fact) ->
wenzelm@30759
    26
    (('c * 'a list) * ('b * 'a list) list) list ->
wenzelm@30759
    27
    (('c * 'att list) * ('fact * 'att list) list) list
wenzelm@20289
    28
  val crude_closure: Proof.context -> src -> src
wenzelm@30525
    29
  val setup: Binding.binding -> attribute context_parser -> string -> theory -> theory
wenzelm@30575
    30
  val attribute_setup: bstring * Position.T -> Symbol_Pos.text * Position.T -> string ->
wenzelm@30575
    31
    theory -> theory
wenzelm@30525
    32
  val add_del: attribute -> attribute -> attribute context_parser
wenzelm@30513
    33
  val thm_sel: Facts.interval list parser
wenzelm@30513
    34
  val thm: thm context_parser
wenzelm@30513
    35
  val thms: thm list context_parser
wenzelm@30513
    36
  val multi_thm: thm list context_parser
wenzelm@24110
    37
  val print_configs: Proof.context -> unit
wenzelm@25983
    38
  val internal: (morphism -> attribute) -> src
wenzelm@36002
    39
  val config_bool: bstring -> (Context.generic -> bool) -> bool Config.T * (theory -> theory)
wenzelm@36002
    40
  val config_int: bstring -> (Context.generic -> int) -> int Config.T * (theory -> theory)
wenzelm@36002
    41
  val config_string: bstring -> (Context.generic -> string) -> string Config.T * (theory -> theory)
wenzelm@36002
    42
  val config_bool_global: bstring -> (Context.generic -> bool) -> bool Config.T * (theory -> theory)
wenzelm@36002
    43
  val config_int_global: bstring -> (Context.generic -> int) -> int Config.T * (theory -> theory)
wenzelm@36002
    44
  val config_string_global: bstring -> (Context.generic -> string) -> string Config.T * (theory -> theory)
wenzelm@5823
    45
end;
wenzelm@5823
    46
wenzelm@5823
    47
structure Attrib: ATTRIB =
wenzelm@5823
    48
struct
wenzelm@5823
    49
wenzelm@28084
    50
(* source and bindings *)
wenzelm@28084
    51
wenzelm@15703
    52
type src = Args.src;
wenzelm@15703
    53
haftmann@29581
    54
type binding = binding * src list;
haftmann@28965
    55
val empty_binding: binding = (Binding.empty, []);
wenzelm@28084
    56
wenzelm@28084
    57
wenzelm@27729
    58
wenzelm@18734
    59
(** named attributes **)
wenzelm@18636
    60
wenzelm@18734
    61
(* theory data *)
wenzelm@5823
    62
wenzelm@33522
    63
structure Attributes = Theory_Data
wenzelm@22846
    64
(
wenzelm@33095
    65
  type T = ((src -> attribute) * string) Name_Space.table;
wenzelm@33159
    66
  val empty : T = Name_Space.empty_table "attribute";
wenzelm@16458
    67
  val extend = I;
wenzelm@33522
    68
  fun merge data : T = Name_Space.merge_tables data;
wenzelm@22846
    69
);
wenzelm@5823
    70
wenzelm@22846
    71
fun print_attributes thy =
wenzelm@22846
    72
  let
wenzelm@24110
    73
    val attribs = Attributes.get thy;
wenzelm@33092
    74
    fun prt_attr (name, (_, comment)) = Pretty.block
wenzelm@22846
    75
      [Pretty.str (name ^ ":"), Pretty.brk 2, Pretty.str comment];
wenzelm@22846
    76
  in
wenzelm@33095
    77
    [Pretty.big_list "attributes:" (map prt_attr (Name_Space.extern_table attribs))]
wenzelm@22846
    78
    |> Pretty.chunks |> Pretty.writeln
wenzelm@22846
    79
  end;
wenzelm@7611
    80
wenzelm@33092
    81
fun add_attribute name att comment thy = thy
wenzelm@33095
    82
  |> Attributes.map (#2 o Name_Space.define true (Sign.naming_of thy) (name, (att, comment)));
wenzelm@31306
    83
wenzelm@5823
    84
wenzelm@21031
    85
(* name space *)
wenzelm@15703
    86
wenzelm@33095
    87
val intern = Name_Space.intern o #1 o Attributes.get;
wenzelm@15703
    88
val intern_src = Args.map_name o intern;
wenzelm@15703
    89
wenzelm@33095
    90
val extern = Name_Space.extern o #1 o Attributes.get o ProofContext.theory_of;
wenzelm@21031
    91
wenzelm@21031
    92
wenzelm@21031
    93
(* pretty printing *)
wenzelm@21031
    94
wenzelm@21031
    95
fun pretty_attribs _ [] = []
wenzelm@21031
    96
  | pretty_attribs ctxt srcs =
wenzelm@21031
    97
      [Pretty.enclose "[" "]"
wenzelm@21031
    98
        (Pretty.commas (map (Args.pretty_src ctxt o Args.map_name (extern ctxt)) srcs))];
wenzelm@21031
    99
wenzelm@15703
   100
wenzelm@18734
   101
(* get attributes *)
wenzelm@5823
   102
wenzelm@26891
   103
val defined = Symtab.defined o #2 o Attributes.get;
wenzelm@26891
   104
wenzelm@18734
   105
fun attribute_i thy =
wenzelm@5823
   106
  let
wenzelm@24110
   107
    val attrs = #2 (Attributes.get thy);
wenzelm@5879
   108
    fun attr src =
wenzelm@16344
   109
      let val ((name, _), pos) = Args.dest_src src in
wenzelm@17412
   110
        (case Symtab.lookup attrs name of
skalberg@15531
   111
          NONE => error ("Unknown attribute: " ^ quote name ^ Position.str_of pos)
wenzelm@33092
   112
        | SOME (att, _) => (Position.report (Markup.attribute name) pos; att src))
wenzelm@5823
   113
      end;
wenzelm@5823
   114
  in attr end;
wenzelm@5823
   115
wenzelm@18734
   116
fun attribute thy = attribute_i thy o intern_src thy;
wenzelm@18636
   117
wenzelm@33666
   118
fun eval_thms ctxt args = ProofContext.note_thmss ""
wenzelm@30759
   119
    [(Thm.empty_binding, args |> map (fn (a, atts) =>
wenzelm@30759
   120
        (ProofContext.get_fact ctxt a, map (attribute (ProofContext.theory_of ctxt)) atts)))] ctxt
wenzelm@26685
   121
  |> fst |> maps snd;
wenzelm@24723
   122
wenzelm@5823
   123
wenzelm@17105
   124
(* attributed declarations *)
wenzelm@17105
   125
wenzelm@17105
   126
fun map_specs f = map (apfst (apsnd (map f)));
wenzelm@30759
   127
wenzelm@17105
   128
fun map_facts f = map (apfst (apsnd (map f)) o apsnd (map (apsnd (map f))));
wenzelm@30759
   129
fun map_facts_refs f g = map_facts f #> map (apsnd (map (apfst g)));
wenzelm@17105
   130
wenzelm@17105
   131
wenzelm@15703
   132
(* crude_closure *)
wenzelm@15703
   133
wenzelm@15703
   134
(*Produce closure without knowing facts in advance! The following
wenzelm@18734
   135
  works reasonably well for attribute parsers that do not peek at the
wenzelm@18734
   136
  thm structure.*)
wenzelm@15703
   137
wenzelm@15703
   138
fun crude_closure ctxt src =
wenzelm@18734
   139
 (try (fn () => attribute_i (ProofContext.theory_of ctxt) src
wenzelm@18734
   140
    (Context.Proof ctxt, Drule.asm_rl)) ();
wenzelm@15703
   141
  Args.closure src);
wenzelm@15703
   142
wenzelm@15703
   143
wenzelm@30525
   144
(* attribute setup *)
wenzelm@30525
   145
wenzelm@31306
   146
fun syntax scan = Args.syntax "attribute" scan;
wenzelm@30525
   147
wenzelm@31306
   148
fun setup name scan =
wenzelm@31306
   149
  add_attribute name
wenzelm@31306
   150
    (fn src => fn (ctxt, th) => let val (a, ctxt') = syntax scan src ctxt in a (ctxt', th) end);
wenzelm@5879
   151
wenzelm@30525
   152
fun attribute_setup name (txt, pos) cmt =
wenzelm@30525
   153
  Context.theory_map (ML_Context.expression pos
wenzelm@30525
   154
    "val (name, scan, comment): binding * attribute context_parser * string"
wenzelm@30525
   155
    "Context.map_theory (Attrib.setup name scan comment)"
wenzelm@37198
   156
    (ML_Lex.read Position.none ("(" ^ ML_Syntax.make_binding name ^ ", ") @
wenzelm@37198
   157
      ML_Lex.read pos txt @
wenzelm@37198
   158
      ML_Lex.read Position.none (", " ^ ML_Syntax.print_string cmt ^ ")")));
wenzelm@30525
   159
wenzelm@30525
   160
wenzelm@31305
   161
(* add/del syntax *)
wenzelm@5823
   162
wenzelm@31305
   163
fun add_del add del = Scan.lift (Args.add >> K add || Args.del >> K del || Scan.succeed add);
wenzelm@5879
   164
wenzelm@5879
   165
wenzelm@25983
   166
wenzelm@25983
   167
(** parsing attributed theorems **)
wenzelm@5879
   168
wenzelm@36950
   169
val thm_sel = Parse.$$$ "(" |-- Parse.list1
wenzelm@36950
   170
 (Parse.nat --| Parse.minus -- Parse.nat >> Facts.FromTo ||
wenzelm@36950
   171
  Parse.nat --| Parse.minus >> Facts.From ||
wenzelm@36950
   172
  Parse.nat >> Facts.Single) --| Parse.$$$ ")";
wenzelm@27812
   173
wenzelm@18636
   174
local
wenzelm@18636
   175
wenzelm@21698
   176
val fact_name = Args.internal_fact >> K "<fact>" || Args.name;
wenzelm@21698
   177
wenzelm@26336
   178
fun gen_thm pick = Scan.depend (fn context =>
wenzelm@26336
   179
  let
wenzelm@26336
   180
    val thy = Context.theory_of context;
wenzelm@26685
   181
    val get = Context.cases (PureThy.get_fact context) ProofContext.get_fact context;
wenzelm@26361
   182
    val get_fact = get o Facts.Fact;
wenzelm@27820
   183
    fun get_named pos name = get (Facts.Named ((name, pos), NONE));
wenzelm@26336
   184
  in
wenzelm@36950
   185
    Parse.$$$ "[" |-- Args.attribs (intern thy) --| Parse.$$$ "]" >> (fn srcs =>
wenzelm@24008
   186
      let
wenzelm@26336
   187
        val atts = map (attribute_i thy) srcs;
wenzelm@26336
   188
        val (context', th') = Library.apply atts (context, Drule.dummy_thm);
wenzelm@26336
   189
      in (context', pick "" [th']) end)
wenzelm@26336
   190
    ||
wenzelm@26336
   191
    (Scan.ahead Args.alt_name -- Args.named_fact get_fact
wenzelm@27820
   192
      >> (fn (s, fact) => ("", Facts.Fact s, fact)) ||
wenzelm@36950
   193
     Scan.ahead (Parse.position fact_name) :|-- (fn (name, pos) =>
wenzelm@27820
   194
      Args.named_fact (get_named pos) -- Scan.option thm_sel
wenzelm@27820
   195
        >> (fn (fact, sel) => (name, Facts.Named ((name, pos), sel), fact))))
wenzelm@26336
   196
    -- Args.opt_attribs (intern thy) >> (fn ((name, thmref, fact), srcs) =>
wenzelm@26336
   197
      let
wenzelm@26336
   198
        val ths = Facts.select thmref fact;
wenzelm@26336
   199
        val atts = map (attribute_i thy) srcs;
wenzelm@30190
   200
        val (context', ths') = Library.foldl_map (Library.apply atts) (context, ths);
wenzelm@26336
   201
      in (context', pick name ths') end)
wenzelm@26336
   202
  end);
berghofe@15456
   203
wenzelm@18636
   204
in
wenzelm@18636
   205
wenzelm@26336
   206
val thm = gen_thm Facts.the_single;
wenzelm@18998
   207
val multi_thm = gen_thm (K I);
wenzelm@19482
   208
val thms = Scan.repeat multi_thm >> flat;
wenzelm@18636
   209
wenzelm@18636
   210
end;
wenzelm@18636
   211
wenzelm@5823
   212
wenzelm@5879
   213
wenzelm@25983
   214
(** basic attributes **)
wenzelm@25983
   215
wenzelm@25983
   216
(* internal *)
wenzelm@25983
   217
wenzelm@36959
   218
fun internal att = Args.src (("Pure.attribute", [Token.mk_attribute att]), Position.none);
wenzelm@25983
   219
wenzelm@25983
   220
wenzelm@25983
   221
(* rule composition *)
wenzelm@25983
   222
wenzelm@25983
   223
val COMP_att =
wenzelm@36950
   224
  Scan.lift (Scan.optional (Args.bracks Parse.nat) 1) -- thm
wenzelm@31305
   225
    >> (fn (i, B) => Thm.rule_attribute (fn _ => fn A => Drule.compose_single (A, i, B)));
wenzelm@25983
   226
wenzelm@25983
   227
val THEN_att =
wenzelm@36950
   228
  Scan.lift (Scan.optional (Args.bracks Parse.nat) 1) -- thm
wenzelm@31305
   229
    >> (fn (i, B) => Thm.rule_attribute (fn _ => fn A => A RSN (i, B)));
wenzelm@25983
   230
wenzelm@25983
   231
val OF_att =
wenzelm@31305
   232
  thms >> (fn Bs => Thm.rule_attribute (fn _ => fn A => Bs MRS A));
wenzelm@25983
   233
wenzelm@25983
   234
wenzelm@25983
   235
(* rename_abs *)
wenzelm@25983
   236
wenzelm@31323
   237
fun rename_abs x = (Scan.repeat (Args.maybe Args.name) >> (apsnd o Drule.rename_bvars')) x;
wenzelm@25983
   238
wenzelm@25983
   239
wenzelm@25983
   240
(* unfold / fold definitions *)
wenzelm@25983
   241
wenzelm@25983
   242
fun unfolded_syntax rule =
wenzelm@31305
   243
  thms >> (fn ths => Thm.rule_attribute (fn context => rule (Context.proof_of context) ths));
wenzelm@25983
   244
wenzelm@35624
   245
val unfolded = unfolded_syntax Local_Defs.unfold;
wenzelm@35624
   246
val folded = unfolded_syntax Local_Defs.fold;
wenzelm@25983
   247
wenzelm@25983
   248
wenzelm@25983
   249
(* rule format *)
wenzelm@25983
   250
wenzelm@31305
   251
val rule_format = Args.mode "no_asm"
wenzelm@35625
   252
  >> (fn true => Object_Logic.rule_format_no_asm | false => Object_Logic.rule_format);
wenzelm@25983
   253
wenzelm@31305
   254
val elim_format = Thm.rule_attribute (K Tactic.make_elim);
wenzelm@25983
   255
wenzelm@25983
   256
wenzelm@25983
   257
(* misc rules *)
wenzelm@25983
   258
wenzelm@31305
   259
val no_vars = Thm.rule_attribute (fn context => fn th =>
wenzelm@26715
   260
  let
wenzelm@26715
   261
    val ctxt = Variable.set_body false (Context.proof_of context);
wenzelm@31794
   262
    val ((_, [th']), _) = Variable.import true [th] ctxt;
wenzelm@31305
   263
  in th' end);
wenzelm@25983
   264
wenzelm@25983
   265
val eta_long =
wenzelm@31305
   266
  Thm.rule_attribute (K (Conv.fconv_rule Drule.eta_long_conversion));
wenzelm@25983
   267
wenzelm@36950
   268
val rotated = Scan.optional Parse.int 1 >> (fn n => Thm.rule_attribute (K (rotate_prems n)));
berghofe@29690
   269
wenzelm@25983
   270
wenzelm@25983
   271
(* theory setup *)
wenzelm@5823
   272
wenzelm@26463
   273
val _ = Context.>> (Context.map_theory
wenzelm@31305
   274
 (setup (Binding.name "attribute") (Scan.lift Args.internal_attribute >> Morphism.form)
wenzelm@31305
   275
    "internal attribute" #>
wenzelm@31305
   276
  setup (Binding.name "tagged") (Scan.lift (Args.name -- Args.name) >> Thm.tag) "tagged theorem" #>
wenzelm@31305
   277
  setup (Binding.name "untagged") (Scan.lift Args.name >> Thm.untag) "untagged theorem" #>
wenzelm@31305
   278
  setup (Binding.name "kind") (Scan.lift Args.name >> Thm.kind) "theorem kind" #>
wenzelm@31305
   279
  setup (Binding.name "COMP") COMP_att "direct composition with rules (no lifting)" #>
wenzelm@31305
   280
  setup (Binding.name "THEN") THEN_att "resolution with rule" #>
wenzelm@31305
   281
  setup (Binding.name "OF") OF_att "rule applied to facts" #>
wenzelm@31305
   282
  setup (Binding.name "rename_abs") (Scan.lift rename_abs)
wenzelm@31305
   283
    "rename bound variables in abstractions" #>
wenzelm@31305
   284
  setup (Binding.name "unfolded") unfolded "unfolded definitions" #>
wenzelm@31305
   285
  setup (Binding.name "folded") folded "folded definitions" #>
wenzelm@36950
   286
  setup (Binding.name "consumes") (Scan.lift (Scan.optional Parse.nat 1) >> Rule_Cases.consumes)
wenzelm@31305
   287
    "number of consumed facts" #>
wenzelm@36950
   288
  setup (Binding.name "constraints") (Scan.lift Parse.nat >> Rule_Cases.constraints)
berghofe@34986
   289
    "number of equality constraints" #>
wenzelm@33368
   290
  setup (Binding.name "case_names") (Scan.lift (Scan.repeat1 Args.name) >> Rule_Cases.case_names)
wenzelm@31305
   291
    "named rule cases" #>
wenzelm@31305
   292
  setup (Binding.name "case_conclusion")
wenzelm@33368
   293
    (Scan.lift (Args.name -- Scan.repeat Args.name) >> Rule_Cases.case_conclusion)
wenzelm@31305
   294
    "named conclusion of rule cases" #>
wenzelm@31305
   295
  setup (Binding.name "params")
wenzelm@36950
   296
    (Scan.lift (Parse.and_list1 (Scan.repeat Args.name)) >> Rule_Cases.params)
wenzelm@31305
   297
    "named rule parameters" #>
wenzelm@35021
   298
  setup (Binding.name "standard") (Scan.succeed (Thm.rule_attribute (K Drule.export_without_context)))
wenzelm@31305
   299
    "result put into standard form (legacy)" #>
wenzelm@31305
   300
  setup (Binding.name "rule_format") rule_format "result put into canonical rule format" #>
wenzelm@31305
   301
  setup (Binding.name "elim_format") (Scan.succeed elim_format)
wenzelm@31305
   302
    "destruct rule turned into elimination rule format" #>
wenzelm@31305
   303
  setup (Binding.name "no_vars") (Scan.succeed no_vars) "frozen schematic vars" #>
wenzelm@31305
   304
  setup (Binding.name "eta_long") (Scan.succeed eta_long)
wenzelm@31305
   305
    "put theorem into eta long beta normal form" #>
wenzelm@35625
   306
  setup (Binding.name "atomize") (Scan.succeed Object_Logic.declare_atomize)
wenzelm@31305
   307
    "declaration of atomize rule" #>
wenzelm@35625
   308
  setup (Binding.name "rulify") (Scan.succeed Object_Logic.declare_rulify)
wenzelm@31305
   309
    "declaration of rulify rule" #>
wenzelm@31305
   310
  setup (Binding.name "rotated") (Scan.lift rotated) "rotated theorem premises" #>
wenzelm@35624
   311
  setup (Binding.name "defn") (add_del Local_Defs.defn_add Local_Defs.defn_del)
wenzelm@31305
   312
    "declaration of definitional transformations" #>
wenzelm@31305
   313
  setup (Binding.name "abs_def") (Scan.succeed (Thm.rule_attribute (K Drule.abs_def)))
wenzelm@31305
   314
    "abstract over free variables of a definition"));
wenzelm@8633
   315
wenzelm@5823
   316
wenzelm@5823
   317
wenzelm@24110
   318
(** configuration options **)
wenzelm@24110
   319
wenzelm@24110
   320
(* naming *)
wenzelm@24110
   321
wenzelm@33522
   322
structure Configs = Theory_Data
wenzelm@24713
   323
(
wenzelm@24110
   324
  type T = Config.value Config.T Symtab.table;
wenzelm@24110
   325
  val empty = Symtab.empty;
wenzelm@24110
   326
  val extend = I;
wenzelm@33522
   327
  fun merge data = Symtab.merge (K true) data;
wenzelm@24713
   328
);
wenzelm@5823
   329
wenzelm@24110
   330
fun print_configs ctxt =
wenzelm@24110
   331
  let
wenzelm@24110
   332
    val thy = ProofContext.theory_of ctxt;
wenzelm@24110
   333
    fun prt (name, config) =
wenzelm@24110
   334
      let val value = Config.get ctxt config in
wenzelm@24110
   335
        Pretty.block [Pretty.str (name ^ ": " ^ Config.print_type value ^ " ="), Pretty.brk 1,
wenzelm@24110
   336
          Pretty.str (Config.print_value value)]
wenzelm@24110
   337
      end;
wenzelm@33095
   338
    val configs = Name_Space.extern_table (#1 (Attributes.get thy), Configs.get thy);
wenzelm@24110
   339
  in Pretty.writeln (Pretty.big_list "configuration options" (map prt configs)) end;
wenzelm@24110
   340
wenzelm@24110
   341
wenzelm@24110
   342
(* concrete syntax *)
wenzelm@23988
   343
wenzelm@24003
   344
local
wenzelm@24003
   345
wenzelm@36950
   346
val equals = Parse.$$$ "=";
wenzelm@24003
   347
wenzelm@24110
   348
fun scan_value (Config.Bool _) =
wenzelm@24110
   349
      equals -- Args.$$$ "false" >> K (Config.Bool false) ||
wenzelm@24110
   350
      equals -- Args.$$$ "true" >> K (Config.Bool true) ||
wenzelm@24110
   351
      Scan.succeed (Config.Bool true)
wenzelm@36950
   352
  | scan_value (Config.Int _) = equals |-- Parse.int >> Config.Int
wenzelm@24110
   353
  | scan_value (Config.String _) = equals |-- Args.name >> Config.String;
wenzelm@24003
   354
wenzelm@24110
   355
fun scan_config thy config =
wenzelm@36787
   356
  let val config_type = Config.get_global thy config
wenzelm@24110
   357
  in scan_value config_type >> (K o Thm.declaration_attribute o K o Config.put_generic config) end;
wenzelm@24003
   358
wenzelm@24003
   359
in
wenzelm@24003
   360
wenzelm@24126
   361
fun register_config config thy =
wenzelm@24126
   362
  let
wenzelm@24126
   363
    val bname = Config.name_of config;
haftmann@28965
   364
    val name = Sign.full_bname thy bname;
wenzelm@24126
   365
  in
wenzelm@24126
   366
    thy
wenzelm@31306
   367
    |> setup (Binding.name bname) (Scan.lift (scan_config thy config) >> Morphism.form)
wenzelm@31306
   368
      "configuration option"
wenzelm@24126
   369
    |> Configs.map (Symtab.update (name, config))
wenzelm@24126
   370
  end;
wenzelm@24110
   371
wenzelm@24110
   372
fun declare_config make coerce global name default =
wenzelm@24110
   373
  let
wenzelm@36000
   374
    val config_value = Config.declare global name (make o default);
wenzelm@24110
   375
    val config = coerce config_value;
wenzelm@24126
   376
  in (config, register_config config_value) end;
wenzelm@24110
   377
wenzelm@24110
   378
val config_bool   = declare_config Config.Bool Config.bool false;
wenzelm@24110
   379
val config_int    = declare_config Config.Int Config.int false;
wenzelm@24110
   380
val config_string = declare_config Config.String Config.string false;
wenzelm@24110
   381
wenzelm@24110
   382
val config_bool_global   = declare_config Config.Bool Config.bool true;
wenzelm@24110
   383
val config_int_global    = declare_config Config.Int Config.int true;
wenzelm@24110
   384
val config_string_global = declare_config Config.String Config.string true;
wenzelm@24003
   385
wenzelm@24003
   386
end;
wenzelm@23988
   387
wenzelm@23988
   388
wenzelm@18636
   389
(* theory setup *)
wenzelm@5823
   390
wenzelm@26463
   391
val _ = Context.>> (Context.map_theory
wenzelm@24178
   392
 (register_config Unify.trace_bound_value #>
wenzelm@24178
   393
  register_config Unify.search_bound_value #>
wenzelm@24178
   394
  register_config Unify.trace_simp_value #>
wenzelm@24178
   395
  register_config Unify.trace_types_value #>
boehmes@35979
   396
  register_config MetaSimplifier.simp_depth_limit_value #>
boehmes@35979
   397
  register_config MetaSimplifier.debug_simp_value #>
boehmes@35979
   398
  register_config MetaSimplifier.trace_simp_value));
wenzelm@5823
   399
wenzelm@5823
   400
end;