1 (* Title: HOL/Statespace/state_space.ML
2 Author: Norbert Schirmer, TU Muenchen
5 signature STATE_SPACE =
8 val distinct_compsN : string
12 val namespaceN : string
14 val valuetypesN : string
16 val namespace_definition :
19 Expression.expression ->
20 string list -> string list -> theory -> theory
22 val define_statespace :
25 (string list * bstring * (string * string) list) list ->
26 (string * string) list -> theory -> theory
27 val define_statespace_i :
31 (typ list * bstring * (string * string) list) list ->
32 (string * typ) list -> theory -> theory
35 ((string list * bstring) *
36 ((string list * xstring * (bstring * bstring) list) list *
37 (bstring * string) list)) parser
40 val neq_x_y : Proof.context -> term -> term -> thm option
41 val distinctNameSolver : Simplifier.solver
42 val distinctTree_tac :
43 Proof.context -> term * int -> Tactical.tactic
44 val distinct_simproc : Simplifier.simproc
47 val get_comp : Context.generic -> string -> (typ * string) Option.option
48 val get_silent : Context.generic -> bool
49 val set_silent : bool -> Context.generic -> Context.generic
51 val gen_lookup_tr : Proof.context -> term -> string -> term
52 val lookup_swap_tr : Proof.context -> term list -> term
53 val lookup_tr : Proof.context -> term list -> term
54 val lookup_tr' : Proof.context -> term list -> term
57 bool -> Proof.context -> string -> term -> term -> term
58 val update_tr : Proof.context -> term list -> term
59 val update_tr' : Proof.context -> term list -> term
62 structure StateSpace : STATE_SPACE =
68 val distinct_compsN = "distinct_names"
69 val namespaceN = "_namespace"
70 val valuetypesN = "_valuetypes"
71 val projectN = "project"
72 val injectN = "inject"
75 val project_injectL = "StateSpaceLocale.project_inject";
76 val KN = "StateFun.K_statefun"
81 fun fold1 f xs = fold f (tl xs) (hd xs)
83 | fold1' f xs _ = fold1 f xs
85 fun sublist_idx eq xs ys =
88 if is_prefix eq xs ys then SOME n
89 else (case ys of [] => NONE
90 | (y::ys') => sublist (n+1) xs ys')
91 in sublist 0 xs ys end;
93 fun is_sublist eq xs ys = is_some (sublist_idx eq xs ys);
95 fun sorted_subset eq [] ys = true
96 | sorted_subset eq (x::xs) [] = false
97 | sorted_subset eq (x::xs) (y::ys) = if eq (x,y) then sorted_subset eq xs ys
98 else sorted_subset eq (x::xs) ys;
102 type namespace_info =
103 {declinfo: (typ*string) Termtab.table, (* type, name of statespace *)
104 distinctthm: thm Symtab.table,
108 structure NameSpaceData = Generic_Data
110 type T = namespace_info;
111 val empty = {declinfo = Termtab.empty, distinctthm = Symtab.empty, silent = false};
114 ({declinfo=declinfo1, distinctthm=distinctthm1, silent=silent1},
115 {declinfo=declinfo2, distinctthm=distinctthm2, silent=silent2}) : T =
116 {declinfo = Termtab.merge (K true) (declinfo1, declinfo2),
117 distinctthm = Symtab.merge (K true) (distinctthm1, distinctthm2),
118 silent = silent1 andalso silent2}
121 fun make_namespace_data declinfo distinctthm silent =
122 {declinfo=declinfo,distinctthm=distinctthm,silent=silent};
125 fun delete_declinfo n ctxt =
126 let val {declinfo,distinctthm,silent} = NameSpaceData.get ctxt;
128 (make_namespace_data (Termtab.delete_safe n declinfo) distinctthm silent) ctxt
132 fun update_declinfo (n,v) ctxt =
133 let val {declinfo,distinctthm,silent} = NameSpaceData.get ctxt;
135 (make_namespace_data (Termtab.update (n,v) declinfo) distinctthm silent) ctxt
138 fun set_silent silent ctxt =
139 let val {declinfo,distinctthm,...} = NameSpaceData.get ctxt;
141 (make_namespace_data declinfo distinctthm silent) ctxt
144 val get_silent = #silent o NameSpaceData.get;
146 fun prove_interpretation_in ctxt_tac (name, expr) thy =
148 |> Expression.sublocale_cmd name expr
149 |> Proof.global_terminal_proof
150 (Method.Basic (fn ctxt => SIMPLE_METHOD (ctxt_tac ctxt)), NONE)
151 |> ProofContext.theory_of
153 fun add_locale name expr elems thy =
155 |> Expression.add_locale (Binding.name name) (Binding.name name) expr elems
157 |> Local_Theory.exit;
159 fun add_locale_cmd name expr elems thy =
161 |> Expression.add_locale_cmd (Binding.name name) Binding.empty expr elems
163 |> Local_Theory.exit;
165 type statespace_info =
166 {args: (string * sort) list, (* type arguments *)
167 parents: (typ list * string * string option list) list,
168 (* type instantiation, state-space name, component renamings *)
169 components: (string * typ) list,
170 types: typ list (* range types of state space *)
173 structure StateSpaceData = Generic_Data
175 type T = statespace_info Symtab.table;
176 val empty = Symtab.empty;
178 fun merge data : T = Symtab.merge (K true) data;
181 fun add_statespace name args parents components types ctxt =
183 (Symtab.update_new (name, {args=args,parents=parents,
184 components=components,types=types}) (StateSpaceData.get ctxt))
187 fun get_statespace ctxt name =
188 Symtab.lookup (StateSpaceData.get ctxt) name;
191 fun lookupI eq xs n =
192 (case AList.lookup eq xs n of
196 fun mk_free ctxt name =
197 if Variable.is_fixed ctxt name orelse Variable.is_declared ctxt name
199 let val n' = lookupI (op =) (Variable.fixes_of ctxt) name
200 in SOME (Free (n',ProofContext.infer_type ctxt (n', dummyT))) end
204 fun get_dist_thm ctxt name = Symtab.lookup (#distinctthm (NameSpaceData.get ctxt)) name;
205 fun get_comp ctxt name =
207 (Termtab.lookup (#declinfo (NameSpaceData.get ctxt)))
208 (mk_free (Context.proof_of ctxt) name);
213 fun neq_x_y ctxt x y =
215 val dist_thm = the (get_dist_thm (Context.Proof ctxt) (#1 (dest_Free x)));
216 val ctree = cprop_of dist_thm |> Thm.dest_comb |> #2 |> Thm.dest_comb |> #2;
217 val tree = term_of ctree;
218 val x_path = the (DistinctTreeProver.find_tree x tree);
219 val y_path = the (DistinctTreeProver.find_tree y tree);
220 val thm = DistinctTreeProver.distinctTreeProver dist_thm x_path y_path;
222 end handle Option => NONE)
224 fun distinctTree_tac ctxt
225 (Const ("Trueprop",_) $
226 (Const ("Not", _) $ (Const ("op =", _) $ (x as Free _)$ (y as Free _))), i) =
227 (case (neq_x_y ctxt x y) of
228 SOME neq => rtac neq i
230 | distinctTree_tac _ _ = no_tac;
232 val distinctNameSolver = mk_solver' "distinctNameSolver"
233 (fn ss => case try Simplifier.the_context ss of
234 SOME ctxt => SUBGOAL (distinctTree_tac ctxt)
235 | NONE => fn i => no_tac)
237 val distinct_simproc =
238 Simplifier.simproc @{theory HOL} "StateSpace.distinct_simproc" ["x = y"]
239 (fn thy => fn ss => (fn (Const ("op =",_)$(x as Free _)$(y as Free _)) =>
240 (case try Simplifier.the_context ss of
241 SOME ctxt => Option.map (fn neq => DistinctTreeProver.neq_to_eq_False OF [neq])
247 val ss = HOL_basic_ss
249 fun interprete_parent name dist_thm_name parent_expr thy =
252 fun solve_tac ctxt (_,i) st =
254 val distinct_thm = ProofContext.get_thm ctxt dist_thm_name;
255 val goal = List.nth (cprems_of st,i-1);
256 val rule = DistinctTreeProver.distinct_implProver distinct_thm goal;
257 in EVERY [rtac rule i] st
260 fun tac ctxt = EVERY [Locale.intro_locales_tac true ctxt [],
261 ALLGOALS (SUBGOAL (solve_tac ctxt))]
264 |> prove_interpretation_in tac (name,parent_expr)
269 fun namespace_definition name nameT parent_expr parent_comps new_comps thy =
271 val all_comps = parent_comps @ new_comps;
272 val vars = (map (fn n => (Binding.name n, NONE, NoSyn)) all_comps);
273 val full_name = Sign.full_bname thy name;
274 val dist_thm_name = distinct_compsN;
276 val dist_thm_full_name = dist_thm_name;
277 fun comps_of_thm thm = prop_of thm
278 |> (fn (_$(_$t)) => DistinctTreeProver.dest_tree t) |> map (fst o dest_Free);
280 fun type_attr phi (ctxt,thm) =
281 (case ctxt of Context.Theory _ => (ctxt,thm)
284 val {declinfo,distinctthm=tt,silent} = (NameSpaceData.get ctxt);
285 val all_names = comps_of_thm thm;
287 (case (Symtab.lookup tt name) of
288 SOME dthm => if sorted_subset (op =) (comps_of_thm dthm) all_names
289 then Symtab.update (name,thm) tt else tt
290 | NONE => Symtab.update (name,thm) tt)
292 val tt' = tt |> fold upd all_names;
293 val activate_simproc =
294 Output.no_warnings_CRITICAL (* FIXME !?! *)
295 (Simplifier.map_ss (fn ss => ss addsimprocs [distinct_simproc]));
298 |> NameSpaceData.put {declinfo=declinfo,distinctthm=tt',silent=silent}
303 val attr = Attrib.internal type_attr;
305 val assumes = Element.Assumes [((Binding.name dist_thm_name,[attr]),
307 (Const ("DistinctTreeProver.all_distinct",
308 Type ("DistinctTreeProver.tree",[nameT]) --> HOLogic.boolT) $
309 DistinctTreeProver.mk_tree (fn n => Free (n,nameT)) nameT
310 (sort fast_string_ord all_comps)),
313 |> add_locale name ([],vars) [assumes]
314 |> ProofContext.theory_of
315 |> interprete_parent name dist_thm_full_name parent_expr
318 fun encode_dot x = if x= #"." then #"_" else x;
320 fun encode_type (TFree (s, _)) = s
321 | encode_type (TVar ((s,i),_)) = "?" ^ s ^ string_of_int i
322 | encode_type (Type (n,Ts)) =
324 val Ts' = fold1' (fn x => fn y => x ^ "_" ^ y) (map encode_type Ts) "";
325 val n' = String.map encode_dot n;
326 in if Ts'="" then n' else Ts' ^ "_" ^ n' end;
328 fun project_name T = projectN ^"_"^encode_type T;
329 fun inject_name T = injectN ^"_"^encode_type T;
331 fun project_free T pT V = Free (project_name T, V --> pT);
332 fun inject_free T pT V = Free (inject_name T, pT --> V);
334 fun get_name n = getN ^ "_" ^ n;
335 fun put_name n = putN ^ "_" ^ n;
336 fun get_const n T nT V = Free (get_name n, (nT --> V) --> T);
337 fun put_const n T nT V = Free (put_name n, T --> (nT --> V) --> (nT --> V));
339 fun lookup_const T nT V = Const ("StateFun.lookup",(V --> T) --> nT --> (nT --> V) --> T);
340 fun update_const T nT V =
341 Const ("StateFun.update",
342 (V --> T) --> (T --> V) --> nT --> (T --> T) --> (nT --> V) --> (nT --> V));
344 fun K_const T = Const ("StateFun.K_statefun",T --> T --> T);
346 val no_syn = #3 (Syntax.no_syn ((),()));
349 fun add_declaration name decl thy =
351 |> Named_Target.init name
352 |> (fn lthy => Local_Theory.declaration false (decl lthy) lthy)
353 |> Local_Theory.exit_global;
355 fun parent_components thy (Ts, pname, renaming) =
357 val ctxt = Context.Theory thy;
358 fun rename [] xs = xs
359 | rename (NONE::rs) (x::xs) = x::rename rs xs
360 | rename (SOME r::rs) ((x,T)::xs) = (r,T)::rename rs xs;
361 val {args,parents,components,...} =
362 the (Symtab.lookup (StateSpaceData.get ctxt) pname);
363 val inst = map fst args ~~ Ts;
364 val subst = Term.map_type_tfree (the o AList.lookup (op =) inst o fst);
366 maps (fn (Ts',n,rs) => parent_components thy (map subst Ts',n,rs)) parents;
367 val all_comps = rename renaming (parent_comps @ map (apsnd subst) components);
370 fun take_upto i xs = List.take(xs,i) handle Subscript => xs;
372 fun statespace_definition state_type args name parents parent_comps components thy =
374 val full_name = Sign.full_bname thy name;
375 val all_comps = parent_comps @ components;
377 val components' = map (fn (n,T) => (n,(T,full_name))) components;
378 val all_comps' = map (fn (n,T) => (n,(T,full_name))) all_comps;
380 fun parent_expr (_,n,rs) = (suffix namespaceN n,((n,false),Expression.Positional rs));
381 (* FIXME: a more specific renaming-prefix (including parameter names) may be nicer *)
382 val parents_expr = map parent_expr parents;
383 fun distinct_types Ts =
384 let val tab = fold (fn T => fn tab => Typtab.update (T,()) tab) Ts Typtab.empty;
385 in map fst (Typtab.dest tab) end;
387 val Ts = distinct_types (map snd all_comps);
388 val arg_names = map fst args;
389 val valueN = Name.variant arg_names "'value";
390 val nameN = Name.variant (valueN::arg_names) "'name";
391 val valueT = TFree (valueN, Sign.defaultS thy);
392 val nameT = TFree (nameN, Sign.defaultS thy);
393 val stateT = nameT --> valueT;
394 fun projectT T = valueT --> T;
395 fun injectT T = T --> valueT;
396 val locinsts = map (fn T => (project_injectL,
397 (("",false),Expression.Positional
398 [SOME (Free (project_name T,projectT T)),
399 SOME (Free ((inject_name T,injectT T)))]))) Ts;
400 val locs = maps (fn T => [(Binding.name (project_name T),NONE,NoSyn),
401 (Binding.name (inject_name T),NONE,NoSyn)]) Ts;
402 val constrains = maps (fn T => [(project_name T,projectT T),(inject_name T,injectT T)]) Ts;
404 fun interprete_parent_valuetypes (Ts, pname, _) thy =
406 val {args,types,...} =
407 the (Symtab.lookup (StateSpaceData.get (Context.Theory thy)) pname);
408 val inst = map fst args ~~ Ts;
409 val subst = Term.map_type_tfree (the o AList.lookup (op =) inst o fst);
410 val pars = maps ((fn T => [project_name T,inject_name T]) o subst) types;
412 val expr = ([(suffix valuetypesN name,
413 (("",false),Expression.Positional (map SOME pars)))],[]);
415 prove_interpretation_in (ALLGOALS o solve_tac o Assumption.all_prems_of)
416 (suffix valuetypesN name, expr) thy
419 fun interprete_parent (_, pname, rs) =
421 val expr = ([(pname, (("",false), Expression.Positional rs))],[])
422 in prove_interpretation_in
423 (fn ctxt => Locale.intro_locales_tac false ctxt [])
424 (full_name, expr) end;
426 fun declare_declinfo updates lthy phi ctxt =
432 val nT = ProofContext.infer_type (Local_Theory.target_of lthy) (n, dummyT)
434 (update_declinfo (Morphism.term phi (Free (n,nT)),v))
436 in ctxt |> fold upd updates end;
438 in Context.mapping I upd_prf ctxt end;
440 fun string_of_typ T =
441 setmp_CRITICAL show_sorts true
442 (Print_Mode.setmp [] (Syntax.string_of_typ (ProofContext.init_global thy))) T;
443 val fixestate = (case state_type of
447 val fx = Element.Fixes [(Binding.name s,SOME (string_of_typ stateT),NoSyn)];
448 val cs = Element.Constrains
449 (map (fn (n,T) => (n,string_of_typ T))
450 ((map (fn (n,_) => (n,nameT)) all_comps) @
457 |> namespace_definition
458 (suffix namespaceN name) nameT (parents_expr,[])
459 (map fst parent_comps) (map fst components)
460 |> Context.theory_map (add_statespace full_name args parents components [])
461 |> add_locale (suffix valuetypesN name) (locinsts,locs) []
462 |> ProofContext.theory_of
463 |> fold interprete_parent_valuetypes parents
464 |> add_locale_cmd name
465 ([(suffix namespaceN full_name ,(("",false),Expression.Named [])),
466 (suffix valuetypesN full_name,(("",false),Expression.Named []))],[]) fixestate
467 |> ProofContext.theory_of
468 |> fold interprete_parent parents
469 |> add_declaration (SOME full_name) (declare_declinfo components')
473 (* prepare arguments *)
475 fun read_raw_parent ctxt raw_T =
476 (case ProofContext.read_typ_abbrev ctxt raw_T of
477 Type (name, Ts) => (Ts, name)
478 | T => error ("Bad parent statespace specification: " ^ Syntax.string_of_typ ctxt T));
480 fun read_typ ctxt raw_T env =
482 val ctxt' = fold (Variable.declare_typ o TFree) env ctxt;
483 val T = Syntax.read_typ ctxt' raw_T;
484 val env' = OldTerm.add_typ_tfrees (T, env);
487 fun cert_typ ctxt raw_T env =
489 val thy = ProofContext.theory_of ctxt;
490 val T = Type.no_tvars (Sign.certify_typ thy raw_T)
491 handle TYPE (msg, _, _) => error msg;
492 val env' = OldTerm.add_typ_tfrees (T, env);
495 fun gen_define_statespace prep_typ state_space args name parents comps thy =
496 let (* - args distinct
497 - only args may occur in comps and parent-instantiations
498 - number of insts must match parent args
499 - no duplicate renamings
500 - renaming should occur in namespace
502 val _ = writeln ("Defining statespace " ^ quote name ^ " ...");
504 val ctxt = ProofContext.init_global thy;
506 fun add_parent (Ts,pname,rs) env =
508 val full_pname = Sign.full_bname thy pname;
509 val {args,components,...} =
510 (case get_statespace (Context.Theory thy) full_pname of
512 | NONE => error ("Undefined statespace " ^ quote pname));
515 val (Ts',env') = fold_map (prep_typ ctxt) Ts env
516 handle ERROR msg => cat_error msg
517 ("The error(s) above occurred in parent statespace specification "
519 val err_insts = if length args <> length Ts' then
520 ["number of type instantiation(s) does not match arguments of parent statespace "
524 val rnames = map fst rs
525 val err_dup_renamings = (case duplicates (op =) rnames of
527 | dups => ["Duplicate renaming(s) for " ^ commas dups])
529 val cnames = map fst components;
530 val err_rename_unknowns = (case subtract (op =) cnames rnames of
532 | rs => ["Unknown components " ^ commas rs]);
535 val rs' = map (AList.lookup (op =) rs o fst) components;
536 val errs =err_insts @ err_dup_renamings @ err_rename_unknowns
537 in if null errs then ((Ts',full_pname,rs'),env')
538 else error (cat_lines (errs @ ["in parent statespace " ^ quote pname]))
541 val (parents',env) = fold_map add_parent parents [];
544 (case duplicates (op =) args of
546 | dups => ["Duplicate type argument(s) " ^ commas dups]);
549 val err_dup_components =
550 (case duplicates (op =) (map fst comps) of
552 | dups => ["Duplicate state-space components " ^ commas dups]);
554 fun prep_comp (n,T) env =
555 let val (T', env') = prep_typ ctxt T env handle ERROR msg =>
556 cat_error msg ("The error(s) above occurred in component " ^ quote n)
557 in ((n,T'), env') end;
559 val (comps',env') = fold_map prep_comp comps env;
561 val err_extra_frees =
562 (case subtract (op =) args (map fst env') of
564 | extras => ["Extra free type variable(s) " ^ commas extras]);
566 val defaultS = Sign.defaultS thy;
567 val args' = map (fn x => (x, AList.lookup (op =) env x |> the_default defaultS)) args;
570 fun fst_eq ((x:string,_),(y,_)) = x = y;
571 fun snd_eq ((_,t:typ),(_,u)) = t = u;
573 val raw_parent_comps = maps (parent_components thy) parents';
574 fun check_type (n,T) =
575 (case distinct (snd_eq) (filter (curry fst_eq (n,T)) raw_parent_comps) of
578 | rs => ["Different types for component " ^ n ^": " ^
579 commas (map (Syntax.string_of_typ ctxt o snd) rs)])
581 val err_dup_types = maps check_type (duplicates fst_eq raw_parent_comps)
583 val parent_comps = distinct (fst_eq) raw_parent_comps;
584 val all_comps = parent_comps @ comps';
585 val err_comp_in_parent = (case duplicates (op =) (map fst all_comps) of
587 | xs => ["Components already defined in parents: " ^ commas xs]);
588 val errs = err_dup_args @ err_dup_components @ err_extra_frees @
589 err_dup_types @ err_comp_in_parent;
591 then thy |> statespace_definition state_space args' name parents' parent_comps comps'
592 else error (cat_lines errs)
594 handle ERROR msg => cat_error msg ("Failed to define statespace " ^ quote name);
596 val define_statespace = gen_define_statespace read_typ NONE;
597 val define_statespace_i = gen_define_statespace cert_typ;
600 (*** parse/print - translations ***)
604 fun map_get_comp f ctxt (Free (name,_)) =
605 (case (get_comp ctxt name) of
606 SOME (T,_) => f T T dummyT
607 | NONE => (Syntax.free "arbitrary"(*; error "context not ready"*)))
608 | map_get_comp _ _ _ = Syntax.free "arbitrary";
610 val get_comp_projection = map_get_comp project_free;
611 val get_comp_injection = map_get_comp inject_free;
613 fun name_of (Free (n,_)) = n;
616 fun gen_lookup_tr ctxt s n =
617 (case get_comp (Context.Proof ctxt) n of
619 Syntax.const "StateFun.lookup"$Syntax.free (project_name T)$Syntax.free n$s
621 if get_silent (Context.Proof ctxt)
622 then Syntax.const "StateFun.lookup" $ Syntax.const "undefined" $ Syntax.free n $ s
623 else raise TERM ("StateSpace.gen_lookup_tr: component " ^ n ^ " not defined",[]));
625 fun lookup_tr ctxt [s,Free (n,_)] = gen_lookup_tr ctxt s n;
626 fun lookup_swap_tr ctxt [Free (n,_),s] = gen_lookup_tr ctxt s n;
628 fun lookup_tr' ctxt [_$Free (prj,_),n as (_$Free (name,_)),s] =
629 ( case get_comp (Context.Proof ctxt) name of
630 SOME (T,_) => if prj=project_name T then
631 Syntax.const "_statespace_lookup" $ s $ n
633 | NONE => raise Match)
634 | lookup_tr' _ ts = raise Match;
636 fun gen_update_tr id ctxt n v s =
638 fun pname T = if id then "Fun.id" else project_name T
639 fun iname T = if id then "Fun.id" else inject_name T
641 (case get_comp (Context.Proof ctxt) n of
642 SOME (T,_) => Syntax.const "StateFun.update"$
643 Syntax.free (pname T)$Syntax.free (iname T)$
644 Syntax.free n$(Syntax.const KN $ v)$s
646 if get_silent (Context.Proof ctxt)
647 then Syntax.const "StateFun.update"$
648 Syntax.const "undefined" $ Syntax.const "undefined" $
649 Syntax.free n $ (Syntax.const KN $ v) $ s
650 else raise TERM ("StateSpace.gen_update_tr: component " ^ n ^ " not defined",[]))
653 fun update_tr ctxt [s,Free (n,_),v] = gen_update_tr false ctxt n v s;
655 fun update_tr' ctxt [_$Free (prj,_),_$Free (inj,_),n as (_$Free (name,_)),(Const (k,_)$v),s] =
656 if Long_Name.base_name k = Long_Name.base_name KN then
657 (case get_comp (Context.Proof ctxt) name of
658 SOME (T,_) => if inj=inject_name T andalso prj=project_name T then
659 Syntax.const "_statespace_update" $ s $ n $ v
661 | NONE => raise Match)
663 | update_tr' _ _ = raise Match;
671 Parse.typ >> single ||
672 Parse.$$$ "(" |-- Parse.!!! (Parse.list1 Parse.typ --| Parse.$$$ ")")
674 val comp = Parse.name -- (Parse.$$$ "::" |-- Parse.!!! Parse.typ);
675 fun plus1_unless test scan =
676 scan ::: Scan.repeat (Parse.$$$ "+" |-- Scan.unless test (Parse.!!! scan));
678 val mapsto = Parse.$$$ "=";
679 val rename = Parse.name -- (mapsto |-- Parse.name);
680 val renames = Scan.optional (Parse.$$$ "[" |-- Parse.!!! (Parse.list1 rename --| Parse.$$$ "]")) [];
683 val parent = ((type_insts -- Parse.xname) || (Parse.xname >> pair [])) -- renames
684 >> (fn ((insts,name),renames) => (insts,name,renames))
687 val statespace_decl =
688 Parse.type_args -- Parse.name --
690 ((Scan.repeat1 comp >> pair []) ||
691 (plus1_unless comp parent --
692 Scan.optional (Parse.$$$ "+" |-- Parse.!!! (Scan.repeat1 comp)) [])))
694 val statespace_command =
695 Outer_Syntax.command "statespace" "define state space" Keyword.thy_decl
696 (statespace_decl >> (fn ((args,name),(parents,comps)) =>
697 Toplevel.theory (define_statespace args name parents comps)))