From: Javier Sagredo Date: Mon, 15 Jun 2026 21:14:18 +0000 (+0200) Subject: Allow using non-terminating streams in phrase_from_stream X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=cc9a859fc63aec9a17a3128796d016a21206aa82;p=scryer-prolog.git Allow using non-terminating streams in phrase_from_stream --- diff --git a/src/lib/pio.pl b/src/lib/pio.pl index 0204a19e..880381e0 100644 --- a/src/lib/pio.pl +++ b/src/lib/pio.pl @@ -140,11 +140,17 @@ buffer_prepare_for_n(Stream, BufferId, BufferPosId, BufferLenId, N) :- ; chars_to_read(CharsToRead), get_n_chars(Stream, CharsToRead, Chars), length(Chars, NChars), - partial_string(Chars, BufferTail, _), - bb_put(BufferId, Buffer), - BufferLen1 is BufferLen + NChars, - bb_put(BufferLenId, BufferLen1), - buffer_prepare_for_n(Stream, BufferId, BufferPosId, BufferLenId, N) + ( NChars =:= 0 -> + % get_n_chars returning [] means EOF, even on streams + % whose at_end_of_stream/1 never reports true (pipes). + BufferTail = [], + bb_put(BufferId, Buffer) + ; partial_string(Chars, BufferTail, _), + bb_put(BufferId, Buffer), + BufferLen1 is BufferLen + NChars, + bb_put(BufferLenId, BufferLen1), + buffer_prepare_for_n(Stream, BufferId, BufferPosId, BufferLenId, N) + ) ) ; true )