From 5eacd6ebc13d908dae55e4b760fa1c87770094ec Mon Sep 17 00:00:00 2001 From: Gabriel Pariat Date: Sun, 20 Feb 2022 15:22:53 -0500 Subject: [PATCH] tweak peek-char --- implementations/c/src/reader.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/implementations/c/src/reader.c b/implementations/c/src/reader.c index 4cc365d..768b0bb 100644 --- a/implementations/c/src/reader.c +++ b/implementations/c/src/reader.c @@ -100,11 +100,9 @@ Pointer read_char_fn(Pointer args, Pointer env) { } static Pointer buffer; -Pointer read_fn(Pointer args, Pointer env) { - Pointer streamPtr = CAR(args); - Stream stream = streamPtr == NIL - ? STREAM(environment_get(env, STANDARD_INPUT)) - : STREAM(streamPtr); + +Pointer read1(Pointer streamPtr, Pointer env) { + Stream stream = STREAM(streamPtr); double num = 0; Pointer macro; Char c = peek_char(T, stream); @@ -138,6 +136,15 @@ Pointer read_fn(Pointer args, Pointer env) { return symbol(STRING(buffer).data, STRING(buffer).length - 1); } +Pointer read_fn(Pointer args, Pointer env) { + Pointer streamPtr = CAR(args); + streamPtr = streamPtr == NIL ? environment_get(env, STANDARD_INPUT) : streamPtr; + Stream stream = STREAM(streamPtr); + Pointer result = read1(streamPtr, env); + peek_char(T, stream); + return result; +} + Pointer set_reader_macro(Pointer c, Pointer fn) { READTABLE = table_set(READTABLE, c, fn); return T;