src/Pure/ML-Systems/compiler_polyml-5.3.ML
changeset 31471 e3987b32e401
parent 31433 12f5f6af3d2d
child 31480 05937d6aafb5
equal deleted inserted replaced
31470:01e7a8bb9e5b 31471:e3987b32e401
    12 in
    12 in
    13 
    13 
    14 fun use_text ({tune_source, name_space, str_of_pos, print, error, ...}: use_context)
    14 fun use_text ({tune_source, name_space, str_of_pos, print, error, ...}: use_context)
    15     (start_line, name) verbose txt =
    15     (start_line, name) verbose txt =
    16   let
    16   let
    17     val current_line = ref start_line;
    17     val line = ref start_line;
    18     val in_buffer = ref (String.explode (tune_source txt));
    18     val in_buffer = ref (String.explode (tune_source txt));
    19     val out_buffer = ref ([]: string list);
    19     val out_buffer = ref ([]: string list);
    20     fun output () = drop_newline (implode (rev (! out_buffer)));
    20     fun output () = drop_newline (implode (rev (! out_buffer)));
    21 
    21 
    22     fun get () =
    22     fun get () =
    23       (case ! in_buffer of
    23       (case ! in_buffer of
    24         [] => NONE
    24         [] => NONE
    25       | c :: cs =>
    25       | c :: cs => (in_buffer := cs; if c = #"\n" then line := ! line + 1 else (); SOME c));
    26           (in_buffer := cs; if c = #"\n" then current_line := ! current_line + 1 else (); SOME c));
       
    27     fun put s = out_buffer := s :: ! out_buffer;
    26     fun put s = out_buffer := s :: ! out_buffer;
    28     fun put_message {message = msg1, hard, location = {startLine = line, ...}, context} =
    27     fun put_message {message = msg1, hard, location = {startLine = line, ...}, context} =
    29      (put (if hard then "Error: " else "Warning: ");
    28      (put (if hard then "Error: " else "Warning: ");
    30       PolyML.prettyPrint (put, 76) msg1;
    29       PolyML.prettyPrint (put, 76) msg1;
    31       (case context of NONE => () | SOME msg2 => PolyML.prettyPrint (put, 76) msg2);
    30       (case context of NONE => () | SOME msg2 => PolyML.prettyPrint (put, 76) msg2);
    32       put ("At" ^ str_of_pos line name ^ "\n"));
    31       put ("At" ^ str_of_pos line name ^ "\n"));
    33 
    32 
    34     val parameters =
    33     val parameters =
    35      [PolyML.Compiler.CPOutStream put,
    34      [PolyML.Compiler.CPOutStream put,
    36       PolyML.Compiler.CPLineNo (fn () => ! current_line),
    35       PolyML.Compiler.CPNameSpace name_space,
    37       PolyML.Compiler.CPErrorMessageProc put_message,
    36       PolyML.Compiler.CPErrorMessageProc put_message,
    38       PolyML.Compiler.CPNameSpace name_space,
    37       PolyML.Compiler.CPLineNo (fn () => ! line),
       
    38       PolyML.Compiler.CPFileName name,
    39       PolyML.Compiler.CPPrintInAlphabeticalOrder false];
    39       PolyML.Compiler.CPPrintInAlphabeticalOrder false];
    40     val _ =
    40     val _ =
    41       (while not (List.null (! in_buffer)) do
    41       (while not (List.null (! in_buffer)) do
    42         PolyML.compiler (get, parameters) ())
    42         PolyML.compiler (get, parameters) ())
    43       handle exn =>
    43       handle exn =>