Extract line reading logic to reader and remove REPL tests
Reading a line into the buffer was the only logic complex enough to be worth testing really, and exposing the necessary parts of it to test it effectively was a pain. Makes more sense to move read_line out and throw away most of the tests.
This commit is contained in:
14
lib/reader.c
14
lib/reader.c
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static int parse_expression(
|
||||
memory_pool_t *pool, const char *input, int len, expression_t **out);
|
||||
@@ -152,6 +153,19 @@ static int parse_expression(
|
||||
return used;
|
||||
}
|
||||
|
||||
int read_line(int (*get_byte)(void), char *buffer, int buffer_size)
|
||||
{
|
||||
for (int len = 0; len < buffer_size; ++len) {
|
||||
const int byte = get_byte();
|
||||
if (EOF == byte)
|
||||
return -1;
|
||||
if ('\n' == byte)
|
||||
return len;
|
||||
buffer[len] = (char)byte;
|
||||
}
|
||||
return buffer_size;
|
||||
}
|
||||
|
||||
const expression_t *
|
||||
read_expression(memory_pool_t *pool, const char *input, int len)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user