added qse_xli_vtext_t to store the outermost braces and brackets in the json format
changed the json format reader to recognize the outermost braces and brackets
This commit is contained in:
parent
4636a46acb
commit
12212d55cc
@ -69,6 +69,7 @@ enum qse_xli_errnum_t
|
||||
QSE_XLI_ESCOLON, /**< semicolon expected in place of '${0}' */
|
||||
QSE_XLI_EEQ, /**< = expected in place of '${0}' */
|
||||
QSE_XLI_ELBREQ, /**< { or = expected in place of '${0}' */
|
||||
QSE_XLI_ELBRAC, /** { or [ expected in place of '${0}' */
|
||||
QSE_XLI_ERBRACE, /**< } expected in place of '${0}' */
|
||||
QSE_XLI_ERBRACK, /**< ] expected in place of '${0}' */
|
||||
QSE_XLI_ECOMMA, /**< , expected in place of '${0}' */
|
||||
@ -168,6 +169,7 @@ typedef struct qse_xli_list_t qse_xli_list_t;
|
||||
typedef struct qse_xli_atom_t qse_xli_atom_t;
|
||||
typedef struct qse_xli_pair_t qse_xli_pair_t;
|
||||
typedef struct qse_xli_text_t qse_xli_text_t;
|
||||
typedef struct qse_xli_vtext_t qse_xli_vtext_t;
|
||||
typedef struct qse_xli_file_t qse_xli_file_t;
|
||||
typedef struct qse_xli_eof_t qse_xli_eof_t;
|
||||
|
||||
@ -187,13 +189,21 @@ enum qse_xli_str_flag_t
|
||||
QSE_XLI_STR_RADIX = (1 << 1),
|
||||
QSE_XLI_STR_FLOAT = (1 << 2)
|
||||
};
|
||||
typedef enum qse_xli_str_flag_t qse_xli_str_flag_t;
|
||||
|
||||
enum qse_xli_list_flag_t
|
||||
{
|
||||
QSE_XLI_LIST_ARRAYED = (1 << 0)
|
||||
};
|
||||
typedef enum qse_xli_list_flag_t qse_xli_list_flag_t;
|
||||
|
||||
enum qse_xli_atom_type_t
|
||||
{
|
||||
QSE_XLI_PAIR,
|
||||
QSE_XLI_TEXT,
|
||||
QSE_XLI_VTEXT, /* verbatim text */
|
||||
QSE_XLI_FILE,
|
||||
QSE_XLI_EOF
|
||||
QSE_XLI_EOF
|
||||
};
|
||||
typedef enum qse_xli_atom_type_t qse_xli_atom_type_t;
|
||||
|
||||
@ -223,6 +233,7 @@ struct qse_xli_false_t
|
||||
struct qse_xli_list_t
|
||||
{
|
||||
QSE_XLI_VAL_HDR;
|
||||
int flags;
|
||||
qse_xli_atom_t* head;
|
||||
qse_xli_atom_t* tail;
|
||||
};
|
||||
@ -264,6 +275,12 @@ struct qse_xli_text_t
|
||||
const qse_char_t* ptr;
|
||||
};
|
||||
|
||||
struct qse_xli_vtext_t
|
||||
{
|
||||
QSE_XLI_ATOM_HDR;
|
||||
const qse_char_t* ptr;
|
||||
};
|
||||
|
||||
struct qse_xli_file_t
|
||||
{
|
||||
QSE_XLI_ATOM_HDR;
|
||||
@ -671,6 +688,13 @@ QSE_EXPORT qse_xli_text_t* qse_xli_inserttext (
|
||||
const qse_char_t* str
|
||||
);
|
||||
|
||||
QSE_EXPORT qse_xli_vtext_t* qse_xli_insertvtext (
|
||||
qse_xli_t* xli,
|
||||
qse_xli_list_t* parent,
|
||||
qse_xli_atom_t* peer,
|
||||
const qse_char_t* str
|
||||
);
|
||||
|
||||
QSE_EXPORT qse_xli_file_t* qse_xli_insertfile (
|
||||
qse_xli_t* xli,
|
||||
qse_xli_list_t* parent,
|
||||
|
@ -49,6 +49,7 @@ const qse_char_t* qse_xli_dflerrstr (const qse_xli_t* xli, qse_xli_errnum_t errn
|
||||
QSE_T("semicolon expected in place of '${0}'"),
|
||||
QSE_T("equal-sign expected in place of '${0}'"),
|
||||
QSE_T("left-brace or equal-sign expected in place of '${0}'"),
|
||||
QSE_T("left-brace or left-bracket expected in place of '${0}'"),
|
||||
QSE_T("right-brace expected in place of '${0}'"),
|
||||
QSE_T("right-bracket expected in place of '${0}'"),
|
||||
QSE_T("comma expected in place of '${0}'"),
|
||||
|
@ -798,21 +798,101 @@ static int read_list (qse_xli_t* xli, qse_xli_list_t* lv)
|
||||
|
||||
static int read_root_list (qse_xli_t* xli)
|
||||
{
|
||||
qse_xli_list_link_t* link;
|
||||
qse_xli_list_link_t* link = QSE_NULL;
|
||||
|
||||
link = qse_xli_makelistlink (xli, &xli->root->list);
|
||||
if (!link) return -1;
|
||||
if (!link) goto oops;
|
||||
|
||||
if (qse_xli_getchar(xli) <= -1 || get_token(xli) <= -1 || __read_list(xli) <= -1)
|
||||
if (qse_xli_getchar(xli) <= -1 || get_token(xli) <= -1) goto oops;
|
||||
|
||||
while (1)
|
||||
{
|
||||
qse_xli_freelistlink (xli, link);
|
||||
return -1;
|
||||
if (MATCH(xli, QSE_XLI_TOK_XINCLUDE))
|
||||
{
|
||||
if (get_token(xli) <= -1) goto oops;
|
||||
|
||||
if (!MATCH(xli,QSE_XLI_TOK_SQSTR) && !MATCH(xli,QSE_XLI_TOK_DQSTR))
|
||||
{
|
||||
qse_xli_seterror (xli, QSE_XLI_EINCLSTR, QSE_NULL, &xli->tok.loc);
|
||||
goto oops;
|
||||
}
|
||||
|
||||
if (begin_include (xli) <= -1) goto oops;
|
||||
}
|
||||
else if (MATCH(xli, QSE_XLI_TOK_TEXT))
|
||||
{
|
||||
if (get_token(xli) <= -1) goto oops;
|
||||
}
|
||||
else if (MATCH(xli, QSE_XLI_TOK_LBRACK))
|
||||
{
|
||||
xli->root->list.flags |= QSE_XLI_LIST_ARRAYED;
|
||||
if (get_token(xli) <= -1) goto oops;
|
||||
break;
|
||||
}
|
||||
else if (MATCH(xli, QSE_XLI_TOK_LBRACE))
|
||||
{
|
||||
if (get_token(xli) <= -1) goto oops;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
qse_xli_seterror (xli, QSE_XLI_ELBRAC, QSE_STR_XSTR(xli->tok.name), &xli->tok.loc);
|
||||
goto oops;
|
||||
}
|
||||
}
|
||||
|
||||
if (__read_list(xli) <= -1) goto oops;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (MATCH(xli, QSE_XLI_TOK_XINCLUDE))
|
||||
{
|
||||
if (get_token(xli) <= -1) goto oops;
|
||||
|
||||
if (!MATCH(xli,QSE_XLI_TOK_SQSTR) && !MATCH(xli,QSE_XLI_TOK_DQSTR))
|
||||
{
|
||||
qse_xli_seterror (xli, QSE_XLI_EINCLSTR, QSE_NULL, &xli->tok.loc);
|
||||
goto oops;
|
||||
}
|
||||
|
||||
if (begin_include (xli) <= -1) goto oops;
|
||||
}
|
||||
else if (MATCH(xli, QSE_XLI_TOK_TEXT))
|
||||
{
|
||||
if (get_token(xli) <= -1) goto oops;
|
||||
}
|
||||
else if (MATCH(xli, QSE_XLI_TOK_RBRACK))
|
||||
{
|
||||
if (!(xli->root->list.flags & QSE_XLI_LIST_ARRAYED)) goto oops_rbrac;
|
||||
if (get_token(xli) <= -1) goto oops;
|
||||
break;
|
||||
}
|
||||
else if (MATCH(xli, QSE_XLI_TOK_RBRACE))
|
||||
{
|
||||
if (xli->root->list.flags & QSE_XLI_LIST_ARRAYED) goto oops_rbrac;
|
||||
if (get_token(xli) <= -1) goto oops;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
oops_rbrac:
|
||||
qse_xli_seterror (xli,
|
||||
((xli->root->list.flags & QSE_XLI_LIST_ARRAYED)? QSE_XLI_ERBRACK: QSE_XLI_ERBRACE),
|
||||
QSE_STR_XSTR(xli->tok.name), &xli->tok.loc
|
||||
);
|
||||
goto oops;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QSE_ASSERT (link == xli->parlink);
|
||||
qse_xli_freelistlink (xli, link);
|
||||
|
||||
return 0;
|
||||
|
||||
oops:
|
||||
if (link) qse_xli_freelistlink (xli, link);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int qse_xli_readjson (qse_xli_t* xli, qse_xli_io_impl_t io)
|
||||
|
@ -152,6 +152,13 @@ static int write_list (qse_xli_t* xli, qse_xli_list_t* list, int depth)
|
||||
break;
|
||||
}
|
||||
|
||||
case QSE_XLI_VTEXT:
|
||||
{
|
||||
/* no vtext element can be included in the ini format */
|
||||
/* do nothing */
|
||||
break;
|
||||
}
|
||||
|
||||
case QSE_XLI_FILE:
|
||||
/* no file inclusion is supported by the ini-format. ignore it */
|
||||
break;
|
||||
|
@ -360,6 +360,13 @@ static int write_list (qse_xli_t* xli, qse_xli_list_t* list, int depth)
|
||||
break;
|
||||
}
|
||||
|
||||
case QSE_XLI_VTEXT:
|
||||
{
|
||||
/* no vtext element can be included in the xli format */
|
||||
/* do nothing */
|
||||
break;
|
||||
}
|
||||
|
||||
case QSE_XLI_FILE:
|
||||
{
|
||||
int i;
|
||||
|
@ -542,6 +542,20 @@ qse_xli_text_t* qse_xli_inserttext (
|
||||
return text;
|
||||
}
|
||||
|
||||
qse_xli_vtext_t* qse_xli_insertvtext (
|
||||
qse_xli_t* xli, qse_xli_list_t* parent, qse_xli_atom_t* peer, const qse_char_t* str)
|
||||
{
|
||||
qse_xli_text_t* text;
|
||||
|
||||
QSE_ASSERT (QSE_SIZEOF(qse_xli_text_t) == QSE_SIZEOF(qse_xli_vtext_t));
|
||||
|
||||
text = qse_xli_inserttext (xli, parent, peer, str);
|
||||
if (!text) return QSE_NULL;
|
||||
|
||||
((qse_xli_vtext_t*)text)->type = QSE_XLI_VTEXT;
|
||||
return (qse_xli_vtext_t*)text;
|
||||
}
|
||||
|
||||
qse_xli_file_t* qse_xli_insertfile (
|
||||
qse_xli_t* xli, qse_xli_list_t* parent, qse_xli_atom_t* peer, const qse_char_t* path)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user