Return fewer NULLs in parsing

This commit is contained in:
2022-11-15 15:42:01 -05:00
parent 785dbf06f6
commit 086d6f9106

View File

@@ -88,7 +88,7 @@ struct ucl_object *ucl_token_next(const char **curr_src) {
// Unreachable // Unreachable
assert(false); assert(false);
return NULL; return ucl_error_create("Unreachable error in ucl_token_next");
} }
struct ucl_object *ucl_tokenize(const char *source) { struct ucl_object *ucl_tokenize(const char *source) {
@@ -129,6 +129,9 @@ struct ucl_object *ucl_parse_token_atom(struct ucl_object *maybe_atom) {
case UCL_TYPE_COUNT: case UCL_TYPE_COUNT:
assert(false); assert(false);
} }
if (atom == NULL) {
return ucl_error_create("Unreachable error in ucl_parse_token_atom");
}
return atom; return atom;
} }
@@ -178,11 +181,6 @@ static struct ucl_object *ucl_parse_tokens_recursive(struct ucl_object **token_i
next_sexp = ucl_parse_tokens_recursive(token_iter); next_sexp = ucl_parse_tokens_recursive(token_iter);
UCL_RET_IF_ERROR(next_sexp); UCL_RET_IF_ERROR(next_sexp);
if (next_sexp == NULL) {
// Error somewhere in the recursive parsing
ucl_object_delete(list);
return NULL;
}
*next_node = ucl_cell_create(next_sexp, NULL); *next_node = ucl_cell_create(next_sexp, NULL);
next_node = &(*next_node)->cell.cdr; next_node = &(*next_node)->cell.cdr;
@@ -192,7 +190,7 @@ static struct ucl_object *ucl_parse_tokens_recursive(struct ucl_object **token_i
} }
// Any other symbol type should have been an atom, this shouldn't happen // Any other symbol type should have been an atom, this shouldn't happen
assert(false); assert(false);
return ucl_error_create("Unreachable parse error"); return ucl_error_create("Unreachable ucl_parse_tokens_recursive error");
} }
// parse_tokens -> doesn't care about quotes, terminates on EOF // parse_tokens -> doesn't care about quotes, terminates on EOF
@@ -218,8 +216,6 @@ struct ucl_object *ucl_parse_tokens(struct ucl_object *tokens) {
} }
return resultl; return resultl;
error:
return NULL;
} }
// TODO: Should the parse a single sexp (return the last-parsed position), or // TODO: Should the parse a single sexp (return the last-parsed position), or