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
|
// TODO: remove malloc and strndup calls
|
||||||
|
|
||||||
static bool nl_is_whitespace(char c) {
|
static bool nl_is_whitespace(char c) {
|
||||||
return c == ' ' || c == '\n';
|
return c == ' ' || c == '\n' || c == '\t';
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool nl_is_token(char c) {
|
static bool nl_is_token(char c) {
|
||||||
@@ -39,6 +39,7 @@ struct nl_object *nl_token_next(const char **curr_src) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
case ' ':
|
case ' ':
|
||||||
case '\n':
|
case '\n':
|
||||||
|
case '\t':
|
||||||
start++;
|
start++;
|
||||||
(*curr_src)++;
|
(*curr_src)++;
|
||||||
continue;
|
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 *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;
|
const char *curr_src = source;
|
||||||
|
|
||||||
while (true) {
|
while ((curr_token = nl_token_next(&curr_src)) != NULL) {
|
||||||
curr_token = nl_token_next(&curr_src);
|
*next_token = curr_token;
|
||||||
if (curr_token == NULL) {
|
next_token = &curr_token->cell.cdr;
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tokens == NULL) {
|
|
||||||
tokens = curr_token;
|
|
||||||
} else {
|
|
||||||
prev_token->cell.cdr = curr_token;
|
|
||||||
}
|
|
||||||
prev_token = curr_token;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return tokens;
|
return tokens;
|
||||||
@@ -107,9 +99,6 @@ struct nl_object *nl_parse(const char *source) {
|
|||||||
for (struct nl_object *token = tokens;
|
for (struct nl_object *token = tokens;
|
||||||
token != NULL;
|
token != NULL;
|
||||||
token = token->cell.cdr) {
|
token = token->cell.cdr) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nl_object_delete(tokens);
|
nl_object_delete(tokens);
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ void test_parse_empty_str() {
|
|||||||
TEST_ASSERT_NULL(response);
|
TEST_ASSERT_NULL(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_parse_empty_str() {
|
void test_parse_symbol() {
|
||||||
response = nl_parse("foo");
|
response = nl_parse("foo");
|
||||||
|
|
||||||
TEST_ASSERT_NOT_NULL(response);
|
TEST_ASSERT_NOT_NULL(response);
|
||||||
|
|||||||
Reference in New Issue
Block a user