Remove read_expression and use parse_expression directly
This commit is contained in:
41
lib/reader.c
41
lib/reader.c
@@ -1,11 +1,20 @@
|
||||
#include "reader.h"
|
||||
|
||||
#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);
|
||||
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;
|
||||
}
|
||||
|
||||
static int parse_whitespace(const char *input, int len)
|
||||
{
|
||||
@@ -104,7 +113,7 @@ static int parse_term(
|
||||
return used;
|
||||
}
|
||||
|
||||
static int parse_expression(
|
||||
int parse_expression(
|
||||
memory_pool_t *pool, const char *input, int len, expression_t **out)
|
||||
{
|
||||
int result, used = 0;
|
||||
@@ -152,27 +161,3 @@ static int parse_expression(
|
||||
*out = expr;
|
||||
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)
|
||||
{
|
||||
expression_t *expression;
|
||||
const int used = parse_expression(pool, input, len, &expression);
|
||||
if (used == len)
|
||||
return expression;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user