12 |
12 |
13 val empty_expr: 'morph expr |
13 val empty_expr: 'morph expr |
14 |
14 |
15 type expression = (string * string map) expr * (Name.binding * string option * mixfix) list |
15 type expression = (string * string map) expr * (Name.binding * string option * mixfix) list |
16 (* type expression_i = Morphism.morphism expr * (Name.binding * typ option * mixfix) list *) |
16 (* type expression_i = Morphism.morphism expr * (Name.binding * typ option * mixfix) list *) |
|
17 |
|
18 (* Processing of locale statements *) |
|
19 val read_statement: Element.context list -> (string * string list) list list -> |
|
20 Proof.context -> (term * term list) list list * Proof.context; |
|
21 val cert_statement: Element.context_i list -> (term * term list) list list -> |
|
22 Proof.context -> (term * term list) list list * Proof.context; |
17 |
23 |
18 (* Declaring locales *) |
24 (* Declaring locales *) |
19 val add_locale: string -> bstring -> expression -> Element.context list -> theory -> |
25 val add_locale: string -> bstring -> expression -> Element.context list -> theory -> |
20 string * Proof.context |
26 string * Proof.context |
21 (* |
27 (* |
129 fun params_inst (expr as (loc, (prfx, Positional insts))) = |
135 fun params_inst (expr as (loc, (prfx, Positional insts))) = |
130 let |
136 let |
131 val (ps, loc') = params_loc loc; |
137 val (ps, loc') = params_loc loc; |
132 val d = length ps - length insts; |
138 val d = length ps - length insts; |
133 val insts' = |
139 val insts' = |
134 if d < 0 then err_in_expr thy "More arguments than parameters in instantiation." |
140 if d < 0 then error ("More arguments than parameters in instantiation of locale " ^ |
135 (Expr [expr]) |
141 quote (NewLocale.extern thy loc)) |
136 else insts @ replicate d NONE; |
142 else insts @ replicate d NONE; |
137 val ps' = (ps ~~ insts') |> |
143 val ps' = (ps ~~ insts') |> |
138 map_filter (fn (p, NONE) => SOME p | (_, SOME _) => NONE); |
144 map_filter (fn (p, NONE) => SOME p | (_, SOME _) => NONE); |
139 in |
145 in |
140 (ps', (loc', (prfx, Positional insts'))) |
146 (ps', (loc', (prfx, Positional insts'))) |
399 fun prep_elems parse_typ parse_prop parse_inst prep_vars |
405 fun prep_elems parse_typ parse_prop parse_inst prep_vars |
400 do_close context fixed raw_insts raw_elems raw_concl = |
406 do_close context fixed raw_insts raw_elems raw_concl = |
401 let |
407 let |
402 val thy = ProofContext.theory_of context; |
408 val thy = ProofContext.theory_of context; |
403 |
409 |
404 fun prep_inst (loc, (prfx, inst)) (i, ids, insts, ctxt) = |
410 fun prep_inst (loc, (prfx, inst)) (i, marked, insts, ctxt) = |
405 let |
411 let |
406 val (parm_names, parm_types) = NewLocale.params_of thy loc |> |
412 val (parm_names, parm_types) = NewLocale.params_of thy loc |> |
407 map (fn (b, SOME T, _) => (Name.name_of b, T)) |> split_list; |
413 map (fn (b, SOME T, _) => (Name.name_of b, T)) |> split_list; |
408 val inst' = parse_inst parm_names inst ctxt; |
414 val inst' = parse_inst parm_names inst ctxt; |
409 val parm_types' = map (TypeInfer.paramify_vars o varify_indexT i) parm_types; |
415 val parm_types' = map (TypeInfer.paramify_vars o varify_indexT i) parm_types; |
410 val inst'' = map2 TypeInfer.constrain parm_types' inst'; |
416 val inst'' = map2 TypeInfer.constrain parm_types' inst'; |
411 val insts' = insts @ [(loc, (prfx, inst''))]; |
417 val insts' = insts @ [(loc, (prfx, inst''))]; |
412 val (insts'', _, _, ctxt') = check_autofix insts' [] [] ctxt; |
418 val (insts'', _, _, ctxt') = check_autofix insts' [] [] ctxt; |
413 val inst''' = insts'' |> List.last |> snd |> snd; |
419 val inst''' = insts'' |> List.last |> snd |> snd; |
414 val (morph, _) = inst_morph (parm_names, parm_types) (prfx, inst''') ctxt; |
420 val (morph, _) = inst_morph (parm_names, parm_types) (prfx, inst''') ctxt; |
415 val (ids', ctxt'') = NewLocale.activate_declarations loc morph thy ids ctxt; |
421 val (marked', ctxt'') = NewLocale.activate_declarations thy (loc, morph) (marked, ctxt); |
416 in (i+1, ids', insts', ctxt'') end; |
422 in (i+1, marked', insts', ctxt'') end; |
417 |
423 |
418 fun prep_elem raw_elem (insts, elems, ctxt) = |
424 fun prep_elem raw_elem (insts, elems, ctxt) = |
419 let |
425 let |
420 val ctxt' = declare_elem prep_vars raw_elem ctxt; |
426 val ctxt' = declare_elem prep_vars raw_elem ctxt; |
421 val elems' = elems @ [parse_elem parse_typ parse_prop ctxt' raw_elem]; |
427 val elems' = elems @ [parse_elem parse_typ parse_prop ctxt' raw_elem]; |
468 |
474 |
469 in |
475 in |
470 |
476 |
471 fun read_elems x = prep_elems Syntax.parse_typ Syntax.parse_prop parse_inst |
477 fun read_elems x = prep_elems Syntax.parse_typ Syntax.parse_prop parse_inst |
472 ProofContext.read_vars x; |
478 ProofContext.read_vars x; |
473 fun cert_elems x = prep_elems (K I) (K I) make_inst |
479 fun cert_elems x = prep_elems (K I) (K I) make_inst |
474 ProofContext.cert_vars x; |
480 ProofContext.cert_vars x; |
475 |
481 |
476 end; |
482 end; |
477 |
483 |
478 |
484 |
479 (* full context statements: import + elements + conclusion *) |
485 (* full context statements: import + elements + conclusion *) |
480 |
486 |
481 local |
487 local |
482 |
488 |
483 fun prep_context_statement prep_expr prep_elems |
489 fun prep_context_statement prep_expr prep_elems activate_elems |
484 do_close imprt elements raw_concl context = |
490 do_close imprt elements raw_concl context = |
485 let |
491 let |
486 val thy = ProofContext.theory_of context; |
492 val thy = ProofContext.theory_of context; |
487 |
493 |
488 val (Expr expr, fixed) = parameters_of thy (apfst (prep_expr thy) imprt); |
494 val (Expr expr, fixed) = parameters_of thy (apfst (prep_expr thy) imprt); |
489 val ctxt = context |> ProofContext.add_fixes fixed |> snd; |
|
490 (* FIXME push inside prep_elems *) |
|
491 val ((parms, fors, deps, elems, concl), (spec, (_, _, defs))) = |
495 val ((parms, fors, deps, elems, concl), (spec, (_, _, defs))) = |
492 prep_elems do_close context fixed expr elements raw_concl; |
496 prep_elems do_close context fixed expr elements raw_concl; |
493 (* FIXME activate deps *) |
497 |
494 val ((elems', _), ctxt') = |
498 val (_, ctxt0) = ProofContext.add_fixes_i fors context; |
495 Element.activate elems (ProofContext.set_stmt true ctxt); |
499 val (_, ctxt) = fold (NewLocale.activate_facts thy) deps (NewLocale.empty, ctxt0); |
|
500 val ((elems', _), ctxt') = activate_elems elems (ProofContext.set_stmt true ctxt); |
496 in |
501 in |
497 (((fors, deps), (ctxt', elems'), (parms, spec, defs)), concl) |
502 (((fors, deps), (ctxt', elems'), (parms, spec, defs)), concl) |
498 end |
503 end; |
|
504 |
|
505 fun prep_statement prep_ctxt elems concl ctxt = |
|
506 let |
|
507 val (((_, (ctxt', _), _)), concl) = prep_ctxt false (Expr [], []) elems concl ctxt |
|
508 in (concl, ctxt') end; |
499 |
509 |
500 in |
510 in |
501 |
511 |
|
512 fun read_statement body concl ctxt = |
|
513 prep_statement (prep_context_statement intern read_elems Element.activate) body concl ctxt; |
|
514 fun cert_statement body concl ctxt = |
|
515 prep_statement (prep_context_statement (K I) cert_elems Element.activate_i) body concl ctxt; |
|
516 |
502 fun read_context imprt body ctxt = |
517 fun read_context imprt body ctxt = |
503 #1 (prep_context_statement intern read_elems true imprt body [] ctxt); |
518 #1 (prep_context_statement intern read_elems Element.activate true imprt body [] ctxt); |
504 (* |
|
505 fun cert_context imprt body ctxt = |
519 fun cert_context imprt body ctxt = |
506 #1 (prep_context_statement (K I) cert_elems true imprt body [] ctxt); |
520 #1 (prep_context_statement (K I) cert_elems Element.activate_i true imprt body [] ctxt); |
507 *) |
521 |
508 end; |
522 end; |
509 |
523 |
510 |
524 |
511 (** Dependencies **) |
525 (** Dependencies **) |
512 |
526 |