author | wenzelm |
Mon, 05 Jun 2017 15:56:00 +0200 | |
changeset 66008 | 010698325e36 |
parent 63402 | f199837304d7 |
child 66334 | b210ae666a42 |
permissions | -rw-r--r-- |
28308 | 1 |
(* Title: HOL/Statespace/state_space.ML |
25171 | 2 |
Author: Norbert Schirmer, TU Muenchen |
3 |
*) |
|
4 |
||
25408 | 5 |
signature STATE_SPACE = |
45362 | 6 |
sig |
7 |
val distinct_compsN : string |
|
8 |
val getN : string |
|
9 |
val putN : string |
|
10 |
val injectN : string |
|
11 |
val namespaceN : string |
|
12 |
val projectN : string |
|
13 |
val valuetypesN : string |
|
25408 | 14 |
|
45362 | 15 |
val namespace_definition : |
16 |
bstring -> |
|
17 |
typ -> |
|
46925 | 18 |
(xstring, string) Expression.expr * (binding * string option * mixfix) list -> |
45362 | 19 |
string list -> string list -> theory -> theory |
25408 | 20 |
|
45362 | 21 |
val define_statespace : |
22 |
string list -> |
|
23 |
string -> |
|
49754
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
48741
diff
changeset
|
24 |
((string * bool) * (string list * bstring * (string * string) list)) list -> |
45362 | 25 |
(string * string) list -> theory -> theory |
26 |
val define_statespace_i : |
|
27 |
string option -> |
|
28 |
string list -> |
|
29 |
string -> |
|
49754
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
48741
diff
changeset
|
30 |
((string * bool) * (typ list * bstring * (string * string) list)) list -> |
45362 | 31 |
(string * typ) list -> theory -> theory |
25408 | 32 |
|
45362 | 33 |
val statespace_decl : |
34 |
((string list * bstring) * |
|
49754
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
48741
diff
changeset
|
35 |
(((string * bool) * (string list * xstring * (bstring * bstring) list)) list * |
45362 | 36 |
(bstring * string) list)) parser |
25408 | 37 |
|
38 |
||
45362 | 39 |
val neq_x_y : Proof.context -> term -> term -> thm option |
40 |
val distinctNameSolver : Simplifier.solver |
|
41 |
val distinctTree_tac : Proof.context -> int -> tactic |
|
42 |
val distinct_simproc : Simplifier.simproc |
|
25408 | 43 |
|
44 |
||
48741 | 45 |
val get_comp : Context.generic -> string -> (typ * string) option |
45362 | 46 |
val get_silent : Context.generic -> bool |
47 |
val set_silent : bool -> Context.generic -> Context.generic |
|
25408 | 48 |
|
45362 | 49 |
val gen_lookup_tr : Proof.context -> term -> string -> term |
50 |
val lookup_swap_tr : Proof.context -> term list -> term |
|
51 |
val lookup_tr : Proof.context -> term list -> term |
|
52 |
val lookup_tr' : Proof.context -> term list -> term |
|
25408 | 53 |
|
45362 | 54 |
val gen_update_tr : |
55 |
bool -> Proof.context -> string -> term -> term -> term |
|
56 |
val update_tr : Proof.context -> term list -> term |
|
57 |
val update_tr' : Proof.context -> term list -> term |
|
58 |
end; |
|
25408 | 59 |
|
29247
95d3a82857e5
adapted statespace module to new locales;
Norbert Schirmer <norbert.schirmer@web.de>
parents:
29064
diff
changeset
|
60 |
structure StateSpace : STATE_SPACE = |
25171 | 61 |
struct |
62 |
||
45362 | 63 |
(* Names *) |
25171 | 64 |
|
65 |
val distinct_compsN = "distinct_names" |
|
66 |
val namespaceN = "_namespace" |
|
67 |
val valuetypesN = "_valuetypes" |
|
68 |
val projectN = "project" |
|
69 |
val injectN = "inject" |
|
70 |
val getN = "get" |
|
71 |
val putN = "put" |
|
72 |
val project_injectL = "StateSpaceLocale.project_inject"; |
|
73 |
||
74 |
||
75 |
(* Library *) |
|
76 |
||
77 |
fun fold1 f xs = fold f (tl xs) (hd xs) |
|
78 |
fun fold1' f [] x = x |
|
79 |
| fold1' f xs _ = fold1 f xs |
|
26478 | 80 |
|
25171 | 81 |
fun sorted_subset eq [] ys = true |
82 |
| sorted_subset eq (x::xs) [] = false |
|
83 |
| sorted_subset eq (x::xs) (y::ys) = if eq (x,y) then sorted_subset eq xs ys |
|
84 |
else sorted_subset eq (x::xs) ys; |
|
85 |
||
86 |
||
87 |
||
88 |
type namespace_info = |
|
89 |
{declinfo: (typ*string) Termtab.table, (* type, name of statespace *) |
|
90 |
distinctthm: thm Symtab.table, |
|
91 |
silent: bool |
|
92 |
}; |
|
26478 | 93 |
|
33519 | 94 |
structure NameSpaceData = Generic_Data |
95 |
( |
|
26478 | 96 |
type T = namespace_info; |
25171 | 97 |
val empty = {declinfo = Termtab.empty, distinctthm = Symtab.empty, silent = false}; |
98 |
val extend = I; |
|
33519 | 99 |
fun merge |
100 |
({declinfo=declinfo1, distinctthm=distinctthm1, silent=silent1}, |
|
101 |
{declinfo=declinfo2, distinctthm=distinctthm2, silent=silent2}) : T = |
|
102 |
{declinfo = Termtab.merge (K true) (declinfo1, declinfo2), |
|
103 |
distinctthm = Symtab.merge (K true) (distinctthm1, distinctthm2), |
|
41472
f6ab14e61604
misc tuning and comments based on review of Theory_Data, Proof_Data, Generic_Data usage;
wenzelm
parents:
41270
diff
changeset
|
104 |
silent = silent1 andalso silent2 (* FIXME odd merge *)} |
33519 | 105 |
); |
25171 | 106 |
|
107 |
fun make_namespace_data declinfo distinctthm silent = |
|
108 |
{declinfo=declinfo,distinctthm=distinctthm,silent=silent}; |
|
109 |
||
110 |
||
111 |
fun update_declinfo (n,v) ctxt = |
|
112 |
let val {declinfo,distinctthm,silent} = NameSpaceData.get ctxt; |
|
26478 | 113 |
in NameSpaceData.put |
25171 | 114 |
(make_namespace_data (Termtab.update (n,v) declinfo) distinctthm silent) ctxt |
115 |
end; |
|
116 |
||
117 |
fun set_silent silent ctxt = |
|
118 |
let val {declinfo,distinctthm,...} = NameSpaceData.get ctxt; |
|
26478 | 119 |
in NameSpaceData.put |
25171 | 120 |
(make_namespace_data declinfo distinctthm silent) ctxt |
121 |
end; |
|
122 |
||
123 |
val get_silent = #silent o NameSpaceData.get; |
|
26478 | 124 |
|
46925 | 125 |
fun expression_no_pos (expr, fixes) : Expression.expression = |
126 |
(map (fn (name, inst) => ((name, Position.none), inst)) expr, fixes); |
|
127 |
||
25171 | 128 |
fun prove_interpretation_in ctxt_tac (name, expr) thy = |
129 |
thy |
|
61673
fd4ac1530d63
represent both algebraic and local-theory views on locale interpretation in interfaces
haftmann
parents:
61669
diff
changeset
|
130 |
|> Interpretation.global_sublocale_cmd (name, Position.none) (expression_no_pos expr) [] [] |
26478 | 131 |
|> Proof.global_terminal_proof |
49889
00ea087e83d8
more method position information, notably finished_pos after end of previous text;
wenzelm
parents:
49866
diff
changeset
|
132 |
((Method.Basic (fn ctxt => SIMPLE_METHOD (ctxt_tac ctxt)), Position.no_range), NONE) |
42361 | 133 |
|> Proof_Context.theory_of |
25171 | 134 |
|
29247
95d3a82857e5
adapted statespace module to new locales;
Norbert Schirmer <norbert.schirmer@web.de>
parents:
29064
diff
changeset
|
135 |
fun add_locale name expr elems thy = |
45362 | 136 |
thy |
57181
2d13bf9ea77b
dropped obscure and unused ad-hoc before_exit hook for named targets
haftmann
parents:
55972
diff
changeset
|
137 |
|> Expression.add_locale (Binding.name name) (Binding.name name) expr elems |
29362 | 138 |
|> snd |
33671 | 139 |
|> Local_Theory.exit; |
29247
95d3a82857e5
adapted statespace module to new locales;
Norbert Schirmer <norbert.schirmer@web.de>
parents:
29064
diff
changeset
|
140 |
|
95d3a82857e5
adapted statespace module to new locales;
Norbert Schirmer <norbert.schirmer@web.de>
parents:
29064
diff
changeset
|
141 |
fun add_locale_cmd name expr elems thy = |
45362 | 142 |
thy |
57181
2d13bf9ea77b
dropped obscure and unused ad-hoc before_exit hook for named targets
haftmann
parents:
55972
diff
changeset
|
143 |
|> Expression.add_locale_cmd (Binding.name name) Binding.empty (expression_no_pos expr) elems |
29362 | 144 |
|> snd |
33671 | 145 |
|> Local_Theory.exit; |
29247
95d3a82857e5
adapted statespace module to new locales;
Norbert Schirmer <norbert.schirmer@web.de>
parents:
29064
diff
changeset
|
146 |
|
25171 | 147 |
type statespace_info = |
148 |
{args: (string * sort) list, (* type arguments *) |
|
149 |
parents: (typ list * string * string option list) list, |
|
150 |
(* type instantiation, state-space name, component renamings *) |
|
151 |
components: (string * typ) list, |
|
152 |
types: typ list (* range types of state space *) |
|
153 |
}; |
|
154 |
||
33519 | 155 |
structure StateSpaceData = Generic_Data |
156 |
( |
|
25171 | 157 |
type T = statespace_info Symtab.table; |
158 |
val empty = Symtab.empty; |
|
159 |
val extend = I; |
|
33519 | 160 |
fun merge data : T = Symtab.merge (K true) data; |
161 |
); |
|
25171 | 162 |
|
163 |
fun add_statespace name args parents components types ctxt = |
|
26478 | 164 |
StateSpaceData.put |
25171 | 165 |
(Symtab.update_new (name, {args=args,parents=parents, |
166 |
components=components,types=types}) (StateSpaceData.get ctxt)) |
|
26478 | 167 |
ctxt; |
25171 | 168 |
|
169 |
fun get_statespace ctxt name = |
|
170 |
Symtab.lookup (StateSpaceData.get ctxt) name; |
|
171 |
||
172 |
||
173 |
fun mk_free ctxt name = |
|
26478 | 174 |
if Variable.is_fixed ctxt name orelse Variable.is_declared ctxt name |
25171 | 175 |
then |
59900
a5591a15112e
imitate old "intern" semantics for the sake of outdated/unmaintained code, notably relevant for Simpl;
wenzelm
parents:
59582
diff
changeset
|
176 |
let val n' = Variable.intern_fixed ctxt name |> perhaps Long_Name.dest_hidden; |
42488
4638622bcaa1
reorganized fixes as specialized (global) name space;
wenzelm
parents:
42368
diff
changeset
|
177 |
in SOME (Free (n', Proof_Context.infer_type ctxt (n', dummyT))) end |
25171 | 178 |
else NONE |
26478 | 179 |
|
180 |
||
25171 | 181 |
fun get_dist_thm ctxt name = Symtab.lookup (#distinctthm (NameSpaceData.get ctxt)) name; |
26478 | 182 |
fun get_comp ctxt name = |
183 |
Option.mapPartial |
|
184 |
(Termtab.lookup (#declinfo (NameSpaceData.get ctxt))) |
|
25171 | 185 |
(mk_free (Context.proof_of ctxt) name); |
186 |
||
187 |
||
188 |
(*** Tactics ***) |
|
189 |
||
190 |
fun neq_x_y ctxt x y = |
|
191 |
(let |
|
26478 | 192 |
val dist_thm = the (get_dist_thm (Context.Proof ctxt) (#1 (dest_Free x))); |
59582 | 193 |
val ctree = Thm.cprop_of dist_thm |> Thm.dest_comb |> #2 |> Thm.dest_comb |> #2; |
194 |
val tree = Thm.term_of ctree; |
|
25171 | 195 |
val x_path = the (DistinctTreeProver.find_tree x tree); |
196 |
val y_path = the (DistinctTreeProver.find_tree y tree); |
|
60327 | 197 |
val thm = DistinctTreeProver.distinctTreeProver ctxt dist_thm x_path y_path; |
26478 | 198 |
in SOME thm |
45361 | 199 |
end handle Option.Option => NONE) |
25171 | 200 |
|
42368
3b8498ac2314
proper subgoal addressing via SUBGOAL/CSUBGOAL -- assuming these tactics did not handle Subscript in any special way;
wenzelm
parents:
42364
diff
changeset
|
201 |
fun distinctTree_tac ctxt = SUBGOAL (fn (goal, i) => |
3b8498ac2314
proper subgoal addressing via SUBGOAL/CSUBGOAL -- assuming these tactics did not handle Subscript in any special way;
wenzelm
parents:
42364
diff
changeset
|
202 |
(case goal of |
3b8498ac2314
proper subgoal addressing via SUBGOAL/CSUBGOAL -- assuming these tactics did not handle Subscript in any special way;
wenzelm
parents:
42364
diff
changeset
|
203 |
Const (@{const_name Trueprop}, _) $ |
3b8498ac2314
proper subgoal addressing via SUBGOAL/CSUBGOAL -- assuming these tactics did not handle Subscript in any special way;
wenzelm
parents:
42364
diff
changeset
|
204 |
(Const (@{const_name Not}, _) $ |
3b8498ac2314
proper subgoal addressing via SUBGOAL/CSUBGOAL -- assuming these tactics did not handle Subscript in any special way;
wenzelm
parents:
42364
diff
changeset
|
205 |
(Const (@{const_name HOL.eq}, _) $ (x as Free _) $ (y as Free _))) => |
3b8498ac2314
proper subgoal addressing via SUBGOAL/CSUBGOAL -- assuming these tactics did not handle Subscript in any special way;
wenzelm
parents:
42364
diff
changeset
|
206 |
(case neq_x_y ctxt x y of |
60754 | 207 |
SOME neq => resolve_tac ctxt [neq] i |
42368
3b8498ac2314
proper subgoal addressing via SUBGOAL/CSUBGOAL -- assuming these tactics did not handle Subscript in any special way;
wenzelm
parents:
42364
diff
changeset
|
208 |
| NONE => no_tac) |
3b8498ac2314
proper subgoal addressing via SUBGOAL/CSUBGOAL -- assuming these tactics did not handle Subscript in any special way;
wenzelm
parents:
42364
diff
changeset
|
209 |
| _ => no_tac)); |
25171 | 210 |
|
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
50214
diff
changeset
|
211 |
val distinctNameSolver = mk_solver "distinctNameSolver" distinctTree_tac; |
25171 | 212 |
|
213 |
val distinct_simproc = |
|
61144 | 214 |
Simplifier.make_simproc @{context} "StateSpace.distinct_simproc" |
215 |
{lhss = [@{term "x = y"}], |
|
216 |
proc = fn _ => fn ctxt => fn ct => |
|
217 |
(case Thm.term_of ct of |
|
218 |
Const (@{const_name HOL.eq},_) $ (x as Free _) $ (y as Free _) => |
|
219 |
Option.map (fn neq => DistinctTreeProver.neq_to_eq_False OF [neq]) |
|
220 |
(neq_x_y ctxt x y) |
|
62913 | 221 |
| _ => NONE)}; |
25171 | 222 |
|
26478 | 223 |
fun interprete_parent name dist_thm_name parent_expr thy = |
25171 | 224 |
let |
42368
3b8498ac2314
proper subgoal addressing via SUBGOAL/CSUBGOAL -- assuming these tactics did not handle Subscript in any special way;
wenzelm
parents:
42364
diff
changeset
|
225 |
fun solve_tac ctxt = CSUBGOAL (fn (goal, i) => |
25171 | 226 |
let |
42361 | 227 |
val distinct_thm = Proof_Context.get_thm ctxt dist_thm_name; |
60327 | 228 |
val rule = DistinctTreeProver.distinct_implProver ctxt distinct_thm goal; |
60754 | 229 |
in resolve_tac ctxt [rule] i end); |
26478 | 230 |
|
42368
3b8498ac2314
proper subgoal addressing via SUBGOAL/CSUBGOAL -- assuming these tactics did not handle Subscript in any special way;
wenzelm
parents:
42364
diff
changeset
|
231 |
fun tac ctxt = |
3b8498ac2314
proper subgoal addressing via SUBGOAL/CSUBGOAL -- assuming these tactics did not handle Subscript in any special way;
wenzelm
parents:
42364
diff
changeset
|
232 |
Locale.intro_locales_tac true ctxt [] THEN ALLGOALS (solve_tac ctxt); |
26478 | 233 |
|
45362 | 234 |
in |
235 |
thy |> prove_interpretation_in tac (name, parent_expr) |
|
26478 | 236 |
end; |
25171 | 237 |
|
26478 | 238 |
fun namespace_definition name nameT parent_expr parent_comps new_comps thy = |
25171 | 239 |
let |
240 |
val all_comps = parent_comps @ new_comps; |
|
29247
95d3a82857e5
adapted statespace module to new locales;
Norbert Schirmer <norbert.schirmer@web.de>
parents:
29064
diff
changeset
|
241 |
val vars = (map (fn n => (Binding.name n, NONE, NoSyn)) all_comps); |
25171 | 242 |
val dist_thm_name = distinct_compsN; |
243 |
||
29247
95d3a82857e5
adapted statespace module to new locales;
Norbert Schirmer <norbert.schirmer@web.de>
parents:
29064
diff
changeset
|
244 |
val dist_thm_full_name = dist_thm_name; |
59582 | 245 |
fun comps_of_thm thm = Thm.prop_of thm |
25171 | 246 |
|> (fn (_$(_$t)) => DistinctTreeProver.dest_tree t) |> map (fst o dest_Free); |
26478 | 247 |
|
38835
088502dfd89f
eliminated broken Output.no_warnings_CRITICAL -- context visibility does the job;
wenzelm
parents:
38715
diff
changeset
|
248 |
fun type_attr phi = Thm.declaration_attribute (fn thm => fn context => |
088502dfd89f
eliminated broken Output.no_warnings_CRITICAL -- context visibility does the job;
wenzelm
parents:
38715
diff
changeset
|
249 |
(case context of |
088502dfd89f
eliminated broken Output.no_warnings_CRITICAL -- context visibility does the job;
wenzelm
parents:
38715
diff
changeset
|
250 |
Context.Theory _ => context |
088502dfd89f
eliminated broken Output.no_warnings_CRITICAL -- context visibility does the job;
wenzelm
parents:
38715
diff
changeset
|
251 |
| Context.Proof ctxt => |
26478 | 252 |
let |
38835
088502dfd89f
eliminated broken Output.no_warnings_CRITICAL -- context visibility does the job;
wenzelm
parents:
38715
diff
changeset
|
253 |
val {declinfo,distinctthm=tt,silent} = NameSpaceData.get context; |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32952
diff
changeset
|
254 |
val all_names = comps_of_thm thm; |
25171 | 255 |
fun upd name tt = |
38835
088502dfd89f
eliminated broken Output.no_warnings_CRITICAL -- context visibility does the job;
wenzelm
parents:
38715
diff
changeset
|
256 |
(case Symtab.lookup tt name of |
25171 | 257 |
SOME dthm => if sorted_subset (op =) (comps_of_thm dthm) all_names |
258 |
then Symtab.update (name,thm) tt else tt |
|
38835
088502dfd89f
eliminated broken Output.no_warnings_CRITICAL -- context visibility does the job;
wenzelm
parents:
38715
diff
changeset
|
259 |
| NONE => Symtab.update (name,thm) tt) |
25171 | 260 |
|
261 |
val tt' = tt |> fold upd all_names; |
|
38835
088502dfd89f
eliminated broken Output.no_warnings_CRITICAL -- context visibility does the job;
wenzelm
parents:
38715
diff
changeset
|
262 |
val context' = |
51717
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
50214
diff
changeset
|
263 |
Context_Position.set_visible false ctxt |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
50214
diff
changeset
|
264 |
addsimprocs [distinct_simproc] |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
50214
diff
changeset
|
265 |
|> Context_Position.restore_visible ctxt |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
50214
diff
changeset
|
266 |
|> Context.Proof |
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
wenzelm
parents:
50214
diff
changeset
|
267 |
|> NameSpaceData.put {declinfo=declinfo,distinctthm=tt',silent=silent}; |
38835
088502dfd89f
eliminated broken Output.no_warnings_CRITICAL -- context visibility does the job;
wenzelm
parents:
38715
diff
changeset
|
268 |
in context' end)); |
26478 | 269 |
|
25171 | 270 |
val attr = Attrib.internal type_attr; |
271 |
||
45362 | 272 |
val assume = |
273 |
((Binding.name dist_thm_name, [attr]), |
|
274 |
[(HOLogic.Trueprop $ |
|
275 |
(Const (@{const_name all_distinct}, Type (@{type_name tree}, [nameT]) --> HOLogic.boolT) $ |
|
276 |
DistinctTreeProver.mk_tree (fn n => Free (n, nameT)) nameT |
|
277 |
(sort fast_string_ord all_comps)), [])]); |
|
278 |
in |
|
279 |
thy |
|
280 |
|> add_locale name ([], vars) [Element.Assumes [assume]] |
|
281 |
|> Proof_Context.theory_of |
|
282 |
|> interprete_parent name dist_thm_full_name parent_expr |
|
25171 | 283 |
end; |
284 |
||
55972 | 285 |
fun encode_dot x = if x = #"." then #"_" else x; |
25171 | 286 |
|
287 |
fun encode_type (TFree (s, _)) = s |
|
288 |
| encode_type (TVar ((s,i),_)) = "?" ^ s ^ string_of_int i |
|
26478 | 289 |
| encode_type (Type (n,Ts)) = |
25171 | 290 |
let |
291 |
val Ts' = fold1' (fn x => fn y => x ^ "_" ^ y) (map encode_type Ts) ""; |
|
32651 | 292 |
val n' = String.map encode_dot n; |
25171 | 293 |
in if Ts'="" then n' else Ts' ^ "_" ^ n' end; |
294 |
||
295 |
fun project_name T = projectN ^"_"^encode_type T; |
|
296 |
fun inject_name T = injectN ^"_"^encode_type T; |
|
297 |
||
298 |
||
299 |
fun add_declaration name decl thy = |
|
300 |
thy |
|
63402 | 301 |
|> Named_Target.init NONE name |
45291
57cd50f98fdc
uniform Local_Theory.declaration with explicit params;
wenzelm
parents:
44121
diff
changeset
|
302 |
|> (fn lthy => Local_Theory.declaration {syntax = false, pervasive = false} (decl lthy) lthy) |
33671 | 303 |
|> Local_Theory.exit_global; |
25171 | 304 |
|
305 |
fun parent_components thy (Ts, pname, renaming) = |
|
306 |
let |
|
307 |
val ctxt = Context.Theory thy; |
|
308 |
fun rename [] xs = xs |
|
309 |
| rename (NONE::rs) (x::xs) = x::rename rs xs |
|
310 |
| rename (SOME r::rs) ((x,T)::xs) = (r,T)::rename rs xs; |
|
45362 | 311 |
val {args, parents, components, ...} = the (Symtab.lookup (StateSpaceData.get ctxt) pname); |
25171 | 312 |
val inst = map fst args ~~ Ts; |
313 |
val subst = Term.map_type_tfree (the o AList.lookup (op =) inst o fst); |
|
26478 | 314 |
val parent_comps = |
49754
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
48741
diff
changeset
|
315 |
maps (fn (Ts',n,rs) => parent_components thy (map subst Ts', n, rs)) parents; |
25171 | 316 |
val all_comps = rename renaming (parent_comps @ map (apsnd subst) components); |
317 |
in all_comps end; |
|
318 |
||
319 |
fun statespace_definition state_type args name parents parent_comps components thy = |
|
26478 | 320 |
let |
28965 | 321 |
val full_name = Sign.full_bname thy name; |
25171 | 322 |
val all_comps = parent_comps @ components; |
323 |
||
324 |
val components' = map (fn (n,T) => (n,(T,full_name))) components; |
|
325 |
||
49754
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
48741
diff
changeset
|
326 |
fun parent_expr (prefix, (_, n, rs)) = |
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
48741
diff
changeset
|
327 |
(suffix namespaceN n, (prefix, Expression.Positional rs)); |
29247
95d3a82857e5
adapted statespace module to new locales;
Norbert Schirmer <norbert.schirmer@web.de>
parents:
29064
diff
changeset
|
328 |
val parents_expr = map parent_expr parents; |
25171 | 329 |
fun distinct_types Ts = |
27276 | 330 |
let val tab = fold (fn T => fn tab => Typtab.update (T,()) tab) Ts Typtab.empty; |
331 |
in map fst (Typtab.dest tab) end; |
|
25171 | 332 |
|
333 |
val Ts = distinct_types (map snd all_comps); |
|
334 |
val arg_names = map fst args; |
|
43324
2b47822868e4
discontinued Name.variant to emphasize that this is old-style / indirect;
wenzelm
parents:
43278
diff
changeset
|
335 |
val valueN = singleton (Name.variant_list arg_names) "'value"; |
2b47822868e4
discontinued Name.variant to emphasize that this is old-style / indirect;
wenzelm
parents:
43278
diff
changeset
|
336 |
val nameN = singleton (Name.variant_list (valueN :: arg_names)) "'name"; |
25171 | 337 |
val valueT = TFree (valueN, Sign.defaultS thy); |
338 |
val nameT = TFree (nameN, Sign.defaultS thy); |
|
339 |
val stateT = nameT --> valueT; |
|
340 |
fun projectT T = valueT --> T; |
|
26478 | 341 |
fun injectT T = T --> valueT; |
29247
95d3a82857e5
adapted statespace module to new locales;
Norbert Schirmer <norbert.schirmer@web.de>
parents:
29064
diff
changeset
|
342 |
val locinsts = map (fn T => (project_injectL, |
49754
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
48741
diff
changeset
|
343 |
((encode_type T,false),Expression.Positional |
45362 | 344 |
[SOME (Free (project_name T,projectT T)), |
29247
95d3a82857e5
adapted statespace module to new locales;
Norbert Schirmer <norbert.schirmer@web.de>
parents:
29064
diff
changeset
|
345 |
SOME (Free ((inject_name T,injectT T)))]))) Ts; |
32952 | 346 |
val locs = maps (fn T => [(Binding.name (project_name T),NONE,NoSyn), |
347 |
(Binding.name (inject_name T),NONE,NoSyn)]) Ts; |
|
348 |
val constrains = maps (fn T => [(project_name T,projectT T),(inject_name T,injectT T)]) Ts; |
|
25171 | 349 |
|
49754
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
48741
diff
changeset
|
350 |
fun interprete_parent_valuetypes (prefix, (Ts, pname, _)) thy = |
25171 | 351 |
let |
26478 | 352 |
val {args,types,...} = |
25171 | 353 |
the (Symtab.lookup (StateSpaceData.get (Context.Theory thy)) pname); |
354 |
val inst = map fst args ~~ Ts; |
|
355 |
val subst = Term.map_type_tfree (the o AList.lookup (op =) inst o fst); |
|
32952 | 356 |
val pars = maps ((fn T => [project_name T,inject_name T]) o subst) types; |
29247
95d3a82857e5
adapted statespace module to new locales;
Norbert Schirmer <norbert.schirmer@web.de>
parents:
29064
diff
changeset
|
357 |
|
45362 | 358 |
val expr = ([(suffix valuetypesN name, |
49754
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
48741
diff
changeset
|
359 |
(prefix, Expression.Positional (map SOME pars)))],[]); |
29291 | 360 |
in |
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
57181
diff
changeset
|
361 |
prove_interpretation_in (fn ctxt => ALLGOALS (solve_tac ctxt (Assumption.all_prems_of ctxt))) |
29291 | 362 |
(suffix valuetypesN name, expr) thy |
363 |
end; |
|
25171 | 364 |
|
49754
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
48741
diff
changeset
|
365 |
fun interprete_parent (prefix, (_, pname, rs)) = |
25171 | 366 |
let |
49754
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
48741
diff
changeset
|
367 |
val expr = ([(pname, (prefix, Expression.Positional rs))],[]) |
26478 | 368 |
in prove_interpretation_in |
29360 | 369 |
(fn ctxt => Locale.intro_locales_tac false ctxt []) |
25171 | 370 |
(full_name, expr) end; |
371 |
||
372 |
fun declare_declinfo updates lthy phi ctxt = |
|
373 |
let |
|
26478 | 374 |
fun upd_prf ctxt = |
25171 | 375 |
let |
376 |
fun upd (n,v) = |
|
377 |
let |
|
42361 | 378 |
val nT = Proof_Context.infer_type (Local_Theory.target_of lthy) (n, dummyT) |
26478 | 379 |
in Context.proof_map |
380 |
(update_declinfo (Morphism.term phi (Free (n,nT)),v)) |
|
25171 | 381 |
end; |
382 |
in ctxt |> fold upd updates end; |
|
383 |
||
384 |
in Context.mapping I upd_prf ctxt end; |
|
385 |
||
26478 | 386 |
fun string_of_typ T = |
39134
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
38864
diff
changeset
|
387 |
Print_Mode.setmp [] |
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
38864
diff
changeset
|
388 |
(Syntax.string_of_typ (Config.put show_sorts true (Syntax.init_pretty_global thy))) T; |
25171 | 389 |
val fixestate = (case state_type of |
390 |
NONE => [] |
|
26478 | 391 |
| SOME s => |
392 |
let |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
32952
diff
changeset
|
393 |
val fx = Element.Fixes [(Binding.name s,SOME (string_of_typ stateT),NoSyn)]; |
26478 | 394 |
val cs = Element.Constrains |
25171 | 395 |
(map (fn (n,T) => (n,string_of_typ T)) |
396 |
((map (fn (n,_) => (n,nameT)) all_comps) @ |
|
397 |
constrains)) |
|
398 |
in [fx,cs] end |
|
399 |
) |
|
400 |
||
26478 | 401 |
|
402 |
in thy |
|
403 |
|> namespace_definition |
|
29247
95d3a82857e5
adapted statespace module to new locales;
Norbert Schirmer <norbert.schirmer@web.de>
parents:
29064
diff
changeset
|
404 |
(suffix namespaceN name) nameT (parents_expr,[]) |
25171 | 405 |
(map fst parent_comps) (map fst components) |
49754
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
48741
diff
changeset
|
406 |
|> Context.theory_map (add_statespace full_name args (map snd parents) components []) |
29247
95d3a82857e5
adapted statespace module to new locales;
Norbert Schirmer <norbert.schirmer@web.de>
parents:
29064
diff
changeset
|
407 |
|> add_locale (suffix valuetypesN name) (locinsts,locs) [] |
45362 | 408 |
|> Proof_Context.theory_of |
26478 | 409 |
|> fold interprete_parent_valuetypes parents |
29247
95d3a82857e5
adapted statespace module to new locales;
Norbert Schirmer <norbert.schirmer@web.de>
parents:
29064
diff
changeset
|
410 |
|> add_locale_cmd name |
95d3a82857e5
adapted statespace module to new locales;
Norbert Schirmer <norbert.schirmer@web.de>
parents:
29064
diff
changeset
|
411 |
([(suffix namespaceN full_name ,(("",false),Expression.Named [])), |
95d3a82857e5
adapted statespace module to new locales;
Norbert Schirmer <norbert.schirmer@web.de>
parents:
29064
diff
changeset
|
412 |
(suffix valuetypesN full_name,(("",false),Expression.Named []))],[]) fixestate |
45362 | 413 |
|> Proof_Context.theory_of |
25171 | 414 |
|> fold interprete_parent parents |
38389
d7d915bae307
Named_Target.init: empty string represents theory target
haftmann
parents:
38350
diff
changeset
|
415 |
|> add_declaration full_name (declare_declinfo components') |
25171 | 416 |
end; |
417 |
||
418 |
||
419 |
(* prepare arguments *) |
|
420 |
||
36149 | 421 |
fun read_typ ctxt raw_T env = |
422 |
let |
|
423 |
val ctxt' = fold (Variable.declare_typ o TFree) env ctxt; |
|
424 |
val T = Syntax.read_typ ctxt' raw_T; |
|
45741 | 425 |
val env' = Term.add_tfreesT T env; |
36149 | 426 |
in (T, env') end; |
427 |
||
428 |
fun cert_typ ctxt raw_T env = |
|
429 |
let |
|
42361 | 430 |
val thy = Proof_Context.theory_of ctxt; |
36149 | 431 |
val T = Type.no_tvars (Sign.certify_typ thy raw_T) |
432 |
handle TYPE (msg, _, _) => error msg; |
|
45741 | 433 |
val env' = Term.add_tfreesT T env; |
36149 | 434 |
in (T, env') end; |
435 |
||
25171 | 436 |
fun gen_define_statespace prep_typ state_space args name parents comps thy = |
437 |
let (* - args distinct |
|
438 |
- only args may occur in comps and parent-instantiations |
|
26478 | 439 |
- number of insts must match parent args |
25171 | 440 |
- no duplicate renamings |
441 |
- renaming should occur in namespace |
|
442 |
*) |
|
26478 | 443 |
val _ = writeln ("Defining statespace " ^ quote name ^ " ..."); |
25171 | 444 |
|
42361 | 445 |
val ctxt = Proof_Context.init_global thy; |
27283 | 446 |
|
49754
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
48741
diff
changeset
|
447 |
fun add_parent (prefix, (Ts, pname, rs)) env = |
25171 | 448 |
let |
49754
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
48741
diff
changeset
|
449 |
val prefix' = |
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
48741
diff
changeset
|
450 |
(case prefix of |
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
48741
diff
changeset
|
451 |
("", mandatory) => (pname, mandatory) |
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
48741
diff
changeset
|
452 |
| _ => prefix); |
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
48741
diff
changeset
|
453 |
|
28965 | 454 |
val full_pname = Sign.full_bname thy pname; |
26478 | 455 |
val {args,components,...} = |
25171 | 456 |
(case get_statespace (Context.Theory thy) full_pname of |
457 |
SOME r => r |
|
458 |
| NONE => error ("Undefined statespace " ^ quote pname)); |
|
459 |
||
460 |
||
27283 | 461 |
val (Ts',env') = fold_map (prep_typ ctxt) Ts env |
26478 | 462 |
handle ERROR msg => cat_error msg |
36149 | 463 |
("The error(s) above occurred in parent statespace specification " |
25171 | 464 |
^ quote pname); |
465 |
val err_insts = if length args <> length Ts' then |
|
466 |
["number of type instantiation(s) does not match arguments of parent statespace " |
|
467 |
^ quote pname] |
|
468 |
else []; |
|
26478 | 469 |
|
25171 | 470 |
val rnames = map fst rs |
471 |
val err_dup_renamings = (case duplicates (op =) rnames of |
|
472 |
[] => [] |
|
473 |
| dups => ["Duplicate renaming(s) for " ^ commas dups]) |
|
474 |
||
475 |
val cnames = map fst components; |
|
36692
54b64d4ad524
farewell to old-style mem infixes -- type inference in situations with mem_int and mem_string should provide enough information to resolve the type of (op =)
haftmann
parents:
36610
diff
changeset
|
476 |
val err_rename_unknowns = (case subtract (op =) cnames rnames of |
25171 | 477 |
[] => [] |
478 |
| rs => ["Unknown components " ^ commas rs]); |
|
26478 | 479 |
|
25171 | 480 |
|
481 |
val rs' = map (AList.lookup (op =) rs o fst) components; |
|
482 |
val errs =err_insts @ err_dup_renamings @ err_rename_unknowns |
|
49754
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
48741
diff
changeset
|
483 |
in |
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
48741
diff
changeset
|
484 |
if null errs then ((prefix', (Ts', full_pname, rs')), env') |
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
48741
diff
changeset
|
485 |
else error (cat_lines (errs @ ["in parent statespace " ^ quote pname])) |
25171 | 486 |
end; |
26478 | 487 |
|
25171 | 488 |
val (parents',env) = fold_map add_parent parents []; |
489 |
||
490 |
val err_dup_args = |
|
491 |
(case duplicates (op =) args of |
|
492 |
[] => [] |
|
493 |
| dups => ["Duplicate type argument(s) " ^ commas dups]); |
|
26478 | 494 |
|
25171 | 495 |
|
26478 | 496 |
val err_dup_components = |
25171 | 497 |
(case duplicates (op =) (map fst comps) of |
498 |
[] => [] |
|
499 |
| dups => ["Duplicate state-space components " ^ commas dups]); |
|
500 |
||
501 |
fun prep_comp (n,T) env = |
|
27283 | 502 |
let val (T', env') = prep_typ ctxt T env handle ERROR msg => |
36149 | 503 |
cat_error msg ("The error(s) above occurred in component " ^ quote n) |
25171 | 504 |
in ((n,T'), env') end; |
505 |
||
506 |
val (comps',env') = fold_map prep_comp comps env; |
|
507 |
||
508 |
val err_extra_frees = |
|
509 |
(case subtract (op =) args (map fst env') of |
|
510 |
[] => [] |
|
511 |
| extras => ["Extra free type variable(s) " ^ commas extras]); |
|
512 |
||
513 |
val defaultS = Sign.defaultS thy; |
|
514 |
val args' = map (fn x => (x, AList.lookup (op =) env x |> the_default defaultS)) args; |
|
515 |
||
516 |
||
517 |
fun fst_eq ((x:string,_),(y,_)) = x = y; |
|
26478 | 518 |
fun snd_eq ((_,t:typ),(_,u)) = t = u; |
25171 | 519 |
|
49754
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
48741
diff
changeset
|
520 |
val raw_parent_comps = maps (parent_components thy o snd) parents'; |
26478 | 521 |
fun check_type (n,T) = |
25171 | 522 |
(case distinct (snd_eq) (filter (curry fst_eq (n,T)) raw_parent_comps) of |
523 |
[] => [] |
|
524 |
| [_] => [] |
|
45660 | 525 |
| rs => ["Different types for component " ^ quote n ^ ": " ^ |
32432
64f30bdd3ba1
modernized messages -- eliminated ctyp/cterm operations;
wenzelm
parents:
32194
diff
changeset
|
526 |
commas (map (Syntax.string_of_typ ctxt o snd) rs)]) |
26478 | 527 |
|
32952 | 528 |
val err_dup_types = maps check_type (duplicates fst_eq raw_parent_comps) |
25171 | 529 |
|
530 |
val parent_comps = distinct (fst_eq) raw_parent_comps; |
|
531 |
val all_comps = parent_comps @ comps'; |
|
532 |
val err_comp_in_parent = (case duplicates (op =) (map fst all_comps) of |
|
533 |
[] => [] |
|
45660 | 534 |
| xs => ["Components already defined in parents: " ^ commas_quote xs]); |
25171 | 535 |
val errs = err_dup_args @ err_dup_components @ err_extra_frees @ |
536 |
err_dup_types @ err_comp_in_parent; |
|
26478 | 537 |
in if null errs |
25171 | 538 |
then thy |> statespace_definition state_space args' name parents' parent_comps comps' |
26478 | 539 |
else error (cat_lines errs) |
25171 | 540 |
end |
541 |
handle ERROR msg => cat_error msg ("Failed to define statespace " ^ quote name); |
|
26478 | 542 |
|
36149 | 543 |
val define_statespace = gen_define_statespace read_typ NONE; |
544 |
val define_statespace_i = gen_define_statespace cert_typ; |
|
26478 | 545 |
|
25171 | 546 |
|
45362 | 547 |
|
25171 | 548 |
(*** parse/print - translations ***) |
549 |
||
550 |
local |
|
55972 | 551 |
|
26478 | 552 |
fun map_get_comp f ctxt (Free (name,_)) = |
553 |
(case (get_comp ctxt name) of |
|
554 |
SOME (T,_) => f T T dummyT |
|
25171 | 555 |
| NONE => (Syntax.free "arbitrary"(*; error "context not ready"*))) |
556 |
| map_get_comp _ _ _ = Syntax.free "arbitrary"; |
|
557 |
||
55972 | 558 |
fun name_of (Free (n,_)) = n; |
25171 | 559 |
|
560 |
in |
|
561 |
||
26478 | 562 |
fun gen_lookup_tr ctxt s n = |
45362 | 563 |
(case get_comp (Context.Proof ctxt) n of |
564 |
SOME (T, _) => |
|
565 |
Syntax.const @{const_name StateFun.lookup} $ |
|
566 |
Syntax.free (project_name T) $ Syntax.free n $ s |
|
567 |
| NONE => |
|
568 |
if get_silent (Context.Proof ctxt) |
|
569 |
then Syntax.const @{const_name StateFun.lookup} $ |
|
570 |
Syntax.const @{const_syntax undefined} $ Syntax.free n $ s |
|
45660 | 571 |
else raise TERM ("StateSpace.gen_lookup_tr: component " ^ quote n ^ " not defined", [])); |
25171 | 572 |
|
42052
34f1d2d81284
statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents:
41585
diff
changeset
|
573 |
fun lookup_tr ctxt [s, x] = |
42264 | 574 |
(case Term_Position.strip_positions x of |
42052
34f1d2d81284
statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents:
41585
diff
changeset
|
575 |
Free (n,_) => gen_lookup_tr ctxt s n |
34f1d2d81284
statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents:
41585
diff
changeset
|
576 |
| _ => raise Match); |
34f1d2d81284
statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents:
41585
diff
changeset
|
577 |
|
25171 | 578 |
fun lookup_swap_tr ctxt [Free (n,_),s] = gen_lookup_tr ctxt s n; |
579 |
||
45362 | 580 |
fun lookup_tr' ctxt [_ $ Free (prj, _), n as (_ $ Free (name, _)), s] = |
581 |
(case get_comp (Context.Proof ctxt) name of |
|
582 |
SOME (T, _) => |
|
583 |
if prj = project_name T |
|
584 |
then Syntax.const "_statespace_lookup" $ s $ n |
|
585 |
else raise Match |
|
25171 | 586 |
| NONE => raise Match) |
55972 | 587 |
| lookup_tr' _ _ = raise Match; |
25171 | 588 |
|
26478 | 589 |
fun gen_update_tr id ctxt n v s = |
25171 | 590 |
let |
45362 | 591 |
fun pname T = if id then @{const_name Fun.id} else project_name T; |
592 |
fun iname T = if id then @{const_name Fun.id} else inject_name T; |
|
593 |
in |
|
594 |
(case get_comp (Context.Proof ctxt) n of |
|
595 |
SOME (T, _) => |
|
596 |
Syntax.const @{const_name StateFun.update} $ |
|
597 |
Syntax.free (pname T) $ Syntax.free (iname T) $ |
|
598 |
Syntax.free n $ (Syntax.const @{const_name K_statefun} $ v) $ s |
|
599 |
| NONE => |
|
600 |
if get_silent (Context.Proof ctxt) then |
|
601 |
Syntax.const @{const_name StateFun.update} $ |
|
602 |
Syntax.const @{const_syntax undefined} $ Syntax.const @{const_syntax undefined} $ |
|
603 |
Syntax.free n $ (Syntax.const @{const_name K_statefun} $ v) $ s |
|
604 |
else raise TERM ("StateSpace.gen_update_tr: component " ^ n ^ " not defined", [])) |
|
25171 | 605 |
end; |
606 |
||
42052
34f1d2d81284
statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents:
41585
diff
changeset
|
607 |
fun update_tr ctxt [s, x, v] = |
42264 | 608 |
(case Term_Position.strip_positions x of |
42052
34f1d2d81284
statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents:
41585
diff
changeset
|
609 |
Free (n, _) => gen_update_tr false ctxt n v s |
34f1d2d81284
statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents:
41585
diff
changeset
|
610 |
| _ => raise Match); |
25171 | 611 |
|
45362 | 612 |
fun update_tr' ctxt |
613 |
[_ $ Free (prj, _), _ $ Free (inj, _), n as (_ $ Free (name, _)), (Const (k, _) $ v), s] = |
|
614 |
if Long_Name.base_name k = Long_Name.base_name @{const_name K_statefun} then |
|
25171 | 615 |
(case get_comp (Context.Proof ctxt) name of |
45362 | 616 |
SOME (T, _) => |
617 |
if inj = inject_name T andalso prj = project_name T then |
|
618 |
Syntax.const "_statespace_update" $ s $ n $ v |
|
619 |
else raise Match |
|
620 |
| NONE => raise Match) |
|
25171 | 621 |
else raise Match |
622 |
| update_tr' _ _ = raise Match; |
|
623 |
||
624 |
end; |
|
625 |
||
626 |
||
627 |
(*** outer syntax *) |
|
628 |
||
45362 | 629 |
local |
630 |
||
25171 | 631 |
val type_insts = |
36960
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents:
36958
diff
changeset
|
632 |
Parse.typ >> single || |
46949 | 633 |
@{keyword "("} |-- Parse.!!! (Parse.list1 Parse.typ --| @{keyword ")"}) |
25171 | 634 |
|
46949 | 635 |
val comp = Parse.name -- (@{keyword "::"} |-- Parse.!!! Parse.typ); |
25171 | 636 |
fun plus1_unless test scan = |
46949 | 637 |
scan ::: Scan.repeat (@{keyword "+"} |-- Scan.unless test (Parse.!!! scan)); |
25171 | 638 |
|
46949 | 639 |
val mapsto = @{keyword "="}; |
36960
01594f816e3a
prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents:
36958
diff
changeset
|
640 |
val rename = Parse.name -- (mapsto |-- Parse.name); |
46949 | 641 |
val renames = Scan.optional (@{keyword "["} |-- Parse.!!! (Parse.list1 rename --| @{keyword "]"})) []; |
25171 | 642 |
|
45362 | 643 |
val parent = |
61606
6d5213bd9709
uniform mandatory qualifier for all locale expressions, including 'statespace' parent;
wenzelm
parents:
61144
diff
changeset
|
644 |
Parse_Spec.locale_prefix -- |
62969 | 645 |
((type_insts -- Parse.name) || (Parse.name >> pair [])) -- renames |
49754
acafcac41690
more explicit namespace prefix for 'statespace' -- duplicate facts;
wenzelm
parents:
48741
diff
changeset
|
646 |
>> (fn ((prefix, (insts, name)), renames) => (prefix, (insts, name, renames))); |
25171 | 647 |
|
45362 | 648 |
in |
25171 | 649 |
|
650 |
val statespace_decl = |
|
45362 | 651 |
Parse.type_args -- Parse.name -- |
46949 | 652 |
(@{keyword "="} |-- |
45362 | 653 |
((Scan.repeat1 comp >> pair []) || |
654 |
(plus1_unless comp parent -- |
|
46949 | 655 |
Scan.optional (@{keyword "+"} |-- Parse.!!! (Scan.repeat1 comp)) []))); |
45362 | 656 |
val _ = |
59936
b8ffc3dc9e24
@{command_spec} is superseded by @{command_keyword};
wenzelm
parents:
59900
diff
changeset
|
657 |
Outer_Syntax.command @{command_keyword statespace} "define state-space as locale context" |
45362 | 658 |
(statespace_decl >> (fn ((args, name), (parents, comps)) => |
659 |
Toplevel.theory (define_statespace args name parents comps))); |
|
25171 | 660 |
|
45362 | 661 |
end; |
25171 | 662 |
|
45362 | 663 |
end; |