src/ZF/thy_syntax.ML
author wenzelm
Thu, 30 Nov 2000 20:05:34 +0100
changeset 10551 ec9fab41b3a0
parent 8813 abc0f3722aed
child 12050 6934c005aec4
permissions -rw-r--r--
renamed "equivalence_class" to "class";
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
797
713efca1f0aa Defines ZF theory sections (inductive, datatype) at the start/
lcp
parents:
diff changeset
     1
(*  Title:      ZF/thy_syntax.ML
713efca1f0aa Defines ZF theory sections (inductive, datatype) at the start/
lcp
parents:
diff changeset
     2
    ID:         $Id$
713efca1f0aa Defines ZF theory sections (inductive, datatype) at the start/
lcp
parents:
diff changeset
     3
    Author:     Lawrence C Paulson
713efca1f0aa Defines ZF theory sections (inductive, datatype) at the start/
lcp
parents:
diff changeset
     4
    Copyright   1994  University of Cambridge
713efca1f0aa Defines ZF theory sections (inductive, datatype) at the start/
lcp
parents:
diff changeset
     5
3622
85898be702b2 use ThySyn.add_syntax;
wenzelm
parents: 3613
diff changeset
     6
Additional theory file sections for ZF.
797
713efca1f0aa Defines ZF theory sections (inductive, datatype) at the start/
lcp
parents:
diff changeset
     7
*)
713efca1f0aa Defines ZF theory sections (inductive, datatype) at the start/
lcp
parents:
diff changeset
     8
3622
85898be702b2 use ThySyn.add_syntax;
wenzelm
parents: 3613
diff changeset
     9
85898be702b2 use ThySyn.add_syntax;
wenzelm
parents: 3613
diff changeset
    10
local
797
713efca1f0aa Defines ZF theory sections (inductive, datatype) at the start/
lcp
parents:
diff changeset
    11
6053
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    12
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    13
open ThyParse;
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    14
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    15
(*ML identifiers for introduction rules.*)
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    16
fun mk_intr_name suffix s =  
6093
87bf8c03b169 eliminated global/local names;
wenzelm
parents: 6070
diff changeset
    17
    if ThmDatabase.is_ml_identifier s then
