author | Christian Urban <urbanc@in.tum.de> |
Thu, 25 Feb 2010 11:51:34 +0100 | |
changeset 1266 | b0a120469041 |
parent 1261 | 853abc14c5c6 |
child 1283 | 6a133abb7633 |
permissions | -rw-r--r-- |
1261
853abc14c5c6
added IsaMakefile...but so far included only a test for the parser
Christian Urban <urbanc@in.tum.de>
parents:
1258
diff
changeset
|
1 |
theory Parser |
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
2 |
imports "Nominal2_Atoms" "Nominal2_Eqvt" "Nominal2_Supp" |
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
3 |
begin |
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
4 |
|
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
5 |
atom_decl name |
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
6 |
|
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
7 |
|
1194
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
8 |
section{* Interface for nominal_datatype *} |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
9 |
|
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
10 |
text {* |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
11 |
|
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
12 |
Nominal-Datatype-part: |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
13 |
|
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
14 |
|
1266 | 15 |
1nd Arg: (string list * binding * mixfix * (binding * typ list * mixfix) list) list |
1194
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
16 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
17 |
type(s) to be defined constructors list |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
18 |
(ty args, name, syn) (name, typs, syn) |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
19 |
|
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
20 |
Binder-Function-part: |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
21 |
|
1266 | 22 |
2rd Arg: (binding * typ option * mixfix) list |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
23 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
1194
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
24 |
binding function(s) |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
25 |
to be defined |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
26 |
(name, type, syn) |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
27 |
|
1266 | 28 |
3th Arg: term list |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
29 |
^^^^^^^^^ |
1194
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
30 |
the equations of the binding functions |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
31 |
(Trueprop equations) |
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
32 |
*} |
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
33 |
|
1194
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
34 |
text {*****************************************************} |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
35 |
ML {* |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
36 |
(* nominal datatype parser *) |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
37 |
local |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
38 |
structure P = OuterParse |
1266 | 39 |
|
40 |
fun tuple ((x, y, z), u) = (x, y, z, u) |
|
1194
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
41 |
in |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
42 |
|
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
43 |
val _ = OuterKeyword.keyword "bind" |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
44 |
val anno_typ = Scan.option (P.name --| P.$$$ "::") -- P.typ |
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
45 |
|
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
46 |
(* binding specification *) |
1266 | 47 |
(* maybe use and_list *) |
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
48 |
val bind_parser = |
1194
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
49 |
P.enum "," ((P.$$$ "bind" |-- P.term) -- (P.$$$ "in" |-- P.name)) |
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
50 |
|
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
51 |
val constr_parser = |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
52 |
P.binding -- Scan.repeat anno_typ |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
53 |
|
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
54 |
(* datatype parser *) |
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
55 |
val dt_parser = |
1266 | 56 |
(P.type_args -- P.binding -- P.opt_infix >> P.triple1) -- |
57 |
(P.$$$ "=" |-- P.enum1 "|" (constr_parser -- bind_parser -- P.opt_mixfix >> P.triple_swap)) >> tuple |
|
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
58 |
|
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
59 |
(* function equation parser *) |
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
60 |
val fun_parser = |
1194
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
61 |
Scan.optional (P.$$$ "binder" |-- P.fixes -- SpecParse.where_alt_specs) ([],[]) |
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
62 |
|
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
63 |
(* main parser *) |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
64 |
val main_parser = |
1266 | 65 |
(P.and_list1 dt_parser) -- fun_parser >> P.triple2 |
1194
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
66 |
|
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
67 |
end |
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
68 |
*} |
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
69 |
|
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
70 |
(* adds "_raw" to the end of constants and types *) |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
71 |
ML {* |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
72 |
fun add_raw s = s ^ "_raw" |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
73 |
fun add_raws ss = map add_raw ss |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
74 |
fun raw_bind bn = Binding.suffix_name "_raw" bn |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
75 |
|
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
76 |
fun replace_str ss s = |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
77 |
case (AList.lookup (op=) ss s) of |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
78 |
SOME s' => s' |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
79 |
| NONE => s |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
80 |
|
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
81 |
fun replace_typ ty_ss (Type (a, Ts)) = Type (replace_str ty_ss a, map (replace_typ ty_ss) Ts) |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
82 |
| replace_typ ty_ss T = T |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
83 |
|
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
84 |
fun raw_dts ty_ss dts = |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
85 |
let |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
86 |
val ty_ss' = ty_ss ~~ (add_raws ty_ss) |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
87 |
|
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
88 |
fun raw_dts_aux1 (bind, tys, mx) = |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
89 |
(raw_bind bind, map (replace_typ ty_ss') tys, mx) |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
90 |
|
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
91 |
fun raw_dts_aux2 (ty_args, bind, mx, constrs) = |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
92 |
(ty_args, raw_bind bind, mx, map raw_dts_aux1 constrs) |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
93 |
in |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
94 |
map raw_dts_aux2 dts |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
95 |
end |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
96 |
|
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
97 |
fun replace_aterm trm_ss (Const (a, T)) = Const (replace_str trm_ss a, T) |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
98 |
| replace_aterm trm_ss (Free (a, T)) = Free (replace_str trm_ss a, T) |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
99 |
| replace_aterm trm_ss trm = trm |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
100 |
|
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
101 |
fun replace_term trm_ss ty_ss trm = |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
102 |
trm |> Term.map_aterms (replace_aterm trm_ss) |> map_types (replace_typ ty_ss) |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
103 |
*} |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
104 |
|
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
105 |
ML {* |
1232
35bc8f7b66f8
parsing of function definitions almost works now; still an error with undefined constants
Christian Urban <urbanc@in.tum.de>
parents:
1228
diff
changeset
|
106 |
fun get_constrs dts = |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
107 |
flat (map (fn (_, _, _, constrs) => constrs) dts) |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
108 |
|
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
109 |
fun get_typed_constrs dts = |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
110 |
flat (map (fn (_, bn, _, constrs) => |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
111 |
(map (fn (bn', _, _) => (Binding.name_of bn, Binding.name_of bn')) constrs)) dts) |
1232
35bc8f7b66f8
parsing of function definitions almost works now; still an error with undefined constants
Christian Urban <urbanc@in.tum.de>
parents:
1228
diff
changeset
|
112 |
|
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
113 |
fun get_constr_strs dts = |
1232
35bc8f7b66f8
parsing of function definitions almost works now; still an error with undefined constants
Christian Urban <urbanc@in.tum.de>
parents:
1228
diff
changeset
|
114 |
map (fn (bn, _, _) => Binding.name_of bn) (get_constrs dts) |
35bc8f7b66f8
parsing of function definitions almost works now; still an error with undefined constants
Christian Urban <urbanc@in.tum.de>
parents:
1228
diff
changeset
|
115 |
|
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
116 |
fun get_bn_fun_strs bn_funs = |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
117 |
map (fn (bn_fun, _, _) => Binding.name_of bn_fun) bn_funs |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
118 |
*} |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
119 |
|
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
120 |
ML {* |
1228
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
121 |
fun raw_dts_decl dt_names dts lthy = |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
122 |
let |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
123 |
val thy = ProofContext.theory_of lthy |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
124 |
val conf = Datatype.default_config |
1228
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
125 |
|
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
126 |
val dt_names' = add_raws dt_names |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
127 |
val dt_full_names = map (Sign.full_bname thy) dt_names |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
128 |
val dts' = raw_dts dt_full_names dts |
1228
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
129 |
in |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
130 |
lthy |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
131 |
|> Local_Theory.theory_result (Datatype.add_datatype conf dt_names' dts') |
1228
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
132 |
end |
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
133 |
*} |
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
134 |
|
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
135 |
ML {* |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
136 |
fun raw_bn_fun_decl dt_names dts bn_funs bn_eqs lthy = |
1228
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
137 |
let |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
138 |
val thy = ProofContext.theory_of lthy |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
139 |
|
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
140 |
val dt_names' = add_raws dt_names |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
141 |
val dt_full_names = map (Sign.full_bname thy) dt_names |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
142 |
val dt_full_names' = map (Sign.full_bname thy) dt_names' |
1266 | 143 |
val dt_env = dt_full_names ~~ dt_full_names' |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
144 |
|
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
145 |
val ctrs_names = map (Sign.full_bname thy) (get_constr_strs dts) |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
146 |
val ctrs_names' = map (fn (x, y) => (Sign.full_bname_path thy (add_raw x) (add_raw y))) |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
147 |
(get_typed_constrs dts) |
1266 | 148 |
val ctrs_env = ctrs_names ~~ ctrs_names' |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
149 |
|
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
150 |
val bn_fun_strs = get_bn_fun_strs bn_funs |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
151 |
val bn_fun_strs' = add_raws bn_fun_strs |
1266 | 152 |
val bn_fun_env = bn_fun_strs ~~ bn_fun_strs' |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
153 |
|
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
154 |
val bn_funs' = map (fn (bn, opt_ty, mx) => |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
155 |
(raw_bind bn, Option.map (replace_typ (dt_full_names ~~ dt_full_names')) opt_ty, mx)) bn_funs |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
156 |
|
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
157 |
val bn_eqs' = map (fn trm => |
1266 | 158 |
(Attrib.empty_binding, replace_term (ctrs_env @ bn_fun_env) dt_env trm)) bn_eqs |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
159 |
in |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
160 |
if null bn_eqs |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
161 |
then (([], []), lthy) |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
162 |
else Primrec.add_primrec bn_funs' bn_eqs' lthy |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
163 |
end |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
164 |
*} |
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
165 |
|
1228
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
166 |
ML {* |
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
167 |
fun nominal_datatype2 dts bn_funs bn_eqs lthy = |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
168 |
let |
1228
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
169 |
val dts_names = map (fn (_, s, _, _) => Binding.name_of s) dts |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
170 |
in |
1228
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
171 |
lthy |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
172 |
|> raw_dts_decl dts_names dts |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
173 |
||>> raw_bn_fun_decl dts_names dts bn_funs bn_eqs |
978
b44592adf235
Improper interface for datatype and function packages and proper interface lateron.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
973
diff
changeset
|
174 |
end |
b44592adf235
Improper interface for datatype and function packages and proper interface lateron.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
973
diff
changeset
|
175 |
*} |
b44592adf235
Improper interface for datatype and function packages and proper interface lateron.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
973
diff
changeset
|
176 |
|
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
177 |
ML {* |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
178 |
fun get_constrs2 thy dts = |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
179 |
let |
1266 | 180 |
(* makes a full named type out of a binding with tvars applied to it *) |
181 |
fun mk_type thy bind tvrs = |
|
182 |
Type (Sign.full_name thy bind, map (fn s => TVar ((s, 0), [])) tvrs) |
|
183 |
||
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
184 |
val dts' = map (fn (tvrs, tname, _, constrs) => (mk_type thy tname tvrs, constrs)) dts |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
185 |
in |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
186 |
flat (map (fn (ty, constrs) => map (fn (bn, tys, mx) => (bn, tys ---> ty, mx)) constrs) dts') |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
187 |
end |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
188 |
*} |
1232
35bc8f7b66f8
parsing of function definitions almost works now; still an error with undefined constants
Christian Urban <urbanc@in.tum.de>
parents:
1228
diff
changeset
|
189 |
|
978
b44592adf235
Improper interface for datatype and function packages and proper interface lateron.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
973
diff
changeset
|
190 |
ML {* |
1266 | 191 |
fun nominal_datatype2_cmd (dt_strs, bn_fun_strs, bn_eq_strs) lthy = |
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
192 |
let |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
193 |
val thy = ProofContext.theory_of lthy |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
194 |
|
1266 | 195 |
fun prep_typ (tvs, tname, mx, _) = (tname, length tvs, mx); |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
196 |
|
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
197 |
(* adding the types for parsing datatypes *) |
1228
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
198 |
val lthy_tmp = lthy |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
199 |
|> Local_Theory.theory (Sign.add_types (map prep_typ dt_strs)) |
978
b44592adf235
Improper interface for datatype and function packages and proper interface lateron.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
973
diff
changeset
|
200 |
|
1228
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
201 |
fun prep_cnstr lthy (((cname, atys), mx), binders) = |
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
202 |
(cname, map (Syntax.read_typ lthy o snd) atys, mx) |
1194
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
203 |
|
1266 | 204 |
fun prep_dt lthy (tvs, tname, mx, cnstrs) = |
1228
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
205 |
(tvs, tname, mx, map (prep_cnstr lthy) cnstrs) |
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
206 |
|
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
207 |
(* parsing the datatypes *) |
1232
35bc8f7b66f8
parsing of function definitions almost works now; still an error with undefined constants
Christian Urban <urbanc@in.tum.de>
parents:
1228
diff
changeset
|
208 |
val dts_prep = map (prep_dt lthy_tmp) dt_strs |
1194
3d54fcc5f41a
start work with the parser
Christian Urban <urbanc@in.tum.de>
parents:
1087
diff
changeset
|
209 |
|
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
210 |
(* adding constructors for parsing functions *) |
1232
35bc8f7b66f8
parsing of function definitions almost works now; still an error with undefined constants
Christian Urban <urbanc@in.tum.de>
parents:
1228
diff
changeset
|
211 |
val lthy_tmp2 = lthy_tmp |
1251
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
212 |
|> Local_Theory.theory (Sign.add_consts_i (get_constrs2 thy dts_prep)) |
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
213 |
|
11b8798dea5d
parsing and definition of raw datatype and bv-function work (not very beautiful)
Christian Urban <urbanc@in.tum.de>
parents:
1232
diff
changeset
|
214 |
val (bn_fun_aux, bn_eq_aux) = fst (Specification.read_spec bn_fun_strs bn_eq_strs lthy_tmp2) |
1232
35bc8f7b66f8
parsing of function definitions almost works now; still an error with undefined constants
Christian Urban <urbanc@in.tum.de>
parents:
1228
diff
changeset
|
215 |
|
35bc8f7b66f8
parsing of function definitions almost works now; still an error with undefined constants
Christian Urban <urbanc@in.tum.de>
parents:
1228
diff
changeset
|
216 |
fun prep_bn_fun ((bn, T), mx) = (bn, SOME T, mx) |
35bc8f7b66f8
parsing of function definitions almost works now; still an error with undefined constants
Christian Urban <urbanc@in.tum.de>
parents:
1228
diff
changeset
|
217 |
|
35bc8f7b66f8
parsing of function definitions almost works now; still an error with undefined constants
Christian Urban <urbanc@in.tum.de>
parents:
1228
diff
changeset
|
218 |
fun prep_bn_eq (attr, t) = t |
1228
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
219 |
|
1232
35bc8f7b66f8
parsing of function definitions almost works now; still an error with undefined constants
Christian Urban <urbanc@in.tum.de>
parents:
1228
diff
changeset
|
220 |
val bn_fun_prep = map prep_bn_fun bn_fun_aux |
35bc8f7b66f8
parsing of function definitions almost works now; still an error with undefined constants
Christian Urban <urbanc@in.tum.de>
parents:
1228
diff
changeset
|
221 |
val bn_eq_prep = map prep_bn_eq bn_eq_aux |
969
cc5d18c78446
Parsing of the input as terms and types, and passing them as such to the function package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
968
diff
changeset
|
222 |
in |
1232
35bc8f7b66f8
parsing of function definitions almost works now; still an error with undefined constants
Christian Urban <urbanc@in.tum.de>
parents:
1228
diff
changeset
|
223 |
nominal_datatype2 dts_prep bn_fun_prep bn_eq_prep lthy |> snd |
969
cc5d18c78446
Parsing of the input as terms and types, and passing them as such to the function package.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
968
diff
changeset
|
224 |
end |
966
8ba35ce16f7e
Some cleaning of thy vs lthy vs context.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
962
diff
changeset
|
225 |
*} |
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
226 |
|
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
227 |
(* Command Keyword *) |
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
228 |
ML {* |
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
229 |
let |
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
230 |
val kind = OuterKeyword.thy_decl |
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
231 |
in |
1228
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
232 |
OuterSyntax.local_theory "nominal_datatype" "test" kind |
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
233 |
(main_parser >> nominal_datatype2_cmd) |
954
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
234 |
end |
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
235 |
*} |
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
236 |
|
c009d2535896
very rough example file for how nominal2 specification can be parsed
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
237 |
|
961
0f88e04eb486
Variable takes a 'name'.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
954
diff
changeset
|
238 |
end |
1223
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
239 |
|
160343d86a6f
"raw"-ified the term-constructors and types given in the specification
Christian Urban <urbanc@in.tum.de>
parents:
1194
diff
changeset
|
240 |
|
1228
c179ad9d2446
declarartion of the raw datatype already works; raw binding functions throw an exception about mutual recursive types
Christian Urban <urbanc@in.tum.de>
parents:
1223
diff
changeset
|
241 |