src/Pure/ML/ml_file.ML
changeset 62902 3c0f53eae166
parent 62873 2f9c8a18f832
child 67377 143665524d8e
equal deleted inserted replaced
62901:0951d6cec68c 62902:3c0f53eae166
     6 
     6 
     7 signature ML_FILE =
     7 signature ML_FILE =
     8 sig
     8 sig
     9   val ML: bool option -> (theory -> Token.file list) -> Toplevel.transition -> Toplevel.transition
     9   val ML: bool option -> (theory -> Token.file list) -> Toplevel.transition -> Toplevel.transition
    10   val SML: bool option -> (theory -> Token.file list) -> Toplevel.transition -> Toplevel.transition
    10   val SML: bool option -> (theory -> Token.file list) -> Toplevel.transition -> Toplevel.transition
    11   val use: bool option -> (theory -> Token.file list) -> Toplevel.transition -> Toplevel.transition
       
    12 end;
    11 end;
    13 
    12 
    14 structure ML_File: ML_FILE =
    13 structure ML_File: ML_FILE =
    15 struct
    14 struct
    16 
    15 
    17 fun command SML debug files = Toplevel.generic_theory (fn gthy =>
    16 fun command SML debug files = Toplevel.generic_theory (fn gthy =>
    18   let
    17   let
    19     val [{src_path, lines, digest, pos}: Token.file] = files (Context.theory_of gthy);
    18     val [{src_path, lines, digest, pos}: Token.file] = files (Context.theory_of gthy);
    20     val provide = Resources.provide (src_path, digest);
    19     val provide = Resources.provide (src_path, digest);
    21     val source = Input.source true (cat_lines lines) (pos, pos);
    20     val source = Input.source true (cat_lines lines) (pos, pos);
    22     val (SML_syntax, SML_env) = SML src_path;
       
    23     val flags =
    21     val flags =
    24       {SML_syntax = SML_syntax, SML_env = SML_env, exchange = false, redirect = true,
    22       {SML = SML, exchange = false, redirect = true, verbose = true,
    25         verbose = true, debug = debug, writeln = writeln, warning = warning};
    23         debug = debug, writeln = writeln, warning = warning};
    26   in
    24   in
    27     gthy
    25     gthy
    28     |> ML_Context.exec (fn () => ML_Context.eval_source flags source)
    26     |> ML_Context.exec (fn () => ML_Context.eval_source flags source)
    29     |> Local_Theory.propagate_ml_env
    27     |> Local_Theory.propagate_ml_env
    30     |> Context.mapping provide (Local_Theory.background_theory provide)
    28     |> Context.mapping provide (Local_Theory.background_theory provide)
    31   end);
    29   end);
    32 
    30 
    33 val ML = command (K (false, false));
    31 val ML = command false;
    34 val SML = command (K (true, true));
    32 val SML = command true;
    35 
       
    36 val use =
       
    37   command (fn path =>
       
    38     (case try (#2 o Path.split_ext) path of
       
    39       SOME "ML" => (false, true)
       
    40     | SOME "sml" => (true, true)
       
    41     | SOME "sig" => (true, true)
       
    42     | _ =>
       
    43         error ("Bad file name " ^ Path.print path ^
       
    44           "\nExpected .ML for Isabelle/ML or .sml/.sig for Standard ML")));
       
    45 
    33 
    46 end;
    34 end;