src/Pure/Isar/attrib.ML
author wenzelm
Sun Apr 17 21:17:45 2011 +0200 (2011-04-17)
changeset 42380 9371ea9f91fb
parent 42375 774df7c59508
child 42616 92715b528e78
permissions -rw-r--r--
markup attributes/methods via name space;
eliminated obsolete markup;
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@18905
    19
  val map_specs: ('a -> 'att) ->
wenzelm@30759
    20
    (('c * 'a list) * 'b) list -> (('c * 'att list) * 'b) list
wenzelm@18905
    21
  val map_facts: ('a -> 'att) ->
wenzelm@17105
    22
    (('c * 'a list) * ('d * 'a list) list) list ->
wenzelm@18905
    23
    (('c * 'att list) * ('d * 'att list) list) list
wenzelm@30759
    24
  val map_facts_refs: ('a -> 'att) -> ('b -> 'fact) ->
wenzelm@30759
    25
    (('c * 'a list) * ('b * 'a list) list) list ->
wenzelm@30759
    26
    (('c * 'att list) * ('fact * 'att list) list) list
wenzelm@38330
    27
  val eval_thms: Proof.context -> (Facts.ref * src list) list -> thm 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@40291
    41
  val config_real: bstring -> (Context.generic -> real) -> real Config.T * (theory -> theory)
wenzelm@36002
    42
  val config_string: bstring -> (Context.generic -> string) -> string Config.T * (theory -> theory)
wenzelm@36002
    43
  val config_bool_global: bstring -> (Context.generic -> bool) -> bool Config.T * (theory -> theory)
wenzelm@36002
    44
  val config_int_global: bstring -> (Context.generic -> int) -> int Config.T * (theory -> theory)
wenzelm@40291
    45
  val config_real_global: bstring -> (Context.generic -> real) -> real Config.T * (theory -> theory)
wenzelm@40291
    46
  val config_string_global:
wenzelm@40291
    47
    bstring -> (Context.generic -> string) -> string Config.T * (theory -> theory)
wenzelm@5823
    48
end;
wenzelm@5823
    49
wenzelm@5823
    50
structure Attrib: ATTRIB =
wenzelm@5823
    51
struct
wenzelm@5823
    52
wenzelm@28084
    53
(* source and bindings *)
wenzelm@28084
    54
wenzelm@15703
    55
type src = Args.src;
wenzelm@15703
    56
haftmann@29581
    57
type binding = binding * src list;
haftmann@28965
    58
val empty_binding: binding = (Binding.empty, []);
wenzelm@28084
    59
wenzelm@28084
    60
wenzelm@27729
    61
wenzelm@18734
    62
(** named attributes **)
wenzelm@18636
    63
wenzelm@18734
    64
(* theory data *)
wenzelm@5823
    65
wenzelm@33522
    66
structure Attributes = Theory_Data
wenzelm@22846
    67
(
wenzelm@33095
    68
  type T = ((src -> attribute) * string) Name_Space.table;
wenzelm@33159
    69
  val empty : T = Name_Space.empty_table "attribute";
wenzelm@16458
    70
  val extend = I;
wenzelm@33522
    71
  fun merge data : T = Name_Space.merge_tables data;
wenzelm@22846
    72
);
wenzelm@5823
    73
wenzelm@22846
    74
fun print_attributes thy =
wenzelm@22846
    75
  let
wenzelm@42360
    76
    val ctxt = Proof_Context.init_global thy;
wenzelm@24110
    77
    val attribs = Attributes.get thy;
wenzelm@33092
    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@42358
    81
    [Pretty.big_list "attributes:" (map prt_attr (Name_Space.extern_table ctxt attribs))]
wenzelm@22846
    82
    |> Pretty.chunks |> Pretty.writeln
wenzelm@22846
    83
  end;
wenzelm@7611
    84
wenzelm@33092
    85
fun add_attribute name att comment thy = thy
wenzelm@42375
    86
  |> Attributes.map
