src/Pure/pure_thy.ML
author wenzelm
Sun Mar 06 16:19:02 2016 +0100 (2016-03-06)
changeset 62529 8b7bdfc09f3b
parent 62107 f74a33b14200
child 62752 d09d71223e7a
permissions -rw-r--r--
clarified treatment of fragments of Isabelle symbols during bootstrap;
     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.make ("fun", @{here}), 2, NoSyn),
    66     (Binding.make ("prop", @{here}), 0, NoSyn),
    67     (Binding.make ("itself", @{here}), 1, NoSyn),
    68     (Binding.make ("dummy", @{here}), 0, NoSyn)]
    69   #> Theory.add_deps_global "fun" ((Defs.Type, "fun"), [typ "'a", typ "'b"]) []
    70   #> Theory.add_deps_global "prop" ((Defs.Type, "prop"), []) []
    71   #> Theory.add_deps_global "itself" ((Defs.Type, "itself"), [typ "'a"]) []
    72   #> Theory.add_deps_global "dummy" ((Defs.Type, "dummy"), []) []
    73   #> Sign.add_nonterminals_global
    74     (map (fn name => Binding.make (name, @{here}))
    75       (Lexicon.terminals @ ["logic", "type", "types", "sort", "classes",
    76         "args", "cargs", "pttrn", "pttrns", "idt", "idts", "aprop", "asms",
    77         "any", "prop'", "num_const", "float_const", "num_position",
    78         "float_position", "index", "struct", "tid_position",
    79         "tvar_position", "id_position", "longid_position", "var_position",
    80         "str_position", "string_position", "cartouche_position", "type_name",
    81         "class_name"]))
    82   #> Sign.add_syntax Syntax.mode_default (map (fn x => (x, typ "'a", NoSyn)) token_markers)
    83   #> Sign.add_syntax Syntax.mode_default
    84    [("",            typ "prop' => prop",               Delimfix "_"),
    85     ("",            typ "logic => any",                Delimfix "_"),
    86     ("",            typ "prop' => any",                Delimfix "_"),
    87     ("",            typ "logic => logic",              Delimfix "'(_')"),
    88     ("",            typ "prop' => prop'",              Delimfix "'(_')"),
    89     ("_constrain",  typ "logic => type => logic",      Mixfix ("_::_", [4, 0], 3)),
    90     ("_constrain",  typ "prop' => type => prop'",      Mixfix ("_::_", [4, 0], 3)),
    91     ("_ignore_type", typ "'a",                         NoSyn),
    92     ("",            typ "tid_position => type",        Delimfix "_"),
    93     ("",            typ "tvar_position => type",       Delimfix "_"),
    94     ("",            typ "type_name => type",           Delimfix "_"),
    95     ("_type_name",  typ "id => type_name",             Delimfix "_"),
    96     ("_type_name",  typ "longid => type_name",         Delimfix "_"),
    97     ("_ofsort",     typ "tid_position => sort => type", Mixfix ("_::_", [1000, 0], 1000)),
    98     ("_ofsort",     typ "tvar_position => sort => type", Mixfix ("_::_", [1000, 0], 1000)),
    99     ("_dummy_ofsort", typ "sort => type",              Mixfix ("'_()::_", [0], 1000)),
   100     ("",            typ "class_name => sort",          Delimfix "_"),
   101     ("_class_name", typ "id => class_name",            Delimfix "_"),
   102     ("_class_name", typ "longid => class_name",        Delimfix "_"),
   103     ("_topsort",    typ "sort",                        Delimfix "{}"),
   104     ("_sort",       typ "classes => sort",             Delimfix "{_}"),
   105     ("",            typ "class_name => classes",       Delimfix "_"),
   106     ("_classes",    typ "class_name => classes => classes", Delimfix "_,_"),
   107     ("_tapp",       typ "type => type_name => type",   Mixfix ("_ _", [1000, 0], 1000)),
   108     ("_tappl",      typ "type => types => type_name => type", Delimfix "((1'(_,/ _')) _)"),
   109     ("",            typ "type => types",               Delimfix "_"),
   110     ("_types",      typ "type => types => types",      Delimfix "_,/ _"),
   111     ("\<^type>fun", typ "type => type => type",        Mixfix ("(_/ \<Rightarrow> _)", [1, 0], 0)),
   112     ("_bracket",    typ "types => type => type",       Mixfix ("([_]/ \<Rightarrow> _)", [0, 0], 0)),
   113     ("",            typ "type => type",                Delimfix "'(_')"),
   114     ("\<^type>dummy", typ "type",                      Delimfix "'_"),
   115     ("_type_prop",  typ "'a",                          NoSyn),
   116     ("_lambda",     typ "pttrns => 'a => logic",       Mixfix ("(3\<lambda>_./ _)", [0, 3], 3)),
   117     ("_abs",        typ "'a",                          NoSyn),
   118     ("",            typ "'a => args",                  Delimfix "_"),
   119     ("_args",       typ "'a => args => args",          Delimfix "_,/ _"),
   120     ("",            typ "id_position => idt",          Delimfix "_"),
   121     ("_idtdummy",   typ "idt",                         Delimfix "'_"),
   122     ("_idtyp",      typ "id_position => type => idt",  Mixfix ("_::_", [], 0)),
   123     ("_idtypdummy", typ "type => idt",                 Mixfix ("'_()::_", [], 0)),
   124     ("",            typ "idt => idt",                  Delimfix "'(_')"),
   125     ("",            typ "idt => idts",                 Delimfix "_"),
   126     ("_idts",       typ "idt => idts => idts",         Mixfix ("_/ _", [1, 0], 0)),
   127     ("",            typ "idt => pttrn",                Delimfix "_"),
   128     ("",            typ "pttrn => pttrns",             Delimfix "_"),
   129     ("_pttrns",     typ "pttrn => pttrns => pttrns",   Mixfix ("_/ _", [1, 0], 0)),
   130     ("",            typ "aprop => aprop",              Delimfix "'(_')"),
   131     ("",            typ "id_position => aprop",        Delimfix "_"),
   132     ("",            typ "longid_position => aprop",    Delimfix "_"),
   133     ("",            typ "var_position => aprop",       Delimfix "_"),
   134     ("_DDDOT",      typ "aprop",                       Delimfix "\<dots>"),
   135     ("_aprop",      typ "aprop => prop",               Delimfix "PROP _"),
   136     ("_asm",        typ "prop => asms",                Delimfix "_"),
   137     ("_asms",       typ "prop => asms => asms",        Delimfix "_;/ _"),
   138     ("_bigimpl",    typ "asms => prop => prop",        Mixfix ("((1\<lbrakk>_\<rbrakk>)/ \<Longrightarrow> _)", [0, 1], 1)),
   139     ("_ofclass",    typ "type => logic => prop",       Delimfix "(1OFCLASS/(1'(_,/ _')))"),
   140     ("_mk_ofclass", typ "dummy",                       NoSyn),
   141     ("_TYPE",       typ "type => logic",               Delimfix "(1TYPE/(1'(_')))"),
   142     ("",            typ "id_position => logic",        Delimfix "_"),
   143     ("",            typ "longid_position => logic",    Delimfix "_"),
   144     ("",            typ "var_position => logic",       Delimfix "_"),
   145     ("_DDDOT",      typ "logic",                       Delimfix "\<dots>"),
   146     ("_strip_positions", typ "'a", NoSyn),
   147     ("_position",   typ "num_token => num_position",   Delimfix "_"),
   148     ("_position",   typ "float_token => float_position", Delimfix "_"),
   149     ("_constify",   typ "num_position => num_const",   Delimfix "_"),
   150     ("_constify",   typ "float_position => float_const", Delimfix "_"),
   151     ("_index",      typ "logic => index",              Delimfix "(00\<^bsub>_\<^esub>)"),
   152     ("_indexdefault", typ "index",                     Delimfix ""),
   153     ("_indexvar",   typ "index",                       Delimfix "'\<index>"),
   154     ("_struct",     typ "index => logic",              NoSyn),
   155     ("_update_name", typ "idt",                        NoSyn),
   156     ("_constrainAbs", typ "'a",                        NoSyn),
   157     ("_position_sort", typ "tid => tid_position",      Delimfix "_"),
   158     ("_position_sort", typ "tvar => tvar_position",    Delimfix "_"),
   159     ("_position",   typ "id => id_position",           Delimfix "_"),
   160     ("_position",   typ "longid => longid_position",   Delimfix "_"),
   161     ("_position",   typ "var => var_position",         Delimfix "_"),
   162     ("_position",   typ "str_token => str_position",   Delimfix "_"),
   163     ("_position",   typ "string_token => string_position", Delimfix "_"),
   164     ("_position",   typ "cartouche => cartouche_position", Delimfix "_"),
   165     ("_type_constraint_", typ "'a",                    NoSyn),
   166     ("_context_const", typ "id_position => logic",     Delimfix "CONST _"),
   167     ("_context_const", typ "id_position => aprop",     Delimfix "CONST _"),
   168     ("_context_const", typ "longid_position => logic", Delimfix "CONST _"),
   169     ("_context_const", typ "longid_position => aprop", Delimfix "CONST _"),
   170     ("_context_xconst", typ "id_position => logic",    Delimfix "XCONST _"),
   171     ("_context_xconst", typ "id_position => aprop",    Delimfix "XCONST _"),
   172     ("_context_xconst", typ "longid_position => logic", Delimfix "XCONST _"),
   173     ("_context_xconst", typ "longid_position => aprop", Delimfix "XCONST _"),
   174     (const "Pure.dummy_pattern", typ "aprop",          Delimfix "'_"),
   175     ("_sort_constraint", typ "type => prop",           Delimfix "(1SORT'_CONSTRAINT/(1'(_')))"),
   176     (const "Pure.term", typ "logic => prop",           Delimfix "TERM _"),
   177     (const "Pure.conjunction", typ "prop => prop => prop", Infixr ("&&&", 2))]
   178   #> Sign.add_syntax Syntax.mode_default applC_syntax
   179   #> Sign.add_syntax (Print_Mode.ASCII, true)
   180    [(tycon "fun",         typ "type => type => type",   Mixfix ("(_/ => _)", [1, 0], 0)),
   181     ("_bracket",          typ "types => type => type",  Mixfix ("([_]/ => _)", [0, 0], 0)),
   182     ("_lambda",           typ "pttrns => 'a => logic",  Mixfix ("(3%_./ _)", [0, 3], 3)),
   183     (const "Pure.eq",     typ "'a => 'a => prop",       Infix ("==", 2)),
   184     (const "Pure.all_binder", typ "idts => prop => prop", Mixfix ("(3!!_./ _)", [0, 0], 0)),
   185     (const "Pure.imp",    typ "prop => prop => prop",   Infixr ("==>", 1)),
   186     ("_DDDOT",            typ "aprop",                  Delimfix "..."),
   187     ("_bigimpl",          typ "asms => prop => prop",   Mixfix ("((3[| _ |])/ ==> _)", [0, 1], 1)),
   188     ("_DDDOT",            typ "logic",                  Delimfix "...")]
   189   #> Sign.add_syntax ("", false)
   190    [(const "Pure.prop", typ "prop => prop", Mixfix ("_", [0], 0))]
   191   #> Sign.add_consts
   192    [(qualify (Binding.make ("eq", @{here})), typ "'a => 'a => prop", Infix ("\<equiv>", 2)),
   193     (qualify (Binding.make ("imp", @{here})), typ "prop => prop => prop", Infixr ("\<Longrightarrow>", 1)),
   194     (qualify (Binding.make ("all", @{here})), typ "('a => prop) => prop", Binder ("\<And>", 0, 0)),
   195     (qualify (Binding.make ("prop", @{here})), typ "prop => prop", NoSyn),
   196     (qualify (Binding.make ("type", @{here})), typ "'a itself", NoSyn),
   197     (qualify (Binding.make ("dummy_pattern", @{here})), typ "'a", Delimfix "'_")]
   198   #> Theory.add_deps_global "Pure.eq" ((Defs.Const, "Pure.eq"), [typ "'a"]) []
   199   #> Theory.add_deps_global "Pure.imp" ((Defs.Const, "Pure.imp"), []) []
   200   #> Theory.add_deps_global "Pure.all" ((Defs.Const, "Pure.all"), [typ "'a"]) []
   201   #> Theory.add_deps_global "Pure.type" ((Defs.Const, "Pure.type"), [typ "'a"]) []
   202   #> Theory.add_deps_global "Pure.dummy_pattern" ((Defs.Const, "Pure.dummy_pattern"), [typ "'a"]) []
   203   #> Sign.parse_ast_translation Syntax_Trans.pure_parse_ast_translation
   204   #> Sign.parse_translation Syntax_Trans.pure_parse_translation
   205   #> Sign.print_ast_translation Syntax_Trans.pure_print_ast_translation
   206   #> Sign.add_consts
   207    [(qualify (Binding.make ("term", @{here})), typ "'a => prop", NoSyn),
   208     (qualify (Binding.make ("sort_constraint", @{here})), typ "'a itself => prop", NoSyn),
   209     (qualify (Binding.make ("conjunction", @{here})), typ "prop => prop => prop", NoSyn)]
   210   #> Sign.local_path
   211   #> (Global_Theory.add_defs false o map Thm.no_attributes)
   212    [(Binding.make ("prop_def", @{here}),
   213       prop "(CONST Pure.prop :: prop => prop) (A::prop) == A::prop"),
   214     (Binding.make ("term_def", @{here}),
   215       prop "(CONST Pure.term :: 'a => prop) (x::'a) == (!!A::prop. A ==> A)"),
   216     (Binding.make ("sort_constraint_def", @{here}),
   217       prop "(CONST Pure.sort_constraint :: 'a itself => prop) (CONST Pure.type :: 'a itself) ==\
   218       \ (CONST Pure.term :: 'a itself => prop) (CONST Pure.type :: 'a itself)"),
   219     (Binding.make ("conjunction_def", @{here}),
   220       prop "(A &&& B) == (!!C::prop. (A ==> B ==> C) ==> C)")] #> snd
   221   #> Global_Theory.add_thmss [((Binding.make ("nothing", @{here}), []), [])] #> snd
   222   #> fold (fn (a, prop) =>
   223       snd o Thm.add_axiom_global (Binding.make (a, @{here}), prop)) Proofterm.equality_axms);
   224 
   225 end;