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