Fix build and minor cleanup
This commit is contained in:
23
src/parse.c
23
src/parse.c
@@ -16,7 +16,7 @@
|
||||
// TODO: remove malloc and strndup calls
|
||||
|
||||
static bool nl_is_whitespace(char c) {
|
||||
return c == ' ' || c == '\n';
|
||||
return c == ' ' || c == '\n' || c == '\t';
|
||||
}
|
||||
|
||||
static bool nl_is_token(char c) {
|
||||
@@ -39,6 +39,7 @@ struct nl_object *nl_token_next(const char **curr_src) {
|
||||
return NULL;
|
||||
case ' ':
|
||||
case '\n':
|
||||
case '\t':
|
||||
start++;
|
||||
(*curr_src)++;
|
||||
continue;
|
||||
@@ -78,21 +79,12 @@ struct nl_object *nl_token_next(const char **curr_src) {
|
||||
}
|
||||
|
||||
struct nl_object *nl_tokenize(const char *source) {
|
||||
struct nl_object *tokens = NULL, *curr_token = NULL, *prev_token = NULL;
|
||||
struct nl_object *tokens = NULL, *curr_token = NULL, **next_token = &tokens;
|
||||
const char *curr_src = source;
|
||||
|
||||
while (true) {
|
||||
curr_token = nl_token_next(&curr_src);
|
||||
if (curr_token == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (tokens == NULL) {
|
||||
tokens = curr_token;
|
||||
} else {
|
||||
prev_token->cell.cdr = curr_token;
|
||||
}
|
||||
prev_token = curr_token;
|
||||
while ((curr_token = nl_token_next(&curr_src)) != NULL) {
|
||||
*next_token = curr_token;
|
||||
next_token = &curr_token->cell.cdr;
|
||||
}
|
||||
|
||||
return tokens;
|
||||
@@ -107,9 +99,6 @@ struct nl_object *nl_parse(const char *source) {
|
||||
for (struct nl_object *token = tokens;
|
||||
token != NULL;
|
||||
token = token->cell.cdr) {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
nl_object_delete(tokens);
|
||||
|
||||
@@ -205,7 +205,7 @@ void test_parse_empty_str() {
|
||||
TEST_ASSERT_NULL(response);
|
||||
}
|
||||
|
||||
void test_parse_empty_str() {
|
||||
void test_parse_symbol() {
|
||||
response = nl_parse("foo");
|
||||
|
||||
TEST_ASSERT_NOT_NULL(response);
|
||||
|
||||
Reference in New Issue
Block a user