38 "val ("^ theorems ^") =\n\ |
38 "val ("^ theorems ^") =\n\ |
39 \Domain_Theorems.theorems thy "^eqname^";\n" ^ |
39 \Domain_Theorems.theorems thy "^eqname^";\n" ^ |
40 (if num > 1 then "val rews = " ^rews1 ^";\n" else "") |
40 (if num > 1 then "val rews = " ^rews1 ^";\n" else "") |
41 end; |
41 end; |
42 |
42 |
43 fun mk_domain (eqs'') = let |
43 fun mk_domain eqs'' = let |
44 val dtnvs = map (rep_Type o fst) eqs''; |
44 val num = length eqs''; |
|
45 val dtnvs = map fst eqs''; |
45 val dnames = map fst dtnvs; |
46 val dnames = map fst dtnvs; |
46 val num = length dnames; |
|
47 val comp_dname = implode (separate "_" dnames); |
47 val comp_dname = implode (separate "_" dnames); |
48 val conss' = ListPair.map |
48 val conss' = ListPair.map |
49 (fn (dname,cons'') => |
49 (fn (dname,cons'') => let fun sel n m = upd_second |
50 let fun sel n m = upd_second |
|
51 (fn None => dname^"_sel_"^(string_of_int n)^ |
50 (fn None => dname^"_sel_"^(string_of_int n)^ |
52 "_"^(string_of_int m) |
51 "_"^(string_of_int m) |
53 | Some s => s) |
52 | Some s => s) |
54 fun fill_sels n con = upd_third (mapn (sel n) 1) con; |
53 fun fill_sels n con = upd_third (mapn (sel n) 1) con; |
55 in mapn fill_sels 1 cons'' end) |
54 in mapn fill_sels 1 cons'' end) |
56 (dnames, map #2 eqs''); |
55 (dnames, map snd eqs''); |
57 val eqs' = dtnvs~~conss'; |
56 val eqs' = dtnvs~~conss'; |
58 |
57 |
59 (* ----- string for calling add_domain -------------------------------------- *) |
58 (* ----- string for calling add_domain -------------------------------------- *) |
60 |
59 |
61 val thy_ext_string = let |
60 val thy_ext_string = let |
62 fun mk_tnv (n,v) = mk_pair (quote n, mk_list (map mk_typ v)) |
|
63 and mk_typ (TFree(name,sort))= "TFree" ^ |
|
64 mk_pair (quote name, mk_list (map quote sort)) |
|
65 | mk_typ (Type (name,args))= "Type" ^mk_tnv(name,args) |
|
66 | mk_typ _ = Imposs "interface:mk_typ"; |
|
67 fun mk_conslist cons' = |
61 fun mk_conslist cons' = |
68 mk_list (map |
62 mk_list (map (fn (c,syn,ts)=> |
69 (fn (c,syn,ts)=> |
63 mk_triple(quote c, syn, mk_list (map (fn (b,s ,tp) => |
70 mk_triple(quote c, syn, |
64 mk_triple(Bool.toString b, quote s, tp)) ts))) cons'); |
71 mk_list |
|
72 (map (fn (b,s ,tp) => |
|
73 mk_triple(Bool.toString b, quote s, |
|
74 mk_typ tp)) ts))) cons'); |
|
75 in "val (thy, "^comp_dname^"_equations) = thy |> Domain_Extender.add_domain \n" |
65 in "val (thy, "^comp_dname^"_equations) = thy |> Domain_Extender.add_domain \n" |
76 ^ mk_pair(quote comp_dname, |
66 ^ mk_pair(quote comp_dname, mk_list(map (fn ((n,vs),cs) => |
77 mk_list(map (fn (t,cs)=> mk_pair (mk_tnv t,mk_conslist cs)) eqs')) |
67 mk_pair (mk_pair (quote n, mk_list vs), |
|
68 mk_conslist cs)) eqs')) |
78 ^ ";\nval thy = thy" |
69 ^ ";\nval thy = thy" |
79 end; |
70 end; |
80 |
71 |
81 (* ----- string for calling (comp_)theorems and producing the structures ---------- *) |
72 (* ----- string for calling (comp_)theorems and producing the structures ---- *) |
82 |
73 |
83 val val_gen_string = let |
74 val val_gen_string = let |
84 fun plural s = if num > 1 then s^"s" else "["^s^"]"; |
75 fun plural s = if num > 1 then s^"s" else "["^s^"]"; |
85 val comp_axioms = [(* copy, *) "reach", "take_def", "finite_def" |
76 val comp_axioms = [(* copy, *) "reach", "take_def", "finite_def" |
86 (*, "bisim_def" *)]; |
77 (*, "bisim_def" *)]; |
124 |
115 |
125 (* ----- parser for domain declaration equation ----------------------------------- *) |
116 (* ----- parser for domain declaration equation ----------------------------------- *) |
126 |
117 |
127 val name' = name >> strip_quotes; |
118 val name' = name >> strip_quotes; |
128 val type_var' = type_var >> strip_quotes; |
119 val type_var' = type_var >> strip_quotes; |
129 val sort = name' >> (fn s => [s]) |
120 fun esc_quote s = let fun esc [] = [] |
130 || "{" $$-- !! (list name' --$$ "}"); |
121 | esc ("\""::xs) = esc xs |
131 val tvar = (type_var' --(optional("::" $$-- !! sort)["_default"])) >>TFree; |
122 | esc ("[" ::xs) = "{"::esc xs |
132 (*val tvar = type_var >> (fn tv => TFree(strip_quotes tv,["pcpo"]));*) |
123 | esc ("]" ::xs) = "}"::esc xs |
133 fun type_args l = ("(" $$-- !! (list1 typ --$$ ")") |
124 | esc (x ::xs) = x ::esc xs |
134 || tvar >> (fn x => [x]) |
125 in implode (esc (explode s)) end; |
135 || empty >> K []) l |
126 val tvar = (type_var' ^^ optional ($$ "::" ^^ (sort >> esc_quote)) "") >> quote; |
136 and con_typ l = (type_args -- name' >> (fn (x,y) => Type(y,x))) l |
127 fun type_args l = (tvar >> (fn x => [x]) |
137 (* here ident may be used instead of name' |
128 || "(" $$-- !! (list1 tvar --$$ ")") |
138 to avoid ambiguity with standard mixfix option *) |
129 || empty >> K []) l |
139 and typ l = (con_typ |
130 fun con_typ l = (type_args -- name' >> (fn (x,y) => (y,x))) l |
140 || tvar) l; |
131 (* here ident may be used instead of name' |
|
132 to avoid ambiguity with standard mixfix option *) |
141 val domain_arg = "(" $$-- (optional ($$ "lazy" >> K true) false) |
133 val domain_arg = "(" $$-- (optional ($$ "lazy" >> K true) false) |
142 -- (optional ((name' >> Some) --$$ "::") None) |
134 -- (optional ((name' >> Some) --$$ "::") None) |
143 -- typ --$$ ")" >> (fn ((lazy,sel),tp) => (lazy,sel,tp)) |
135 -- typ --$$ ")" >> (fn ((lazy,sel),tp) => (lazy,sel,tp)) |
144 || name' >> (fn x => (false,None,Type(x,[]))) |
136 || typ >> (fn x => (false,None,x)) |
145 || tvar >> (fn x => (false,None,x)); |
|
146 val domain_cons = name' -- !! (repeat domain_arg) |
137 val domain_cons = name' -- !! (repeat domain_arg) |
147 -- ThyOps.opt_cmixfix |
138 -- ThyOps.opt_cmixfix |
148 >> (fn ((con,args),syn) => (con,syn,args)); |
139 >> (fn ((con,args),syn) => (con,syn,args)); |
149 in |
140 in |
150 val domain_decl = (enum1 "," (con_typ --$$ "=" -- !! |
141 val domain_decl = (enum1 "," (con_typ --$$ "=" -- !! |
151 (enum1 "|" domain_cons))) >> mk_domain; |
142 (enum1 "|" domain_cons))) >> mk_domain; |
152 val gen_by_decl = (optional ($$ "finite" >> K true) false) -- |
143 val gen_by_decl = (optional ($$ "finite" >> K true) false) -- |
153 (enum1 "," (name' --$$ "by" -- !! |
144 (enum1 "," (name' --$$ "by" -- !! |
154 (enum1 "|" name'))) >> mk_gen_by; |
145 (enum1 "|" name'))) >> mk_gen_by; |
155 |
146 |
156 val _ = ThySyn.add_syntax |
147 val _ = ThySyn.add_syntax |