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:
		| @ -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) | ||||
| { | ||||
|  | ||||
		Reference in New Issue
	
	Block a user