src/Pure/pure_thy.ML
author wenzelm
Fri Aug 23 20:35:50 2013 +0200 (2013-08-23)
changeset 53171 a5e54d4d9081
parent 52211 66bc827e37f8
child 55033 8e8243975860
permissions -rw-r--r--
added Theory.setup convenience;
wenzelm@3987
     1
(*  Title:      Pure/pure_thy.ML
wenzelm@3987
     2
    Author:     Markus Wenzel, TU Muenchen
wenzelm@3987
     3
wenzelm@39557
     4
Pure theory syntax and further logical content.
wenzelm@3987
     5
*)
wenzelm@3987
     6
wenzelm@3987
     7
signature PURE_THY =
wenzelm@3987
     8
sig
wenzelm@26959
     9
  val old_appl_syntax: theory -> bool
wenzelm@26959
    10
  val old_appl_syntax_setup: theory -> theory
wenzelm@52160
    11
  val token_markers: string list
wenzelm@3987
    12
end;
wenzelm@3987
    13
wenzelm@39557
    14
structure Pure_Thy: PURE_THY =
wenzelm@3987
    15
struct
wenzelm@3987
    16
wenzelm@33384
    17
val typ = Simple_Syntax.read_typ;
wenzelm@33384
    18
val prop = Simple_Syntax.read_prop;
wenzelm@35429
    19
wenzelm@42290
    20
val tycon = Lexicon.mark_type;
wenzelm@42290
    21
val const = Lexicon.mark_const;
wenzelm@24243
    22
wenzelm@26959
    23
wenzelm@26959
    24
(* application syntax variants *)
wenzelm@26959
    25
wenzelm@26959
    26
val appl_syntax =
wenzelm@26959
    27
 [("_appl", typ "('b => 'a) => args => logic", Mixfix ("(1_/(1'(_')))", [1000, 0], 1000)),
wenzelm@26959
    28
  ("_appl", typ "('b => 'a) => args => aprop", Mixfix ("(1_/(1'(_')))", [1000, 0], 1000))];
wenzelm@26959
    29
wenzelm@26959
    30
val applC_syntax =
wenzelm@26959
    31
 [("",       typ "'a => cargs",                  Delimfix "_"),
wenzelm@26959
    32
  ("_cargs", typ "'a => cargs => cargs",         Mixfix ("_/ _", [1000, 1000], 1000)),
wenzelm@26959
    33
  ("_applC", typ "('b => 'a) => cargs => logic", Mixfix ("(1_/ _)", [1000, 1000], 999)),
wenzelm@26959
    34
  ("_applC", typ "('b => 'a) => cargs => aprop", Mixfix ("(1_/ _)", [1000, 1000], 999))];
wenzelm@26959
    35
wenzelm@37216
    36
structure Old_Appl_Syntax = Theory_Data
wenzelm@26959
    37
(
wenzelm@26959
    38
  type T = bool;
wenzelm@26959
    39
  val empty = false;
wenzelm@26959
    40
  val extend = I;
wenzelm@33522
    41
  fun merge (b1, b2) : T =
wenzelm@26959
    42
    if b1 = b2 then b1
wenzelm@26959
    43
    else error "Cannot merge theories with different application syntax";
wenzelm@26959
    44
);
wenzelm@26959
    45
wenzelm@37216
    46
val old_appl_syntax = Old_Appl_Syntax.get;
wenzelm@26959
    47
wenzelm@26959
    48
val old_appl_syntax_setup =
wenzelm@37216
    49
  Old_Appl_Syntax.put true #>
wenzelm@26959
    50
  Sign.del_modesyntax_i Syntax.mode_default applC_syntax #>
wenzelm@26959
    51
  Sign.add_syntax_i appl_syntax;
wenzelm@26959
    52
wenzelm@26959
    53
wenzelm@26959
    54
(* main content *)
wenzelm@26959
    55
wenzelm@52160
    56
val token_markers =
wenzelm@52160
    57
  ["_tfree", "_tvar", "_free", "_bound", "_loose", "_var", "_numeral", "_inner_string"];
wenzelm@52160
    58
wenzelm@53171
    59
