Commit c411a3fd authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2002-10-29 23:53:39 by cvscast] Empty log message

Original author: cvscast
Date: 2002-10-29 23:53:39+00:00
parent 1a2faa50
open Printf
type line_buffer =
{ mutable buffer : string ;
mutable length : int;
mutable abs_pos: int ;
maxlength: int;
}
(* Discard data left in lexer buffer. *)
let empty_buf buf =
buf.length <- 0;
buf.abs_pos <- 0;
(* this function fills the line buffer printing
the prompt :-> at the first line *)
let first_line = ref true
let got_eof = ref false;;
let refill_buf buffer len =
if !got_eof then (got_eof := false; 0) else begin
let prompt =
if !first_line then ":-> "
else " "
in
output_string stdout prompt; flush stdout;
first_line := false;
let i = ref 0 in
try
while true do
if !i >= len then raise Exit;
let c = input_char stdin in
buffer.[!i] <- c;
incr i;
if c = '\n' then raise Exit;
done;
!i
with
| End_of_file ->
if !i > 0 then (got_eof := true; !i) else 0
| Exit -> !i
end
(* The function scan takes a linebuffer buffer
and returns a function fomr the current stream count to a char
option that is used to create the Stream
*)
let rec scan line_buf count =
let element = count-(line_buf.abs_pos) in
if element < line_buf.length-1 then (* send to stream the character *)
Some line_buf.buffer.[element]
else ( (* read another line*)
line_buf.abs_pos <- (line_buf.abs_pos) + line_buf.length;
line_buf.length <- refill_buf line_buf.buffer line_buf.maxlength;
scan line_buf count)
(* JUST FOR TESTING *)
let loop =
fprintf stdout " CDuce version 0.2a1\n\n";
let line_buffer =
{ buffer = " ";
length = 0;
abs_pos = 0;
maxlength = 60;
} in
let input = Stream.from (scan line_buffer) in
Sys.catch_break true;
while true do
empty_buf line_buffer;
first_line := true;
let doublesemicolon = ref false in
let semicolon = ref false in
while not !doublesemicolon do
let c = Stream.next input in
if c = ';' then (if !semicolon then doublesemicolon := true else semicolon := true) else semicolon := false;(* output_char stdout c *)
done
done
(* THE REAL LOOP
let loop ppf =
fprintf ppf " CDuce version 0.2a1";
(*
initialize_toplevel_env ();
*)
let line_buffer =
{ buffer = ref " ";
lenth = ref 0;
abs_pos = ref 0;
maxlength = 60;
}
let input = Stream.from scan line_buffer
Sys.catch_break true;
while true do
try
empty_buf line_buffer;
first_line := true;
let
while not lexed ";;"
Parse and catch ";;" to end inner loop
print type line
print execution line
with
| End_of_file -> exit 0
| Sys.Break -> fprintf ppf "Interrupted.@."
| PPerror -> ()
| x -> Errors.report_error ppf x
done
*)
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