6 |
6 |
7 signature EXPRESSION = |
7 signature EXPRESSION = |
8 sig |
8 sig |
9 datatype 'term map = Positional of 'term option list | Named of (string * 'term) list; |
9 datatype 'term map = Positional of 'term option list | Named of (string * 'term) list; |
10 type 'term expr = (string * (string * 'term map)) list; |
10 type 'term expr = (string * (string * 'term map)) list; |
11 type expression = string expr * (Name.binding * string option * mixfix) list; |
11 type expression = string expr * (Binding.T * string option * mixfix) list; |
12 type expression_i = term expr * (Name.binding * typ option * mixfix) list; |
12 type expression_i = term expr * (Binding.T * typ option * mixfix) list; |
13 |
13 |
14 (* Processing of context statements *) |
14 (* Processing of context statements *) |
15 val read_statement: Element.context list -> (string * string list) list list -> |
15 val read_statement: Element.context list -> (string * string list) list list -> |
16 Proof.context -> (term * term list) list list * Proof.context; |
16 Proof.context -> (term * term list) list list * Proof.context; |
17 val cert_statement: Element.context_i list -> (term * term list) list list -> |
17 val cert_statement: Element.context_i list -> (term * term list) list list -> |
45 Positional of 'term option list | |
45 Positional of 'term option list | |
46 Named of (string * 'term) list; |
46 Named of (string * 'term) list; |
47 |
47 |
48 type 'term expr = (string * (string * 'term map)) list; |
48 type 'term expr = (string * (string * 'term map)) list; |
49 |
49 |
50 type expression = string expr * (Name.binding * string option * mixfix) list; |
50 type expression = string expr * (Binding.T * string option * mixfix) list; |
51 type expression_i = term expr * (Name.binding * typ option * mixfix) list; |
51 type expression_i = term expr * (Binding.T * typ option * mixfix) list; |
52 |
52 |
53 |
53 |
54 (** Parsing and printing **) |
54 (** Parsing and printing **) |
55 |
55 |
56 local |
56 local |
162 val (ps', i') = params_inst i; |
162 val (ps', i') = params_inst i; |
163 val ps'' = AList.join bind_eq (fn p => fn (mx1, mx2) => |
163 val ps'' = AList.join bind_eq (fn p => fn (mx1, mx2) => |
164 (* FIXME: should check for bindings being the same. |
164 (* FIXME: should check for bindings being the same. |
165 Instead we check for equal name and syntax. *) |
165 Instead we check for equal name and syntax. *) |
166 if mx1 = mx2 then mx1 |
166 if mx1 = mx2 then mx1 |
167 else error ("Conflicting syntax for parameter" ^ quote (Name.display p) ^ |
167 else error ("Conflicting syntax for parameter" ^ quote (Binding.display p) ^ |
168 " in expression.")) (ps, ps') |
168 " in expression.")) (ps, ps') |
169 in (i', ps'') end) is [] |
169 in (i', ps'') end) is [] |
170 in (ps', is') end; |
170 in (ps', is') end; |
171 |
171 |
172 val (implicit, expr') = params_expr expr; |
172 val (implicit, expr') = params_expr expr; |
226 inst => SOME inst); |
226 inst => SOME inst); |
227 val instT = Symtab.make (type_parm_names ~~ map Logic.dest_type type_parms''); |
227 val instT = Symtab.make (type_parm_names ~~ map Logic.dest_type type_parms''); |
228 val inst = Symtab.make insts''; |
228 val inst = Symtab.make insts''; |
229 in |
229 in |
230 (Element.inst_morphism (ProofContext.theory_of ctxt) (instT, inst) $> |
230 (Element.inst_morphism (ProofContext.theory_of ctxt) (instT, inst) $> |
231 Morphism.name_morphism (Name.qualified prfx), ctxt') |
231 Morphism.binding_morphism (Binding.qualify prfx), ctxt') |
232 end; |
232 end; |
233 |
233 |
234 |
234 |
235 (*** Locale processing ***) |
235 (*** Locale processing ***) |
236 |
236 |
237 (** Parsing **) |
237 (** Parsing **) |
238 |
238 |
239 fun parse_elem prep_typ prep_term ctxt elem = |
239 fun parse_elem prep_typ prep_term ctxt elem = |
240 Element.map_ctxt {name = I, var = I, typ = prep_typ ctxt, |
240 Element.map_ctxt {binding = I, var = I, typ = prep_typ ctxt, |
241 term = prep_term ctxt, fact = I, attrib = I} elem; |
241 term = prep_term ctxt, fact = I, attrib = I} elem; |
242 |
242 |
243 fun parse_concl prep_term ctxt concl = |
243 fun parse_concl prep_term ctxt concl = |
244 (map o map) (fn (t, ps) => |
244 (map o map) (fn (t, ps) => |
245 (prep_term ctxt, map (prep_term ctxt) ps)) concl; |
245 (prep_term ctxt, map (prep_term ctxt) ps)) concl; |
314 |
314 |
315 fun declare_elem prep_vars (Fixes fixes) ctxt = |
315 fun declare_elem prep_vars (Fixes fixes) ctxt = |
316 let val (vars, _) = prep_vars fixes ctxt |
316 let val (vars, _) = prep_vars fixes ctxt |
317 in ctxt |> ProofContext.add_fixes_i vars |> snd end |
317 in ctxt |> ProofContext.add_fixes_i vars |> snd end |
318 | declare_elem prep_vars (Constrains csts) ctxt = |
318 | declare_elem prep_vars (Constrains csts) ctxt = |
319 ctxt |> prep_vars (map (fn (x, T) => (Name.binding x, SOME T, NoSyn)) csts) |> snd |
319 ctxt |> prep_vars (map (fn (x, T) => (Binding.name x, SOME T, NoSyn)) csts) |> snd |
320 | declare_elem _ (Assumes _) ctxt = ctxt |
320 | declare_elem _ (Assumes _) ctxt = ctxt |
321 | declare_elem _ (Defines _) ctxt = ctxt |
321 | declare_elem _ (Defines _) ctxt = ctxt |
322 | declare_elem _ (Notes _) ctxt = ctxt; |
322 | declare_elem _ (Notes _) ctxt = ctxt; |
323 |
323 |
324 (** Finish locale elements, extract specification text **) |
324 (** Finish locale elements, extract specification text **) |
395 val (morph, _) = inst_morph (parm_names, parm_types) (prfx, inst) ctxt; |
395 val (morph, _) = inst_morph (parm_names, parm_types) (prfx, inst) ctxt; |
396 val asm' = Option.map (Morphism.term morph) asm; |
396 val asm' = Option.map (Morphism.term morph) asm; |
397 val defs' = map (Morphism.term morph) defs; |
397 val defs' = map (Morphism.term morph) defs; |
398 val text' = text |> |
398 val text' = text |> |
399 (if is_some asm |
399 (if is_some asm |
400 then eval_text ctxt false (Assumes [(Attrib.no_binding, [(the asm', [])])]) |
400 then eval_text ctxt false (Assumes [(Attrib.empty_binding, [(the asm', [])])]) |
401 else I) |> |
401 else I) |> |
402 (if not (null defs) |
402 (if not (null defs) |
403 then eval_text ctxt false (Defines (map (fn def => (Attrib.no_binding, (def, []))) defs')) |
403 then eval_text ctxt false (Defines (map (fn def => (Attrib.empty_binding, (def, []))) defs')) |
404 else I) |
404 else I) |
405 (* FIXME clone from new_locale.ML *) |
405 (* FIXME clone from new_locale.ML *) |
406 in ((loc, morph), text') end; |
406 in ((loc, morph), text') end; |
407 |
407 |
408 fun finish_elem ctxt parms do_close elem text = |
408 fun finish_elem ctxt parms do_close elem text = |
578 val exp_fact = Drule.zero_var_indexes_list o map Thm.strip_shyps o Morphism.fact export; |
578 val exp_fact = Drule.zero_var_indexes_list o map Thm.strip_shyps o Morphism.fact export; |
579 (* val exp_term = TermSubst.zero_var_indexes o Morphism.term export; *) |
579 (* val exp_term = TermSubst.zero_var_indexes o Morphism.term export; *) |
580 val exp_term = Drule.term_rule thy (singleton exp_fact); |
580 val exp_term = Drule.term_rule thy (singleton exp_fact); |
581 val exp_typ = Logic.type_map exp_term; |
581 val exp_typ = Logic.type_map exp_term; |
582 val export' = |
582 val export' = |
583 Morphism.morphism {name = I, var = I, typ = exp_typ, term = exp_term, fact = exp_fact}; |
583 Morphism.morphism {binding = I, var = I, typ = exp_typ, term = exp_term, fact = exp_fact}; |
584 in ((propss, deps, export'), goal_ctxt) end; |
584 in ((propss, deps, export'), goal_ctxt) end; |
585 |
585 |
586 in |
586 in |
587 |
587 |
588 fun read_goal_expression x = prep_goal_expression read_full_context_statement x; |
588 fun read_goal_expression x = prep_goal_expression read_full_context_statement x; |
632 - thy: the theory |
632 - thy: the theory |
633 *) |
633 *) |
634 |
634 |
635 fun def_pred bname parms defs ts norm_ts thy = |
635 fun def_pred bname parms defs ts norm_ts thy = |
636 let |
636 let |
637 val name = Sign.full_name thy bname; |
637 val name = Sign.full_bname thy bname; |
638 |
638 |
639 val (body, bodyT, body_eq) = atomize_spec thy norm_ts; |
639 val (body, bodyT, body_eq) = atomize_spec thy norm_ts; |
640 val env = Term.add_term_free_names (body, []); |
640 val env = Term.add_term_free_names (body, []); |
641 val xs = filter (member (op =) env o #1) parms; |
641 val xs = filter (member (op =) env o #1) parms; |
642 val Ts = map #2 xs; |
642 val Ts = map #2 xs; |
649 val statement = ObjectLogic.ensure_propT thy head; |
649 val statement = ObjectLogic.ensure_propT thy head; |
650 |
650 |
651 val ([pred_def], defs_thy) = |
651 val ([pred_def], defs_thy) = |
652 thy |
652 thy |
653 |> bodyT = propT ? Sign.add_advanced_trfuns ([], [], [aprop_tr' (length args) name], []) |
653 |> bodyT = propT ? Sign.add_advanced_trfuns ([], [], [aprop_tr' (length args) name], []) |
654 |> Sign.declare_const [] ((Name.binding bname, predT), NoSyn) |> snd |
654 |> Sign.declare_const [] ((Binding.name bname, predT), NoSyn) |> snd |
655 |> PureThy.add_defs false |
655 |> PureThy.add_defs false |
656 [((Thm.def_name bname, Logic.mk_equals (head, body)), [Thm.kind_internal])]; |
656 [((Thm.def_name bname, Logic.mk_equals (head, body)), [Thm.kind_internal])]; |
657 val defs_ctxt = ProofContext.init defs_thy |> Variable.declare_term head; |
657 val defs_ctxt = ProofContext.init defs_thy |> Variable.declare_term head; |
658 |
658 |
659 val cert = Thm.cterm_of defs_thy; |
659 val cert = Thm.cterm_of defs_thy; |
691 val (_, thy'') = |
691 val (_, thy'') = |
692 thy' |
692 thy' |
693 |> Sign.add_path aname |
693 |> Sign.add_path aname |
694 |> Sign.no_base_names |
694 |> Sign.no_base_names |
695 |> PureThy.note_thmss Thm.internalK |
695 |> PureThy.note_thmss Thm.internalK |
696 [((Name.binding introN, []), [([intro], [NewLocale.unfold_attrib])])] |
696 [((Binding.name introN, []), [([intro], [NewLocale.unfold_attrib])])] |
697 ||> Sign.restore_naming thy'; |
697 ||> Sign.restore_naming thy'; |
698 in (SOME statement, SOME intro, axioms, thy'') end; |
698 in (SOME statement, SOME intro, axioms, thy'') end; |
699 val (b_pred, b_intro, b_axioms, thy'''') = |
699 val (b_pred, b_intro, b_axioms, thy'''') = |
700 if null ints then (NONE, NONE, [], thy'') |
700 if null ints then (NONE, NONE, [], thy'') |
701 else |
701 else |
706 val (_, thy'''') = |
706 val (_, thy'''') = |
707 thy''' |
707 thy''' |
708 |> Sign.add_path pname |
708 |> Sign.add_path pname |
709 |> Sign.no_base_names |
709 |> Sign.no_base_names |
710 |> PureThy.note_thmss Thm.internalK |
710 |> PureThy.note_thmss Thm.internalK |
711 [((Name.binding introN, []), [([intro], [NewLocale.intro_attrib])]), |
711 [((Binding.name introN, []), [([intro], [NewLocale.intro_attrib])]), |
712 ((Name.binding axiomsN, []), |
712 ((Binding.name axiomsN, []), |
713 [(map (Drule.standard o Element.conclude_witness) axioms, [])])] |
713 [(map (Drule.standard o Element.conclude_witness) axioms, [])])] |
714 ||> Sign.restore_naming thy'''; |
714 ||> Sign.restore_naming thy'''; |
715 in (SOME statement, SOME intro, axioms, thy'''') end; |
715 in (SOME statement, SOME intro, axioms, thy'''') end; |
716 in ((a_pred, a_intro, a_axioms), (b_pred, b_intro, b_axioms), thy'''') end; |
716 in ((a_pred, a_intro, a_axioms), (b_pred, b_intro, b_axioms), thy'''') end; |
717 |
717 |
739 |
739 |
740 fun gen_add_locale prep_decl |
740 fun gen_add_locale prep_decl |
741 bname predicate_name raw_imprt raw_body thy = |
741 bname predicate_name raw_imprt raw_body thy = |
742 let |
742 let |
743 val thy_ctxt = ProofContext.init thy; |
743 val thy_ctxt = ProofContext.init thy; |
744 val name = Sign.full_name thy bname; |
744 val name = Sign.full_bname thy bname; |
745 val _ = NewLocale.test_locale thy name andalso |
745 val _ = NewLocale.test_locale thy name andalso |
746 error ("Duplicate definition of locale " ^ quote name); |
746 error ("Duplicate definition of locale " ^ quote name); |
747 |
747 |
748 val ((fixed, deps, body_elems), text as (parms, ((_, exts'), _), defs)) = |
748 val ((fixed, deps, body_elems), text as (parms, ((_, exts'), _), defs)) = |
749 prep_decl raw_imprt raw_body thy_ctxt; |
749 prep_decl raw_imprt raw_body thy_ctxt; |
763 val notes = body_elems' |> |
763 val notes = body_elems' |> |
764 (fn elems => fold_map assumes_to_notes elems (map Element.conclude_witness a_axioms)) |> |
764 (fn elems => fold_map assumes_to_notes elems (map Element.conclude_witness a_axioms)) |> |
765 fst |> map (Element.morph_ctxt satisfy) |> |
765 fst |> map (Element.morph_ctxt satisfy) |> |
766 map_filter (fn Notes notes => SOME notes | _ => NONE) |> |
766 map_filter (fn Notes notes => SOME notes | _ => NONE) |> |
767 (if is_some asm |
767 (if is_some asm |
768 then cons (Thm.internalK, [((Name.binding (bname ^ "_" ^ axiomsN), []), |
768 then cons (Thm.internalK, [((Binding.name (bname ^ "_" ^ axiomsN), []), |
769 [([assume (cterm_of thy' (the asm))], [(Attrib.internal o K) NewLocale.witness_attrib])])]) |
769 [([assume (cterm_of thy' (the asm))], [(Attrib.internal o K) NewLocale.witness_attrib])])]) |
770 else I); |
770 else I); |
771 |
771 |
772 val deps' = map (fn (l, morph) => (l, morph $> satisfy)) deps; |
772 val deps' = map (fn (l, morph) => (l, morph $> satisfy)) deps; |
773 |
773 |