src/Pure/Isar/toplevel.ML
changeset 25527 330ca6e1dca8
parent 25441 4028958d19ff
child 25551 87d89b0f847a
equal deleted inserted replaced
25526:05ee7d85912e 25527:330ca6e1dca8
    96   val exn: unit -> (exn * string) option
    96   val exn: unit -> (exn * string) option
    97   val >> : transition -> bool
    97   val >> : transition -> bool
    98   val >>> : transition list -> unit
    98   val >>> : transition list -> unit
    99   val init_state: unit -> unit
    99   val init_state: unit -> unit
   100   type 'a isar
   100   type 'a isar
   101   val loop: 'a isar -> unit
   101   val loop: bool -> 'a isar -> unit
   102 end;
   102 end;
   103 
   103 
   104 structure Toplevel: TOPLEVEL =
   104 structure Toplevel: TOPLEVEL =
   105 struct
   105 struct
   106 
   106 
   751   (transition, (transition option,
   751   (transition, (transition option,
   752     (OuterLex.token, (OuterLex.token option, (OuterLex.token, (OuterLex.token,
   752     (OuterLex.token, (OuterLex.token option, (OuterLex.token, (OuterLex.token,
   753       Position.T * (Symbol.symbol, (string, 'a) Source.source) Source.source)
   753       Position.T * (Symbol.symbol, (string, 'a) Source.source) Source.source)
   754           Source.source) Source.source) Source.source) Source.source) Source.source) Source.source;
   754           Source.source) Source.source) Source.source) Source.source) Source.source) Source.source;
   755 
   755 
       
   756 local
       
   757 
   756 (*Spurious interrupts ahead!  Race condition?*)
   758 (*Spurious interrupts ahead!  Race condition?*)
   757 fun get_interrupt src = SOME (Source.get_single src) handle Interrupt => NONE;
   759 fun get_interrupt src = SOME (Source.get_single src) handle Interrupt => NONE;
   758 
   760 
   759 fun warn_secure () =
   761 fun raw_loop secure src =
   760   let val secure = Secure.is_secure ()
   762   let
   761   in if secure then warning "Cannot exit to ML in secure mode" else (); secure end;
   763     fun check_secure () =
   762 
   764       (if secure then warning "Secure loop -- cannot exit to ML" else (); secure);
   763 fun raw_loop src =
   765     val prompt = Output.escape (Markup.enclose Markup.prompt Source.default_prompt);
   764   let val prompt = Output.escape (Markup.enclose Markup.prompt Source.default_prompt) in
   766   in
   765     (case get_interrupt (Source.set_prompt prompt src) of
   767     (case get_interrupt (Source.set_prompt prompt src) of
   766       NONE => (writeln "\nInterrupt."; raw_loop src)
   768       NONE => (writeln "\nInterrupt."; raw_loop secure src)
   767     | SOME NONE => if warn_secure () then quit () else ()
   769     | SOME NONE => if secure then quit () else ()
   768     | SOME (SOME (tr, src')) =>
   770     | SOME (SOME (tr, src')) => if >> tr orelse check_secure () then raw_loop secure src' else ())
   769         if >> tr orelse warn_secure () then raw_loop src'
       
   770         else ())
       
   771   end;
   771   end;
   772 
   772 
   773 fun loop src = ignore_interrupt raw_loop src;
   773 in
   774 
   774 
   775 end;
   775 fun loop secure src = ignore_interrupt (raw_loop secure) src;
       
   776 
       
   777 end;
       
   778 
       
   779 end;