wenzelm@42375
    87
    (Name_Space.define (Proof_Context.init_global thy) true (Sign.naming_of thy)
wenzelm@42375
    88
      (name, (att, comment)) #> snd);
wenzelm@31306
    89
wenzelm@5823
    90
wenzelm@21031
    91
(* name space *)
wenzelm@15703
    92
wenzelm@33095
    93
val intern = Name_Space.intern o #1 o Attributes.get;
wenzelm@15703
    94
val intern_src = Args.map_name o intern;
wenzelm@15703
    95
wenzelm@42360
    96
fun extern ctxt = Name_Space.extern ctxt (#1 (Attributes.get (Proof_Context.theory_of ctxt)));
wenzelm@21031
    97
wenzelm@21031
    98
wenzelm@21031
    99
(* pretty printing *)
wenzelm@21031
   100
wenzelm@21031
   101
fun pretty_attribs _ [] = []
wenzelm@21031
   102
  | pretty_attribs ctxt srcs =
wenzelm@38329
   103
      [Pretty.enum "," "[" "]" (map (Args.pretty_src ctxt o Args.map_name (extern ctxt)) srcs)];
wenzelm@21031
   104
wenzelm@15703
   105
wenzelm@18734
   106
(* get attributes *)
wenzelm@5823
   107
wenzelm@26891
   108
val defined = Symtab.defined o #2 o Attributes.get;
wenzelm@26891
   109
wenzelm@18734
   110
fun attribute_i thy =
wenzelm@5823
   111
  let
wenzelm@42380
   112
    val (space, tab) = Attributes.get thy;
wenzelm@5879
   113
    fun attr src =
wenzelm@16344
   114
      let val ((name, _), pos) = Args.dest_src src in
wenzelm@42380
   115
        (case Symtab.lookup tab name of
skalberg@15531
   116
          NONE => error ("Unknown attribute: " ^ quote name ^ Position.str_of pos)
wenzelm@42380
   117
        | SOME (att, _) => (Position.report pos (Name_Space.markup space name); att src))
wenzelm@5823
   118
      end;
wenzelm@5823
   119
  in attr end;
wenzelm@5823
   120
wenzelm@18734
   121
fun attribute thy = attribute_i thy o intern_src thy;
wenzelm@18636
   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@38330
   132
(* fact expressions *)
wenzelm@38330
   133
wenzelm@38330
   134
fun eval_thms ctxt srcs = ctxt
wenzelm@42360
   135
  |> Proof_Context.note_thmss ""
wenzelm@42360
   136
    (map_facts_refs (attribute (Proof_Context.theory_of ctxt)) (Proof_Context.get_fact ctxt)
wenzelm@38330
   137
      [((Binding.empty, []), srcs)])
wenzelm@38330
   138
  |> fst |> maps snd;
wenzelm@38330
   139
wenzelm@38330
   140
wenzelm@15703
   141
(* crude_closure *)
wenzelm@15703
   142
wenzelm@15703
   143
(*Produce closure without knowing facts in advance! The following
wenzelm@18734
   144
  works reasonably well for attribute parsers that do not peek at the
wenzelm@18734
   145
  thm structure.*)
wenzelm@15703
   146
wenzelm@15703
   147
fun crude_closure ctxt src =
wenzelm@42360
   148
 (try (fn () => attribute_i (Proof_Context.theory_of ctxt) src
wenzelm@18734
   149
    (Context.Proof ctxt, Drule.asm_rl)) ();
wenzelm@15703
   150
  Args.closure src);
wenzelm@15703
   151
wenzelm@15703
   152
wenzelm@30525
   153
(* attribute setup *)
wenzelm@30525
   154
wenzelm@31306
   155
fun syntax scan = Args.syntax "attribute" scan;
wenzelm@30525
   156
wenzelm@31306
   157
fun setup name scan =
wenzelm@31306
   158
  add_attribute name
wenzelm@31306
   159
    (fn src => fn (ctxt, th) => let val (a, ctxt') = syntax scan src ctxt in a (ctxt', th) end);
wenzelm@5879
   160
wenzelm@30525
   161
fun attribute_setup name (txt, pos) cmt =
wenzelm@30525
   162
  Context.theory_map (ML_Context.expression pos
wenzelm@30525
   163
    "val (name, scan, comment): binding * attribute context_parser * string"
wenzelm@30525
   164
    "Context.map_theory (Attrib.setup name scan comment)"
wenzelm@37198
   165
    (ML_Lex.read Position.none ("(" ^ ML_Syntax.make_binding name ^ ", ") @
wenzelm@37198
   166
      ML_Lex.read pos txt @
wenzelm@37198
   167
      ML_Lex.read Position.none (", " ^ ML_Syntax.print_string cmt ^ ")")));
wenzelm@30525
   168
wenzelm@30525
   169
wenzelm@31305
   170
(* add/del syntax *)
wenzelm@5823
   171
wenzelm@31305
   172
fun add_del add del = Scan.lift (Args.add >> K add || Args.del >> K del || Scan.succeed add);
wenzelm@5879
   173
wenzelm@5879
   174
wenzelm@25983
   175
wenzelm@25983
   176
(** parsing attributed theorems **)
wenzelm@5879
   177
wenzelm@36950
   178
val thm_sel = Parse.$$$ "(" |-- Parse.list1
wenzelm@36950
   179
 (Parse.nat --| Parse.minus -- Parse.nat >> Facts.FromTo ||
wenzelm@36950
   180
  Parse.nat --| Parse.minus >> Facts.From ||
wenzelm@36950
   181
  Parse.nat >> Facts.Single) --| Parse.$$$ ")";
wenzelm@27812
   182
wenzelm@18636
   183
local
wenzelm@18636
   184
wenzelm@21698
   185
val fact_name = Args.internal_fact >> K "<fact>" || Args.name;
wenzelm@21698
   186
wenzelm@26336
   187
fun gen_thm pick = Scan.depend (fn context =>
wenzelm@26336
   188
  let
wenzelm@26336
   189
    val thy = Context.theory_of context;
wenzelm@42360
   190
    val get = Context.cases (Global_Theory.get_fact context) Proof_Context.get_fact context;
wenzelm@26361
   191
    val get_fact = get o Facts.Fact;
wenzelm@27820
   192
    fun get_named pos name = get (Facts.Named ((name, pos), NONE));
wenzelm@26336
   193
  in
wenzelm@36950
   194
    Parse.$$$ "[" |-- Args.attribs (intern thy) --| Parse.$$$ "]" >> (fn srcs =>
wenzelm@24008
   195
      let
wenzelm@26336
   196
        val atts = map (attribute_i thy) srcs;
wenzelm@26336
   197
        val (context', th') = Library.apply atts (context, Drule.dummy_thm);
wenzelm@26336
   198
      in (context', pick "" [th']) end)
wenzelm@26336
   199
    ||
wenzelm@26336
   200
    (Scan.ahead Args.alt_name -- Args.named_fact get_fact
wenzelm@27820
   201
      >> (fn (s, fact) => ("", Facts.Fact s, fact)) ||
wenzelm@36950
   202
     Scan.ahead (Parse.position fact_name) :|-- (fn (name, pos) =>
wenzelm@27820
   203
      Args.named_fact (get_named pos) -- Scan.option thm_sel
wenzelm@27820
   204
        >> (fn (fact, sel) => (name, Facts.Named ((name, pos), sel), fact))))
wenzelm@26336
   205
    -- Args.opt_attribs (intern thy) >> (fn ((name, thmref, fact), srcs) =>
wenzelm@26336
   206
      let
wenzelm@26336
   207
        val ths = Facts.select thmref fact;
wenzelm@26336
   208
        val atts = map (attribute_i thy) srcs;
wenzelm@30190
   209
        val (context', ths') = Library.foldl_map (Library.apply atts) (context, ths);
wenzelm@26336
   210
      in (context', pick name ths') end)
wenzelm@26336
   211
  end);
berghofe@15456
   212
wenzelm@18636
   213
in
wenzelm@18636
   214
wenzelm@26336
   215
val thm = gen_thm Facts.the_single;
wenzelm@18998
   216
val multi_thm = gen_thm (K I);
wenzelm@19482
   217
val thms = Scan.repeat multi_thm >> flat;
wenzelm@18636
   218
wenzelm@18636
   219
end;
wenzelm@18636
   220
wenzelm@5823
   221
wenzelm@5879
   222
wenzelm@25983
   223
(** basic attributes **)
wenzelm@25983
   224
wenzelm@25983
   225
(* internal *)
wenzelm@25983
   226
wenzelm@36959
   227
fun internal att = Args.src (("Pure.attribute", [Token.mk_attribute att]), Position.none);
wenzelm@25983
   228
wenzelm@25983
   229
wenzelm@25983
   230
(* rule composition *)
wenzelm@25983
   231
wenzelm@25983
   232
val COMP_att =
wenzelm@36950
   233
  Scan.lift (Scan.optional (Args.bracks Parse.nat) 1) -- thm
wenzelm@31305
   234
    >> (fn (i, B) => Thm.rule_attribute (fn _ => fn A => Drule.compose_single (A, i, B)));
wenzelm@25983
   235
wenzelm@25983
   236
val THEN_att =
wenzelm@36950
   237
  Scan.lift (Scan.optional (Args.bracks Parse.nat) 1) -- thm
wenzelm@31305
   238
    >> (fn (i, B) => Thm.rule_attribute (fn _ => fn A => A RSN (i, B)));
wenzelm@25983
   239
wenzelm@25983
   240
val OF_att =
wenzelm@31305
   241
  thms >> (fn Bs => Thm.rule_attribute (fn _ => fn A => Bs MRS A));
wenzelm@25983
   242
wenzelm@25983
   243
wenzelm@25983
   244
(* rename_abs *)
wenzelm@25983
   245
wenzelm@31323
   246
fun rename_abs x = (Scan.repeat (Args.maybe Args.name) >> (apsnd o Drule.rename_bvars')) x;
wenzelm@25983
   247
wenzelm@25983
   248
wenzelm@25983
   249
(* unfold / fold definitions *)
wenzelm@25983
   250
wenzelm@25983
   251
fun unfolded_syntax rule =
wenzelm@31305
   252
  thms >> (fn ths => Thm.rule_attribute (fn context => rule (Context.proof_of context) ths));
wenzelm@25983
   253
wenzelm@35624
   254
val unfolded = unfolded_syntax Local_Defs.unfold;
wenzelm@35624
   255
val folded = unfolded_syntax Local_Defs.fold;
wenzelm@25983
   256
wenzelm@25983
   257
wenzelm@25983
   258
(* rule format *)
wenzelm@25983
   259
wenzelm@31305
   260
val rule_format = Args.mode "no_asm"
wenzelm@35625
   261
  >> (fn true => Object_Logic.rule_format_no_asm | false => Object_Logic.rule_format);
wenzelm@25983
   262
wenzelm@31305
   263
val elim_format = Thm.rule_attribute (K Tactic.make_elim);
wenzelm@25983
   264
wenzelm@25983
   265
wenzelm@25983
   266
(* misc rules *)
wenzelm@25983
   267
wenzelm@31305
   268
val no_vars = Thm.rule_attribute (fn context => fn th =>
wenzelm@26715
   269
  let
wenzelm@26715
   270
    val ctxt = Variable.set_body false (Context.proof_of context);
wenzelm@31794
   271
    val ((_, [th']), _) = Variable.import true [th] ctxt;
wenzelm@31305
   272
  in th' end);
wenzelm@25983
   273
wenzelm@25983
   274
val eta_long =
wenzelm@31305
   275
  Thm.rule_attribute (K (Conv.fconv_rule Drule.eta_long_conversion));
wenzelm@25983
   276
wenzelm@36950
   277
val rotated = Scan.optional Parse.int 1 >> (fn n => Thm.rule_attribute (K (rotate_prems n)));
berghofe@29690
   278
wenzelm@25983
   279
wenzelm@25983
   280
(* theory setup *)
wenzelm@5823
   281
wenzelm@26463
   282
val _ = Context.>> (Context.map_theory
wenzelm@31305
   283
 (setup (Binding.name "attribute") (Scan.lift Args.internal_attribute >> Morphism.form)
wenzelm@31305
   284
    "internal attribute" #>
wenzelm@31305
   285
  setup (Binding.name "tagged") (Scan.lift (Args.name -- Args.name) >> Thm.tag) "tagged theorem" #>
wenzelm@31305
   286
  setup (Binding.name "untagged") (Scan.lift Args.name >> Thm.untag) "untagged theorem" #>
wenzelm@31305
   287
  setup (Binding.name "kind") (Scan.lift Args.name >> Thm.kind) "theorem kind" #>
wenzelm@31305
   288
  setup (Binding.name "COMP") COMP_att "direct composition with rules (no lifting)" #>
wenzelm@31305
   289
  setup (Binding.name "THEN") THEN_att "resolution with rule" #>
wenzelm@31305
   290
  setup (Binding.name "OF") OF_att "rule applied to facts" #>
wenzelm@31305
   291
  setup (Binding.name "rename_abs") (Scan.lift rename_abs)
wenzelm@31305
   292
    "rename bound variables in abstractions" #>
wenzelm@31305
   293
  setup (Binding.name "unfolded") unfolded "unfolded definitions" #>
wenzelm@31305
   294
  setup (Binding.name "folded") folded "folded definitions" #>
wenzelm@36950
   295
  setup (Binding.name "consumes") (Scan.lift (Scan.optional Parse.nat 1) >> Rule_Cases.consumes)
wenzelm@31305
   296
    "number of consumed facts" #>
wenzelm@36950
   297
  setup (Binding.name "constraints") (Scan.lift Parse.nat >> Rule_Cases.constraints)
berghofe@34986
   298
    "number of equality constraints" #>
wenzelm@33368
   299
  setup (Binding.name "case_names") (Scan.lift (Scan.repeat1 Args.name) >> Rule_Cases.case_names)
wenzelm@31305
   300
    "named rule cases" #>
wenzelm@31305
   301
  setup (Binding.name "case_conclusion")
wenzelm@33368
   302
    (Scan.lift (Args.name -- Scan.repeat Args.name) >> Rule_Cases.case_conclusion)
wenzelm@31305
   303
    "named conclusion of rule cases" #>
wenzelm@31305
   304
  setup (Binding.name "params")
wenzelm@36950
   305
    (Scan.lift (Parse.and_list1 (Scan.repeat Args.name)) >> Rule_Cases.params)
wenzelm@31305
   306
    "named rule parameters" #>
wenzelm@35021
   307
  setup (Binding.name "standard") (Scan.succeed (Thm.rule_attribute (K Drule.export_without_context)))
wenzelm@31305
   308
    "result put into standard form (legacy)" #>
wenzelm@31305
   309
  setup (Binding.name "rule_format") rule_format "result put into canonical rule format" #>
wenzelm@31305
   310
  setup (Binding.name "elim_format") (Scan.succeed elim_format)
wenzelm@31305
   311
    "destruct rule turned into elimination rule format" #>
wenzelm@31305
   312
  setup (Binding.name "no_vars") (Scan.succeed no_vars) "frozen schematic vars" #>
wenzelm@31305
   313
  setup (Binding.name "eta_long") (Scan.succeed eta_long)
wenzelm@31305
   314
    "put theorem into eta long beta normal form" #>
wenzelm@35625
   315
  setup (Binding.name "atomize") (Scan.succeed Object_Logic.declare_atomize)
wenzelm@31305
   316
    "declaration of atomize rule" #>
wenzelm@35625
   317
  setup (Binding.name "rulify") (Scan.succeed Object_Logic.declare_rulify)
wenzelm@31305
   318
    "declaration of rulify rule" #>
wenzelm@31305
   319
  setup (Binding.name "rotated") (Scan.lift rotated) "rotated theorem premises" #>
wenzelm@35624
   320
  setup (Binding.name "defn") (add_del Local_Defs.defn_add Local_Defs.defn_del)
wenzelm@31305
   321
    "declaration of definitional transformations" #>
wenzelm@31305
   322
  setup (Binding.name "abs_def") (Scan.succeed (Thm.rule_attribute (K Drule.abs_def)))
wenzelm@31305
   323
    "abstract over free variables of a definition"));
wenzelm@8633
   324
wenzelm@5823
   325
wenzelm@5823
   326
wenzelm@24110
   327
(** configuration options **)
wenzelm@24110
   328
wenzelm@24110
   329
(* naming *)
wenzelm@24110
   330
wenzelm@33522
   331
structure Configs = Theory_Data
wenzelm@24713
   332
(
wenzelm@39163
   333
  type T = Config.raw Symtab.table;
wenzelm@24110
   334
  val empty = Symtab.empty;
wenzelm@24110
   335
  val extend = I;
wenzelm@33522
   336
  fun merge data = Symtab.merge (K true) data;
wenzelm@24713
   337
);
wenzelm@5823
   338
wenzelm@24110
   339
fun print_configs ctxt =
wenzelm@24110
   340
  let
wenzelm@42360
   341
    val thy = Proof_Context.theory_of ctxt;
wenzelm@24110
   342
    fun prt (name, config) =
wenzelm@24110
   343
      let val value = Config.get ctxt config in
wenzelm@24110
   344
        Pretty.block [Pretty.str (name ^ ": " ^ Config.print_type value ^ " ="), Pretty.brk 1,
wenzelm@24110
   345
          Pretty.str (Config.print_value value)]
wenzelm@24110
   346
      end;
wenzelm@42358
   347
    val configs = Name_Space.extern_table ctxt (#1 (Attributes.get thy), Configs.get thy);
wenzelm@24110
   348
  in Pretty.writeln (Pretty.big_list "configuration options" (map prt configs)) end;
wenzelm@24110
   349
wenzelm@24110
   350
wenzelm@24110
   351
(* concrete syntax *)
wenzelm@23988
   352
wenzelm@24003
   353
local
wenzelm@24003
   354
wenzelm@36950
   355
val equals = Parse.$$$ "=";
wenzelm@24003
   356
wenzelm@24110
   357
fun scan_value (Config.Bool _) =
wenzelm@24110
   358
      equals -- Args.$$$ "false" >> K (Config.Bool false) ||
wenzelm@24110
   359
      equals -- Args.$$$ "true" >> K (Config.Bool true) ||
wenzelm@24110
   360
      Scan.succeed (Config.Bool true)
wenzelm@36950
   361
  | scan_value (Config.Int _) = equals |-- Parse.int >> Config.Int
wenzelm@40291
   362
  | scan_value (Config.Real _) = equals |-- Parse.real >> Config.Real
wenzelm@24110
   363
  | scan_value (Config.String _) = equals |-- Args.name >> Config.String;
wenzelm@24003
   364
wenzelm@24110
   365
fun scan_config thy config =
wenzelm@36787
   366
  let val config_type = Config.get_global thy config
wenzelm@24110
   367
  in scan_value config_type >> (K o Thm.declaration_attribute o K o Config.put_generic config) end;
wenzelm@24003
   368
wenzelm@24003
   369
in
wenzelm@24003
   370
wenzelm@24126
   371
fun register_config config thy =
wenzelm@24126
   372
  let
wenzelm@24126
   373
    val bname = Config.name_of config;
haftmann@28965
   374
    val name = Sign.full_bname thy bname;
wenzelm@24126
   375
  in
wenzelm@24126
   376
    thy
wenzelm@31306
   377
    |> setup (Binding.name bname) (Scan.lift (scan_config thy config) >> Morphism.form)
wenzelm@31306
   378
      "configuration option"
wenzelm@24126
   379
    |> Configs.map (Symtab.update (name, config))
wenzelm@24126
   380
  end;
wenzelm@24110
   381
wenzelm@24110
   382
fun declare_config make coerce global name default =
wenzelm@24110
   383
  let
wenzelm@39116
   384
    val config_value = Config.declare_generic {global = global} name (make o default);
wenzelm@24110
   385
    val config = coerce config_value;
wenzelm@24126
   386
  in (config, register_config config_value) end;
wenzelm@24110
   387
wenzelm@42289
   388
val config_bool = declare_config Config.Bool Config.bool false;
wenzelm@42289
   389
val config_int = declare_config Config.Int Config.int false;
wenzelm@42289
   390
val config_real = declare_config Config.Real Config.real false;
wenzelm@24110
   391
val config_string = declare_config Config.String Config.string false;
wenzelm@24110
   392
wenzelm@42289
   393
val config_bool_global = declare_config Config.Bool Config.bool true;
wenzelm@42289
   394
val config_int_global = declare_config Config.Int Config.int true;
wenzelm@42289
   395
val config_real_global = declare_config Config.Real Config.real 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@42277
   404
 (register_config Ast.trace_raw #>
wenzelm@42277
   405
  register_config Ast.stat_raw #>
wenzelm@42056
   406
  register_config Syntax.positions_raw #>
wenzelm@42289
   407
  register_config Printer.show_brackets_raw #>
wenzelm@42289
   408
  register_config Printer.show_sorts_raw #>
wenzelm@42289
   409
  register_config Printer.show_types_raw #>
wenzelm@42289
   410
  register_config Printer.show_structs_raw #>
wenzelm@42289
   411
  register_config Printer.show_question_marks_raw #>
wenzelm@39163
   412
  register_config Syntax.ambiguity_level_raw #>
wenzelm@42284
   413
  register_config Syntax_Trans.eta_contract_raw #>
wenzelm@42358
   414
  register_config Name_Space.long_names_raw #>
wenzelm@42358
   415
  register_config Name_Space.short_names_raw #>
wenzelm@42358
   416
  register_config Name_Space.unique_names_raw #>
wenzelm@41375
   417
  register_config ML_Context.trace_raw #>
wenzelm@42360
   418
  register_config Proof_Context.show_abbrevs_raw #>
wenzelm@39163
   419
  register_config Goal_Display.goals_limit_raw #>
wenzelm@39163
   420
  register_config Goal_Display.show_main_goal_raw #>
wenzelm@39163
   421
  register_config Goal_Display.show_consts_raw #>
wenzelm@39166
   422
  register_config Display.show_hyps_raw #>
wenzelm@39166
   423
  register_config Display.show_tags_raw #>
wenzelm@39163
   424
  register_config Unify.trace_bound_raw #>
wenzelm@39163
   425
  register_config Unify.search_bound_raw #>
wenzelm@39163
   426
  register_config Unify.trace_simp_raw #>
wenzelm@39163
   427
  register_config Unify.trace_types_raw #>
wenzelm@41228
   428
  register_config Raw_Simplifier.simp_depth_limit_raw #>
wenzelm@41228
   429
  register_config Raw_Simplifier.simp_trace_depth_limit_raw #>
wenzelm@41228
   430
  register_config Raw_Simplifier.simp_debug_raw #>
wenzelm@41228
   431
  register_config Raw_Simplifier.simp_trace_raw));
wenzelm@5823
   432
wenzelm@5823
   433
end;