src/Pure/Isar/locale.ML
changeset 20037 d4102c7cf051
parent 20035 80c79876d2de
child 20059 25935807eb08
equal deleted inserted replaced
20036:fa655d0e18c2 20037:d4102c7cf051
    93     theory -> ((string * thm list) list * (string * thm list) list) * (Proof.context * theory)
    93     theory -> ((string * thm list) list * (string * thm list) list) * (Proof.context * theory)
    94   val add_thmss: string -> string ->
    94   val add_thmss: string -> string ->
    95     ((string * Attrib.src list) * (thm list * Attrib.src list) list) list ->
    95     ((string * Attrib.src list) * (thm list * Attrib.src list) list) list ->
    96     Proof.context ->
    96     Proof.context ->
    97     ((string * thm list) list * (string * thm list) list) * Proof.context
    97     ((string * thm list) list * (string * thm list) list) * Proof.context
    98   val add_term_syntax: string -> (Proof.context -> Proof.context) ->
    98   val add_term_syntax: string -> (Proof.context -> Proof.context) -> Proof.context -> Proof.context
    99     cterm list * Proof.context -> Proof.context
       
   100 
    99 
   101   val theorem: string -> Method.text option -> (thm list list -> theory -> theory) ->
   100   val theorem: string -> Method.text option -> (thm list list -> theory -> theory) ->
   102     string * Attrib.src list -> Element.context element list -> Element.statement ->
   101     string * Attrib.src list -> Element.context element list -> Element.statement ->
   103     theory -> Proof.state
   102     theory -> Proof.state
   104   val theorem_i: string -> Method.text option -> (thm list list -> theory -> theory) ->
   103   val theorem_i: string -> Method.text option -> (thm list list -> theory -> theory) ->
  1521 
  1520 
  1522 
  1521 
  1523 (* term syntax *)
  1522 (* term syntax *)
  1524 
  1523 
  1525 fun add_term_syntax loc syn =
  1524 fun add_term_syntax loc syn =
  1526   snd #> syn #> ProofContext.map_theory (change_locale loc
  1525   syn #> ProofContext.map_theory (change_locale loc
  1527     (fn (axiom, import, elems, params, lparams, term_syntax, regs, intros) =>
  1526     (fn (axiom, import, elems, params, lparams, term_syntax, regs, intros) =>
  1528       (axiom, import, elems, params, lparams, (syn, stamp ()) :: term_syntax, regs, intros)));
  1527       (axiom, import, elems, params, lparams, (syn, stamp ()) :: term_syntax, regs, intros)));
  1529 
  1528 
  1530 fun init_term_syntax loc ctxt =
  1529 fun init_term_syntax loc ctxt =
  1531   fold_rev (fn (f, _) => fn ctxt' => f ctxt')
  1530   fold_rev (fn (f, _) => fn ctxt' => f ctxt')
  1540 (* theory/locale results *)
  1539 (* theory/locale results *)
  1541 
  1540 
  1542 fun theory_results kind prefix results ctxt thy =
  1541 fun theory_results kind prefix results ctxt thy =
  1543   let
  1542   let
  1544     val thy_ctxt = ProofContext.init thy;
  1543     val thy_ctxt = ProofContext.init thy;
  1545     val export = ProofContext.export_view [] ctxt thy_ctxt;
  1544     val export = singleton (ProofContext.export_standard ctxt thy_ctxt);
  1546     val facts = map (fn (name, ths) => ((name, []), [(map export ths, [])])) results;
  1545     val facts = map (fn (name, ths) => ((name, []), [(map export ths, [])])) results;
  1547   in thy |> PureThy.note_thmss_qualified kind prefix facts end;
  1546   in thy |> PureThy.note_thmss_qualified kind prefix facts end;
  1548 
  1547 
  1549 local
  1548 local
  1550 
  1549 
  1859     val atts = map (prep_src thy) raw_atts;
  1858     val atts = map (prep_src thy) raw_atts;
  1860     val ((concl_elems, concl), mk_stmt) = conclusion (prep_src thy) raw_concl;
  1859     val ((concl_elems, concl), mk_stmt) = conclusion (prep_src thy) raw_concl;
  1861     val thy_ctxt = ProofContext.init thy;
  1860     val thy_ctxt = ProofContext.init thy;
  1862     val elems = map (prep_elem thy) (raw_elems @ concl_elems);
  1861     val elems = map (prep_elem thy) (raw_elems @ concl_elems);
  1863     val (_, _, ctxt, propp) = prep_stmt NONE elems (map snd concl) thy_ctxt;
  1862     val (_, _, ctxt, propp) = prep_stmt NONE elems (map snd concl) thy_ctxt;
  1864     val ((stmt, facts), goal_ctxt) = ctxt
  1863     val ((stmt, facts), goal_ctxt) = mk_stmt (map fst concl ~~ propp) ctxt;
  1865       |> ProofContext.add_view thy_ctxt []
       
  1866       |> mk_stmt (map fst concl ~~ propp);
       
  1867   in
  1864   in
  1868     global_goal kind before_qed after_qed (SOME "") (name, atts) stmt goal_ctxt
  1865     global_goal kind before_qed after_qed (SOME "") (name, atts) stmt goal_ctxt
  1869     |> Proof.refine_insert facts
  1866     |> Proof.refine_insert facts
  1870   end;
  1867   end;
  1871 
  1868 
  1881     val names = map (fst o fst) concl;
  1878     val names = map (fst o fst) concl;
  1882 
  1879 
  1883     val thy_ctxt = init_term_syntax loc (ProofContext.init thy);
  1880     val thy_ctxt = init_term_syntax loc (ProofContext.init thy);
  1884     val (_, loc_ctxt, elems_ctxt, propp) =
  1881     val (_, loc_ctxt, elems_ctxt, propp) =
  1885       prep_stmt (SOME raw_loc) elems (map snd concl) thy_ctxt;
  1882       prep_stmt (SOME raw_loc) elems (map snd concl) thy_ctxt;
  1886     val elems_ctxt' = elems_ctxt
       
  1887       |> ProofContext.add_view loc_ctxt []
       
  1888       |> ProofContext.add_view thy_ctxt [];
       
  1889     val loc_ctxt' = loc_ctxt
       
  1890       |> ProofContext.add_view thy_ctxt [];
       
  1891 
  1883 
  1892     val ((stmt, facts), goal_ctxt) =
  1884     val ((stmt, facts), goal_ctxt) =
  1893       elems_ctxt' |> mk_stmt (map (apsnd (K []) o fst) concl ~~ propp);
  1885       mk_stmt (map (apsnd (K []) o fst) concl ~~ propp) elems_ctxt;
  1894 
  1886 
  1895     fun after_qed' results =
  1887     fun after_qed' results =
  1896       let val loc_results = results |> map
  1888       let val loc_results = results |> map
  1897           (ProofContext.export_standard goal_ctxt loc_ctxt') in
  1889           (ProofContext.export_standard goal_ctxt loc_ctxt) in
  1898         curry (locale_results kind loc ((names ~~ loc_attss) ~~ loc_results)) loc_ctxt
  1890         curry (locale_results kind loc ((names ~~ loc_attss) ~~ loc_results)) loc_ctxt
  1899         #-> (fn res =>
  1891         #-> (fn res =>
  1900           if name = "" andalso null loc_atts then I
  1892           if name = "" andalso null loc_atts then I
  1901           else #2 o locale_results kind loc [((name, loc_atts), maps #2 res)])
  1893           else #2 o locale_results kind loc [((name, loc_atts), maps #2 res)])
  1902         #> #2
  1894         #> #2