src/Pure/pure_thy.ML
author wenzelm
Fri Apr 08 15:02:11 2011 +0200 (2011-04-08)
changeset 42288 2074b31650e6
parent 42284 326f57825e1a
child 42290 b1f544c84040
permissions -rw-r--r--
discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
clarified Syntax.root;
     1 (*  Title:      Pure/pure_thy.ML
     2     Author:     Markus Wenzel, TU Muenchen
     3 
     4 Pure theory syntax and further logical content.
     5 *)
     6 
     7 signature PURE_THY =
     8 sig
     9   val old_appl_syntax: theory -> bool
    10   val old_appl_syntax_setup: theory -> theory
    11 end;
    12 
    13 structure Pure_Thy: PURE_THY =
    14 struct
    15 
    16 val typ = Simple_Syntax.read_typ;
    17 val prop = Simple_Syntax.read_prop;
    18 
    19 val tycon = Syntax.mark_type;
    20 val const = Syntax.mark_const;
    21 
    22 val typeT = Syntax_Ext.typeT;
    23 val spropT = Syntax_Ext.spropT;
    24 
    25 
    26 (* application syntax variants *)
    27 
    28 val appl_syntax =
    29  [("_appl", typ "('b => 'a) => args => logic", Mixfix ("(1_/(1'(_')))", [1000, 0], 1000)),
    30   ("_appl", typ "('b => 'a) => args => aprop", Mixfix ("(1_/(1'(_')))", [1000, 0], 1000))];
    31 
    32 val applC_syntax =
    33  [("",       typ "'a => cargs",                  Delimfix "_"),
    34   ("_cargs", typ "'a => cargs => cargs",         Mixfix ("_/ _", [1000, 1000], 1000)),
    35   ("_applC", typ "('b => 'a) => cargs => logic", Mixfix ("(1_/ _)", [1000, 1000], 999)),
    36   ("_applC", typ "('b => 'a) => cargs => aprop", Mixfix ("(1_/ _)", [1000, 1000], 999))];
    37 
    38 structure Old_Appl_Syntax = Theory_Data
    39 (
    40   type T = bool;
    41   val empty = false;
    42   val extend = I;
    43   fun merge (b1, b2) : T =
    44     if b1 = b2 then b1
    45     else error "Cannot merge theories with different application syntax";
    46 );
    47 
    48 val old_appl_syntax = Old_Appl_Syntax.get;
    49 
    50 val old_appl_syntax_setup =
    51   Old_Appl_Syntax.put true #>
    52   Sign.del_modesyntax_i Syntax.mode_default applC_syntax #>
    53   Sign.add_syntax_i appl_syntax;
    54 
    55 
    56 (* main content *)
    57 
    58 val _ = Context.>> (Context.map_theory
    59   (Sign.map_naming (Name_Space.set_theory_name Context.PureN) #>
    60    Old_Appl_Syntax.put false #>
    61    Sign.add_types
    62    [(Binding.name "fun", 2, NoSyn),
    63     (Binding.name "prop", 0, NoSyn),
    64     (Binding.name "itself", 1, NoSyn),
    65     (Binding.name "dummy", 0, NoSyn)]
    66   #> Sign.add_nonterminals (map Binding.name Syntax.basic_nonterms)
    67   #> Sign.add_syntax_i
    68    [("",            typ "tid => type",                 Delimfix "_"),
    69     ("",            typ "tvar => type",                Delimfix "_"),
    70     ("",            typ "type_name => type",           Delimfix "_"),
    71     ("_type_name",  typ "id => type_name",             Delimfix "_"),
    72     ("_type_name",  typ "longid => type_name",         Delimfix "_"),
    73     ("_ofsort",     typ "tid => sort => type",         Mixfix ("_::_", [Syntax.max_pri, 0], Syntax.max_pri)),
    74     ("_ofsort",     typ "tvar => sort => type",        Mixfix ("_::_", [Syntax.max_pri, 0], Syntax.max_pri)),
    75     ("_dummy_ofsort", typ "sort => type",              Mixfix ("'_()::_", [0], Syntax.max_pri)),
    76     ("",            typ "class_name => sort",          Delimfix "_"),
    77     ("_class_name", typ "id => class_name",            Delimfix "_"),
    78     ("_class_name", typ "longid => class_name",        Delimfix "_"),
    79     ("_topsort",    typ "sort",                        Delimfix "{}"),
    80     ("_sort",       typ "classes => sort",             Delimfix "{_}"),
    81     ("",            typ "class_name => classes",       Delimfix "_"),
    82     ("_classes",    typ "class_name => classes => classes", Delimfix "_,_"),
    83     ("_tapp",       typ "type => type_name => type",   Mixfix ("_ _", [Syntax.max_pri, 0], Syntax.max_pri)),
    84     ("_tappl",      typ "type => types => type_name => type", Delimfix "((1'(_,/ _')) _)"),
    85     ("",            typ "type => types",               Delimfix "_"),
    86     ("_types",      typ "type => types => types",      Delimfix "_,/ _"),
    87     ("\\<^type>fun", typ "type => type => type",       Mixfix ("(_/ => _)", [1, 0], 0)),
    88     ("_bracket",    typ "types => type => type",       Mixfix ("([_]/ => _)", [0, 0], 0)),
    89     ("",            typ "type => type",                Delimfix "'(_')"),
    90     ("\\<^type>dummy", typ "type",                     Delimfix "'_"),
    91     ("_type_prop",  typ "'a",                          NoSyn),
    92     ("_lambda",     typ "pttrns => 'a => logic",       Mixfix ("(3%_./ _)", [0, 3], 3)),
    93     ("_abs",        typ "'a",                          NoSyn),
    94     ("",            typ "'a => args",                  Delimfix "_"),
    95     ("_args",       typ "'a => args => args",          Delimfix "_,/ _"),
    96     ("",            typ "id_position => idt",          Delimfix "_"),
    97     ("_idtdummy",   typ "idt",                         Delimfix "'_"),
    98     ("_idtyp",      typ "id_position => type => idt",  Mixfix ("_::_", [], 0)),
    99     ("_idtypdummy", typ "type => idt",                 Mixfix ("'_()::_", [], 0)),
   100     ("",            typ "idt => idt",                  Delimfix "'(_')"),
   101     ("",            typ "idt => idts",                 Delimfix "_"),
   102     ("_idts",       typ "idt => idts => idts",         Mixfix ("_/ _", [1, 0], 0)),
   103     ("",            typ "idt => pttrn",                Delimfix "_"),
   104     ("",            typ "pttrn => pttrns",             Delimfix "_"),
   105     ("_pttrns",     typ "pttrn => pttrns => pttrns",   Mixfix ("_/ _", [1, 0], 0)),
   106     ("",            typ "aprop => aprop",              Delimfix "'(_')"),
   107     ("",            typ "id_position => aprop",        Delimfix "_"),
   108     ("",            typ "longid_position => aprop",    Delimfix "_"),
   109     ("",            typ "var => aprop",                Delimfix "_"),
   110     ("_DDDOT",      typ "aprop",                       Delimfix "..."),
   111     ("_aprop",      typ "aprop => prop",               Delimfix "PROP _"),
   112     ("_asm",        typ "prop => asms",                Delimfix "_"),
   113     ("_asms",       typ "prop => asms => asms",        Delimfix "_;/ _"),
   114     ("_bigimpl",    typ "asms => prop => prop",        Mixfix ("((3[| _ |])/ ==> _)", [0, 1], 1)),
   115     ("_ofclass",    typ "type => logic => prop",       Delimfix "(1OFCLASS/(1'(_,/ _')))"),
   116     ("_mk_ofclass", typ "dummy",                       NoSyn),
   117     ("_TYPE",       typ "type => logic",               Delimfix "(1TYPE/(1'(_')))"),
   118     ("",            typ "id_position => logic",        Delimfix "_"),
   119     ("",            typ "longid_position => logic",    Delimfix "_"),
   120     ("",            typ "var => logic",                Delimfix "_"),
   121     ("_DDDOT",      typ "logic",                       Delimfix "..."),
   122     ("_strip_positions", typ "'a", NoSyn),
   123     ("_constify",   typ "num => num_const",            Delimfix "_"),
   124     ("_constify",   typ "float_token => float_const",  Delimfix "_"),
   125     ("_indexnum",   typ "num_const => index",          Delimfix "\\<^sub>_"),
   126     ("_index",      typ "logic => index",              Delimfix "(00\\<^bsub>_\\<^esub>)"),
   127     ("_indexdefault", typ "index",                     Delimfix ""),
   128     ("_indexvar",   typ "index",                       Delimfix "'\\<index>"),
   129     ("_struct",     typ "index => logic",              Mixfix ("\\<struct>_", [1000], 1000)),
   130     ("_update_name", typ "idt",                        NoSyn),
   131     ("_constrainAbs", typ "'a",                       NoSyn),
   132     ("_constrain_position", typ "id => id_position",   Delimfix "_"),
   133     ("_constrain_position", typ "longid => longid_position", Delimfix "_"),
   134     ("_type_constraint_", typ "'a",                    NoSyn),
   135     (const "==>",   typ "prop => prop => prop",        Delimfix "op ==>"),
   136     (const Term.dummy_patternN, typ "aprop",           Delimfix "'_"),
   137     ("_sort_constraint", typ "type => prop",           Delimfix "(1SORT'_CONSTRAINT/(1'(_')))"),
   138     (const "Pure.term", typ "logic => prop",           Delimfix "TERM _"),
   139     (const "Pure.conjunction", typ "prop => prop => prop", Infixr ("&&&", 2))]
   140   #> Sign.add_syntax_i applC_syntax
   141   #> Sign.add_modesyntax_i (Symbol.xsymbolsN, true)
   142    [(tycon "fun",         typ "type => type => type",   Mixfix ("(_/ \\<Rightarrow> _)", [1, 0], 0)),
   143     ("_bracket",          typ "types => type => type",  Mixfix ("([_]/ \\<Rightarrow> _)", [0, 0], 0)),
   144     ("_ofsort",           typ "tid => sort => type",    Mixfix ("_\\<Colon>_", [1000, 0], 1000)),
   145     ("_constrain",        typ "logic => type => logic", Mixfix ("_\\<Colon>_", [4, 0], 3)),
   146     ("_constrain",        [spropT, typeT] ---> spropT,  Mixfix ("_\\<Colon>_", [4, 0], 3)),
   147     ("_idtyp",            typ "id_position => type => idt", Mixfix ("_\\<Colon>_", [], 0)),
   148     ("_idtypdummy",       typ "type => idt",            Mixfix ("'_()\\<Colon>_", [], 0)),
   149     ("_lambda",           typ "pttrns => 'a => logic",  Mixfix ("(3\\<lambda>_./ _)", [0, 3], 3)),
   150     (const "==",          typ "'a => 'a => prop",       Infixr ("\\<equiv>", 2)),
   151     (const "all_binder",  typ "idts => prop => prop",   Mixfix ("(3\\<And>_./ _)", [0, 0], 0)),
   152     (const "==>",         typ "prop => prop => prop",   Infixr ("\\<Longrightarrow>", 1)),
   153     ("_DDDOT",            typ "aprop",                  Delimfix "\\<dots>"),
   154     ("_bigimpl",          typ "asms => prop => prop",   Mixfix ("((1\\<lbrakk>_\\<rbrakk>)/ \\<Longrightarrow> _)", [0, 1], 1)),
   155     ("_DDDOT",            typ "logic",                  Delimfix "\\<dots>")]
   156   #> Sign.add_modesyntax_i ("", false)
   157    [(const "prop", typ "prop => prop", Mixfix ("_", [0], 0))]
   158   #> Sign.add_modesyntax_i ("HTML", false)
   159    [("_lambda", typ "pttrns => 'a => logic", Mixfix ("(3\\<lambda>_./ _)", [0, 3], 3))]
   160   #> Sign.add_consts_i
   161    [(Binding.name "==", typ "'a => 'a => prop", Infixr ("==", 2)),
   162     (Binding.name "==>", typ "prop => prop => prop", Mixfix ("(_/ ==> _)", [2, 1], 1)),
   163     (Binding.name "all", typ "('a => prop) => prop", Binder ("!!", 0, 0)),
   164     (Binding.name "prop", typ "prop => prop", NoSyn),
   165     (Binding.name "TYPE", typ "'a itself", NoSyn),
   166     (Binding.name Term.dummy_patternN, typ "'a", Delimfix "'_")]
   167   #> Theory.add_deps "==" ("==", typ "'a => 'a => prop") []
   168   #> Theory.add_deps "==>" ("==>", typ "prop => prop => prop") []
   169   #> Theory.add_deps "all" ("all", typ "('a => prop) => prop") []
   170   #> Theory.add_deps "TYPE" ("TYPE", typ "'a itself") []
   171   #> Theory.add_deps Term.dummy_patternN (Term.dummy_patternN, typ "'a") []
   172   #> Sign.add_trfuns Syntax_Trans.pure_trfuns
   173   #> Sign.local_path
   174   #> Sign.add_consts_i
   175    [(Binding.name "term", typ "'a => prop", NoSyn),
   176     (Binding.name "sort_constraint", typ "'a itself => prop", NoSyn),
   177     (Binding.name "conjunction", typ "prop => prop => prop", NoSyn)]
   178   #> (Global_Theory.add_defs false o map Thm.no_attributes)
   179    [(Binding.name "prop_def", prop "(CONST prop :: prop => prop) (A::prop) == A::prop"),
   180     (Binding.name "term_def", prop "(CONST Pure.term :: 'a => prop) (x::'a) == (!!A::prop. A ==> A)"),
   181     (Binding.name "sort_constraint_def",
   182       prop "(CONST Pure.sort_constraint :: 'a itself => prop) (CONST TYPE :: 'a itself) ==\
   183       \ (CONST Pure.term :: 'a itself => prop) (CONST TYPE :: 'a itself)"),
   184     (Binding.name "conjunction_def", prop "(A &&& B) == (!!C::prop. (A ==> B ==> C) ==> C)")] #> snd
   185   #> Sign.hide_const false "Pure.term"
   186   #> Sign.hide_const false "Pure.sort_constraint"
   187   #> Sign.hide_const false "Pure.conjunction"
   188   #> Global_Theory.add_thmss [((Binding.name "nothing", []), [])] #> snd
   189   #> fold (fn (a, prop) => snd o Thm.add_axiom (Binding.name a, prop)) Proofterm.equality_axms));
   190 
   191 end;