Minor parsing cleanup
This commit is contained in:
13
src/parse.c
13
src/parse.c
@@ -141,6 +141,9 @@ struct ucl_object *ucl_parse_token_atom(struct ucl_object *maybe_atom) {
|
|||||||
case UCL_TYPE_INT:
|
case UCL_TYPE_INT:
|
||||||
atom = ucl_int_create(maybe_atom->integer);
|
atom = ucl_int_create(maybe_atom->integer);
|
||||||
break;
|
break;
|
||||||
|
case UCL_TYPE_ERROR:
|
||||||
|
case UCL_TYPE_BUILTIN:
|
||||||
|
case UCL_TYPE_SPECIAL:
|
||||||
case UCL_TYPE_COUNT:
|
case UCL_TYPE_COUNT:
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
@@ -150,6 +153,10 @@ struct ucl_object *ucl_parse_token_atom(struct ucl_object *maybe_atom) {
|
|||||||
return atom;
|
return atom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void advance_token_iter(struct ucl_object **token_iter) {
|
||||||
|
*token_iter = (*token_iter)->cell.cdr;
|
||||||
|
}
|
||||||
|
|
||||||
static struct ucl_object *ucl_parse_tokens_recursive(struct ucl_object **token_iter) {
|
static struct ucl_object *ucl_parse_tokens_recursive(struct ucl_object **token_iter) {
|
||||||
// Invariants:
|
// Invariants:
|
||||||
// - This function returns NULL if it encounters the first unmatched END_LIST_CHAR
|
// - This function returns NULL if it encounters the first unmatched END_LIST_CHAR
|
||||||
@@ -168,7 +175,7 @@ static struct ucl_object *ucl_parse_tokens_recursive(struct ucl_object **token_i
|
|||||||
}
|
}
|
||||||
struct ucl_object *next_sexp = ucl_parse_token_atom(token);
|
struct ucl_object *next_sexp = ucl_parse_token_atom(token);
|
||||||
if (next_sexp != NULL) {
|
if (next_sexp != NULL) {
|
||||||
*token_iter = (*token_iter)->cell.cdr;
|
advance_token_iter(token_iter);
|
||||||
return next_sexp;
|
return next_sexp;
|
||||||
}
|
}
|
||||||
assert(token->type == UCL_TYPE_SYMBOL);
|
assert(token->type == UCL_TYPE_SYMBOL);
|
||||||
@@ -177,7 +184,7 @@ static struct ucl_object *ucl_parse_tokens_recursive(struct ucl_object **token_i
|
|||||||
struct ucl_object *list = NULL;
|
struct ucl_object *list = NULL;
|
||||||
struct ucl_object **next_node = &list;
|
struct ucl_object **next_node = &list;
|
||||||
// Consume the START_LIST_CHAR
|
// Consume the START_LIST_CHAR
|
||||||
*token_iter = (*token_iter)->cell.cdr;
|
advance_token_iter(token_iter);
|
||||||
while (1) {
|
while (1) {
|
||||||
if (*token_iter == NULL) {
|
if (*token_iter == NULL) {
|
||||||
// Unexpected end of parsing
|
// Unexpected end of parsing
|
||||||
@@ -187,7 +194,7 @@ static struct ucl_object *ucl_parse_tokens_recursive(struct ucl_object **token_i
|
|||||||
token = (*token_iter)->cell.car;
|
token = (*token_iter)->cell.car;
|
||||||
|
|
||||||
if (token->type == UCL_TYPE_SYMBOL && token->symbol[0] == END_LIST_CHAR) {
|
if (token->type == UCL_TYPE_SYMBOL && token->symbol[0] == END_LIST_CHAR) {
|
||||||
*token_iter = (*token_iter)->cell.cdr;
|
advance_token_iter(token_iter);
|
||||||
if (list == NULL) {
|
if (list == NULL) {
|
||||||
list = ucl_cell_create(NULL, NULL);
|
list = ucl_cell_create(NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user