fx.serial: remove references to obsolete classes
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
#include <fx/collections/array.h>
|
||||
#include <fx/collections/dict.h>
|
||||
#include <fx/int.h>
|
||||
#include <fx/serial/ctx.h>
|
||||
#include <fx/serial/toml.h>
|
||||
@@ -9,6 +8,7 @@
|
||||
|
||||
int main(void)
|
||||
{
|
||||
#if 0
|
||||
fx_serial_ctx *ctx = fx_toml_serial_ctx_create();
|
||||
|
||||
fx_dict *dict = fx_dict_create();
|
||||
@@ -33,6 +33,7 @@ int main(void)
|
||||
|
||||
fx_dict_unref(dict);
|
||||
fx_serial_ctx_unref(ctx);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#include <fx/bool.h>
|
||||
#include <fx/collections/array.h>
|
||||
#include <fx/collections/datetime.h>
|
||||
#include <fx/collections/dict.h>
|
||||
#include <fx/double.h>
|
||||
#include <fx/float.h>
|
||||
#include <fx/int.h>
|
||||
#include <fx/serial/ctx.h>
|
||||
#include <fx/serial/toml.h>
|
||||
@@ -16,8 +15,10 @@ void write_raw_string(const fx_string *data)
|
||||
fx_stream_write_cstr(fx_stdout, "\"", NULL);
|
||||
|
||||
const fx_iterator *it = fx_iterator_cbegin(data);
|
||||
fx_foreach_c(fx_wchar, c, it)
|
||||
fx_foreach(val, it)
|
||||
{
|
||||
fx_wchar c;
|
||||
fx_value_get_wchar(&val, &c);
|
||||
if (c >= 0x10000) {
|
||||
c -= 0x10000;
|
||||
long hi = 0xD800 | ((c >> 10) & 0x3FF);
|
||||
@@ -55,6 +56,7 @@ void write_tagged_string(fx_string *data)
|
||||
|
||||
void write_tagged_integer(fx_int *data)
|
||||
{
|
||||
#if 0
|
||||
fx_stream_write_cstr(
|
||||
fx_stdout,
|
||||
"{ \"type\": \"integer\", \"value\": \"",
|
||||
@@ -78,10 +80,12 @@ void write_tagged_integer(fx_int *data)
|
||||
}
|
||||
|
||||
fx_stream_write_cstr(fx_stdout, "\" }", NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
void write_tagged_float(fx_double *data)
|
||||
{
|
||||
#if 0
|
||||
fx_stream_write_cstr(
|
||||
fx_stdout,
|
||||
"{ \"type\": \"float\", \"value\": \"",
|
||||
@@ -106,16 +110,19 @@ void write_tagged_float(fx_double *data)
|
||||
}
|
||||
|
||||
fx_stream_write_cstr(fx_stdout, "\" }", NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
void write_tagged_bool(fx_bool *data)
|
||||
{
|
||||
#if 0
|
||||
fx_stream_write_fmt(
|
||||
fx_stdout,
|
||||
NULL,
|
||||
"{ \"type\": \"bool\", \"value\": \"%s\" }",
|
||||
fx_bool_get_value(data) ? "true" : "false",
|
||||
NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
void write_tagged_datetime(fx_datetime *data)
|
||||
@@ -154,6 +161,7 @@ void write_tagged_datetime(fx_datetime *data)
|
||||
fx_string_unref(new_data);
|
||||
}
|
||||
|
||||
#if 0
|
||||
void write_tagged_dict(fx_dict *data)
|
||||
{
|
||||
fx_stream_write_cstr(fx_stdout, "{ ", NULL);
|
||||
@@ -175,6 +183,7 @@ void write_tagged_dict(fx_dict *data)
|
||||
|
||||
fx_stream_write_cstr(fx_stdout, " }", NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
void write_tagged_array(fx_array *data)
|
||||
{
|
||||
@@ -182,8 +191,10 @@ void write_tagged_array(fx_array *data)
|
||||
|
||||
int i = 0;
|
||||
fx_iterator *it = fx_iterator_begin(data);
|
||||
fx_foreach(fx_object *, obj, it)
|
||||
fx_foreach(val, it)
|
||||
{
|
||||
fx_object *obj;
|
||||
fx_value_get_object(&val, &obj);
|
||||
if (i++ > 0) {
|
||||
fx_stream_write_cstr(fx_stdout, ", ", NULL);
|
||||
}
|
||||
@@ -197,20 +208,19 @@ void write_tagged_array(fx_array *data)
|
||||
|
||||
void write_tagged_value(fx_object *data)
|
||||
{
|
||||
#if 0
|
||||
if (fx_object_is_type(data, FX_TYPE_DICT)) {
|
||||
write_tagged_dict(data);
|
||||
} else if (fx_object_is_type(data, FX_TYPE_ARRAY)) {
|
||||
} else
|
||||
#endif
|
||||
if (fx_object_is_type(data, FX_TYPE_ARRAY)) {
|
||||
write_tagged_array(data);
|
||||
} else if (fx_object_is_type(data, FX_TYPE_STRING)) {
|
||||
write_tagged_string(data);
|
||||
} else if (fx_object_is_type(data, FX_TYPE_DATETIME)) {
|
||||
write_tagged_datetime(data);
|
||||
} else if (fx_object_is_type(data, FX_TYPE_INT)) {
|
||||
write_tagged_integer(data);
|
||||
} else if (fx_object_is_type(data, FX_TYPE_BOOL)) {
|
||||
write_tagged_bool(data);
|
||||
} else if (fx_object_is_type(data, FX_TYPE_DOUBLE)) {
|
||||
write_tagged_float(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+137
-71
@@ -1,17 +1,16 @@
|
||||
#include <fx/bool.h>
|
||||
#include <fx/collections/array.h>
|
||||
#include <fx/collections/datetime.h>
|
||||
#include <fx/collections/dict.h>
|
||||
#include <fx/collections/hashmap.h>
|
||||
#include <fx/double.h>
|
||||
#include <fx/collections/hashtable.h>
|
||||
#include <fx/error.h>
|
||||
#include <fx/float.h>
|
||||
#include <fx/int.h>
|
||||
#include <fx/serial/ctx.h>
|
||||
#include <fx/serial/toml.h>
|
||||
#include <fx/status.h>
|
||||
#include <fx/string.h>
|
||||
#include <fx/stringstream.h>
|
||||
#include <fx/uint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -139,8 +138,9 @@ static void ctx_set_object_flags(
|
||||
.key_flags = FX_HASHMAP_KEY_F_INTVALUE,
|
||||
};
|
||||
|
||||
const fx_hashmap_value *old_value
|
||||
= fx_hashmap_get(ctx->ctx_objects_flags, &key);
|
||||
const fx_hashmap_value *old_value = fx_hashmap_get(
|
||||
ctx->ctx_objects_flags,
|
||||
&key);
|
||||
|
||||
enum object_flags new_flags = 0;
|
||||
if (old_value) {
|
||||
@@ -172,8 +172,9 @@ static void ctx_clear_object_flags(
|
||||
.key_flags = FX_HASHMAP_KEY_F_INTVALUE,
|
||||
};
|
||||
|
||||
const fx_hashmap_value *old_value
|
||||
= fx_hashmap_get(ctx->ctx_objects_flags, &key);
|
||||
const fx_hashmap_value *old_value = fx_hashmap_get(
|
||||
ctx->ctx_objects_flags,
|
||||
&key);
|
||||
|
||||
enum object_flags new_flags = 0;
|
||||
if (old_value) {
|
||||
@@ -202,8 +203,9 @@ static enum object_flags ctx_get_object_flags(struct ctx *ctx, fx_object *obj)
|
||||
.key_flags = FX_HASHMAP_KEY_F_INTVALUE,
|
||||
};
|
||||
|
||||
const fx_hashmap_value *value
|
||||
= fx_hashmap_get(ctx->ctx_objects_flags, &key);
|
||||
const fx_hashmap_value *value = fx_hashmap_get(
|
||||
ctx->ctx_objects_flags,
|
||||
&key);
|
||||
if (value) {
|
||||
return (enum object_flags)(uintptr_t)value->value_data;
|
||||
}
|
||||
@@ -924,8 +926,11 @@ static void split_word(struct ctx *ctx, fx_string *wordbuf)
|
||||
FX_STRING_TOK_F_INCLUDE_EMPTY_TOKENS);
|
||||
|
||||
size_t i = 0;
|
||||
fx_foreach_c(const char *, tok, it)
|
||||
fx_foreach(tokv, it)
|
||||
{
|
||||
const char *tok = NULL;
|
||||
fx_value_get_cstr(&tokv, &tok);
|
||||
|
||||
if (i > 0) {
|
||||
enqueue_token(ctx, TOK_DOT);
|
||||
}
|
||||
@@ -1028,8 +1033,10 @@ static void read_word(struct ctx *ctx)
|
||||
}
|
||||
|
||||
fx_iterator *it = fx_iterator_begin(wordbuf);
|
||||
fx_foreach(fx_wchar, c, it)
|
||||
fx_foreach(cv, it)
|
||||
{
|
||||
fx_wchar c = FX_WCHAR_INVALID;
|
||||
fx_value_get_wchar(&cv, &c);
|
||||
/* only allow ASCII numbers/letters here */
|
||||
bool ok = isalnum(c) || c == '_' || c == '-' || c == '.';
|
||||
if (!ok) {
|
||||
@@ -1177,8 +1184,8 @@ static void read_string(struct ctx *ctx, bool squote)
|
||||
}
|
||||
|
||||
if (c != '\n') {
|
||||
ctx->ctx_result
|
||||
= FX_RESULT_ERR(BAD_FORMAT);
|
||||
ctx->ctx_result = FX_RESULT_ERR(
|
||||
BAD_FORMAT);
|
||||
fail = true;
|
||||
break;
|
||||
}
|
||||
@@ -1223,16 +1230,18 @@ static void read_string(struct ctx *ctx, bool squote)
|
||||
case 'U':
|
||||
c = read_unicode_sequence(ctx);
|
||||
if (c == FX_WCHAR_INVALID) {
|
||||
ctx->ctx_result
|
||||
= FX_RESULT_ERR(BAD_FORMAT);
|
||||
ctx->ctx_result = FX_RESULT_ERR(
|
||||
BAD_FORMAT);
|
||||
fail = true;
|
||||
break;
|
||||
}
|
||||
|
||||
ctx->ctx_result
|
||||
= FX_OK(fx_string_append_wc(str, c))
|
||||
? FX_SUCCESS
|
||||
: FX_RESULT_ERR(BAD_FORMAT);
|
||||
ctx->ctx_result = FX_OK(fx_string_append_wc(
|
||||
str,
|
||||
c))
|
||||
? FX_SUCCESS
|
||||
: FX_RESULT_ERR(
|
||||
BAD_FORMAT);
|
||||
fail = !FX_OK(ctx->ctx_result);
|
||||
break;
|
||||
default:
|
||||
@@ -1664,7 +1673,7 @@ static void print_token(struct token *tok)
|
||||
}
|
||||
|
||||
static fx_result parse_value(struct ctx *ctx, fx_object **result);
|
||||
static fx_result parse_key_value_pair(struct ctx *ctx, fx_dict *container);
|
||||
static fx_result parse_key_value_pair(struct ctx *ctx, fx_hashtable *container);
|
||||
|
||||
static fx_result parse_timestamp(struct ctx *ctx, fx_object **result)
|
||||
{
|
||||
@@ -1690,6 +1699,7 @@ static fx_result parse_string(struct ctx *ctx, fx_object **result)
|
||||
|
||||
static fx_result parse_int(struct ctx *ctx, fx_object **result)
|
||||
{
|
||||
#if 0
|
||||
struct token *tok = peek_token(ctx);
|
||||
fx_int *val = fx_int_create(tok->tok_value.i.v);
|
||||
if (!val) {
|
||||
@@ -1711,11 +1721,13 @@ static fx_result parse_int(struct ctx *ctx, fx_object **result)
|
||||
}
|
||||
|
||||
*result = (val);
|
||||
#endif
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_result parse_float(struct ctx *ctx, fx_object **result)
|
||||
{
|
||||
#if 0
|
||||
struct token *tok = peek_token(ctx);
|
||||
fx_double *val = fx_double_create(tok->tok_value.f.v);
|
||||
if (!val) {
|
||||
@@ -1737,11 +1749,13 @@ static fx_result parse_float(struct ctx *ctx, fx_object **result)
|
||||
}
|
||||
|
||||
*result = (val);
|
||||
#endif
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_result parse_bool(struct ctx *ctx, fx_object **result)
|
||||
{
|
||||
#if 0
|
||||
struct token *tok = peek_token(ctx);
|
||||
fx_bool *val = fx_bool_create(tok->tok_value.b);
|
||||
if (!val) {
|
||||
@@ -1749,6 +1763,7 @@ static fx_result parse_bool(struct ctx *ctx, fx_object **result)
|
||||
}
|
||||
|
||||
*result = (val);
|
||||
#endif
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1758,7 +1773,7 @@ static fx_result parse_table_inline(struct ctx *ctx, fx_object **result)
|
||||
|
||||
advance_token(ctx);
|
||||
|
||||
fx_dict *table = fx_dict_create();
|
||||
fx_hashtable *table = fx_hashtable_create();
|
||||
if (!table) {
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
@@ -1775,14 +1790,14 @@ static fx_result parse_table_inline(struct ctx *ctx, fx_object **result)
|
||||
fx_object *value;
|
||||
fx_result status = parse_key_value_pair(ctx, table);
|
||||
if (!FX_OK(status)) {
|
||||
fx_dict_unref(table);
|
||||
fx_hashtable_unref(table);
|
||||
return status;
|
||||
}
|
||||
|
||||
tok = peek_token(ctx);
|
||||
|
||||
if (!tok) {
|
||||
fx_dict_unref(table);
|
||||
fx_hashtable_unref(table);
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -1794,7 +1809,7 @@ static fx_result parse_table_inline(struct ctx *ctx, fx_object **result)
|
||||
advance_token(ctx);
|
||||
break;
|
||||
default:
|
||||
fx_dict_unref(table);
|
||||
fx_hashtable_unref(table);
|
||||
return FX_RESULT_ERR(BAD_FORMAT);
|
||||
}
|
||||
}
|
||||
@@ -1857,7 +1872,9 @@ static fx_result parse_array_inline(struct ctx *ctx, fx_object **result)
|
||||
return status;
|
||||
}
|
||||
|
||||
#if 0
|
||||
fx_array_append(array, FX_RV(value));
|
||||
#endif
|
||||
ENABLE_EXTENDED_LEXING(ctx);
|
||||
|
||||
advance_token(ctx);
|
||||
@@ -1912,7 +1929,7 @@ static fx_result parse_value(struct ctx *ctx, fx_object **result)
|
||||
}
|
||||
}
|
||||
|
||||
static fx_result parse_key_value_pair(struct ctx *ctx, fx_dict *container)
|
||||
static fx_result parse_key_value_pair(struct ctx *ctx, fx_hashtable *container)
|
||||
{
|
||||
struct token *tok = peek_token(ctx);
|
||||
if (!IS_VALID_KEY_COMPONENT(tok)) {
|
||||
@@ -1931,19 +1948,26 @@ static fx_result parse_key_value_pair(struct ctx *ctx, fx_dict *container)
|
||||
}
|
||||
|
||||
while (tok && tok->tok_type == TOK_DOT) {
|
||||
fx_object *sub_dict = fx_dict_at_sk(container, key);
|
||||
if (!sub_dict) {
|
||||
sub_dict = (fx_dict_create());
|
||||
fx_dict_put_sk(container, key, FX_RV(sub_dict));
|
||||
const fx_value *child = fx_hashtable_get(
|
||||
container,
|
||||
&FX_VALUE_OBJECT(key));
|
||||
fx_hashmap *subtable = NULL;
|
||||
fx_value_get_object(child, &subtable);
|
||||
if (!subtable) {
|
||||
subtable = (fx_hashtable_create());
|
||||
fx_hashtable_put(
|
||||
container,
|
||||
&FX_VALUE_OBJECT(key),
|
||||
&FX_VALUE_OBJECT(subtable));
|
||||
} else if (
|
||||
sub_dict
|
||||
&& !fx_object_is_type(sub_dict, FX_TYPE_DICT)) {
|
||||
subtable
|
||||
&& !fx_object_is_type(subtable, FX_TYPE_HASHTABLE)) {
|
||||
free(key);
|
||||
return FX_RESULT_ERR(BAD_FORMAT);
|
||||
}
|
||||
|
||||
#if 1
|
||||
enum object_flags flags = ctx_get_object_flags(ctx, sub_dict);
|
||||
enum object_flags flags = ctx_get_object_flags(ctx, subtable);
|
||||
if (flags
|
||||
& (OBJECT_KV_END_DEFINED | OBJECT_HEADER_END_DEFINED)) {
|
||||
free(key);
|
||||
@@ -1951,7 +1975,7 @@ static fx_result parse_key_value_pair(struct ctx *ctx, fx_dict *container)
|
||||
}
|
||||
#endif
|
||||
|
||||
ctx_set_object_flags(ctx, sub_dict, OBJECT_KV_MID_DEFINED);
|
||||
ctx_set_object_flags(ctx, subtable, OBJECT_KV_MID_DEFINED);
|
||||
|
||||
advance_token(ctx);
|
||||
tok = peek_token(ctx);
|
||||
@@ -1960,7 +1984,7 @@ static fx_result parse_key_value_pair(struct ctx *ctx, fx_dict *container)
|
||||
return FX_RESULT_ERR(BAD_FORMAT);
|
||||
}
|
||||
|
||||
container = sub_dict;
|
||||
container = subtable;
|
||||
fx_string_unref(key);
|
||||
key = fx_string_duplicate(tok->tok_str);
|
||||
if (!key) {
|
||||
@@ -1971,7 +1995,7 @@ static fx_result parse_key_value_pair(struct ctx *ctx, fx_dict *container)
|
||||
tok = peek_token(ctx);
|
||||
}
|
||||
|
||||
if (fx_dict_has_skey(container, key)) {
|
||||
if (fx_hashtable_get(container, &FX_VALUE_OBJECT(key))) {
|
||||
return FX_RESULT_ERR(BAD_FORMAT);
|
||||
}
|
||||
|
||||
@@ -2001,9 +2025,13 @@ static fx_result parse_key_value_pair(struct ctx *ctx, fx_dict *container)
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
fx_dict_put_sk(container, key, FX_RV(value));
|
||||
fx_hashtable_put(
|
||||
container,
|
||||
&FX_VALUE_OBJECT(key),
|
||||
&FX_VALUE_OBJECT(value));
|
||||
fx_object_unref(value);
|
||||
|
||||
if (fx_object_is_type(value, FX_TYPE_DICT)
|
||||
if (fx_object_is_type(value, FX_TYPE_HASHTABLE)
|
||||
|| fx_object_is_type(value, FX_TYPE_ARRAY)) {
|
||||
ctx_set_object_flags(ctx, value, OBJECT_KV_END_DEFINED);
|
||||
}
|
||||
@@ -2013,8 +2041,8 @@ static fx_result parse_key_value_pair(struct ctx *ctx, fx_dict *container)
|
||||
|
||||
static fx_result parse_table_header(
|
||||
struct ctx *ctx,
|
||||
fx_dict *container,
|
||||
fx_dict **new_container)
|
||||
fx_hashtable *container,
|
||||
fx_hashtable **new_container)
|
||||
{
|
||||
advance_token(ctx);
|
||||
struct token *tok = peek_token(ctx);
|
||||
@@ -2034,17 +2062,26 @@ static fx_result parse_table_header(
|
||||
}
|
||||
|
||||
while (tok && tok->tok_type == TOK_DOT) {
|
||||
fx_object *sub_dict = fx_dict_at_sk(container, key);
|
||||
enum object_flags flags = ctx_get_object_flags(ctx, sub_dict);
|
||||
if (!sub_dict) {
|
||||
sub_dict = (fx_dict_create());
|
||||
fx_dict_put_sk(container, key, FX_RV(sub_dict));
|
||||
} else if (fx_object_is_type(sub_dict, FX_TYPE_ARRAY)) {
|
||||
|
||||
sub_dict = fx_array_at(
|
||||
sub_dict,
|
||||
fx_array_size(sub_dict) - 1);
|
||||
} else if (!fx_object_is_type(sub_dict, FX_TYPE_DICT)) {
|
||||
const fx_value *value = fx_hashtable_get(
|
||||
container,
|
||||
&FX_VALUE_OBJECT(key));
|
||||
fx_object *subtable = NULL;
|
||||
fx_value_get_object(value, &subtable);
|
||||
enum object_flags flags = ctx_get_object_flags(ctx, subtable);
|
||||
if (!subtable) {
|
||||
subtable = (fx_hashtable_create());
|
||||
fx_hashtable_put(
|
||||
container,
|
||||
&FX_VALUE_OBJECT(key),
|
||||
&FX_VALUE_OBJECT(subtable));
|
||||
fx_object_unref(subtable);
|
||||
} else if (fx_object_is_type(subtable, FX_TYPE_ARRAY)) {
|
||||
#if 0
|
||||
subtable = fx_array_at(
|
||||
subtable,
|
||||
fx_array_size(subtable) - 1);
|
||||
#endif
|
||||
} else if (!fx_object_is_type(subtable, FX_TYPE_HASHTABLE)) {
|
||||
return FX_RESULT_ERR(BAD_FORMAT);
|
||||
}
|
||||
|
||||
@@ -2058,9 +2095,9 @@ static fx_result parse_table_header(
|
||||
return FX_RESULT_ERR(BAD_FORMAT);
|
||||
}
|
||||
|
||||
ctx_set_object_flags(ctx, sub_dict, OBJECT_HEADER_MID_DEFINED);
|
||||
ctx_set_object_flags(ctx, subtable, OBJECT_HEADER_MID_DEFINED);
|
||||
|
||||
container = sub_dict;
|
||||
container = subtable;
|
||||
fx_string_unref(key);
|
||||
key = fx_string_duplicate(tok->tok_str);
|
||||
if (!key) {
|
||||
@@ -2075,20 +2112,28 @@ static fx_result parse_table_header(
|
||||
return FX_RESULT_ERR(BAD_FORMAT);
|
||||
}
|
||||
|
||||
fx_dict *new_table = fx_dict_at_sk(container, key);
|
||||
const fx_value *child = fx_hashtable_get(
|
||||
container,
|
||||
&FX_VALUE_OBJECT(key));
|
||||
fx_hashtable *new_table = NULL;
|
||||
fx_value_get_object(child, &new_table);
|
||||
|
||||
if (!new_table) {
|
||||
new_table = fx_dict_create();
|
||||
new_table = fx_hashtable_create();
|
||||
|
||||
if (!new_table) {
|
||||
free(key);
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
fx_dict_put_sk(container, key, FX_RV(new_table));
|
||||
fx_hashtable_put(
|
||||
container,
|
||||
&FX_VALUE_OBJECT(key),
|
||||
&FX_VALUE_OBJECT(new_table));
|
||||
fx_hashtable_unref(new_table);
|
||||
}
|
||||
|
||||
if (!fx_object_is_type((new_table), FX_TYPE_DICT)) {
|
||||
if (!fx_object_is_type((new_table), FX_TYPE_HASHTABLE)) {
|
||||
return FX_RESULT_ERR(BAD_FORMAT);
|
||||
}
|
||||
|
||||
@@ -2109,8 +2154,8 @@ static fx_result parse_table_header(
|
||||
|
||||
static fx_result parse_array_header(
|
||||
struct ctx *ctx,
|
||||
fx_dict *container,
|
||||
fx_dict **new_container)
|
||||
fx_hashtable *container,
|
||||
fx_hashtable **new_container)
|
||||
{
|
||||
advance_token(ctx);
|
||||
struct token *tok = peek_token(ctx);
|
||||
@@ -2130,15 +2175,26 @@ static fx_result parse_array_header(
|
||||
}
|
||||
|
||||
while (tok && tok->tok_type == TOK_DOT) {
|
||||
fx_object *sub_dict = fx_dict_at_sk(container, key);
|
||||
const fx_value *child = fx_hashtable_get(
|
||||
container,
|
||||
&FX_VALUE_OBJECT(key));
|
||||
fx_object *sub_dict = NULL;
|
||||
fx_value_get_object(child, &sub_dict);
|
||||
|
||||
if (!sub_dict) {
|
||||
sub_dict = (fx_dict_create());
|
||||
fx_dict_put_sk(container, key, FX_RV(sub_dict));
|
||||
sub_dict = (fx_hashtable_create());
|
||||
fx_hashtable_put(
|
||||
container,
|
||||
&FX_VALUE_OBJECT(key),
|
||||
&FX_VALUE_OBJECT(sub_dict));
|
||||
fx_hashtable_unref(sub_dict);
|
||||
} else if (fx_object_is_type(sub_dict, FX_TYPE_ARRAY)) {
|
||||
#if 0
|
||||
sub_dict = fx_array_at(
|
||||
sub_dict,
|
||||
fx_array_size(sub_dict) - 1);
|
||||
} else if (!fx_object_is_type(sub_dict, FX_TYPE_DICT)) {
|
||||
#endif
|
||||
} else if (!fx_object_is_type(sub_dict, FX_TYPE_HASHTABLE)) {
|
||||
return FX_RESULT_ERR(BAD_FORMAT);
|
||||
}
|
||||
|
||||
@@ -2163,10 +2219,18 @@ static fx_result parse_array_header(
|
||||
return FX_RESULT_ERR(BAD_FORMAT);
|
||||
}
|
||||
|
||||
fx_array *array = fx_dict_get_sk(container, key);
|
||||
const fx_value *child = fx_hashtable_get(
|
||||
container,
|
||||
&FX_VALUE_OBJECT(key));
|
||||
fx_array *array = NULL;
|
||||
fx_value_get_object(child, &array);
|
||||
|
||||
if (!array) {
|
||||
array = fx_array_create();
|
||||
fx_dict_put_sk(container, key, FX_RV(array));
|
||||
fx_hashtable_put(
|
||||
container,
|
||||
&FX_VALUE_OBJECT(key),
|
||||
&FX_VALUE_OBJECT(array));
|
||||
} else if (!fx_object_is_type(array, FX_TYPE_ARRAY)) {
|
||||
return FX_RESULT_ERR(BAD_FORMAT);
|
||||
}
|
||||
@@ -2177,23 +2241,25 @@ static fx_result parse_array_header(
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
fx_dict *new_table = fx_dict_create();
|
||||
fx_hashtable *new_table = fx_hashtable_create();
|
||||
if (!new_table) {
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
#if 0
|
||||
fx_array_append(array, FX_RV(new_table));
|
||||
#endif
|
||||
|
||||
advance_token(ctx);
|
||||
*new_container = new_table;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_result parse_root(struct ctx *ctx, fx_dict **out)
|
||||
static fx_result parse_root(struct ctx *ctx, fx_hashtable **out)
|
||||
{
|
||||
fx_result result = FX_RESULT_SUCCESS;
|
||||
fx_dict *root = fx_dict_create();
|
||||
fx_dict *current = root;
|
||||
fx_hashtable *root = fx_hashtable_create();
|
||||
fx_hashtable *current = root;
|
||||
|
||||
while (!(ctx->ctx_flags & CTX_EOF) && fx_result_is_success(result)) {
|
||||
struct token *tok = peek_token(ctx);
|
||||
@@ -2253,7 +2319,7 @@ static fx_result parse_root(struct ctx *ctx, fx_dict **out)
|
||||
}
|
||||
|
||||
if (fx_result_is_error(result)) {
|
||||
fx_dict_unref(root);
|
||||
fx_hashtable_unref(root);
|
||||
root = NULL;
|
||||
}
|
||||
|
||||
@@ -2285,11 +2351,11 @@ static fx_result toml_deserialise(
|
||||
}
|
||||
|
||||
if (ctx.ctx_flags & CTX_EOF) {
|
||||
*dest = (fx_dict_create());
|
||||
*dest = (fx_hashtable_create());
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
fx_dict *data = NULL;
|
||||
fx_hashtable *data = NULL;
|
||||
ctx.ctx_result = parse_root(&ctx, &data);
|
||||
if (fx_result_is_error(ctx.ctx_result)) {
|
||||
return fx_result_propagate(ctx.ctx_result);
|
||||
|
||||
Reference in New Issue
Block a user