From 7cda6152f3bc3681499559a04fd6a02b5d100e4d Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 30 Aug 2015 13:22:17 +0000 Subject: [PATCH] added more ini-format reader code into xli --- qse/include/qse/xli/xli.h | 6 +++- qse/lib/xli/err.c | 6 +++- qse/lib/xli/read-ini.c | 59 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/qse/include/qse/xli/xli.h b/qse/include/qse/xli/xli.h index 9901364e..61440955 100644 --- a/qse/include/qse/xli/xli.h +++ b/qse/include/qse/xli/xli.h @@ -66,6 +66,7 @@ enum qse_xli_errnum_t QSE_XLI_ESYNTAX, /**< syntax error */ 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_ERBRCE, /**< } expected in place of '${0}' */ QSE_XLI_EPAVAL, /**< pair value expected in place of '${0}' */ @@ -77,12 +78,15 @@ enum qse_xli_errnum_t QSE_XLI_EXKWNR, /**< @word '${0}' not recognized */ QSE_XLI_EXKWEM, /**< @ not followed by a valid word */ QSE_XLI_EIDENT, /**< invalid identifier '${0}' */ + QSE_XLI_EKEY, /**< key expected in place of '${0}' */ QSE_XLI_ENOKEY, /**< missing key after key tag */ QSE_XLI_EUDKEY, /**< undefined key '${0}' */ QSE_XLI_ENOALI, /**< no alias for '${0}' */ + QSE_XLI_EVAL, /**< value expected in place of '${0}' */ QSE_XLI_EILVAL, /**< illegal value for '${0}' */ QSE_XLI_ENOVAL, /**< no value for '${0}' */ - QSE_XLI_ESTRSEG /**< too many string segments for '${0}' */ + QSE_XLI_ESTRSEG, /**< too many string segments for '${0}' */ + QSE_XLI_ESECTAG, /**< section tag expected in place of '${0}' */ }; typedef enum qse_xli_errnum_t qse_xli_errnum_t; diff --git a/qse/lib/xli/err.c b/qse/lib/xli/err.c index 7e2582da..a89e2ad5 100644 --- a/qse/lib/xli/err.c +++ b/qse/lib/xli/err.c @@ -47,6 +47,7 @@ const qse_char_t* qse_xli_dflerrstr ( QSE_T("syntax error"), 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("right-brace expected in place of '${0}'"), QSE_T("pair value expected in place of '${0}'"), @@ -58,12 +59,15 @@ const qse_char_t* qse_xli_dflerrstr ( QSE_T("'${0}' not recognized"), QSE_T("@ not followed by a valid word"), QSE_T("invalid identifier '${0}'"), + QSE_T("key expected in place of '${0}'"), QSE_T("missing key after key tag"), QSE_T("undefined key '${0}'"), QSE_T("no alias for '${0}'"), + QSE_T("value expected in place of '${0}'"), QSE_T("illegal value for '${0}'"), QSE_T("no value for '${0}'"), - QSE_T("uncomplying number of string segments for '${0}'") + QSE_T("uncomplying number of string segments for '${0}'"), + QSE_T("section tag expected in place of '${0}'"), }; return (errnum >= 0 && errnum < QSE_COUNTOF(errstr))? diff --git a/qse/lib/xli/read-ini.c b/qse/lib/xli/read-ini.c index 3941141b..aa02078d 100644 --- a/qse/lib/xli/read-ini.c +++ b/qse/lib/xli/read-ini.c @@ -46,7 +46,8 @@ enum { - TOK_STATUS_UPTO_EOL = (1 << 0) + TOK_STATUS_SAME_LINE = (1 << 0), + TOK_STATUS_UPTO_EOL = (1 << 1) }; #define GET_CHAR(xli) \ @@ -267,8 +268,60 @@ static int get_token (qse_xli_t* xli) return get_token_into (xli, &xli->tok); } -static int __read_list (qse_xli_t* xli, const qse_xli_scm_t* override) +static int read_list (qse_xli_t* xli) { + + while (1) + { + if (MATCH(xli, QSE_XLI_TOK_EOF)) break; + + if (MATCH(xli, QSE_XLI_TOK_TAG)) + { + if (get_token(xli) <= -1) return -1; + + if (MATCH(xli, QSE_XLI_TOK_EOF)) break; + if (MATCH(xli, QSE_XLI_TOK_TAG)) continue; + + if (!MATCH(xli, QSE_XLI_TOK_IDENT)) + { + qse_xli_seterror (xli, QSE_XLI_EKEY, QSE_STR_XSTR(xli->tok.name), &xli->tok.loc); + return -1; + } + +/* key is the token... */ + xli->tok_status |= TOK_STATUS_SAME_LINE; + if (get_token (xli) <= -1) return -1; + + if (!MATCH(xli, QSE_XLI_TOK_EQ)) + { + qse_xli_seterror (xli, QSE_XLI_EEQ, QSE_STR_XSTR(xli->tok.name), &xli->tok.loc); + return -1; + } + + xli->tok_status |= TOK_STATUS_UPTO_EOL; + if (get_token (xli) <= -1) return -1; + + xli->tok_status &= ~(TOK_STATUS_SAME_LINE | TOK_STATUS_UPTO_EOL); + + if (MATCH(xli, QSE_XLI_TOK_EOF)) + { + /* empty value */ + break; + } + + if (!MATCH(xli, QSE_XLI_TOK_SQSTR)) + { + qse_xli_seterror (xli, QSE_XLI_EVAL, QSE_STR_XSTR(xli->tok.name), &xli->tok.loc); + return -1; + } + } + else + { + qse_xli_seterror (xli, QSE_XLI_ESECTAG, QSE_STR_XSTR(xli->tok.name), &xli->tok.loc); + return -1; + } + } + return 0; } @@ -279,7 +332,7 @@ static int read_root_list (qse_xli_t* xli) link = qse_xli_makelistlink (xli, &xli->root->list); if (!link) return -1; - if (qse_xli_getchar (xli) <= -1 || __read_list (xli, QSE_NULL) <= -1) + if (qse_xli_getchar (xli) <= -1 || get_token (xli) <= -1 || read_list (xli) <= -1) { qse_xli_freelistlink (xli, link); return -1;