src/Pure/Isar/toplevel.ML
changeset 72453 e4dde7beab39
parent 72450 24bd1316eaae
child 72505 974071d873ba
equal deleted inserted replaced
72452:9017dfa56367 72453:e4dde7beab39
    52   val generic_theory: (generic_theory -> generic_theory) -> transition -> transition
    52   val generic_theory: (generic_theory -> generic_theory) -> transition -> transition
    53   val theory': (bool -> theory -> theory) -> transition -> transition
    53   val theory': (bool -> theory -> theory) -> transition -> transition
    54   val theory: (theory -> theory) -> transition -> transition
    54   val theory: (theory -> theory) -> transition -> transition
    55   val begin_main_target: bool -> (theory -> local_theory) -> transition -> transition
    55   val begin_main_target: bool -> (theory -> local_theory) -> transition -> transition
    56   val end_main_target: transition -> transition
    56   val end_main_target: transition -> transition
    57   val begin_nested_target: (local_theory -> local_theory) -> transition -> transition
    57   val begin_nested_target: (Context.generic -> local_theory) -> transition -> transition
    58   val end_nested_target: transition -> transition
    58   val end_nested_target: transition -> transition
    59   val local_theory': (bool * Position.T) option -> (xstring * Position.T) option ->
    59   val local_theory': (bool * Position.T) option -> (xstring * Position.T) option ->
    60     (bool -> local_theory -> local_theory) -> transition -> transition
    60     (bool -> local_theory -> local_theory) -> transition -> transition
    61   val local_theory: (bool * Position.T) option -> (xstring * Position.T) option ->
    61   val local_theory: (bool * Position.T) option -> (xstring * Position.T) option ->
    62     (local_theory -> local_theory) -> transition -> transition
    62     (local_theory -> local_theory) -> transition -> transition
   434 
   434 
   435 fun begin_main_target begin f = transaction (fn _ =>
   435 fun begin_main_target begin f = transaction (fn _ =>
   436   (fn Theory (Context.Theory thy) =>
   436   (fn Theory (Context.Theory thy) =>
   437         let
   437         let
   438           val lthy = f thy;
   438           val lthy = f thy;
   439           val gthy = if begin then Context.Proof lthy else Context.Theory (Named_Target.exit lthy);
   439           val gthy =
       
   440             if begin
       
   441             then Context.Proof lthy
       
   442             else Context.Theory (Target_Context.end_named_cmd lthy);
   440           val _ =
   443           val _ =
   441             (case Local_Theory.pretty lthy of
   444             (case Local_Theory.pretty lthy of
   442               [] => ()
   445               [] => ()
   443             | prts => Output.state (Pretty.string_of (Pretty.chunks prts)));
   446             | prts => Output.state (Pretty.string_of (Pretty.chunks prts)));
   444         in (Theory gthy, lthy) end
   447         in (Theory gthy, lthy) end
   445     | _ => raise UNDEF));
   448     | _ => raise UNDEF));
   446 
   449 
   447 val end_main_target = transaction (fn _ =>
   450 val end_main_target = transaction (fn _ =>
   448   (fn Theory (Context.Proof lthy) => (Theory (Context.Theory (Named_Target.exit lthy)), lthy)
   451   (fn Theory (Context.Proof lthy) => (Theory (Context.Theory (Target_Context.end_named_cmd lthy)), lthy)
   449     | _ => raise UNDEF));
   452     | _ => raise UNDEF));
   450 
   453 
   451 fun begin_nested_target f = transaction0 (fn _ =>
   454 fun begin_nested_target f = transaction0 (fn _ =>
   452   (fn Theory gthy =>
   455   (fn Theory gthy =>
   453         let
   456         let
   454           val lthy = Bundle.begin_nested_target gthy;
   457           val lthy' = f gthy;
   455           val lthy' = f lthy
       
   456         in Theory (Context.Proof lthy') end
   458         in Theory (Context.Proof lthy') end
   457     | _ => raise UNDEF));
   459     | _ => raise UNDEF));
   458 
   460 
   459 val end_nested_target = transaction (fn _ =>
   461 val end_nested_target = transaction (fn _ =>
   460   (fn Theory (Context.Proof lthy) =>
   462   (fn Theory (Context.Proof lthy) =>
   461         (case try Local_Theory.end_nested lthy of
   463         (case try Local_Theory.end_nested lthy of
   462           SOME lthy' =>
   464           SOME lthy' =>
   463             let val gthy' = Bundle.end_nested_target lthy'
   465             let val gthy' = Target_Context.end_nested_cmd lthy'
   464             in (Theory gthy', lthy) end
   466             in (Theory gthy', lthy) end
   465         | NONE => raise UNDEF)
   467         | NONE => raise UNDEF)
   466     | _ => raise UNDEF));
   468     | _ => raise UNDEF));
   467 
   469 
   468 fun restricted_context (SOME (strict, scope)) =
   470 fun restricted_context (SOME (strict, scope)) =
   470   | restricted_context NONE = I;
   472   | restricted_context NONE = I;
   471 
   473 
   472 fun local_theory' restricted target f = present_transaction (fn int =>
   474 fun local_theory' restricted target f = present_transaction (fn int =>
   473   (fn Theory gthy =>
   475   (fn Theory gthy =>
   474         let
   476         let
   475           val (finish, lthy) = Named_Target.switch target gthy;
   477           val (finish, lthy) = Target_Context.switch_named_cmd target gthy;
   476           val lthy' = lthy
   478           val lthy' = lthy
   477             |> restricted_context restricted
   479             |> restricted_context restricted
   478             |> Local_Theory.new_group
   480             |> Local_Theory.new_group
   479             |> f int
   481             |> f int
   480             |> Local_Theory.reset_group;
   482             |> Local_Theory.reset_group;
   484 
   486 
   485 fun local_theory restricted target f = local_theory' restricted target (K f);
   487 fun local_theory restricted target f = local_theory' restricted target (K f);
   486 
   488 
   487 fun present_local_theory target = present_transaction (fn _ =>
   489 fun present_local_theory target = present_transaction (fn _ =>
   488   (fn Theory gthy =>
   490   (fn Theory gthy =>
   489         let val (finish, lthy) = Named_Target.switch target gthy;
   491         let val (finish, lthy) = Target_Context.switch_named_cmd target gthy;
   490         in (Theory (finish lthy), lthy) end
   492         in (Theory (finish lthy), lthy) end
   491     | _ => raise UNDEF));
   493     | _ => raise UNDEF));
   492 
   494 
   493 
   495 
   494 (* proof transitions *)
   496 (* proof transitions *)
   529 in
   531 in
   530 
   532 
   531 fun local_theory_to_proof' restricted target f = begin_proof
   533 fun local_theory_to_proof' restricted target f = begin_proof
   532   (fn int => fn gthy =>
   534   (fn int => fn gthy =>
   533     let
   535     let
   534       val (finish, lthy) = Named_Target.switch target gthy;
   536       val (finish, lthy) = Target_Context.switch_named_cmd target gthy;
   535       val prf = lthy
   537       val prf = lthy
   536         |> restricted_context restricted
   538         |> restricted_context restricted
   537         |> Local_Theory.new_group
   539         |> Local_Theory.new_group
   538         |> f int;
   540         |> f int;
   539     in (finish o Local_Theory.reset_group, prf) end);
   541     in (finish o Local_Theory.reset_group, prf) end);
   787       end;
   789       end;
   788 
   790 
   789 end;
   791 end;
   790 
   792 
   791 end;
   793 end;
   792 
       
   793 structure Local_Theory : LOCAL_THEORY = struct open Local_Theory; end;