src/Pure/pure_thy.ML
author wenzelm
Fri Mar 21 11:42:32 2014 +0100 (2014-03-21)
changeset 56241 029246729dc0
parent 56240 938c6c7e10eb
child 56243 2e10a36b8d46
permissions -rw-r--r--
more qualified names;
     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   val token_markers: string list
    12 end;
    13 
    14 structure Pure_Thy: PURE_THY =
    15 struct
    16 
    17 val typ = Simple_Syntax.read_typ;
    18 val prop = Simple_Syntax.read_prop;
    19 
    20 val tycon = Lexicon.mark_type;
    21 val const = Lexicon.mark_const;
    22 
    23 val qualify = Binding.qualify true Context.PureN;
    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_syntax Syntax.mode_default applC_syntax #>
    53   Sign.add_syntax Syntax.mode_default appl_syntax;
    54 
    55 
    56 (* main content *)
    57 
    58 val token_markers =
    59   ["_tfree", "_tvar", "_free", "_bound", "_loose", "_var", "_numeral", "_inner_string"];
    60 
    61 val _ = Theory.setup
    62   (Sign.map_naming (Name_Space.set_theory_name Context.PureN) #>
    63    Old_Appl_Syntax.put false #>
    64    Sign.add_types_global
    65    [(Binding.name "fun", 2, NoSyn),
    66     (Binding.name "prop", 0, NoSyn),
    67     (Binding.name "itself", 1, NoSyn),
    68     (Binding.name "dummy", 0, NoSyn)]
    69   #> Sign.add_nonterminals_global
    70     (map Binding.name
    71       (Lexicon.terminals @ ["logic", "type", "types", "sort", "classes",
    72         "args", "cargs", "pttrn", "pttrns", "idt", "idts", "aprop", "asms",
    73         "any", "prop'", "num_const", "float_const", "xnum_const", "num_position",
    74         "float_position", "xnum_position", "index", "struct", "tid_position",
    75         "tvar_position", "id_position", "longid_position", "var_position",
    76         "str_position", "string_position", "cartouche_position", "type_name",
    77         "class_name"]))
    78   #> Sign.add_syntax Syntax.mode_default (map (fn x => (x, typ "'a", NoSyn)) token_markers)
    79   #> Sign.add_syntax Syntax.mode_default
    80    [("",            typ "prop' => prop",               Delimfix "_"),
    81     ("",            typ "logic => any",                Delimfix "_"),
    82     ("",            typ "prop' => any",                Delimfix "_"),
    83     ("",            typ "logic => logic",              Delimfix "'(_')"),
    84     ("",            typ "prop' => prop'",              Delimfix "'(_')"),
    85     ("_constrain",  typ "logic => type => logic",      Mixfix ("_::_", [4, 0], 3)),
    86     ("_constrain",  typ "prop' => type => prop'",      Mixfix ("_::_", [4, 0], 3)),
    87     ("_ignore_type", typ "'a",                         NoSyn),
    88     ("",            typ "tid_position => type",        Delimfix "_"),
    89     ("",            typ "tvar_position => type",       Delimfix "_"),
    90     ("",            typ "type_name => type",           Delimfix "_"),
    91     ("_type_name",  typ "id => type_name",             Delimfix "_"),
    92     ("_type_name",  typ "longid => type_name",         Delimfix "_"),
    93     ("_ofsort",     typ "tid_position => sort => type", Mixfix ("_::_", [1000, 0], 1000)),
    94     ("_ofsort",     typ "tvar_position => sort => type", Mixfix ("_::_", [1000, 0], 1000)),
    95     ("_dummy_ofsort", typ "sort => type",              Mixfix ("'_()::_", [0], 1000)),
    96     ("",            typ "class_name => sort",          Delimfix "_"),
    97     ("_class_name", typ "id => class_name",            Delimfix "_"),
    98     ("_class_name", typ "longid => class_name",        Delimfix "_"),
    99     ("_topsort",    typ "sort",                        Delimfix "{}"),
   100     ("_sort",       typ "classes => sort",             Delimfix "{_}"),
   101     ("",            typ "class_name => classes",       Delimfix "_"),
   102     ("_classes",    typ "class_name => classes => classes", Delimfix "_,_"),
   103     ("_tapp",       typ "type => type_name => type",   Mixfix ("_ _", [1000, 0], 1000)),
   104     ("_tappl",      typ "type => types => type_name => type", Delimfix "((1'(_,/ _')) _)"),
   105     ("",            typ "type => types",               Delimfix "_"),
   106     ("_types",      typ "type => types => types",      Delimfix "_,/ _"),
   107     ("\\<^type>fun", typ "type => type => type",       Mixfix ("(_/ => _)", [1, 0], 0)),
   108     ("_bracket",    typ "types => type => type",       Mixfix ("([_]/ => _)", [0, 0], 0)),
   109     ("",            typ "type => type",                Delimfix "'(_')"),
   110     ("\\<^type>dummy", typ "type",                     Delimfix "'_"),
   111     ("_type_prop",  typ "'a",                          NoSyn),
   112     ("_lambda",     typ "pttrns => 'a => logic",       Mixfix ("(3%_./ _)", [0, 3], 3)),
   113     ("_abs",        typ "'a",                          NoSyn),
   114     ("",            typ "'a => args",                  Delimfix "_"),
   115     ("_args",       typ "'a => args => args",          Delimfix "_,/ _"),
   116     ("",            typ "id_position => idt",          Delimfix "_"),
   117     ("_idtdummy",   typ "idt",                         Delimfix "'_"),
   118     ("_idtyp",      typ "id_position => type => idt",  Mixfix ("_::_", [], 0)),
   119     ("_idtypdummy", typ "type => idt",                 Mixfix ("'_()::_", [], 0)),
   120     ("",            typ "idt => idt",                  Delimfix "'(_')"),
   121     ("",            typ "idt => idts",                 Delimfix "_"),
   122     ("_idts",       typ "idt => idts => idts",         Mixfix ("_/ _", [1, 0], 0)),
   123     ("",            typ "idt => pttrn",                Delimfix "_"),
   124     ("",            typ "pttrn => pttrns",             Delimfix "_"),
   125     ("_pttrns",     typ "pttrn => pttrns => pttrns",   Mixfix ("_/ _", [1, 0], 0)),
   126     ("",            typ "aprop => aprop",              Delimfix "'(_')"),
   127     ("",            typ "id_position => aprop",        Delimfix "_"),
   128     ("",            typ "longid_position => aprop",    Delimfix "_"),
   129     ("",            typ "var_position => aprop",       Delimfix "_"),
   130     ("_DDDOT",      typ "aprop",                       Delimfix "..."),
   131     ("_aprop",      typ "aprop => prop",               Delimfix "PROP _"),
   132     ("_asm",        typ "prop => asms",                Delimfix "_"),
   133     ("_asms",       typ "prop => asms => asms",        Delimfix "_;/ _"),
   134     ("_bigimpl",    typ "asms => prop => prop",        Mixfix ("((3[| _ |])/ ==> _)", [0, 1], 1)),
   135     ("_ofclass",    typ "type => logic => prop",       Delimfix "(1OFCLASS/(1'(_,/ _')))"),
   136     ("_mk_ofclass", typ "dummy",                       NoSyn),
   137     ("_TYPE",       typ "type => logic",               Delimfix "(1TYPE/(1'(_')))"),
   138     ("",            typ "id_position => logic",        Delimfix "_"),
   139     ("",            typ "longid_position => logic",    Delimfix "_"),
   140     ("",            typ "var_position => logic",       Delimfix "_"),
   141     ("_DDDOT",      typ "logic",                       Delimfix "..."),
   142     ("_strip_positions", typ "'a", NoSyn),
   143     ("_position",   typ "num_token => num_position",   Delimfix "_"),
   144     ("_position",   typ "float_token => float_position", Delimfix "_"),
   145     ("_position",   typ "xnum_token => xnum_position", Delimfix "_"),
   146     ("_constify",   typ "num_position => num_const",   Delimfix "_"),
   147     ("_constify",   typ "float_position => float_const", Delimfix "_"),
   148     ("_constify",   typ "xnum_position => xnum_const", Delimfix "_"),
   149     ("_index",      typ "logic => index",              Delimfix "(00\\<^bsub>_\\<^esub>)"),
   150     ("_indexdefault", typ "index",                     Delimfix ""),
   151     ("_indexvar",   typ "index",                       Delimfix "'\\<index>"),
   152     ("_struct",     typ "index => logic",              Mixfix ("\\<struct>_", [1000], 1000)),
   153     ("_update_name", typ "idt",                        NoSyn),
   154     ("_constrainAbs", typ "'a",                        NoSyn),
   155     ("_position_sort", typ "tid => tid_position",      Delimfix "_"),
   156     ("_position_sort", typ "tvar => tvar_position",    Delimfix "_"),
   157     ("_position",   typ "id => id_position",           Delimfix "_"),
   158     ("_position",   typ "longid => longid_position",   Delimfix "_"),
   159     ("_position",   typ "var => var_position",         Delimfix "_"),
   160     ("_position",   typ "str_token => str_position",   Delimfix "_"),
   161     ("_position",   typ "string_token => string_position", Delimfix "_"),
   162     ("_position",   typ "cartouche => cartouche_position", Delimfix "_"),
   163     ("_type_constraint_", typ "'a",                    NoSyn),
   164     ("_context_const", typ "id_position => logic",     Delimfix "CONST _"),
   165     ("_context_const", typ "id_position => aprop",     Delimfix "CONST _"),
   166     ("_context_const", typ "longid_position => logic", Delimfix "CONST _"),
   167     ("_context_const", typ "longid_position => aprop", Delimfix "CONST _"),
   168     ("_context_xconst", typ "id_position => logic",    Delimfix "XCONST _"),
   169     ("_context_xconst", typ "id_position => aprop",    Delimfix "XCONST _"),
   170     ("_context_xconst", typ "longid_position => logic", Delimfix "XCONST _"),
   171     ("_context_xconst", typ "longid_position => aprop", Delimfix "XCONST _"),
   172     (const "==>",   typ "prop => prop => prop",        Delimfix "op ==>"),
   173     (const "Pure.dummy_pattern", typ "aprop",          Delimfix "'_"),
   174     ("_sort_constraint", typ "type => prop",           Delimfix "(1SORT'_CONSTRAINT/(1'(_')))"),
   175     (const "Pure.term", typ "logic => prop",           Delimfix "TERM _"),
   176     (const "Pure.conjunction", typ "prop => prop => prop", Infixr ("&&&", 2))]
   177   #> Sign.add_syntax Syntax.mode_default applC_syntax
   178   #> Sign.add_syntax (Symbol.xsymbolsN, true)
   179    [(tycon "fun",         typ "type => type => type",   Mixfix ("(_/ \\<Rightarrow> _)", [1, 0], 0)),
   180     ("_bracket",          typ "types => type => type",  Mixfix ("([_]/ \\<Rightarrow> _)", [0, 0], 0)),
   181     ("_ofsort",           typ "tid_position => sort => type", Mixfix ("_\\<Colon>_", [1000, 0], 1000)),
   182     ("_constrain",        typ "logic => type => logic", Mixfix ("_\\<Colon>_", [4, 0], 3)),
   183     ("_constrain",        typ "prop' => type => prop'", Mixfix ("_\\<Colon>_", [4, 0], 3)),
   184     ("_idtyp",            typ "id_position => type => idt", Mixfix ("_\\<Colon>_", [], 0)),
   185     ("_idtypdummy",       typ "type => idt",            Mixfix ("'_()\\<Colon>_", [], 0)),
   186     ("_lambda",           typ "pttrns => 'a => logic",  Mixfix ("(3\\<lambda>_./ _)", [0, 3], 3)),
   187     (const "==",          typ "'a => 'a => prop",       Infix ("\\<equiv>", 2)),
   188     (const "all_binder",  typ "idts => prop => prop",   Mixfix ("(3\\<And>_./ _)", [0, 0], 0)),
   189     (const "==>",         typ "prop => prop => prop",   Infixr ("\\<Longrightarrow>", 1)),
   190     ("_DDDOT",            typ "aprop",                  Delimfix "\\<dots>"),
   191     ("_bigimpl",          typ "asms => prop => prop",   Mixfix ("((1\\<lbrakk>_\\<rbrakk>)/ \\<Longrightarrow> _)", [0, 1], 1)),
   192     ("_DDDOT",            typ "logic",                  Delimfix "\\<dots>")]
   193   #> Sign.add_syntax ("", false)
   194    [(const "prop", typ "prop => prop", Mixfix ("_", [0], 0))]
   195   #> Sign.add_syntax ("HTML", false)
   196    [("_lambda", typ "pttrns => 'a => logic", Mixfix ("(3\\<lambda>_./ _)", [0, 3], 3))]
   197   #> Sign.add_consts
   198    [(Binding.name "==", typ "'a => 'a => prop", Infix ("==", 2)),
   199     (Binding.name "==>", typ "prop => prop => prop", Mixfix ("(_/ ==> _)", [2, 1], 1)),
   200     (Binding.name "all", typ "('a => prop) => prop", Binder ("!!", 0, 0)),
   201     (Binding.name "prop", typ "prop => prop", NoSyn),
   202     (Binding.name "TYPE", typ "'a itself", NoSyn),
   203     (qualify (Binding.name "dummy_pattern"), typ "'a", Delimfix "'_")]
   204   #> Theory.add_deps_global "==" ("==", typ "'a => 'a => prop") []
   205   #> Theory.add_deps_global "==>" ("==>", typ "prop => prop => prop") []
   206   #> Theory.add_deps_global "all" ("all", typ "('a => prop) => prop") []
   207   #> Theory.add_deps_global "TYPE" ("TYPE", typ "'a itself") []
   208   #> Theory.add_deps_global "Pure.dummy_pattern" ("Pure.dummy_pattern", typ "'a") []
   209   #> Sign.parse_ast_translation Syntax_Trans.pure_parse_ast_translation
   210   #> Sign.parse_translation Syntax_Trans.pure_parse_translation
   211   #> Sign.print_ast_translation Syntax_Trans.pure_print_ast_translation
   212   #> Sign.add_consts
   213    [(qualify (Binding.name "term"), typ "'a => prop", NoSyn),
   214     (qualify (Binding.name "sort_constraint"), typ "'a itself => prop", NoSyn),
   215     (qualify (Binding.name "conjunction"), typ "prop => prop => prop", NoSyn)]
   216   #> Sign.local_path
   217   #> (Global_Theory.add_defs false o map Thm.no_attributes)
   218    [(Binding.name "prop_def", prop "(CONST prop :: prop => prop) (A::prop) == A::prop"),
   219     (Binding.name "term_def", prop "(CONST Pure.term :: 'a => prop) (x::'a) == (!!A::prop. A ==> A)"),
   220     (Binding.name "sort_constraint_def",
   221       prop "(CONST Pure.sort_constraint :: 'a itself => prop) (CONST TYPE :: 'a itself) ==\
   222       \ (CONST Pure.term :: 'a itself => prop) (CONST TYPE :: 'a itself)"),
   223     (Binding.name "conjunction_def", prop "(A &&& B) == (!!C::prop. (A ==> B ==> C) ==> C)")] #> snd
   224   #> Global_Theory.add_thmss [((Binding.name "nothing", []), [])] #> snd
   225   #> fold (fn (a, prop) =>
   226       snd o Thm.add_axiom_global (Binding.name a, prop)) Proofterm.equality_axms);
   227 
   228 end;