6053
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    18
	"op " ^ s ^ suffix  (*the "op" cancels any infix status*)
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    19
    else "_";               (*bad name, don't try to bind*)
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    20
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    21
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    22
(*For lists of theorems.  Either a string (an ML list expression) or else
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    23
  a list of identifiers.*)
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    24
fun optlist s = 
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    25
    optional (s $$-- 
6642
732af87c0650 strip_quotes replaced by unenclose;
wenzelm
parents: 6112
diff changeset
    26
	      (string >> unenclose
732af87c0650 strip_quotes replaced by unenclose;
wenzelm
parents: 6112
diff changeset
    27
	       || list1 (name>>unenclose) >> mk_list)) 
6053
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    28
    "[]";
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    29
8813
abc0f3722aed added scan_to_id (used to be in Pure/section_utils.ML);
wenzelm
parents: 8127
diff changeset
    30
(*Skipping initial blanks, find the first identifier*)  (* FIXME slightly broken! *)
abc0f3722aed added scan_to_id (used to be in Pure/section_utils.ML);
wenzelm
parents: 8127
diff changeset
    31
fun scan_to_id s =
abc0f3722aed added scan_to_id (used to be in Pure/section_utils.ML);
wenzelm
parents: 8127
diff changeset
    32
    s |> Symbol.explode
abc0f3722aed added scan_to_id (used to be in Pure/section_utils.ML);
wenzelm
parents: 8127
diff changeset
    33
    |> Scan.error (Scan.finite Symbol.stopper
abc0f3722aed added scan_to_id (used to be in Pure/section_utils.ML);
wenzelm
parents: 8127
diff changeset
    34
      (Scan.!! (fn _ => "Expected to find an identifier in " ^ s)
abc0f3722aed added scan_to_id (used to be in Pure/section_utils.ML);
wenzelm
parents: 8127
diff changeset
    35
        (Scan.any Symbol.is_blank |-- Syntax.scan_id)))
abc0f3722aed added scan_to_id (used to be in Pure/section_utils.ML);
wenzelm
parents: 8127
diff changeset
    36
    |> #1;
6053
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    37
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    38
(*(Co)Inductive definitions theory section."*)
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    39
fun inductive_decl coind =
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    40
  let  
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    41
    fun mk_params ((((((recs, sdom_sum), ipairs), 
1461
6bcb44e4d6e5 expanded tabs
clasohm
parents: 1428
diff changeset
    42
                      monos), con_defs), type_intrs), type_elims) =
1428
15a69dd0a145 Reduced indentation; no change in function
paulson
parents: 1418
diff changeset
    43
      let val big_rec_name = space_implode "_" 
6642
732af87c0650 strip_quotes replaced by unenclose;
wenzelm
parents: 6112
diff changeset
    44
                           (map (scan_to_id o unenclose) recs)
6053
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    45
          and srec_tms = mk_list recs
1461
6bcb44e4d6e5 expanded tabs
clasohm
parents: 1428
diff changeset
    46
          and sintrs   = mk_big_list (map snd ipairs)
6053
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    47
          and inames   = mk_list (map (mk_intr_name "" o fst) ipairs)
1428
15a69dd0a145 Reduced indentation; no change in function
paulson
parents: 1418
diff changeset
    48
      in
6053
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    49
	 ";\n\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    50
	 \local\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    51
	 \val (thy, {defs, intrs, elim, mk_cases, \
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    52
		    \bnd_mono, dom_subset, induct, mutual_induct, ...}) =\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    53
	 \  " ^
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    54
	 (if coind then "Co" else "") ^ 
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    55
	 "Ind_Package.add_inductive (" ^  srec_tms ^ ", " ^ sdom_sum ^ ", " ^
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    56
	  sintrs ^ ", " ^ monos ^ ", " ^ con_defs ^ ", " ^ 
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    57
	  type_intrs ^ ", " ^ type_elims ^ ") thy;\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    58
	 \in\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    59
	 \structure " ^ big_rec_name ^ " =\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    60
	 \struct\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    61
	 \  val defs = defs\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    62
	 \  val bnd_mono = bnd_mono\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    63
	 \  val dom_subset = dom_subset\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    64
	 \  val intrs = intrs\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    65
	 \  val elim = elim\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    66
	 \  val " ^ (if coind then "co" else "") ^ "induct = induct\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    67
	 \  val mutual_induct = mutual_induct\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    68
	 \  val mk_cases = mk_cases\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    69
	 \  val " ^ inames ^ " = intrs\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    70
	 \end;\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    71
	 \val thy = thy;\nend;\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    72
	 \val thy = thy\n"
1428
15a69dd0a145 Reduced indentation; no change in function
paulson
parents: 1418
diff changeset
    73
      end
15a69dd0a145 Reduced indentation; no change in function
paulson
parents: 1418
diff changeset
    74
    val domains = "domains" $$-- enum1 "+" string --$$ "<=" -- !! string
15a69dd0a145 Reduced indentation; no change in function
paulson
parents: 1418
diff changeset
    75
    val ipairs  = "intrs"   $$-- repeat1 (ident -- !! string)
6053
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    76
  in domains -- ipairs -- optlist "monos" -- optlist "con_defs"
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    77
             -- optlist "type_intrs" -- optlist "type_elims"
797
713efca1f0aa Defines ZF theory sections (inductive, datatype) at the start/
lcp
parents:
diff changeset
    78
     >> mk_params
713efca1f0aa Defines ZF theory sections (inductive, datatype) at the start/
lcp
parents:
diff changeset
    79
  end;
713efca1f0aa Defines ZF theory sections (inductive, datatype) at the start/
lcp
parents:
diff changeset
    80
713efca1f0aa Defines ZF theory sections (inductive, datatype) at the start/
lcp
parents:
diff changeset
    81
6053
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    82
(*Datatype definitions theory section.   co is true for codatatypes*)
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    83
fun datatype_decl coind =
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    84
  let
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    85
    (*generate strings*)
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    86
    fun mk_const ((x, y), z) = mk_triple (x, mk_list y, z);
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    87
    val mk_data = mk_list o map mk_const o snd
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    88
    val mk_scons = mk_big_list o map mk_data
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    89
    fun mk_params ((((sdom, rec_pairs), monos), type_intrs), type_elims) =
6642
732af87c0650 strip_quotes replaced by unenclose;
wenzelm
parents: 6112
diff changeset
    90
      let val rec_names = map (scan_to_id o unenclose o fst) rec_pairs
6053
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    91
	  val big_rec_name = space_implode "_" rec_names
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    92
	  and srec_tms = mk_list (map fst rec_pairs)
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    93
	  and scons    = mk_scons rec_pairs
6642
732af87c0650 strip_quotes replaced by unenclose;
wenzelm
parents: 6112
diff changeset
    94
	  val con_names = flat (map (map (unenclose o #1 o #1) o snd)
6053
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    95
				rec_pairs)
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    96
          val inames = mk_list (map (mk_intr_name "_I") con_names)
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    97
      in
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    98
	 ";\n\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
    99
	 \local\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   100
	 \val (thy,\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   101
         \     {defs, intrs, elim, mk_cases, \
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   102
		    \bnd_mono, dom_subset, induct, mutual_induct, ...},\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   103
         \     {con_defs, case_eqns, recursor_eqns, free_iffs, free_SEs, mk_free, ...}) =\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   104
	 \  " ^
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   105
	 (if coind then "Co" else "") ^ 
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   106
	 "Data_Package.add_datatype (" ^  sdom ^ ", " ^ srec_tms ^ ", " ^
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   107
	  scons ^ ", " ^ monos ^ ", " ^ 
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   108
	  type_intrs ^ ", " ^ type_elims ^ ") thy;\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   109
	 \in\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   110
	 \structure " ^ big_rec_name ^ " =\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   111
	 \struct\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   112
	 \  val defs = defs\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   113
	 \  val bnd_mono = bnd_mono\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   114
	 \  val dom_subset = dom_subset\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   115
	 \  val intrs = intrs\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   116
	 \  val elim = elim\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   117
	 \  val " ^ (if coind then "co" else "") ^ "induct = induct\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   118
	 \  val mutual_induct = mutual_induct\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   119
	 \  val mk_cases = mk_cases\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   120
	 \  val con_defs = con_defs\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   121
	 \  val case_eqns = case_eqns\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   122
	 \  val recursor_eqns = recursor_eqns\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   123
	 \  val free_iffs = free_iffs\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   124
	 \  val free_SEs = free_SEs\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   125
	 \  val mk_free = mk_free\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   126
	 \  val " ^ inames ^ " = intrs;\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   127
	 \end;\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   128
	 \val thy = thy;\nend;\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   129
	 \val thy = thy\n"
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   130
      end
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   131
    val string_list = "(" $$-- list1 string --$$ ")" || ThyParse.empty;
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   132
    val construct = name -- string_list -- opt_mixfix;
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   133
  in optional ("<=" $$-- string) "\"\"" --
8127
68c6159440f1 new lemmas for Ntree recursor example; more simprules; more lemmas borrowed
paulson
parents: 6642
diff changeset
   134
     enum1 "and" (name --$$ "=" -- enum1 "|" construct) --
6053
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   135
     optlist "monos" -- optlist "type_intrs" -- optlist "type_elims"
797
713efca1f0aa Defines ZF theory sections (inductive, datatype) at the start/
lcp
parents:
diff changeset
   136
     >> mk_params
713efca1f0aa Defines ZF theory sections (inductive, datatype) at the start/
lcp
parents:
diff changeset
   137
end;
713efca1f0aa Defines ZF theory sections (inductive, datatype) at the start/
lcp
parents:
diff changeset
   138
713efca1f0aa Defines ZF theory sections (inductive, datatype) at the start/
lcp
parents:
diff changeset
   139
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
   140
(** rep_datatype **)
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
   141
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
   142
fun mk_rep_dt_string (((elim, induct), case_eqns), recursor_eqns) =
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
   143
  "|> DatatypeTactics.rep_datatype_i " ^ elim ^ " " ^ induct ^ "\n    " ^
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
   144
  mk_list case_eqns ^ " " ^ mk_list recursor_eqns;
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
   145
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
   146
val rep_datatype_decl =
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
   147
  (("elim" $$-- ident) -- 
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
   148
   ("induct" $$-- ident) --
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
   149
   ("case_eqns" $$-- list1 ident) -- 
6112
5e4871c5136b datatype package improvements
paulson
parents: 6093
diff changeset
   150
   optional ("recursor_eqns" $$-- list1 ident) []) >> mk_rep_dt_string;
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
   151
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
   152
6053
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   153
(** primrec **)
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   154
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   155
fun mk_primrec_decl eqns =
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   156
  let val names = map fst eqns
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   157
  in
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   158
    ";\nval (thy, " ^ mk_list names ^
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   159
    ") = PrimrecPackage.add_primrec " ^
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   160
      mk_list (map mk_pair (map (apfst quote) eqns)) ^ " " ^ " thy;\n\
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   161
    \val thy = thy\n"
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   162
  end;
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   163
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   164
(* either names and axioms or just axioms *)
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   165
val primrec_decl = 
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   166
    ((repeat1 ((ident -- string) || (string >> pair "_")))) >> mk_primrec_decl;
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   167
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   168
8a1059aa01f0 new inductive, datatype and primrec packages, etc.
paulson
parents: 3925
diff changeset
   169
797
713efca1f0aa Defines ZF theory sections (inductive, datatype) at the start/
lcp
parents:
diff changeset
   170
3622
85898be702b2 use ThySyn.add_syntax;
wenzelm
parents: 3613
diff changeset
   171
(** augment thy syntax **)
85898be702b2 use ThySyn.add_syntax;
wenzelm
parents: 3613
diff changeset
   172
85898be702b2 use ThySyn.add_syntax;
wenzelm
parents: 3613
diff changeset
   173
in
797
713efca1f0aa Defines ZF theory sections (inductive, datatype) at the start/
lcp
parents:
diff changeset
   174
3622
85898be702b2 use ThySyn.add_syntax;
wenzelm
parents: 3613
diff changeset
   175
val _ = ThySyn.add_syntax
85898be702b2 use ThySyn.add_syntax;
wenzelm
parents: 3613
diff changeset
   176
 ["inductive", "coinductive", "datatype", "codatatype", "and", "|",
6070
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
   177
  "<=", "domains", "intrs", "monos", "con_defs", "type_intrs", "type_elims",
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
   178
  (*rep_datatype*)
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
   179
  "elim", "induct", "case_eqns", "recursor_eqns"]
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
   180
 [section "inductive"    "" (inductive_decl false),
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
   181
  section "coinductive"  "" (inductive_decl true),
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
   182
  section "datatype"     "" (datatype_decl false),
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
   183
  section "codatatype"   "" (datatype_decl true),
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
   184
  section "rep_datatype" "" rep_datatype_decl,
032babd0120b ZF: the natural numbers as a datatype
paulson
parents: 6053
diff changeset
   185
  section "primrec"      "" primrec_decl];
3622
85898be702b2 use ThySyn.add_syntax;
wenzelm
parents: 3613
diff changeset
   186
797
713efca1f0aa Defines ZF theory sections (inductive, datatype) at the start/
lcp
parents:
diff changeset
   187
end;