src/HOL/Tools/datatype_package.ML
changeset 24867 e5b55d7be9bb
parent 24830 a7b3ab44d993
child 24959 119793c84647
equal deleted inserted replaced
24866:6e6d9e80ebb4 24867:e5b55d7be9bb
   906 
   906 
   907 (* outer syntax *)
   907 (* outer syntax *)
   908 
   908 
   909 local structure P = OuterParse and K = OuterKeyword in
   909 local structure P = OuterParse and K = OuterKeyword in
   910 
   910 
       
   911 val _ = OuterSyntax.keywords ["distinct", "inject", "induction"];
       
   912 
   911 val datatype_decl =
   913 val datatype_decl =
   912   Scan.option (P.$$$ "(" |-- P.name --| P.$$$ ")") -- P.type_args -- P.name -- P.opt_infix --
   914   Scan.option (P.$$$ "(" |-- P.name --| P.$$$ ")") -- P.type_args -- P.name -- P.opt_infix --
   913     (P.$$$ "=" |-- P.enum1 "|" (P.name -- Scan.repeat P.typ -- P.opt_mixfix));
   915     (P.$$$ "=" |-- P.enum1 "|" (P.name -- Scan.repeat P.typ -- P.opt_mixfix));
   914 
   916 
   915 fun mk_datatype args =
   917 fun mk_datatype args =
   917     val names = map (fn ((((NONE, _), t), _), _) => t | ((((SOME t, _), _), _), _) => t) args;
   919     val names = map (fn ((((NONE, _), t), _), _) => t | ((((SOME t, _), _), _), _) => t) args;
   918     val specs = map (fn ((((_, vs), t), mx), cons) =>
   920     val specs = map (fn ((((_, vs), t), mx), cons) =>
   919       (vs, t, mx, map (fn ((x, y), z) => (x, y, z)) cons)) args;
   921       (vs, t, mx, map (fn ((x, y), z) => (x, y, z)) cons)) args;
   920   in snd o add_datatype false names specs end;
   922   in snd o add_datatype false names specs end;
   921 
   923 
   922 val datatypeP =
   924 val _ =
   923   OuterSyntax.command "datatype" "define inductive datatypes" K.thy_decl
   925   OuterSyntax.command "datatype" "define inductive datatypes" K.thy_decl
   924     (P.and_list1 datatype_decl >> (Toplevel.theory o mk_datatype));
   926     (P.and_list1 datatype_decl >> (Toplevel.theory o mk_datatype));
   925 
   927 
   926 
   928 
   927 val rep_datatype_decl =
   929 val rep_datatype_decl =
   930     Scan.optional (P.$$$ "inject" |-- P.!!! (P.and_list1 SpecParse.xthms1)) [[]] --
   932     Scan.optional (P.$$$ "inject" |-- P.!!! (P.and_list1 SpecParse.xthms1)) [[]] --
   931     (P.$$$ "induction" |-- P.!!! SpecParse.xthm);
   933     (P.$$$ "induction" |-- P.!!! SpecParse.xthm);
   932 
   934 
   933 fun mk_rep_datatype (((opt_ts, dss), iss), ind) = #2 o rep_datatype opt_ts dss iss ind;
   935 fun mk_rep_datatype (((opt_ts, dss), iss), ind) = #2 o rep_datatype opt_ts dss iss ind;
   934 
   936 
   935 val rep_datatypeP =
   937 val _ =
   936   OuterSyntax.command "rep_datatype" "represent existing types inductively" K.thy_decl
   938   OuterSyntax.command "rep_datatype" "represent existing types inductively" K.thy_decl
   937     (rep_datatype_decl >> (Toplevel.theory o mk_rep_datatype));
   939     (rep_datatype_decl >> (Toplevel.theory o mk_rep_datatype));
   938 
   940 
   939 
       
   940 val _ = OuterSyntax.add_keywords ["distinct", "inject", "induction"];
       
   941 val _ = OuterSyntax.add_parsers [datatypeP, rep_datatypeP];
       
   942 
       
   943 end;
   941 end;
   944 
   942 
   945 
   943 
   946 end;
   944 end;
   947 
   945