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;
     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.typeT;
    23 val spropT = Syntax.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    [("_lambda",     typ "pttrns => 'a => logic",       Mixfix ("(3%_./ _)", [0, 3], 3)),
    69     ("_abs",        typ "'a",                          NoSyn),
    70     ("",            typ "'a => args",                  Delimfix "_"),
    71     ("_args",       typ "'a => args => args",          Delimfix "_,/ _"),
    72     ("",            typ "id_position => idt",          Delimfix "_"),
    73     ("_idtdummy",   typ "idt",                         Delimfix "'_"),
    74     ("_idtyp",      typ "id_position => type => idt",  Mixfix ("_::_", [], 0)),
    75     ("_idtypdummy", typ "type => idt",                 Mixfix ("'_()::_", [], 0)),
    76     ("",            typ "idt => idt",                  Delimfix "'(_')"),
    77     ("",            typ "idt => idts",                 Delimfix "_"),
    78     ("_idts",       typ "idt => idts => idts",         Mixfix ("_/ _", [1, 0], 0)),
    79     ("",            typ "idt => pttrn",                Delimfix "_"),
    80     ("",            typ "pttrn => pttrns",             Delimfix "_"),
    81     ("_pttrns",     typ "pttrn => pttrns => pttrns",   Mixfix ("_/ _", [1, 0], 0)),
    82     ("",            typ "aprop => aprop",              Delimfix "'(_')"),
    83     ("",            typ "id_position => aprop",        Delimfix "_"),
    84     ("",            typ "longid_position => aprop",    Delimfix "_"),
    85     ("",            typ "var => aprop",                Delimfix "_"),
    86     ("_DDDOT",      typ "aprop",                       Delimfix "..."),
    87     ("_aprop",      typ "aprop => prop",               Delimfix "PROP _"),
    88     ("_asm",        typ "prop => asms",                Delimfix "_"),
    89     ("_asms",       typ "prop => asms => asms",        Delimfix "_;/ _"),
    90     ("_bigimpl",    typ "asms => prop => prop",        Mixfix ("((3[| _ |])/ ==> _)", [0, 1], 1)),
    91     ("_ofclass",    typ "type => logic => prop",       Delimfix "(1OFCLASS/(1'(_,/ _')))"),
    92     ("_mk_ofclass", typ "dummy",                       NoSyn),
    93     ("_TYPE",       typ "type => logic",               Delimfix "(1TYPE/(1'(_')))"),
    94     ("",            typ "id_position => logic",        Delimfix "_"),
    95     ("",            typ "longid_position => logic",    Delimfix "_"),
    96     ("",            typ "var => logic",                Delimfix "_"),
    97     ("_DDDOT",      typ "logic",                       Delimfix "..."),
    98     ("_constify",   typ "num => num_const",            Delimfix "_"),
    99     ("_constify",   typ "float_token => float_const",  Delimfix "_"),
   100     ("_indexnum",   typ "num_const => index",          Delimfix "\\<^sub>_"),
   101     ("_index",      typ "logic => index",              Delimfix "(00\\<^bsub>_\\<^esub>)"),
   102     ("_indexdefault", typ "index",                     Delimfix ""),
   103     ("_indexvar",   typ "index",                       Delimfix "'\\<index>"),
   104     ("_struct",     typ "index => logic",              Mixfix ("\\<struct>_", [1000], 1000)),
   105     ("_update_name", typ "idt",                        NoSyn),
   106     (Syntax.constrainAbsC, typ "'a",                   NoSyn),
   107     ("_constrain_position", typ "id => id_position",   Delimfix "_"),
   108     ("_constrain_position", typ "longid => longid_position", Delimfix "_"),
   109     ("_type_constraint_", typ "'a",                    NoSyn),
   110     (const "==>",   typ "prop => prop => prop",        Delimfix "op ==>"),
   111     (const Term.dummy_patternN, typ "aprop",           Delimfix "'_"),
   112     ("_sort_constraint", typ "type => prop",           Delimfix "(1SORT'_CONSTRAINT/(1'(_')))"),
   113     (const "Pure.term", typ "logic => prop",           Delimfix "TERM _"),
   114     (const "Pure.conjunction", typ "prop => prop => prop", Infixr ("&&&", 2))]
   115   #> Sign.add_syntax_i applC_syntax
   116   #> Sign.add_modesyntax_i (Symbol.xsymbolsN, true)
   117    [(tycon "fun",         typ "type => type => type",   Mixfix ("(_/ \\<Rightarrow> _)", [1, 0], 0)),
   118     ("_bracket",          typ "types => type => type",  Mixfix ("([_]/ \\<Rightarrow> _)", [0, 0], 0)),
   119     ("_ofsort",           typ "tid => sort => type",    Mixfix ("_\\<Colon>_", [1000, 0], 1000)),
   120     ("_constrain",        typ "logic => type => logic", Mixfix ("_\\<Colon>_", [4, 0], 3)),
   121     ("_constrain",        [spropT, typeT] ---> spropT,  Mixfix ("_\\<Colon>_", [4, 0], 3)),
   122     ("_idtyp",            typ "id_position => type => idt", Mixfix ("_\\<Colon>_", [], 0)),
   123     ("_idtypdummy",       typ "type => idt",            Mixfix ("'_()\\<Colon>_", [], 0)),
   124     ("_lambda",           typ "pttrns => 'a => logic",  Mixfix ("(3\\<lambda>_./ _)", [0, 3], 3)),
   125     (const "==",          typ "'a => 'a => prop",       Infixr ("\\<equiv>", 2)),
   126     (const "all_binder",  typ "idts => prop => prop",   Mixfix ("(3\\<And>_./ _)", [0, 0], 0)),
   127     (const "==>",         typ "prop => prop => prop",   Infixr ("\\<Longrightarrow>", 1)),
   128     ("_DDDOT",            typ "aprop",                  Delimfix "\\<dots>"),
   129     ("_bigimpl",          typ "asms => prop => prop",   Mixfix ("((1\\<lbrakk>_\\<rbrakk>)/ \\<Longrightarrow> _)", [0, 1], 1)),
   130     ("_DDDOT",            typ "logic",                  Delimfix "\\<dots>")]
   131   #> Sign.add_modesyntax_i ("", false)
   132    [(const "prop", typ "prop => prop", Mixfix ("_", [0], 0))]
   133   #> Sign.add_modesyntax_i ("HTML", false)
   134    [("_lambda", typ "pttrns => 'a => logic", Mixfix ("(3\\<lambda>_./ _)", [0, 3], 3))]
   135   #> Sign.add_consts_i
   136    [(Binding.name "==", typ "'a => 'a => prop", Infixr ("==", 2)),
   137     (Binding.name "==>", typ "prop => prop => prop", Mixfix ("(_/ ==> _)", [2, 1], 1)),
   138     (Binding.name "all", typ "('a => prop) => prop", Binder ("!!", 0, 0)),
   139     (Binding.name "prop", typ "prop => prop", NoSyn),
   140     (Binding.name "TYPE", typ "'a itself", NoSyn),
   141     (Binding.name Term.dummy_patternN, typ "'a", Delimfix "'_")]
   142   #> Theory.add_deps "==" ("==", typ "'a => 'a => prop") []
   143   #> Theory.add_deps "==>" ("==>", typ "prop => prop => prop") []
   144   #> Theory.add_deps "all" ("all", typ "('a => prop) => prop") []
   145   #> Theory.add_deps "TYPE" ("TYPE", typ "'a itself") []
   146   #> Theory.add_deps Term.dummy_patternN (Term.dummy_patternN, typ "'a") []
   147   #> Sign.add_trfuns Syntax.pure_trfuns
   148   #> Sign.add_trfunsT Syntax.pure_trfunsT
   149   #> Sign.local_path
   150   #> Sign.add_consts_i
   151    [(Binding.name "term", typ "'a => prop", NoSyn),
   152     (Binding.name "sort_constraint", typ "'a itself => prop", NoSyn),
   153     (Binding.name "conjunction", typ "prop => prop => prop", NoSyn)]
   154   #> (Global_Theory.add_defs false o map Thm.no_attributes)
   155    [(Binding.name "prop_def", prop "(CONST prop :: prop => prop) (A::prop) == A::prop"),
   156     (Binding.name "term_def", prop "(CONST Pure.term :: 'a => prop) (x::'a) == (!!A::prop. A ==> A)"),
   157     (Binding.name "sort_constraint_def",
   158       prop "(CONST Pure.sort_constraint :: 'a itself => prop) (CONST TYPE :: 'a itself) ==\
   159       \ (CONST Pure.term :: 'a itself => prop) (CONST TYPE :: 'a itself)"),
   160     (Binding.name "conjunction_def", prop "(A &&& B) == (!!C::prop. (A ==> B ==> C) ==> C)")] #> snd
   161   #> Sign.hide_const false "Pure.term"
   162   #> Sign.hide_const false "Pure.sort_constraint"
   163   #> Sign.hide_const false "Pure.conjunction"
   164   #> Global_Theory.add_thmss [((Binding.name "nothing", []), [])] #> snd
   165   #> fold (fn (a, prop) => snd o Thm.add_axiom (Binding.name a, prop)) Proofterm.equality_axms));
   166 
   167 end;