// $Id$ //$module Stream : IStream; $use Access Apply Box Class Compare Error StdIO; //** $func Stream s.func e.args = stream; Stream s.func e.args, { # = , $fail; ; }; $func? Read_Expr s.box = v.expr; Read_Expr s.box = : v.expr, , v.expr; //** $func Expr-Open expr = stream; Expr_Open expr = :: s.box, ; //** $func File-Open e.filename = stream; //** $func File-Close stream = ; File_Open e.filename = :: s.channel, , ; File_Close stream, { : (e.buf) (s.func e.args), { e.args : s.ch e.rest, = ; = $fail; }; = $fail; }; //** $func StdIStream = stream; $box StdIStream_Box; StdIStream, { : stream = stream; :: stream, , stream; }; //** $func? Getc stream = term; Getc stream = : term, term; //** $func? Gets stream s.n = expr; Gets stream s.n, { : (e.buf) (s.func e.args) = e.buf $iter { e.buf ; = $fail; } :: e.buf, ) (s.n)> = ) (s.func e.args)>, ; = $fail; }; //** $func Ungets stream expr = ; Ungets stream expr, { : (e.buf) (s.func e.args) = ; = $fail; }; //** $func Scanc stream t1 = empty-or-t1; Scanc stream t1, { : { t1 = t1; t2 = ; }; /*empty*/; }; //** $func Get-Delim stream t.delim = expr; Get_Delim stream t.delim, { : (e.buf) (s.func e.args) = (/*e.str*/) (e.buf) $iter { e.buf : e1 t.delim e2 = (e.str e1 t.delim) (e2) Stop; (e.str e.buf) (); (e.str e.buf) () Stop; } :: (e.str) (e.buf) e.Isstop, e.Isstop : Stop = , e.str; = $fail; }; //** $func Get-Line stream = expr; //Get-Line stream = ; $func? Not_EOL t1 = ; Not_EOL t1 = # t1 : \{ '\n'; '\r'; }; Get_Line stream = ; //** $func Get-While stream s.pred = expr; Get_While stream s.pred, { : (e.buf) (s.func e.args) = (/*e.str*/) (e.buf) $iter { e.buf : t1 e2, { : e = (e.str t1) (e2); (e.str) (e.buf) Stop; }; (e.str) (); (e.str) (e.buf) Stop; } :: (e.str) (e.buf) e.Isstop, e.Isstop : Stop = , e.str; = $fail; }; //** $func? End-of-Stream? stream = ; IsEnd_of_Stream stream, { : (e.buf) (s.func e.args) = { e.buf $iter :: e.buf, e.buf : v = , $fail; /*We are at the end of the stream*/; }; = $fail; };