Commit b05e438f authored by Kim Nguyễn's avatar Kim Nguyễn

Correctly flush the toplevel output in case the lexer consumes the

"\n" after the ;; token.
parent 36b83c45
...@@ -103,6 +103,18 @@ let outflush s = ...@@ -103,6 +103,18 @@ let outflush s =
output_string stdout s; output_string stdout s;
flush stdout flush stdout
let has_newline b =
let rec loop i found =
if i >= 1 then
let c = Buffer.nth b i in
if c == ';' && Buffer.nth b (i-1) == ';'
then found
else loop (i - 1) (c == '\n')
else false
in
loop (Buffer.length b - 1) false
let toploop () = let toploop () =
let restore = let restore =
try try
...@@ -141,6 +153,8 @@ let toploop () = ...@@ -141,6 +153,8 @@ let toploop () =
bol := false; bol := false;
Buffer.clear buf_in; Buffer.clear buf_in;
ignore (Cduce.topinput ppf ppf_err input); ignore (Cduce.topinput ppf ppf_err input);
if not (has_newline buf_in) then
(* ";;\n" was eaten by a regular expression in the lexer *)
while (input_char stdin != '\n') do () done; while (input_char stdin != '\n') do () done;
loop () in loop () in
(try loop () with End_of_file -> ()); (try loop () with End_of_file -> ());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment