src/Pure/pure_thy.ML
author wenzelm
Tue Mar 22 13:32:20 2011 +0100 (2011-03-22)
changeset 42048 afd11ca8e018
parent 39557 fe5722fce758
child 42057 3eba96ff3d3e
permissions -rw-r--r--
support for encoded positions (for id_position, longid_position) as pseudo type-constraints -- still inactive;
simplified/generalized abs_tr/binder_tr: allow iterated constraints, stemming from positions;
Ast.pretty_ast: special treatment of encoded positions;
eliminated Ast.str_of_ast in favour of uniform Ast.pretty_ast;
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@3987
    11
end;
wenzelm@3987
    12
wenzelm@39557
    13
structure Pure_Thy: PURE_THY =
wenzelm@3987
    14
struct
wenzelm@3987
    15
wenzelm@33384
    16
val typ = Simple_Syntax.read_typ;
wenzelm@33384
    17
val prop = Simple_Syntax.read_prop;
wenzelm@35429
    18
wenzelm@35429
    19
val tycon = Syntax.mark_type;
wenzelm@35262
    20
val const = Syntax.mark_const;
wenzelm@24243
    21
wenzelm@28856
    22
val typeT = Syntax.typeT;
wenzelm@28856
    23
val spropT = Syntax.spropT;
wenzelm@28856
    24
wenzelm@26959
    25
wenzelm@26959
    26
(* application syntax variants *)
wenzelm@26959
    27
wenzelm@26959
    28
val appl_syntax =
wenzelm@26959
    29
 [("_appl", typ "('b => 'a) => args => logic", Mixfix ("(1_/(1'(_')))", [1000, 0], 1000)),
wenzelm@26959
    30
  ("_appl", typ "('b => 'a) => args => aprop", Mixfix ("(1_/(1'(_')))", [1000, 0], 1000))];
wenzelm@26959
    31
wenzelm@26959
    32
val applC_syntax =
wenzelm@26959
    33
 [("",       typ "'a => cargs",                  Delimfix "_"),
wenzelm@26959
    34
  ("_cargs", typ "'a => cargs => cargs",         Mixfix ("_/ _", [1000, 1000], 1000)),
wenzelm@26959
    35
  ("_applC", typ "('b => 'a) => cargs => logic", Mixfix ("(1_/ _)", [1000, 1000], 999)),
wenzelm@26959
    36
  ("_applC", typ "('b => 'a) => cargs => aprop", Mixfix ("(1_/ _)", [1000, 1000], 999))];
wenzelm@26959
    37
wenzelm@37216
    38
structure Old_Appl_Syntax = Theory_Data
wenzelm@26959
    39
(
wenzelm@26959
    40
  type T = bool;
wenzelm@26959
    41
  val empty = false;
wenzelm@26959
    42
  val extend = I;
wenzelm@33522
    43
  fun merge (b1, b2) : T =
wenzelm@26959
    44
    if b1 = b2 then b1
wenzelm@26959
    45
    else error "Cannot merge theories with different application syntax";
wenzelm@26959
    46
);
wenzelm@26959
    47
wenzelm@37216
    48
val old_appl_syntax = Old_Appl_Syntax.get;
wenzelm@26959
    49
wenzelm@26959
    50
val old_appl_syntax_setup =
wenzelm@37216
    51
  Old_Appl_Syntax.put true #>
wenzelm@26959
    52
  Sign.del_modesyntax_i Syntax.mode_default applC_syntax #>
wenzelm@26959
    53
  Sign.add_syntax_i appl_syntax;
wenzelm@26959
    54
wenzelm@26959
    55
wenzelm@26959
    56
(* main content *)
wenzelm@26959
    57
wenzelm@26463
    58