val _ = Theory.setup
haftmann@33365
    60
  (Sign.map_naming (Name_Space.set_theory_name Context.PureN) #>
wenzelm@37216
    61
   Old_Appl_Syntax.put false #>
wenzelm@42375
    62
   Sign.add_types_global
wenzelm@30344
    63
   [(Binding.name "fun", 2, NoSyn),
wenzelm@30344
    64
    (Binding.name "prop", 0, NoSyn),
wenzelm@30344
    65
    (Binding.name "itself", 1, NoSyn),
wenzelm@30344
    66
    (Binding.name "dummy", 0, NoSyn)]
wenzelm@52160
    67
  #> Sign.add_nonterminals_global
wenzelm@52160
    68
    (map Binding.name
wenzelm@52160
    69
      (Lexicon.terminals @ ["logic", "type", "types", "sort", "classes",
wenzelm@52160
    70
        "args", "cargs", "pttrn", "pttrns", "idt", "idts", "aprop", "asms",
wenzelm@52160
    71
        "any", "prop'", "num_const", "float_const", "xnum_const", "num_position",
wenzelm@52160
    72
        "float_position", "xnum_position", "index", "struct", "tid_position",
wenzelm@52160
    73
        "tvar_position", "id_position", "longid_position", "var_position", "str_position",
wenzelm@52160
    74
        "type_name", "class_name"]))
wenzelm@52160
    75
  #> Sign.add_syntax_i (map (fn x => (x, typ "'a", NoSyn)) token_markers)
wenzelm@26430
    76
  #> Sign.add_syntax_i
wenzelm@42294
    77
   [("",            typ "prop' => prop",               Delimfix "_"),
wenzelm@42294
    78
    ("",            typ "logic => any",                Delimfix "_"),
wenzelm@42294
    79
    ("",            typ "prop' => any",                Delimfix "_"),
wenzelm@42294
    80
    ("",            typ "logic => logic",              Delimfix "'(_')"),
wenzelm@42294
    81
    ("",            typ "prop' => prop'",              Delimfix "'(_')"),
wenzelm@42294
    82
    ("_constrain",  typ "logic => type => logic",      Mixfix ("_::_", [4, 0], 3)),
wenzelm@42294
    83
    ("_constrain",  typ "prop' => type => prop'",      Mixfix ("_::_", [4, 0], 3)),
wenzelm@52211
    84
    ("_ignore_type", typ "'a",                         NoSyn),
wenzelm@49674
    85
    ("",            typ "tid_position => type",        Delimfix "_"),
wenzelm@49674
    86
    ("",            typ "tvar_position => type",       Delimfix "_"),
wenzelm@42263
    87
    ("",            typ "type_name => type",           Delimfix "_"),
wenzelm@42263
    88
    ("_type_name",  typ "id => type_name",             Delimfix "_"),
wenzelm@42263
    89
    ("_type_name",  typ "longid => type_name",         Delimfix "_"),
wenzelm@49685
    90
    ("_ofsort",     typ "tid_position => sort => type", Mixfix ("_::_", [1000, 0], 1000)),
wenzelm@49685
    91
    ("_ofsort",     typ "tvar_position => sort => type", Mixfix ("_::_", [1000, 0], 1000)),
wenzelm@42297
    92
    ("_dummy_ofsort", typ "sort => type",              Mixfix ("'_()::_", [0], 1000)),
wenzelm@42263
    93
    ("",            typ "class_name => sort",          Delimfix "_"),
wenzelm@42263
    94
    ("_class_name", typ "id => class_name",            Delimfix "_"),
wenzelm@42263
    95
    ("_class_name", typ "longid => class_name",        Delimfix "_"),
wenzelm@42263
    96
    ("_topsort",    typ "sort",                        Delimfix "{}"),
wenzelm@42263
    97
    ("_sort",       typ "classes => sort",             Delimfix "{_}"),
wenzelm@42263
    98
    ("",            typ "class_name => classes",       Delimfix "_"),
wenzelm@42263
    99
    ("_classes",    typ "class_name => classes => classes", Delimfix "_,_"),
wenzelm@42297
   100
    ("_tapp",       typ "type => type_name => type",   Mixfix ("_ _", [1000, 0], 1000)),
wenzelm@42263
   101
    ("_tappl",      typ "type => types => type_name => type", Delimfix "((1'(_,/ _')) _)"),
wenzelm@42263
   102
    ("",            typ "type => types",               Delimfix "_"),
wenzelm@42263
   103
    ("_types",      typ "type => types => types",      Delimfix "_,/ _"),
wenzelm@42263
   104
    ("\\<^type>fun", typ "type => type => type",       Mixfix ("(_/ => _)", [1, 0], 0)),
wenzelm@42263
   105
    ("_bracket",    typ "types => type => type",       Mixfix ("([_]/ => _)", [0, 0], 0)),
wenzelm@42263
   106
    ("",            typ "type => type",                Delimfix "'(_')"),
wenzelm@42263
   107
    ("\\<^type>dummy", typ "type",                     Delimfix "'_"),
wenzelm@42263
   108
    ("_type_prop",  typ "'a",                          NoSyn),
wenzelm@42263
   109
    ("_lambda",     typ "pttrns => 'a => logic",       Mixfix ("(3%_./ _)", [0, 3], 3)),
wenzelm@26436
   110
    ("_abs",        typ "'a",                          NoSyn),
wenzelm@26436
   111
    ("",            typ "'a => args",                  Delimfix "_"),
wenzelm@26436
   112
    ("_args",       typ "'a => args => args",          Delimfix "_,/ _"),
wenzelm@42048
   113
    ("",            typ "id_position => idt",          Delimfix "_"),
wenzelm@26436
   114
    ("_idtdummy",   typ "idt",                         Delimfix "'_"),
wenzelm@42048
   115
    ("_idtyp",      typ "id_position => type => idt",  Mixfix ("_::_", [], 0)),
wenzelm@26436
   116
    ("_idtypdummy", typ "type => idt",                 Mixfix ("'_()::_", [], 0)),
wenzelm@26436
   117
    ("",            typ "idt => idt",                  Delimfix "'(_')"),
wenzelm@26436
   118
    ("",            typ "idt => idts",                 Delimfix "_"),
wenzelm@26436
   119
    ("_idts",       typ "idt => idts => idts",         Mixfix ("_/ _", [1, 0], 0)),
wenzelm@26436
   120
    ("",            typ "idt => pttrn",                Delimfix "_"),
wenzelm@26436
   121
    ("",            typ "pttrn => pttrns",             Delimfix "_"),
wenzelm@26436
   122
    ("_pttrns",     typ "pttrn => pttrns => pttrns",   Mixfix ("_/ _", [1, 0], 0)),
wenzelm@28856
   123
    ("",            typ "aprop => aprop",              Delimfix "'(_')"),
wenzelm@42048
   124
    ("",            typ "id_position => aprop",        Delimfix "_"),
wenzelm@42048
   125
    ("",            typ "longid_position => aprop",    Delimfix "_"),
wenzelm@51612
   126
    ("",            typ "var_position => aprop",       Delimfix "_"),
wenzelm@26436
   127
    ("_DDDOT",      typ "aprop",                       Delimfix "..."),
wenzelm@26436
   128
    ("_aprop",      typ "aprop => prop",               Delimfix "PROP _"),
wenzelm@26436
   129
    ("_asm",        typ "prop => asms",                Delimfix "_"),
wenzelm@26436
   130
    ("_asms",       typ "prop => asms => asms",        Delimfix "_;/ _"),
wenzelm@26436
   131
    ("_bigimpl",    typ "asms => prop => prop",        Mixfix ("((3[| _ |])/ ==> _)", [0, 1], 1)),
wenzelm@26436
   132
    ("_ofclass",    typ "type => logic => prop",       Delimfix "(1OFCLASS/(1'(_,/ _')))"),
wenzelm@26436
   133
    ("_mk_ofclass", typ "dummy",                       NoSyn),
wenzelm@26436
   134
    ("_TYPE",       typ "type => logic",               Delimfix "(1TYPE/(1'(_')))"),
wenzelm@42048
   135
    ("",            typ "id_position => logic",        Delimfix "_"),
wenzelm@42048
   136
    ("",            typ "longid_position => logic",    Delimfix "_"),
wenzelm@51612
   137
    ("",            typ "var_position => logic",       Delimfix "_"),
wenzelm@26436
   138
    ("_DDDOT",      typ "logic",                       Delimfix "..."),
wenzelm@42057
   139
    ("_strip_positions", typ "'a", NoSyn),
wenzelm@46236
   140
    ("_position",   typ "num_token => num_position",   Delimfix "_"),
wenzelm@46236
   141
    ("_position",   typ "float_token => float_position", Delimfix "_"),
wenzelm@46236
   142
    ("_position",   typ "xnum_token => xnum_position", Delimfix "_"),
wenzelm@46236
   143
    ("_constify",   typ "num_position => num_const",   Delimfix "_"),
wenzelm@46236
   144
    ("_constify",   typ "float_position => float_const", Delimfix "_"),
wenzelm@46236
   145
    ("_constify",   typ "xnum_position => xnum_const", Delimfix "_"),
wenzelm@26436
   146
    ("_index",      typ "logic => index",              Delimfix "(00\\<^bsub>_\\<^esub>)"),
wenzelm@26436
   147
    ("_indexdefault", typ "index",                     Delimfix ""),
wenzelm@26436
   148
    ("_indexvar",   typ "index",                       Delimfix "'\\<index>"),
wenzelm@26436
   149
    ("_struct",     typ "index => logic",              Mixfix ("\\<struct>_", [1000], 1000)),
wenzelm@35145
   150
    ("_update_name", typ "idt",                        NoSyn),
wenzelm@42295
   151
    ("_constrainAbs", typ "'a",                        NoSyn),
wenzelm@49674
   152
    ("_position_sort", typ "tid => tid_position",      Delimfix "_"),
wenzelm@49674
   153
    ("_position_sort", typ "tvar => tvar_position",    Delimfix "_"),
wenzelm@42410
   154
    ("_position",   typ "id => id_position",           Delimfix "_"),
wenzelm@42410
   155
    ("_position",   typ "longid => longid_position",   Delimfix "_"),
wenzelm@51612
   156
    ("_position",   typ "var => var_position",         Delimfix "_"),
wenzelm@46483
   157
    ("_position",   typ "str_token => str_position",   Delimfix "_"),
wenzelm@42048
   158
    ("_type_constraint_", typ "'a",                    NoSyn),
wenzelm@42296
   159
    ("_context_const", typ "id_position => logic",     Delimfix "CONST _"),
wenzelm@42296
   160
    ("_context_const", typ "id_position => aprop",     Delimfix "CONST _"),
wenzelm@42296
   161
    ("_context_const", typ "longid_position => logic", Delimfix "CONST _"),
wenzelm@42296
   162
    ("_context_const", typ "longid_position => aprop", Delimfix "CONST _"),
wenzelm@42296
   163
    ("_context_xconst", typ "id_position => logic",    Delimfix "XCONST _"),
wenzelm@42296
   164
    ("_context_xconst", typ "id_position => aprop",    Delimfix "XCONST _"),
wenzelm@42296
   165
    ("_context_xconst", typ "longid_position => logic", Delimfix "XCONST _"),
wenzelm@42296
   166
    ("_context_xconst", typ "longid_position => aprop", Delimfix "XCONST _"),
wenzelm@35255
   167
    (const "==>",   typ "prop => prop => prop",        Delimfix "op ==>"),
wenzelm@52161
   168
    (const "dummy_pattern", typ "aprop",               Delimfix "'_"),
wenzelm@28856
   169
    ("_sort_constraint", typ "type => prop",           Delimfix "(1SORT'_CONSTRAINT/(1'(_')))"),
wenzelm@35255
   170
    (const "Pure.term", typ "logic => prop",           Delimfix "TERM _"),
wenzelm@35255
   171
    (const "Pure.conjunction", typ "prop => prop => prop", Infixr ("&&&", 2))]
wenzelm@26959
   172
  #> Sign.add_syntax_i applC_syntax
wenzelm@26430
   173
  #> Sign.add_modesyntax_i (Symbol.xsymbolsN, true)
wenzelm@35429
   174
   [(tycon "fun",         typ "type => type => type",   Mixfix ("(_/ \\<Rightarrow> _)", [1, 0], 0)),
wenzelm@35429
   175
    ("_bracket",          typ "types => type => type",  Mixfix ("([_]/ \\<Rightarrow> _)", [0, 0], 0)),
wenzelm@49685
   176
    ("_ofsort",           typ "tid_position => sort => type", Mixfix ("_\\<Colon>_", [1000, 0], 1000)),
wenzelm@35429
   177
    ("_constrain",        typ "logic => type => logic", Mixfix ("_\\<Colon>_", [4, 0], 3)),
wenzelm@42293
   178
    ("_constrain",        typ "prop' => type => prop'", Mixfix ("_\\<Colon>_", [4, 0], 3)),
wenzelm@42048
   179
    ("_idtyp",            typ "id_position => type => idt", Mixfix ("_\\<Colon>_", [], 0)),
wenzelm@35429
   180
    ("_idtypdummy",       typ "type => idt",            Mixfix ("'_()\\<Colon>_", [], 0)),
wenzelm@35429
   181
    ("_lambda",           typ "pttrns => 'a => logic",  Mixfix ("(3\\<lambda>_./ _)", [0, 3], 3)),
wenzelm@50636
   182
    (const "==",          typ "'a => 'a => prop",       Infix ("\\<equiv>", 2)),
wenzelm@35429
   183
    (const "all_binder",  typ "idts => prop => prop",   Mixfix ("(3\\<And>_./ _)", [0, 0], 0)),
wenzelm@35429
   184
    (const "==>",         typ "prop => prop => prop",   Infixr ("\\<Longrightarrow>", 1)),
wenzelm@35429
   185
    ("_DDDOT",            typ "aprop",                  Delimfix "\\<dots>"),
wenzelm@35429
   186
    ("_bigimpl",          typ "asms => prop => prop",   Mixfix ("((1\\<lbrakk>_\\<rbrakk>)/ \\<Longrightarrow> _)", [0, 1], 1)),
wenzelm@35429
   187
    ("_DDDOT",            typ "logic",                  Delimfix "\\<dots>")]
wenzelm@26430
   188
  #> Sign.add_modesyntax_i ("", false)
wenzelm@35255
   189
   [(const "prop", typ "prop => prop", Mixfix ("_", [0], 0))]
wenzelm@26430
   190
  #> Sign.add_modesyntax_i ("HTML", false)
wenzelm@24243
   191
   [("_lambda", typ "pttrns => 'a => logic", Mixfix ("(3\\<lambda>_./ _)", [0, 3], 3))]
wenzelm@26430
   192
  #> Sign.add_consts_i
nipkow@50603
   193
   [(Binding.name "==", typ "'a => 'a => prop", Infix ("==", 2)),
wenzelm@30344
   194
    (Binding.name "==>", typ "prop => prop => prop", Mixfix ("(_/ ==> _)", [2, 1], 1)),
wenzelm@30344
   195
    (Binding.name "all", typ "('a => prop) => prop", Binder ("!!", 0, 0)),
wenzelm@30344
   196
    (Binding.name "prop", typ "prop => prop", NoSyn),
wenzelm@30344
   197
    (Binding.name "TYPE", typ "'a itself", NoSyn),
wenzelm@52161
   198
    (Binding.name "dummy_pattern", typ "'a", Delimfix "'_")]
wenzelm@42375
   199
  #> Theory.add_deps_global "==" ("==", typ "'a => 'a => prop") []
wenzelm@42375
   200
  #> Theory.add_deps_global "==>" ("==>", typ "prop => prop => prop") []
wenzelm@42375
   201
  #> Theory.add_deps_global "all" ("all", typ "('a => prop) => prop") []
wenzelm@42375
   202
  #> Theory.add_deps_global "TYPE" ("TYPE", typ "'a itself") []
wenzelm@52161
   203
  #> Theory.add_deps_global "dummy_pattern" ("dummy_pattern", typ "'a") []
wenzelm@52143
   204
  #> Sign.parse_ast_translation Syntax_Trans.pure_parse_ast_translation
wenzelm@52143
   205
  #> Sign.parse_translation Syntax_Trans.pure_parse_translation
wenzelm@52143
   206
  #> Sign.print_ast_translation Syntax_Trans.pure_print_ast_translation
wenzelm@26430
   207
  #> Sign.local_path
wenzelm@26430
   208
  #> Sign.add_consts_i
wenzelm@30344
   209
   [(Binding.name "term", typ "'a => prop", NoSyn),
wenzelm@30344
   210
    (Binding.name "sort_constraint", typ "'a itself => prop", NoSyn),
wenzelm@30344
   211
    (Binding.name "conjunction", typ "prop => prop => prop", NoSyn)]
wenzelm@39557
   212
  #> (Global_Theory.add_defs false o map Thm.no_attributes)
haftmann@29579
   213
   [(Binding.name "prop_def", prop "(CONST prop :: prop => prop) (A::prop) == A::prop"),
haftmann@29579
   214
    (Binding.name "term_def", prop "(CONST Pure.term :: 'a => prop) (x::'a) == (!!A::prop. A ==> A)"),
haftmann@29579
   215
    (Binding.name "sort_constraint_def",
wenzelm@28622
   216
      prop "(CONST Pure.sort_constraint :: 'a itself => prop) (CONST TYPE :: 'a itself) ==\
wenzelm@28622
   217
      \ (CONST Pure.term :: 'a itself => prop) (CONST TYPE :: 'a itself)"),
haftmann@29579
   218
    (Binding.name "conjunction_def", prop "(A &&& B) == (!!C::prop. (A ==> B ==> C) ==> C)")] #> snd
wenzelm@28622
   219
  #> Sign.hide_const false "Pure.term"
wenzelm@28622
   220
  #> Sign.hide_const false "Pure.sort_constraint"
wenzelm@26666
   221
  #> Sign.hide_const false "Pure.conjunction"
wenzelm@39557
   222
  #> Global_Theory.add_thmss [((Binding.name "nothing", []), [])] #> snd
wenzelm@42375
   223
  #> fold (fn (a, prop) =>
wenzelm@53171
   224
      snd o Thm.add_axiom_global (Binding.name a, prop)) Proofterm.equality_axms);
wenzelm@3987
   225
wenzelm@3987
   226
end;