src/Pure/Isar/toplevel.ML
changeset 49062 7e31dfd99ce7
parent 49042 01041f7bf9b4
child 49863 b5fb6e7f8d81
equal deleted inserted replaced
49061:7449b804073b 49062:7e31dfd99ce7
    51   val keep': (bool -> state -> unit) -> transition -> transition
    51   val keep': (bool -> state -> unit) -> transition -> transition
    52   val imperative: (unit -> unit) -> transition -> transition
    52   val imperative: (unit -> unit) -> transition -> transition
    53   val ignored: Position.T -> transition
    53   val ignored: Position.T -> transition
    54   val malformed: Position.T -> string -> transition
    54   val malformed: Position.T -> string -> transition
    55   val is_malformed: transition -> bool
    55   val is_malformed: transition -> bool
    56   val join_recent_proofs: state -> unit
       
    57   val generic_theory: (generic_theory -> generic_theory) -> transition -> transition
    56   val generic_theory: (generic_theory -> generic_theory) -> transition -> transition
    58   val theory': (bool -> theory -> theory) -> transition -> transition
    57   val theory': (bool -> theory -> theory) -> transition -> transition
    59   val theory: (theory -> theory) -> transition -> transition
    58   val theory: (theory -> theory) -> transition -> transition
    60   val begin_local_theory: bool -> (theory -> local_theory) -> transition -> transition
    59   val begin_local_theory: bool -> (theory -> local_theory) -> transition -> transition
    61   val end_local_theory: transition -> transition
    60   val end_local_theory: transition -> transition
   421 val unknown_theory = imperative (fn () => warning "Unknown theory context");
   420 val unknown_theory = imperative (fn () => warning "Unknown theory context");
   422 val unknown_proof = imperative (fn () => warning "Unknown proof context");
   421 val unknown_proof = imperative (fn () => warning "Unknown proof context");
   423 val unknown_context = imperative (fn () => warning "Unknown context");
   422 val unknown_context = imperative (fn () => warning "Unknown context");
   424 
   423 
   425 
   424 
   426 (* forked proofs *)
       
   427 
       
   428 val begin_proofs =
       
   429   Context.mapping (Context.theory_map Thm.begin_proofs #> Theory.checkpoint)
       
   430     Local_Theory.begin_proofs;
       
   431 
       
   432 fun join_recent_proofs st =
       
   433   (case try proof_of st of
       
   434     SOME prf => Proof.join_recent_proofs prf
       
   435   | NONE =>
       
   436       (case try theory_of st of
       
   437         SOME thy => Thm.join_recent_proofs thy
       
   438       | NONE => ()));
       
   439 
       
   440 
       
   441 (* theory transitions *)
   425 (* theory transitions *)
   442 
   426 
   443 fun generic_theory f = transaction (fn _ =>
   427 fun generic_theory f = transaction (fn _ =>
   444   (fn Theory (gthy, _) => Theory (f gthy, NONE)
   428   (fn Theory (gthy, _) => Theory (f gthy, NONE)
   445     | _ => raise UNDEF));
   429     | _ => raise UNDEF));
   485 local
   469 local
   486 
   470 
   487 fun local_theory_presentation loc f = present_transaction (fn int =>
   471 fun local_theory_presentation loc f = present_transaction (fn int =>
   488   (fn Theory (gthy, _) =>
   472   (fn Theory (gthy, _) =>
   489         let
   473         let
   490           val (finish, lthy) = gthy
   474           val (finish, lthy) = loc_begin loc gthy;
   491             |> begin_proofs
       
   492             |> loc_begin loc;
       
   493           val lthy' = lthy
   475           val lthy' = lthy
   494             |> Local_Theory.new_group
   476             |> Local_Theory.new_group
   495             |> f int
   477             |> f int
   496             |> Local_Theory.reset_group;
   478             |> Local_Theory.reset_group;
   497         in Theory (finish lthy', SOME lthy') end
   479         in Theory (finish lthy', SOME lthy') end
   543 
   525 
   544 in
   526 in
   545 
   527 
   546 fun local_theory_to_proof' loc f = begin_proof
   528 fun local_theory_to_proof' loc f = begin_proof
   547   (fn int => fn gthy =>
   529   (fn int => fn gthy =>
   548     let val (finish, lthy) = gthy
   530     let val (finish, lthy) = loc_begin loc gthy
   549       |> begin_proofs
       
   550       |> loc_begin loc;
       
   551     in (finish o Local_Theory.reset_group, f int (Local_Theory.new_group lthy)) end);
   531     in (finish o Local_Theory.reset_group, f int (Local_Theory.new_group lthy)) end);
   552 
   532 
   553 fun local_theory_to_proof loc f = local_theory_to_proof' loc (K f);
   533 fun local_theory_to_proof loc f = local_theory_to_proof' loc (K f);
   554 
   534 
   555 fun theory_to_proof f = begin_proof
   535 fun theory_to_proof f = begin_proof
   556   (fn _ => fn gthy =>
   536   (fn _ => fn gthy =>
   557     (Context.Theory o Sign.reset_group o Proof_Context.theory_of,
   537     (Context.Theory o Sign.reset_group o Proof_Context.theory_of,
   558       (case begin_proofs gthy of
   538       (case gthy of
   559         Context.Theory thy => f (Theory.checkpoint (Sign.new_group thy))
   539         Context.Theory thy => f (Theory.checkpoint (Sign.new_group thy))
   560       | _ => raise UNDEF)));
   540       | _ => raise UNDEF)));
   561 
   541 
   562 end;
   542 end;
   563 
   543 
   565   (fn Proof (_, (_, orig_gthy)) => Theory (orig_gthy, NONE)
   545   (fn Proof (_, (_, orig_gthy)) => Theory (orig_gthy, NONE)
   566     | SkipProof (_, (_, orig_gthy)) => Theory (orig_gthy, NONE)
   546     | SkipProof (_, (_, orig_gthy)) => Theory (orig_gthy, NONE)
   567     | _ => raise UNDEF));
   547     | _ => raise UNDEF));
   568 
   548 
   569 val present_proof = present_transaction (fn _ =>
   549 val present_proof = present_transaction (fn _ =>
   570   (fn Proof (prf, x) => Proof (Proof_Node.apply Proof.begin_proofs prf, x)
   550   (fn Proof (prf, x) => Proof (Proof_Node.apply I prf, x)
   571     | skip as SkipProof _ => skip
   551     | skip as SkipProof _ => skip
   572     | _ => raise UNDEF));
   552     | _ => raise UNDEF));
   573 
   553 
   574 fun proofs' f = transaction (fn int =>
   554 fun proofs' f = transaction (fn int =>
   575   (fn Proof (prf, x) => Proof (Proof_Node.applys (f int o Proof.begin_proofs) prf, x)
   555   (fn Proof (prf, x) => Proof (Proof_Node.applys (f int) prf, x)
   576     | skip as SkipProof _ => skip
   556     | skip as SkipProof _ => skip
   577     | _ => raise UNDEF));
   557     | _ => raise UNDEF));
   578 
   558 
   579 fun proof' f = proofs' (Seq.single oo f);
   559 fun proof' f = proofs' (Seq.single oo f);
   580 val proofs = proofs' o K;
   560 val proofs = proofs' o K;