val _ = Context.>> (Context.map_theory
haftmann@33365
    59
  (Sign.map_naming (Name_Space.set_theory_name Context.PureN) #>
wenzelm@37216
    60
   Old_Appl_Syntax.put false #>
wenzelm@26959
    61
   Sign.add_types
wenzelm@30344
    62
   [(Binding.name "fun", 2, NoSyn),
wenzelm@30344
    63
    (Binding.name "prop", 0, NoSyn),
wenzelm@30344
    64
    (Binding.name "itself", 1, NoSyn),
wenzelm@30344
    65
    (Binding.name "dummy", 0, NoSyn)]
wenzelm@30344
    66
  #> Sign.add_nonterminals (map Binding.name Syntax.basic_nonterms)
wenzelm@26430
    67
  #> Sign.add_syntax_i
wenzelm@26436
    68
   [("_lambda",     typ "pttrns => 'a => logic",       Mixfix ("(3%_./ _)", [0, 3], 3)),
wenzelm@26436
    69
    ("_abs",        typ "'a",                          NoSyn),
wenzelm@26436
    70
    ("",            typ "'a => args",                  Delimfix "_"),
wenzelm@26436
    71
    ("_args",       typ "'a => args => args",          Delimfix "_,/ _"),
wenzelm@42048
    72
    ("",            typ "id_position => idt",          Delimfix "_"),
wenzelm@26436
    73
    ("_idtdummy",   typ "idt",                         Delimfix "'_"),
wenzelm@42048
    74
    ("_idtyp",      typ "id_position => type => idt",  Mixfix ("_::_", [], 0)),
wenzelm@26436
    75
    ("_idtypdummy", typ "type => idt",                 Mixfix ("'_()::_", [], 0)),
wenzelm@26436
    76
    ("",            typ "idt => idt",                  Delimfix "'(_')"),
wenzelm@26436
    77
    ("",            typ "idt => idts",                 Delimfix "_"),
wenzelm@26436
    78
    ("_idts",       typ "idt => idts => idts",         Mixfix ("_/ _", [1, 0], 0)),
wenzelm@26436
    79
    ("",            typ "idt => pttrn",                Delimfix "_"),
wenzelm@26436
    80
    ("",            typ "pttrn => pttrns",             Delimfix "_"),
wenzelm@26436
    81
    ("_pttrns",     typ "pttrn => pttrns => pttrns",   Mixfix ("_/ _", [1, 0], 0)),
wenzelm@28856
    82
    ("",            typ "aprop => aprop",              Delimfix "'(_')"),
wenzelm@42048
    83
    ("",            typ "id_position => aprop",        Delimfix "_"),
wenzelm@42048
    84
    ("",            typ "longid_position => aprop",    Delimfix "_"),
wenzelm@26436
    85
    ("",            typ "var => aprop",                Delimfix "_"),
wenzelm@26436
    86
    ("_DDDOT",      typ "aprop",                       Delimfix "..."),
wenzelm@26436
    87
    ("_aprop",      typ "aprop => prop",               Delimfix "PROP _"),
wenzelm@26436
    88
    ("_asm",        typ "prop => asms",                Delimfix "_"),
wenzelm@26436
    89
    ("_asms",       typ "prop => asms => asms",        Delimfix "_;/ _"),
wenzelm@26436
    90
    ("_bigimpl",    typ "asms => prop => prop",        Mixfix ("((3[| _ |])/ ==> _)", [0, 1], 1)),
wenzelm@26436
    91
    ("_ofclass",    typ "type => logic => prop",       Delimfix "(1OFCLASS/(1'(_,/ _')))"),
wenzelm@26436
    92
    ("_mk_ofclass", typ "dummy",                       NoSyn),
wenzelm@26436
    93
    ("_TYPE",       typ "type => logic",               Delimfix "(1TYPE/(1'(_')))"),
wenzelm@42048
    94
    ("",            typ "id_position => logic",        Delimfix "_"),
wenzelm@42048
    95
    ("",            typ "longid_position => logic",    Delimfix "_"),
wenzelm@26436
    96
    ("",            typ "var => logic",                Delimfix "_"),
wenzelm@26436
    97
    ("_DDDOT",      typ "logic",                       Delimfix "..."),
wenzelm@26436
    98
    ("_constify",   typ "num => num_const",            Delimfix "_"),
wenzelm@29156
    99
    ("_constify",   typ "float_token => float_const",  Delimfix "_"),
wenzelm@26436
   100
    ("_indexnum",   typ "num_const => index",          Delimfix "\\<^sub>_"),
wenzelm@26436
   101
    ("_index",      typ "logic => index",              Delimfix "(00\\<^bsub>_\\<^esub>)"),
wenzelm@26436
   102
    ("_indexdefault", typ "index",                     Delimfix ""),
wenzelm@26436
   103
    ("_indexvar",   typ "index",                       Delimfix "'\\<index>"),
wenzelm@26436
   104
    ("_struct",     typ "index => logic",              Mixfix ("\\<struct>_", [1000], 1000)),
wenzelm@35145
   105
    ("_update_name", typ "idt",                        NoSyn),
wenzelm@38975
   106
    (Syntax.constrainAbsC, typ "'a",                   NoSyn),
wenzelm@42048
   107
    ("_constrain_position", typ "id => id_position",   Delimfix "_"),
wenzelm@42048
   108
    ("_constrain_position", typ "longid => longid_position", Delimfix "_"),
wenzelm@42048
   109
    ("_type_constraint_", typ "'a",                    NoSyn),
wenzelm@35255
   110
    (const "==>",   typ "prop => prop => prop",        Delimfix "op ==>"),
wenzelm@35255
   111
    (const Term.dummy_patternN, typ "aprop",           Delimfix "'_"),
wenzelm@28856
   112
    ("_sort_constraint", typ "type => prop",           Delimfix "(1SORT'_CONSTRAINT/(1'(_')))"),
wenzelm@35255
   113
    (const "Pure.term", typ "logic => prop",           Delimfix "TERM _"),
wenzelm@35255
   114
    (const "Pure.conjunction", typ "prop => prop => prop", Infixr ("&&&", 2))]
wenzelm@26959
   115
  #> Sign.add_syntax_i applC_syntax
wenzelm@26430
   116
  #> Sign.add_modesyntax_i (Symbol.xsymbolsN, true)
wenzelm@35429
   117
   [(tycon "fun",         typ "type => type => type",   Mixfix ("(_/ \\<Rightarrow> _)", [1, 0], 0)),
wenzelm@35429
   118
    ("_bracket",          typ "types => type => type",  Mixfix ("([_]/ \\<Rightarrow> _)", [0, 0], 0)),
wenzelm@35429
   119
    ("_ofsort",           typ "tid => sort => type",    Mixfix ("_\\<Colon>_", [1000, 0], 1000)),
wenzelm@35429
   120
    ("_constrain",        typ "logic => type => logic", Mixfix ("_\\<Colon>_", [4, 0], 3)),
wenzelm@35429
   121
    ("_constrain",        [spropT, typeT] ---> spropT,  Mixfix ("_\\<Colon>_", [4, 0], 3)),
wenzelm@42048
   122
    ("_idtyp",            typ "id_position => type => idt", Mixfix ("_\\<Colon>_", [], 0)),
wenzelm@35429
   123
    ("_idtypdummy",       typ "type => idt",            Mixfix ("'_()\\<Colon>_", [], 0)),
wenzelm@35429
   124
    ("_lambda",           typ "pttrns => 'a => logic",  Mixfix ("(3\\<lambda>_./ _)", [0, 3], 3)),
wenzelm@35429
   125
    (const "==",          typ "'a => 'a => prop",       Infixr ("\\<equiv>", 2)),
wenzelm@35429
   126
    (const "all_binder",  typ "idts => prop => prop",   Mixfix ("(3\\<And>_./ _)", [0, 0], 0)),
wenzelm@35429
   127
    (const "==>",         typ "prop => prop => prop",   Infixr ("\\<Longrightarrow>", 1)),
wenzelm@35429
   128
    ("_DDDOT",            typ "aprop",                  Delimfix "\\<dots>"),
wenzelm@35429
   129
    ("_bigimpl",          typ "asms => prop => prop",   Mixfix ("((1\\<lbrakk>_\\<rbrakk>)/ \\<Longrightarrow> _)", [0, 1], 1)),
wenzelm@35429
   130
    ("_DDDOT",            typ "logic",                  Delimfix "\\<dots>")]
wenzelm@26430
   131
  #> Sign.add_modesyntax_i ("", false)
wenzelm@35255
   132
   [(const "prop", typ "prop => prop", Mixfix ("_", [0], 0))]
wenzelm@26430
   133
  #> Sign.add_modesyntax_i ("HTML", false)
wenzelm@24243
   134
   [("_lambda", typ "pttrns => 'a => logic", Mixfix ("(3\\<lambda>_./ _)", [0, 3], 3))]
wenzelm@26430
   135
  #> Sign.add_consts_i
wenzelm@35130
   136
   [(Binding.name "==", typ "'a => 'a => prop", Infixr ("==", 2)),
wenzelm@30344
   137
    (Binding.name "==>", typ "prop => prop => prop", Mixfix ("(_/ ==> _)", [2, 1], 1)),
wenzelm@30344
   138
    (Binding.name "all", typ "('a => prop) => prop", Binder ("!!", 0, 0)),
wenzelm@30344
   139
    (Binding.name "prop", typ "prop => prop", NoSyn),
wenzelm@30344
   140
    (Binding.name "TYPE", typ "'a itself", NoSyn),
wenzelm@30344
   141
    (Binding.name Term.dummy_patternN, typ "'a", Delimfix "'_")]
wenzelm@26430
   142
  #> Theory.add_deps "==" ("==", typ "'a => 'a => prop") []
wenzelm@26430
   143
  #> Theory.add_deps "==>" ("==>", typ "prop => prop => prop") []
wenzelm@26430
   144
  #> Theory.add_deps "all" ("all", typ "('a => prop) => prop") []
wenzelm@26430
   145
  #> Theory.add_deps "TYPE" ("TYPE", typ "'a itself") []
wenzelm@26430
   146
  #> Theory.add_deps Term.dummy_patternN (Term.dummy_patternN, typ "'a") []
wenzelm@26430
   147
  #> Sign.add_trfuns Syntax.pure_trfuns
wenzelm@26430
   148
  #> Sign.add_trfunsT Syntax.pure_trfunsT
wenzelm@26430
   149
  #> Sign.local_path
wenzelm@26430
   150
  #> Sign.add_consts_i
wenzelm@30344
   151
   [(Binding.name "term", typ "'a => prop", NoSyn),
wenzelm@30344
   152
    (Binding.name "sort_constraint", typ "'a itself => prop", NoSyn),
wenzelm@30344
   153
    (Binding.name "conjunction", typ "prop => prop => prop", NoSyn)]
wenzelm@39557
   154
  #> (Global_Theory.add_defs false o map Thm.no_attributes)
haftmann@29579
   155
   [(Binding.name "prop_def", prop "(CONST prop :: prop => prop) (A::prop) == A::prop"),
haftmann@29579
   156
    (Binding.name "term_def", prop "(CONST Pure.term :: 'a => prop) (x::'a) == (!!A::prop. A ==> A)"),
haftmann@29579
   157
    (Binding.name "sort_constraint_def",
wenzelm@28622
   158
      prop "(CONST Pure.sort_constraint :: 'a itself => prop) (CONST TYPE :: 'a itself) ==\
wenzelm@28622
   159
      \ (CONST Pure.term :: 'a itself => prop) (CONST TYPE :: 'a itself)"),
haftmann@29579
   160
    (Binding.name "conjunction_def", prop "(A &&& B) == (!!C::prop. (A ==> B ==> C) ==> C)")] #> snd
wenzelm@28622
   161
  #> Sign.hide_const false "Pure.term"
wenzelm@28622
   162
  #> Sign.hide_const false "Pure.sort_constraint"
wenzelm@26666
   163
  #> Sign.hide_const false "Pure.conjunction"
wenzelm@39557
   164
  #> Global_Theory.add_thmss [((Binding.name "nothing", []), [])] #> snd
wenzelm@35856
   165
  #> fold (fn (a, prop) => snd o Thm.add_axiom (Binding.name a, prop)) Proofterm.equality_axms));
wenzelm@3987
   166
wenzelm@3987
   167
end;