2013-02-05 15:04:15 +00:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
2019-06-06 05:28:23 +00:00
|
|
|
Copyright (c) 2006-2019 Chung, Hyung-Hwan. All rights reserved.
|
2013-02-05 15:04:15 +00:00
|
|
|
|
2014-11-19 14:42:24 +00:00
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
2013-02-05 15:04:15 +00:00
|
|
|
|
2014-11-19 14:42:24 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
|
|
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2013-02-05 15:04:15 +00:00
|
|
|
*/
|
|
|
|
|
2018-07-14 17:05:08 +00:00
|
|
|
#include "xli-prv.h"
|
2013-02-05 15:04:15 +00:00
|
|
|
#include <qse/cmn/chr.h>
|
|
|
|
|
2013-02-06 14:31:32 +00:00
|
|
|
static int get_token (qse_xli_t* xli);
|
2014-11-13 10:15:53 +00:00
|
|
|
static int read_list (qse_xli_t* xli, qse_xli_list_t* list, const qse_xli_scm_t* override);
|
2013-07-01 15:16:19 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
TOK_STATUS_ENABLE_NSTR = (1 << 0)
|
|
|
|
};
|
|
|
|
|
2014-11-13 10:15:53 +00:00
|
|
|
static qse_xli_scm_t scm_val_iffy = { QSE_XLI_SCM_VALSTR | QSE_XLI_SCM_KEYNODUP, 1, 1 };
|
|
|
|
|
2015-09-02 01:27:08 +00:00
|
|
|
int qse_xli_openrstream (qse_xli_t* xli, qse_xli_io_arg_t* arg)
|
2015-08-29 13:04:46 +00:00
|
|
|
{
|
|
|
|
qse_ssize_t n;
|
|
|
|
|
|
|
|
n = xli->rio.impl (xli, QSE_XLI_IO_OPEN, arg, QSE_NULL, 0);
|
|
|
|
if (n <= -1)
|
|
|
|
{
|
|
|
|
if (xli->errnum == QSE_XLI_ENOERR)
|
|
|
|
qse_xli_seterrnum (xli, QSE_XLI_EIOUSR, QSE_NULL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-09-02 01:27:08 +00:00
|
|
|
int qse_xli_closeactiverstream (qse_xli_t* xli)
|
2013-02-05 15:04:15 +00:00
|
|
|
{
|
|
|
|
qse_ssize_t n;
|
|
|
|
|
2013-06-29 17:01:32 +00:00
|
|
|
n = xli->rio.impl (xli, QSE_XLI_IO_CLOSE, xli->rio.inp, QSE_NULL, 0);
|
2013-02-05 15:04:15 +00:00
|
|
|
if (n <= -1)
|
|
|
|
{
|
2013-02-09 13:31:31 +00:00
|
|
|
if (xli->errnum == QSE_XLI_ENOERR)
|
|
|
|
qse_xli_seterrnum (xli, QSE_XLI_EIOUSR, QSE_NULL);
|
2013-02-05 15:04:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GET_CHAR(xli) \
|
2015-08-29 13:04:46 +00:00
|
|
|
do { if (qse_xli_getchar(xli) <= -1) return -1; } while(0)
|
2013-02-05 15:04:15 +00:00
|
|
|
|
|
|
|
#define GET_CHAR_TO(xli,c) \
|
|
|
|
do { \
|
2015-08-29 13:04:46 +00:00
|
|
|
if (qse_xli_getchar(xli) <= -1) return -1; \
|
2013-06-29 17:01:32 +00:00
|
|
|
c = (xli)->rio.last.c; \
|
2013-02-05 15:04:15 +00:00
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define ADD_TOKEN_CHAR(xli,tok,c) \
|
|
|
|
do { \
|
|
|
|
if (qse_str_ccat((tok)->name,(c)) == (qse_size_t)-1) \
|
|
|
|
{ \
|
2013-02-09 13:31:31 +00:00
|
|
|
qse_xli_seterrnum (xli, QSE_XLI_ENOMEM, QSE_NULL); \
|
2013-02-05 15:04:15 +00:00
|
|
|
return -1; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define ADD_TOKEN_STR(xli,tok,s,l) \
|
|
|
|
do { \
|
|
|
|
if (qse_str_ncat((tok)->name,(s),(l)) == (qse_size_t)-1) \
|
|
|
|
{ \
|
2013-02-09 13:31:31 +00:00
|
|
|
qse_xli_seterrnum (xli, QSE_XLI_ENOMEM, QSE_NULL); \
|
2013-02-05 15:04:15 +00:00
|
|
|
return -1; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define SET_TOKEN_TYPE(xli,tok,code) \
|
|
|
|
do { (tok)->type = (code); } while (0)
|
|
|
|
|
|
|
|
#define MATCH(xli,tok_type) ((xli)->tok.type == (tok_type))
|
|
|
|
|
|
|
|
typedef struct kwent_t kwent_t;
|
|
|
|
|
|
|
|
struct kwent_t
|
|
|
|
{
|
2014-07-08 14:30:42 +00:00
|
|
|
qse_cstr_t name;
|
2018-01-10 10:01:41 +00:00
|
|
|
qse_xli_tok_type_t type;
|
2013-02-05 15:04:15 +00:00
|
|
|
};
|
|
|
|
|
2013-09-17 01:28:04 +00:00
|
|
|
/* note that the keyword must start with @. */
|
2013-02-05 15:04:15 +00:00
|
|
|
static kwent_t kwtab[] =
|
|
|
|
{
|
|
|
|
/* keep it sorted by the first field for binary search */
|
2015-08-30 03:11:54 +00:00
|
|
|
{ { QSE_T("@include"), 8 }, QSE_XLI_TOK_XINCLUDE }
|
2013-02-05 15:04:15 +00:00
|
|
|
};
|
|
|
|
|
2018-01-10 10:01:41 +00:00
|
|
|
static kwent_t boolkwtab[] =
|
|
|
|
{
|
|
|
|
/* keep it sorted by the first field for binary search */
|
|
|
|
{ { QSE_T("false"), 5 }, QSE_XLI_TOK_FALSE },
|
|
|
|
{ { QSE_T("true"), 4 }, QSE_XLI_TOK_TRUE }
|
|
|
|
};
|
|
|
|
|
2015-08-29 13:04:46 +00:00
|
|
|
int qse_xli_getchar (qse_xli_t* xli)
|
2013-02-05 15:04:15 +00:00
|
|
|
{
|
|
|
|
qse_ssize_t n;
|
2015-08-30 03:11:54 +00:00
|
|
|
qse_char_t lc, ec;
|
|
|
|
|
|
|
|
if (xli->rio.inp->b.state == -1)
|
|
|
|
{
|
|
|
|
xli->rio.inp->b.state = 0;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else if (xli->rio.inp->b.state == 1)
|
|
|
|
{
|
|
|
|
xli->rio.inp->b.state = 0;
|
|
|
|
goto return_eof;
|
|
|
|
}
|
2013-02-05 15:04:15 +00:00
|
|
|
|
2013-06-29 17:01:32 +00:00
|
|
|
if (xli->rio.inp->b.pos >= xli->rio.inp->b.len)
|
2013-02-05 15:04:15 +00:00
|
|
|
{
|
2013-06-29 17:01:32 +00:00
|
|
|
n = xli->rio.impl (
|
|
|
|
xli, QSE_XLI_IO_READ, xli->rio.inp,
|
|
|
|
xli->rio.inp->b.buf, QSE_COUNTOF(xli->rio.inp->b.buf)
|
2013-02-05 15:04:15 +00:00
|
|
|
);
|
|
|
|
if (n <= -1)
|
|
|
|
{
|
|
|
|
if (xli->errnum == QSE_XLI_ENOERR)
|
2013-02-09 13:31:31 +00:00
|
|
|
qse_xli_seterrnum (xli, QSE_XLI_EIOUSR, QSE_NULL);
|
2013-02-05 15:04:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n == 0)
|
|
|
|
{
|
2015-08-30 03:11:54 +00:00
|
|
|
return_eof:
|
2013-06-29 17:01:32 +00:00
|
|
|
xli->rio.inp->last.c = QSE_CHAR_EOF;
|
|
|
|
xli->rio.inp->last.line = xli->rio.inp->line;
|
|
|
|
xli->rio.inp->last.colm = xli->rio.inp->colm;
|
|
|
|
xli->rio.inp->last.file = xli->rio.inp->name;
|
|
|
|
xli->rio.last = xli->rio.inp->last;
|
2013-02-05 15:04:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-29 17:01:32 +00:00
|
|
|
xli->rio.inp->b.pos = 0;
|
2014-11-12 05:59:47 +00:00
|
|
|
xli->rio.inp->b.len = n;
|
2013-02-05 15:04:15 +00:00
|
|
|
}
|
|
|
|
|
2013-06-29 17:01:32 +00:00
|
|
|
if (xli->rio.inp->last.c == QSE_T('\n'))
|
2013-02-05 15:04:15 +00:00
|
|
|
{
|
|
|
|
/* if the previous charater was a newline,
|
|
|
|
* increment the line counter and reset column to 1.
|
|
|
|
* incrementing it line number here instead of
|
|
|
|
* updating inp->last causes the line number for
|
2015-08-30 03:11:54 +00:00
|
|
|
* QSE_XLI_TOK_EOF to be the same line as the last newline. */
|
2013-06-29 17:01:32 +00:00
|
|
|
xli->rio.inp->line++;
|
|
|
|
xli->rio.inp->colm = 1;
|
2013-02-05 15:04:15 +00:00
|
|
|
}
|
2015-08-30 03:11:54 +00:00
|
|
|
|
|
|
|
lc = xli->rio.inp->b.buf[xli->rio.inp->b.pos++];
|
|
|
|
if (lc == QSE_T('\n') || lc == QSE_T('\r'))
|
|
|
|
{
|
|
|
|
/* handle common newline conventions.
|
|
|
|
* LF+CR
|
|
|
|
* CR+LF
|
|
|
|
* LF
|
|
|
|
* CR
|
|
|
|
* convert all above to a single LF.
|
|
|
|
*/
|
|
|
|
if (xli->rio.inp->b.pos >= xli->rio.inp->b.len)
|
|
|
|
{
|
|
|
|
n = xli->rio.impl (
|
|
|
|
xli, QSE_XLI_IO_READ, xli->rio.inp,
|
|
|
|
xli->rio.inp->b.buf, QSE_COUNTOF(xli->rio.inp->b.buf)
|
|
|
|
);
|
|
|
|
if (n <= -1)
|
|
|
|
{
|
|
|
|
xli->rio.inp->b.state = -1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
else if (n == 0)
|
|
|
|
{
|
|
|
|
xli->rio.inp->b.state = 1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xli->rio.inp->b.pos = 0;
|
|
|
|
xli->rio.inp->b.len = n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ec = (lc == '\n')? '\r': '\n';
|
|
|
|
if (xli->rio.inp->b.buf[xli->rio.inp->b.pos] == ec) xli->rio.inp->b.pos++;
|
|
|
|
|
|
|
|
done:
|
|
|
|
lc = QSE_T('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
xli->rio.inp->last.c = lc;
|
2013-06-29 17:01:32 +00:00
|
|
|
xli->rio.inp->last.line = xli->rio.inp->line;
|
|
|
|
xli->rio.inp->last.colm = xli->rio.inp->colm++;
|
|
|
|
xli->rio.inp->last.file = xli->rio.inp->name;
|
|
|
|
xli->rio.last = xli->rio.inp->last;
|
2015-08-30 03:11:54 +00:00
|
|
|
|
2013-02-05 15:04:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int skip_spaces (qse_xli_t* xli)
|
|
|
|
{
|
2013-06-29 17:01:32 +00:00
|
|
|
qse_cint_t c = xli->rio.last.c;
|
2013-02-05 15:04:15 +00:00
|
|
|
while (QSE_ISSPACE(c)) GET_CHAR_TO (xli, c);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-01 13:34:57 +00:00
|
|
|
static int skip_comment (qse_xli_t* xli, qse_xli_tok_t* tok)
|
2013-02-05 15:04:15 +00:00
|
|
|
{
|
2013-06-29 17:01:32 +00:00
|
|
|
qse_cint_t c = xli->rio.last.c;
|
2013-02-05 15:04:15 +00:00
|
|
|
|
|
|
|
if (c == QSE_T('#'))
|
|
|
|
{
|
|
|
|
/* skip up to \n */
|
2015-08-31 13:31:30 +00:00
|
|
|
|
2013-06-01 13:34:57 +00:00
|
|
|
qse_str_clear (tok->name);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
GET_CHAR_TO (xli, c);
|
|
|
|
if (c == QSE_T('\n') || c == QSE_CHAR_EOF) break;
|
2013-06-23 14:44:29 +00:00
|
|
|
|
|
|
|
if (xli->opt.trait & QSE_XLI_KEEPTEXT) ADD_TOKEN_CHAR (xli, tok, c);
|
2013-06-01 13:34:57 +00:00
|
|
|
}
|
|
|
|
while (1);
|
|
|
|
|
2013-06-23 14:44:29 +00:00
|
|
|
if ((xli->opt.trait & QSE_XLI_KEEPTEXT) &&
|
|
|
|
qse_xli_inserttext (xli, xli->parlink->list, QSE_NULL, QSE_STR_PTR(tok->name)) == QSE_NULL) return -1;
|
2013-06-01 13:34:57 +00:00
|
|
|
|
2013-02-05 15:04:15 +00:00
|
|
|
GET_CHAR (xli); /* eat the new line letter */
|
|
|
|
return 1; /* comment by # */
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-10 10:01:41 +00:00
|
|
|
static qse_xli_tok_type_t classify_ident (qse_xli_t* xli, const qse_cstr_t* name)
|
2013-02-05 15:04:15 +00:00
|
|
|
{
|
|
|
|
/* perform binary search */
|
|
|
|
|
|
|
|
/* declaring left, right, mid to be the int type is ok
|
|
|
|
* because we know kwtab is small enough. */
|
2018-01-10 10:01:41 +00:00
|
|
|
int left, right, mid;
|
|
|
|
int bool_checked = 0;
|
|
|
|
kwent_t* kwtabp;
|
2013-02-05 15:04:15 +00:00
|
|
|
|
2018-01-10 10:01:41 +00:00
|
|
|
left = 0;
|
|
|
|
right = QSE_COUNTOF(kwtab) - 1;
|
|
|
|
kwtabp = kwtab;
|
|
|
|
|
|
|
|
retry:
|
2013-02-05 15:04:15 +00:00
|
|
|
while (left <= right)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
kwent_t* kwp;
|
|
|
|
|
2017-05-02 01:14:32 +00:00
|
|
|
/*mid = (left + right) / 2;*/
|
|
|
|
mid = left + (right - left) / 2;
|
2018-01-10 10:01:41 +00:00
|
|
|
kwp = &kwtabp[mid];
|
2013-02-05 15:04:15 +00:00
|
|
|
|
2018-01-19 03:53:43 +00:00
|
|
|
/* the identifier classification is not affected by case-insensivity */
|
|
|
|
n = qse_strxncmp(kwp->name.ptr, kwp->name.len, name->ptr, name->len);
|
2013-02-05 15:04:15 +00:00
|
|
|
if (n > 0)
|
|
|
|
{
|
|
|
|
/* if left, right, mid were of qse_size_t,
|
|
|
|
* you would need the following line.
|
|
|
|
if (mid == 0) break;
|
|
|
|
*/
|
|
|
|
right = mid - 1;
|
|
|
|
}
|
|
|
|
else if (n < 0) left = mid + 1;
|
2013-02-06 14:31:32 +00:00
|
|
|
else return kwp->type;
|
2013-02-05 15:04:15 +00:00
|
|
|
}
|
|
|
|
|
2018-01-10 10:01:41 +00:00
|
|
|
if (!bool_checked && (xli->opt.trait & QSE_XLI_BOOLEAN))
|
|
|
|
{
|
|
|
|
bool_checked = 1;
|
|
|
|
kwtabp = boolkwtab;
|
|
|
|
left = 0;
|
|
|
|
right = QSE_COUNTOF(boolkwtab) - 1;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
2015-08-30 03:11:54 +00:00
|
|
|
return QSE_XLI_TOK_IDENT;
|
2013-02-05 15:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int get_symbols (qse_xli_t* xli, qse_cint_t c, qse_xli_tok_t* tok)
|
|
|
|
{
|
|
|
|
struct ops_t
|
|
|
|
{
|
|
|
|
const qse_char_t* str;
|
|
|
|
qse_size_t len;
|
2018-01-09 10:45:43 +00:00
|
|
|
int tid;
|
2013-02-05 15:04:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct ops_t ops[] =
|
|
|
|
{
|
2018-01-09 10:45:43 +00:00
|
|
|
{ QSE_T("="), 1, QSE_XLI_TOK_EQ },
|
|
|
|
{ QSE_T(","), 1, QSE_XLI_TOK_COMMA },
|
|
|
|
{ QSE_T(";"), 1, QSE_XLI_TOK_SEMICOLON },
|
|
|
|
{ QSE_T("{"), 1, QSE_XLI_TOK_LBRACE },
|
|
|
|
{ QSE_T("}"), 1, QSE_XLI_TOK_RBRACE },
|
|
|
|
{ QSE_NULL, 0, 0, }
|
2013-02-05 15:04:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ops_t* p;
|
|
|
|
int idx = 0;
|
|
|
|
|
|
|
|
/* note that the loop below is not generaic enough.
|
|
|
|
* you must keep the operators strings in a particular order */
|
|
|
|
|
2018-01-09 10:45:43 +00:00
|
|
|
|
2013-02-05 15:04:15 +00:00
|
|
|
for (p = ops; p->str != QSE_NULL; )
|
|
|
|
{
|
|
|
|
if (p->str[idx] == QSE_T('\0'))
|
|
|
|
{
|
|
|
|
ADD_TOKEN_STR (xli, tok, p->str, p->len);
|
2018-01-09 10:45:43 +00:00
|
|
|
SET_TOKEN_TYPE (xli, tok, p->tid);
|
2013-02-05 15:04:15 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == p->str[idx])
|
|
|
|
{
|
|
|
|
idx++;
|
|
|
|
GET_CHAR_TO (xli, c);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-23 14:44:29 +00:00
|
|
|
static int end_include (qse_xli_t* xli, int noeof)
|
2013-02-06 14:31:32 +00:00
|
|
|
{
|
|
|
|
int x;
|
|
|
|
qse_xli_io_arg_t* cur;
|
|
|
|
|
2013-06-29 17:01:32 +00:00
|
|
|
if (xli->rio.inp == &xli->rio.top) return 0; /* no include */
|
2013-02-06 14:31:32 +00:00
|
|
|
|
2013-06-23 14:44:29 +00:00
|
|
|
|
2013-02-06 14:31:32 +00:00
|
|
|
/* if it is an included file, close it and
|
|
|
|
* retry to read a character from an outer file */
|
|
|
|
|
2013-06-29 17:01:32 +00:00
|
|
|
x = xli->rio.impl (
|
2013-02-06 14:31:32 +00:00
|
|
|
xli, QSE_XLI_IO_CLOSE,
|
2013-06-29 17:01:32 +00:00
|
|
|
xli->rio.inp, QSE_NULL, 0);
|
2013-02-06 14:31:32 +00:00
|
|
|
|
|
|
|
/* if closing has failed, still destroy the
|
|
|
|
* sio structure first as normal and return
|
|
|
|
* the failure below. this way, the caller
|
|
|
|
* does not call QSE_XLI_SIO_CLOSE on
|
2013-06-29 17:01:32 +00:00
|
|
|
* xli->rio.inp again. */
|
2013-02-06 14:31:32 +00:00
|
|
|
|
2013-06-29 17:01:32 +00:00
|
|
|
cur = xli->rio.inp;
|
|
|
|
xli->rio.inp = xli->rio.inp->prev;
|
2013-02-06 14:31:32 +00:00
|
|
|
|
|
|
|
QSE_ASSERT (cur->name != QSE_NULL);
|
2019-06-24 14:24:14 +00:00
|
|
|
qse_xli_freemem (xli, cur);
|
2013-02-06 14:31:32 +00:00
|
|
|
/* xli->parse.depth.incl--; */
|
|
|
|
|
2013-06-23 14:44:29 +00:00
|
|
|
if ((xli->opt.trait & QSE_XLI_KEEPFILE) && !noeof &&
|
|
|
|
qse_xli_inserteof (xli, xli->parlink->list, QSE_NULL) == QSE_NULL) return -1;
|
|
|
|
|
2013-02-06 14:31:32 +00:00
|
|
|
if (x != 0)
|
|
|
|
{
|
|
|
|
/* the failure mentioned above is returned here */
|
2013-02-09 13:31:31 +00:00
|
|
|
if (xli->errnum == QSE_XLI_ENOERR)
|
|
|
|
qse_xli_seterrnum (xli, QSE_XLI_EIOUSR, QSE_NULL);
|
2013-02-06 14:31:32 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-06-29 17:01:32 +00:00
|
|
|
xli->rio.last = xli->rio.inp->last;
|
2013-02-06 14:31:32 +00:00
|
|
|
return 1; /* ended the included file successfully */
|
|
|
|
}
|
|
|
|
|
|
|
|
static int begin_include (qse_xli_t* xli)
|
|
|
|
{
|
2013-05-15 12:05:24 +00:00
|
|
|
qse_link_t* link;
|
2013-02-06 14:31:32 +00:00
|
|
|
qse_xli_io_arg_t* arg = QSE_NULL;
|
|
|
|
|
2019-06-24 14:24:14 +00:00
|
|
|
link = (qse_link_t*)qse_xli_callocmem(xli,
|
2013-05-15 12:05:24 +00:00
|
|
|
QSE_SIZEOF(*link) + QSE_SIZEOF(qse_char_t) * (QSE_STR_LEN(xli->tok.name) + 1));
|
|
|
|
if (link == QSE_NULL) goto oops;
|
|
|
|
|
|
|
|
qse_strncpy ((qse_char_t*)(link + 1), QSE_STR_PTR(xli->tok.name), QSE_STR_LEN(xli->tok.name));
|
2013-06-29 17:01:32 +00:00
|
|
|
link->link = xli->rio_names;
|
|
|
|
xli->rio_names = link;
|
2013-02-06 14:31:32 +00:00
|
|
|
|
2019-06-24 14:24:14 +00:00
|
|
|
arg = (qse_xli_io_arg_t*)qse_xli_callocmem(xli, QSE_SIZEOF(*arg));
|
2013-02-18 13:45:50 +00:00
|
|
|
if (arg == QSE_NULL) goto oops;
|
2013-02-06 14:31:32 +00:00
|
|
|
|
2013-05-15 12:05:24 +00:00
|
|
|
arg->name = (const qse_char_t*)(link + 1);
|
2013-02-06 14:31:32 +00:00
|
|
|
arg->line = 1;
|
|
|
|
arg->colm = 1;
|
|
|
|
|
2013-05-15 12:05:24 +00:00
|
|
|
/* let the argument's prev point field to the current */
|
2013-06-29 17:01:32 +00:00
|
|
|
arg->prev = xli->rio.inp;
|
2013-05-15 12:05:24 +00:00
|
|
|
|
2015-09-02 01:27:08 +00:00
|
|
|
if (qse_xli_openrstream(xli, arg) <= -1) goto oops;
|
2013-02-06 14:31:32 +00:00
|
|
|
|
2013-05-15 12:05:24 +00:00
|
|
|
/* i update the current pointer after opening is successful */
|
2013-06-29 17:01:32 +00:00
|
|
|
xli->rio.inp = arg;
|
2013-02-06 14:31:32 +00:00
|
|
|
/* xli->parse.depth.incl++; */
|
|
|
|
|
|
|
|
/* read in the first character in the included file.
|
|
|
|
* so the next call to get_token() sees the character read
|
|
|
|
* from this file. */
|
2015-08-29 13:04:46 +00:00
|
|
|
if (qse_xli_getchar (xli) <= -1 || get_token (xli) <= -1)
|
2013-02-06 14:31:32 +00:00
|
|
|
{
|
2013-06-23 14:44:29 +00:00
|
|
|
end_include (xli, 1);
|
2013-02-06 14:31:32 +00:00
|
|
|
/* i don't jump to oops since i've called
|
2013-06-29 17:01:32 +00:00
|
|
|
* end_include() where xli->rio.inp/arg is freed. */
|
2013-02-06 14:31:32 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-06-23 14:44:29 +00:00
|
|
|
if ((xli->opt.trait & QSE_XLI_KEEPFILE) &&
|
|
|
|
qse_xli_insertfile (xli, xli->parlink->list, QSE_NULL, arg->name) == QSE_NULL)
|
|
|
|
{
|
|
|
|
end_include (xli, 1);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-02-06 14:31:32 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
oops:
|
2013-05-15 12:05:24 +00:00
|
|
|
/* i don't need to free 'link' since it's linked to
|
2013-06-29 17:01:32 +00:00
|
|
|
* xli->rio_names that's freed at the beginning of qse_xli_read()
|
2013-05-15 12:05:24 +00:00
|
|
|
* or by qse_xli_fini() */
|
2019-06-24 14:24:14 +00:00
|
|
|
if (arg) qse_xli_freemem (xli, arg);
|
2013-02-06 14:31:32 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-05 15:04:15 +00:00
|
|
|
static int get_token_into (qse_xli_t* xli, qse_xli_tok_t* tok)
|
|
|
|
{
|
|
|
|
qse_cint_t c;
|
2018-01-09 10:45:43 +00:00
|
|
|
int n;
|
2013-02-05 15:04:15 +00:00
|
|
|
int skip_semicolon_after_include = 0;
|
|
|
|
|
|
|
|
retry:
|
|
|
|
do
|
|
|
|
{
|
2013-06-01 13:34:57 +00:00
|
|
|
if (skip_spaces (xli) <= -1) return -1;
|
|
|
|
if ((n = skip_comment (xli, tok)) <= -1) return -1;
|
2013-02-05 15:04:15 +00:00
|
|
|
}
|
|
|
|
while (n >= 1);
|
|
|
|
|
|
|
|
qse_str_clear (tok->name);
|
2013-06-29 17:01:32 +00:00
|
|
|
tok->loc.file = xli->rio.last.file;
|
|
|
|
tok->loc.line = xli->rio.last.line;
|
|
|
|
tok->loc.colm = xli->rio.last.colm;
|
2013-02-05 15:04:15 +00:00
|
|
|
|
2013-06-29 17:01:32 +00:00
|
|
|
c = xli->rio.last.c;
|
2013-02-05 15:04:15 +00:00
|
|
|
|
|
|
|
if (c == QSE_CHAR_EOF)
|
|
|
|
{
|
2013-06-23 14:44:29 +00:00
|
|
|
n = end_include (xli, 0);
|
2013-02-05 15:04:15 +00:00
|
|
|
if (n <= -1) return -1;
|
|
|
|
if (n >= 1)
|
|
|
|
{
|
2013-06-29 17:01:32 +00:00
|
|
|
/*xli->rio.last = xli->rio.inp->last;*/
|
2013-02-05 15:04:15 +00:00
|
|
|
/* mark that i'm retrying after end of an included file */
|
|
|
|
skip_semicolon_after_include = 1;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
ADD_TOKEN_STR (xli, tok, QSE_T("<EOF>"), 5);
|
2015-08-30 03:11:54 +00:00
|
|
|
SET_TOKEN_TYPE (xli, tok, QSE_XLI_TOK_EOF);
|
2015-08-29 13:04:46 +00:00
|
|
|
}
|
2013-02-05 15:04:15 +00:00
|
|
|
else if (c == QSE_T('@'))
|
|
|
|
{
|
2013-09-17 01:28:04 +00:00
|
|
|
/* keyword/directive - start with @ */
|
|
|
|
|
2013-02-05 15:04:15 +00:00
|
|
|
int type;
|
|
|
|
|
|
|
|
ADD_TOKEN_CHAR (xli, tok, c);
|
|
|
|
GET_CHAR_TO (xli, c);
|
|
|
|
|
2019-04-15 04:30:49 +00:00
|
|
|
if (!QSE_ISALPHA(c))
|
2013-02-05 15:04:15 +00:00
|
|
|
{
|
2013-09-17 01:28:04 +00:00
|
|
|
/* this directive is empty, not followed by a valid word */
|
2013-09-24 14:02:06 +00:00
|
|
|
qse_xli_seterror (xli, QSE_XLI_EXKWEM, QSE_NULL, &tok->loc);
|
2013-02-05 15:04:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-09-17 01:28:04 +00:00
|
|
|
/* expect an identifier starting with an alphabet. the identifier
|
|
|
|
* forming a keyword/directory is composed of alphabets. */
|
2013-02-05 15:04:15 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
ADD_TOKEN_CHAR (xli, tok, c);
|
|
|
|
GET_CHAR_TO (xli, c);
|
|
|
|
}
|
2019-04-15 04:30:49 +00:00
|
|
|
while (QSE_ISALPHA(c));
|
2013-02-05 15:04:15 +00:00
|
|
|
|
2014-07-02 12:28:58 +00:00
|
|
|
type = classify_ident (xli, QSE_STR_XSTR(tok->name));
|
2015-08-30 03:11:54 +00:00
|
|
|
if (type == QSE_XLI_TOK_IDENT)
|
2013-02-05 15:04:15 +00:00
|
|
|
{
|
2013-09-17 01:28:04 +00:00
|
|
|
/* this keyword/directive is not recognized */
|
2014-07-02 12:28:58 +00:00
|
|
|
qse_xli_seterror (xli, QSE_XLI_EXKWNR, QSE_STR_XSTR(tok->name), &tok->loc);
|
2013-02-05 15:04:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
SET_TOKEN_TYPE (xli, tok, type);
|
|
|
|
}
|
2019-04-15 04:30:49 +00:00
|
|
|
else if (c == QSE_T('_') || QSE_ISALPHA(c) ||
|
2013-09-17 01:28:04 +00:00
|
|
|
(!(xli->tok_status & TOK_STATUS_ENABLE_NSTR) &&
|
|
|
|
(xli->opt.trait & QSE_XLI_LEADDIGIT) &&
|
|
|
|
QSE_ISDIGIT(c)))
|
2013-02-05 15:04:15 +00:00
|
|
|
{
|
2013-09-17 01:28:04 +00:00
|
|
|
int lead_digit = QSE_ISDIGIT(c);
|
|
|
|
int all_digits = 1;
|
2018-01-10 10:01:41 +00:00
|
|
|
qse_xli_tok_type_t type;
|
2013-02-05 15:04:15 +00:00
|
|
|
|
2013-11-14 14:07:16 +00:00
|
|
|
/* a normal identifier can be composed of wider varieties of
|
|
|
|
* characters than a keyword/directive */
|
2013-09-17 01:28:04 +00:00
|
|
|
while (1)
|
2013-02-05 15:04:15 +00:00
|
|
|
{
|
|
|
|
ADD_TOKEN_CHAR (xli, tok, c);
|
|
|
|
GET_CHAR_TO (xli, c);
|
2013-09-17 01:28:04 +00:00
|
|
|
|
|
|
|
if (c == QSE_T('_') || c == QSE_T('-') ||
|
2018-01-09 10:45:43 +00:00
|
|
|
c == QSE_T(':') || c == QSE_T('*') ||
|
2019-04-15 04:30:49 +00:00
|
|
|
c == QSE_T('/') || QSE_ISALPHA(c))
|
2013-09-17 01:28:04 +00:00
|
|
|
{
|
|
|
|
all_digits = 0;
|
|
|
|
}
|
2013-09-27 16:19:44 +00:00
|
|
|
else if (QSE_ISDIGIT(c))
|
2013-09-17 01:28:04 +00:00
|
|
|
{
|
|
|
|
/* nothing to do */
|
|
|
|
}
|
|
|
|
else break;
|
2013-02-05 15:04:15 +00:00
|
|
|
}
|
|
|
|
|
2013-09-17 01:28:04 +00:00
|
|
|
if (lead_digit && all_digits)
|
|
|
|
{
|
2018-01-09 10:45:43 +00:00
|
|
|
/* if an identifier begins with a digit, it must contain a non-digits character */
|
2014-07-02 12:28:58 +00:00
|
|
|
qse_xli_seterror (xli, QSE_XLI_EIDENT, QSE_STR_XSTR(tok->name), &tok->loc);
|
2013-09-17 01:28:04 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-01-10 10:01:41 +00:00
|
|
|
type = classify_ident (xli, QSE_STR_XSTR(tok->name));
|
|
|
|
SET_TOKEN_TYPE (xli, tok, type);
|
2013-09-17 01:28:04 +00:00
|
|
|
}
|
|
|
|
else if ((xli->tok_status & TOK_STATUS_ENABLE_NSTR) && QSE_ISDIGIT(c))
|
|
|
|
{
|
2015-08-30 03:11:54 +00:00
|
|
|
SET_TOKEN_TYPE (xli, tok, QSE_XLI_TOK_NSTR);
|
2013-09-17 01:28:04 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
ADD_TOKEN_CHAR (xli, tok, c);
|
|
|
|
GET_CHAR_TO (xli, c);
|
|
|
|
}
|
|
|
|
while (QSE_ISDIGIT(c));
|
2013-02-05 15:04:15 +00:00
|
|
|
}
|
2013-07-01 15:16:19 +00:00
|
|
|
else if (c == QSE_T('\''))
|
2013-02-05 15:04:15 +00:00
|
|
|
{
|
|
|
|
/* single-quoted string - no escaping */
|
2015-08-30 03:11:54 +00:00
|
|
|
SET_TOKEN_TYPE (xli, tok, QSE_XLI_TOK_SQSTR);
|
2013-02-05 15:04:15 +00:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
GET_CHAR_TO (xli, c);
|
|
|
|
|
|
|
|
if (c == QSE_CHAR_EOF)
|
|
|
|
{
|
|
|
|
/* the string is not closed */
|
2013-09-24 14:02:06 +00:00
|
|
|
qse_xli_seterror (xli, QSE_XLI_ESTRNC, QSE_NULL, &tok->loc);
|
2013-02-05 15:04:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-07-01 15:16:19 +00:00
|
|
|
if (c == QSE_T('\''))
|
2013-02-05 15:04:15 +00:00
|
|
|
{
|
|
|
|
/* terminating quote */
|
|
|
|
GET_CHAR (xli);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ADD_TOKEN_CHAR (xli, tok, c);
|
|
|
|
}
|
|
|
|
}
|
2013-07-01 15:16:19 +00:00
|
|
|
else if (c == QSE_T('\"'))
|
|
|
|
{
|
|
|
|
/* double-quoted string - support escaping */
|
|
|
|
int escaped = 0;
|
|
|
|
|
2015-08-30 03:11:54 +00:00
|
|
|
SET_TOKEN_TYPE (xli, tok, QSE_XLI_TOK_DQSTR);
|
2013-07-01 15:16:19 +00:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
GET_CHAR_TO (xli, c);
|
|
|
|
|
|
|
|
if (c == QSE_CHAR_EOF)
|
|
|
|
{
|
|
|
|
/* the string is not closed */
|
2013-09-24 14:02:06 +00:00
|
|
|
qse_xli_seterror (xli, QSE_XLI_ESTRNC, QSE_NULL, &tok->loc);
|
2013-07-01 15:16:19 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!escaped)
|
|
|
|
{
|
|
|
|
if (c == QSE_T('\\'))
|
|
|
|
{
|
|
|
|
escaped = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == QSE_T('\"'))
|
|
|
|
{
|
|
|
|
/* terminating quote */
|
|
|
|
GET_CHAR (xli);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ADD_TOKEN_CHAR (xli, tok, c);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ADD_TOKEN_CHAR (xli, tok, c);
|
|
|
|
escaped = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-09 10:45:43 +00:00
|
|
|
else if ((xli->opt.trait & (QSE_XLI_KEYTAG | QSE_XLI_STRTAG)) && c == QSE_T('['))
|
2013-09-24 14:02:06 +00:00
|
|
|
{
|
|
|
|
/* a string tag is a bracketed word placed in front of a string value.
|
|
|
|
* A = [tg] "abc";
|
|
|
|
* "tg" is stored into the tag field of qse_xli_str_t.
|
|
|
|
*/
|
2018-01-05 10:55:20 +00:00
|
|
|
|
2018-01-09 10:45:43 +00:00
|
|
|
SET_TOKEN_TYPE (xli, tok, QSE_XLI_TOK_TAG);
|
|
|
|
|
2013-09-24 14:02:06 +00:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
GET_CHAR_TO (xli, c);
|
|
|
|
|
2015-08-31 13:31:30 +00:00
|
|
|
if (c == QSE_CHAR_EOF || c == QSE_T('\n'))
|
2013-09-24 14:02:06 +00:00
|
|
|
{
|
|
|
|
/* the string tag is not closed */
|
|
|
|
qse_xli_seterror (xli, QSE_XLI_ETAGNC, QSE_NULL, &xli->tok.loc);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-01-09 10:45:43 +00:00
|
|
|
if (c == QSE_T(']'))
|
2013-09-24 14:02:06 +00:00
|
|
|
{
|
|
|
|
/* terminating quote */
|
|
|
|
GET_CHAR (xli);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-11-14 14:07:16 +00:00
|
|
|
if (!QSE_ISALNUM(c) && c != QSE_T('-') && c != QSE_T('_') &&
|
|
|
|
c != QSE_T(':') && c != QSE_T('*') && c != QSE_T('/') &&
|
|
|
|
c != QSE_T(',') && c != QSE_T('.') && c != QSE_T('|'))
|
2013-09-24 14:02:06 +00:00
|
|
|
{
|
|
|
|
qse_char_t cc = (qse_char_t)c;
|
2014-07-08 14:30:42 +00:00
|
|
|
qse_cstr_t ea;
|
2013-09-24 14:02:06 +00:00
|
|
|
ea.ptr = &cc;
|
|
|
|
ea.len = 1;
|
|
|
|
qse_xli_seterror (xli, QSE_XLI_ETAGCHR, &ea, &tok->loc);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ADD_TOKEN_CHAR (xli, tok, c);
|
|
|
|
}
|
|
|
|
}
|
2013-02-05 15:04:15 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
n = get_symbols (xli, c, tok);
|
2015-09-15 13:29:15 +00:00
|
|
|
if (n <= -1) return -1; /* hard failure */
|
2013-02-05 15:04:15 +00:00
|
|
|
if (n == 0)
|
|
|
|
{
|
|
|
|
/* not handled yet */
|
|
|
|
if (c == QSE_T('\0'))
|
|
|
|
{
|
2014-07-08 14:30:42 +00:00
|
|
|
qse_cstr_t ea;
|
2013-02-18 13:45:50 +00:00
|
|
|
ea.ptr = QSE_T("<NUL>");
|
|
|
|
ea.len = 5;
|
|
|
|
qse_xli_seterror (xli, QSE_XLI_ELXCHR, &ea, &tok->loc);
|
2013-02-05 15:04:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qse_char_t cc = (qse_char_t)c;
|
2014-07-08 14:30:42 +00:00
|
|
|
qse_cstr_t ea;
|
2013-02-18 13:45:50 +00:00
|
|
|
ea.ptr = &cc;
|
|
|
|
ea.len = 1;
|
|
|
|
qse_xli_seterror (xli, QSE_XLI_ELXCHR, &ea, &tok->loc);
|
2013-02-05 15:04:15 +00:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-08-30 03:11:54 +00:00
|
|
|
if (skip_semicolon_after_include && tok->type == QSE_XLI_TOK_SEMICOLON)
|
2013-02-05 15:04:15 +00:00
|
|
|
{
|
|
|
|
/* this handles the optional semicolon after the
|
|
|
|
* included file named as in @include "file-name"; */
|
|
|
|
skip_semicolon_after_include = 0;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (skip_semicolon_after_include)
|
|
|
|
{
|
|
|
|
/* semiclon has not been skipped yet */
|
2014-07-02 12:28:58 +00:00
|
|
|
qse_xli_seterror (xli, QSE_XLI_ESCOLON, QSE_STR_XSTR(tok->name), &tok->loc);
|
2013-02-05 15:04:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_token (qse_xli_t* xli)
|
|
|
|
{
|
|
|
|
return get_token_into (xli, &xli->tok);
|
|
|
|
}
|
|
|
|
|
2014-11-13 10:15:53 +00:00
|
|
|
static int read_pair (qse_xli_t* xli, const qse_char_t* keytag, const qse_xli_scm_t* override)
|
2013-02-05 15:04:15 +00:00
|
|
|
{
|
2014-07-08 14:30:42 +00:00
|
|
|
qse_cstr_t key;
|
2013-07-11 16:55:08 +00:00
|
|
|
qse_xli_loc_t kloc;
|
|
|
|
qse_char_t* name;
|
2013-02-06 14:31:32 +00:00
|
|
|
qse_xli_pair_t* pair;
|
2013-06-23 14:44:29 +00:00
|
|
|
qse_xli_list_t* parlist;
|
2013-07-11 16:55:08 +00:00
|
|
|
qse_size_t dotted_curkey_len;
|
2013-09-25 06:40:40 +00:00
|
|
|
qse_char_t* strtag;
|
2013-07-12 15:37:29 +00:00
|
|
|
|
2014-11-13 10:15:53 +00:00
|
|
|
const qse_xli_scm_t* scm = QSE_NULL;
|
|
|
|
int key_nodup = 0, key_alias = 0, val_iffy = 0;
|
2018-01-19 15:57:44 +00:00
|
|
|
|
2013-07-11 16:55:08 +00:00
|
|
|
|
|
|
|
key.ptr = QSE_NULL;
|
|
|
|
name = QSE_NULL;
|
2013-09-25 06:40:40 +00:00
|
|
|
strtag = QSE_NULL;
|
2013-07-11 16:55:08 +00:00
|
|
|
dotted_curkey_len = (qse_size_t)-1;
|
2013-06-23 14:44:29 +00:00
|
|
|
|
|
|
|
parlist = xli->parlink->list;
|
2013-02-06 14:31:32 +00:00
|
|
|
|
2013-07-12 15:37:29 +00:00
|
|
|
if (xli->opt.trait & QSE_XLI_KEYNODUP) key_nodup = 1;
|
|
|
|
if (xli->opt.trait & QSE_XLI_KEYALIAS) key_alias = 1;
|
2014-11-12 05:59:47 +00:00
|
|
|
|
2013-07-11 16:55:08 +00:00
|
|
|
kloc = xli->tok.loc;
|
|
|
|
key.len = QSE_STR_LEN(xli->tok.name);
|
2019-06-24 14:24:14 +00:00
|
|
|
key.ptr = qse_strdup (QSE_STR_PTR(xli->tok.name), qse_xli_getmmgr(xli));
|
2013-07-11 16:55:08 +00:00
|
|
|
if (key.ptr == QSE_NULL)
|
|
|
|
{
|
|
|
|
qse_xli_seterrnum (xli, QSE_XLI_ENOMEM, QSE_NULL);
|
|
|
|
goto oops;
|
|
|
|
}
|
|
|
|
|
|
|
|
dotted_curkey_len = QSE_STR_LEN (xli->dotted_curkey);
|
2018-01-09 10:45:43 +00:00
|
|
|
if ((dotted_curkey_len > 0 && qse_str_cat (xli->dotted_curkey, QSE_T(".")) == (qse_size_t)-1) ||
|
|
|
|
qse_str_cat (xli->dotted_curkey, key.ptr) == (qse_size_t)-1)
|
2013-02-05 15:04:15 +00:00
|
|
|
{
|
2013-02-09 13:31:31 +00:00
|
|
|
qse_xli_seterrnum (xli, QSE_XLI_ENOMEM, QSE_NULL);
|
2013-02-06 14:31:32 +00:00
|
|
|
goto oops;
|
2013-02-05 15:04:15 +00:00
|
|
|
}
|
|
|
|
|
2014-11-13 10:15:53 +00:00
|
|
|
if (xli->opt.trait & QSE_XLI_VALIDATE)
|
2013-07-11 16:55:08 +00:00
|
|
|
{
|
2014-11-13 10:15:53 +00:00
|
|
|
if (override) scm = override;
|
|
|
|
else
|
2013-07-11 16:55:08 +00:00
|
|
|
{
|
2014-11-13 10:15:53 +00:00
|
|
|
qse_rbt_pair_t* pair;
|
2013-07-11 16:55:08 +00:00
|
|
|
|
2014-11-13 10:15:53 +00:00
|
|
|
pair = qse_rbt_search (xli->schema, QSE_STR_PTR(xli->dotted_curkey), QSE_STR_LEN(xli->dotted_curkey));
|
|
|
|
if (pair == QSE_NULL)
|
|
|
|
{
|
|
|
|
qse_xli_seterror (xli, QSE_XLI_EUDKEY, (const qse_cstr_t*)&key, &kloc);
|
|
|
|
goto oops;
|
|
|
|
}
|
|
|
|
|
|
|
|
scm = (qse_xli_scm_t*)QSE_RBT_VPTR(pair);
|
|
|
|
}
|
2013-07-11 16:55:08 +00:00
|
|
|
|
2013-07-12 15:37:29 +00:00
|
|
|
if (scm->flags & QSE_XLI_SCM_KEYNODUP) key_nodup = 2;
|
|
|
|
if (scm->flags & QSE_XLI_SCM_KEYALIAS) key_alias = 2;
|
2014-11-13 10:15:53 +00:00
|
|
|
if (scm->flags & QSE_XLI_SCM_VALIFFY) val_iffy = 1;
|
2013-07-12 15:37:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (key_nodup)
|
|
|
|
{
|
|
|
|
qse_xli_atom_t* atom;
|
|
|
|
|
|
|
|
/* find any key conflicts in the current scope */
|
|
|
|
/* TODO: optimization. no sequential search */
|
|
|
|
atom = parlist->tail;
|
|
|
|
while (atom)
|
2013-07-11 16:55:08 +00:00
|
|
|
{
|
2013-07-12 15:37:29 +00:00
|
|
|
if (atom->type == QSE_XLI_PAIR &&
|
2018-01-19 03:53:43 +00:00
|
|
|
xli->opt.strcmp(((qse_xli_pair_t*)atom)->key, QSE_STR_PTR(xli->tok.name)) == 0)
|
2013-07-12 15:37:29 +00:00
|
|
|
{
|
2014-07-02 12:28:58 +00:00
|
|
|
qse_xli_seterror (xli, QSE_XLI_EEXIST, QSE_STR_XSTR(xli->tok.name), &xli->tok.loc);
|
2013-07-12 15:37:29 +00:00
|
|
|
goto oops;
|
|
|
|
}
|
|
|
|
|
|
|
|
atom = atom->prev;
|
2013-07-11 16:55:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-09 10:45:43 +00:00
|
|
|
/* once the key name is read, enable the numeric string for a value */
|
2013-07-01 15:16:19 +00:00
|
|
|
xli->tok_status |= TOK_STATUS_ENABLE_NSTR;
|
|
|
|
|
2018-01-09 10:45:43 +00:00
|
|
|
if (get_token (xli) <= -1) goto oops;
|
2013-02-09 13:31:31 +00:00
|
|
|
|
2013-07-12 15:37:29 +00:00
|
|
|
if (key_alias)
|
2013-02-06 14:31:32 +00:00
|
|
|
{
|
2013-09-25 06:40:40 +00:00
|
|
|
/* the alias part must be unique for the same key(s) */
|
2018-01-09 10:45:43 +00:00
|
|
|
if (MATCH(xli, QSE_XLI_TOK_IDENT) || MATCH(xli, QSE_XLI_TOK_DQSTR) || MATCH(xli, QSE_XLI_TOK_SQSTR) || MATCH(xli, QSE_XLI_TOK_NSTR))
|
2013-02-06 14:31:32 +00:00
|
|
|
{
|
2013-02-09 13:31:31 +00:00
|
|
|
qse_xli_atom_t* atom;
|
2013-02-05 15:04:15 +00:00
|
|
|
|
2013-06-23 14:44:29 +00:00
|
|
|
atom = parlist->tail;
|
2013-02-09 13:31:31 +00:00
|
|
|
while (atom)
|
|
|
|
{
|
|
|
|
if (atom->type == QSE_XLI_PAIR &&
|
2013-07-01 15:16:19 +00:00
|
|
|
((qse_xli_pair_t*)atom)->alias &&
|
2018-01-19 03:53:43 +00:00
|
|
|
xli->opt.strcmp(((qse_xli_pair_t*)atom)->key, key.ptr) == 0 &&
|
|
|
|
xli->opt.strcmp(((qse_xli_pair_t*)atom)->alias, QSE_STR_PTR(xli->tok.name)) == 0)
|
2013-02-09 13:31:31 +00:00
|
|
|
{
|
2014-07-02 12:28:58 +00:00
|
|
|
qse_xli_seterror (xli, QSE_XLI_EEXIST, QSE_STR_XSTR(xli->tok.name), &xli->tok.loc);
|
2013-02-09 13:31:31 +00:00
|
|
|
goto oops;
|
|
|
|
}
|
|
|
|
atom = atom->prev;
|
|
|
|
}
|
|
|
|
|
2019-06-24 14:24:14 +00:00
|
|
|
name = qse_strdup (QSE_STR_PTR(xli->tok.name), qse_xli_getmmgr(xli));
|
2013-02-09 13:31:31 +00:00
|
|
|
if (name == QSE_NULL)
|
|
|
|
{
|
|
|
|
qse_xli_seterrnum (xli, QSE_XLI_ENOMEM, QSE_NULL);
|
|
|
|
goto oops;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_token (xli) <= -1) goto oops;
|
|
|
|
}
|
2013-07-12 15:37:29 +00:00
|
|
|
else if (key_alias == 2)
|
|
|
|
{
|
|
|
|
/* SCM_KEYALIAS is specified for this particular item. Let the alias be required.
|
|
|
|
* If KEYALIAS is globally specified with the specific one, it's optional. */
|
2014-07-08 14:30:42 +00:00
|
|
|
qse_xli_seterrnum (xli, QSE_XLI_ENOALI, (const qse_cstr_t*)&key);
|
2013-07-12 15:37:29 +00:00
|
|
|
goto oops;
|
|
|
|
}
|
2013-02-06 14:31:32 +00:00
|
|
|
}
|
|
|
|
|
2018-01-08 08:25:49 +00:00
|
|
|
if (MATCH(xli, QSE_XLI_TOK_EQ))
|
2013-02-06 14:31:32 +00:00
|
|
|
{
|
|
|
|
if (get_token (xli) <= -1) goto oops;
|
2013-02-09 13:31:31 +00:00
|
|
|
|
2018-01-09 10:45:43 +00:00
|
|
|
if ((xli->opt.trait & QSE_XLI_STRTAG) && MATCH(xli, QSE_XLI_TOK_TAG))
|
2013-09-24 14:02:06 +00:00
|
|
|
{
|
2019-06-24 14:24:14 +00:00
|
|
|
strtag = qse_strxdup (QSE_STR_PTR(xli->tok.name), QSE_STR_LEN(xli->tok.name), qse_xli_getmmgr(xli));
|
2013-09-25 06:40:40 +00:00
|
|
|
if (strtag == QSE_NULL)
|
2013-09-24 14:02:06 +00:00
|
|
|
{
|
|
|
|
qse_xli_seterrnum (xli, QSE_XLI_ENOMEM, QSE_NULL);
|
|
|
|
goto oops;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_token (xli) <= -1) goto oops;
|
|
|
|
}
|
|
|
|
|
2018-01-10 10:01:41 +00:00
|
|
|
if (MATCH(xli, QSE_XLI_TOK_TRUE) || MATCH(xli, QSE_XLI_TOK_FALSE))
|
|
|
|
{
|
|
|
|
qse_xli_val_t* v;
|
|
|
|
|
|
|
|
v = MATCH(xli, QSE_XLI_TOK_TRUE)? (qse_xli_val_t*)&xli->root->xtrue:
|
|
|
|
(qse_xli_val_t*)&xli->root->xfalse;
|
|
|
|
pair = qse_xli_insertpair(xli, parlist, QSE_NULL, key.ptr, name, keytag, v);
|
|
|
|
if (pair == QSE_NULL) goto oops;
|
|
|
|
|
2018-01-19 15:57:44 +00:00
|
|
|
if (xli->opt.cbs.pair_read) xli->opt.cbs.pair_read (xli, pair, &kloc);
|
|
|
|
|
2018-01-10 10:01:41 +00:00
|
|
|
if (get_token (xli) <= -1) goto oops; /* skip the value */
|
|
|
|
|
|
|
|
if (!MATCH(xli, QSE_XLI_TOK_SEMICOLON))
|
|
|
|
{
|
|
|
|
qse_xli_seterror (xli, QSE_XLI_ESCOLON, QSE_STR_XSTR(xli->tok.name), &xli->tok.loc);
|
|
|
|
goto oops;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_token (xli) <= -1) goto oops; /* skip the value */
|
|
|
|
}
|
|
|
|
else if (MATCH(xli, QSE_XLI_TOK_SQSTR) || MATCH(xli, QSE_XLI_TOK_DQSTR) || MATCH(xli, QSE_XLI_TOK_NSTR) || MATCH(xli, QSE_XLI_TOK_IDENT))
|
2013-02-09 13:31:31 +00:00
|
|
|
{
|
2013-06-29 17:01:32 +00:00
|
|
|
qse_xli_str_t* curstrseg;
|
2013-07-11 16:55:08 +00:00
|
|
|
qse_size_t segcount = 0;
|
|
|
|
|
2013-07-12 15:37:29 +00:00
|
|
|
if (scm && !(scm->flags & QSE_XLI_SCM_VALSTR))
|
2013-07-11 16:55:08 +00:00
|
|
|
{
|
|
|
|
/* check the value type */
|
2014-07-08 14:30:42 +00:00
|
|
|
qse_xli_seterror (xli, QSE_XLI_EILVAL, (const qse_cstr_t*)&key, &kloc);
|
2014-10-14 12:55:00 +00:00
|
|
|
goto oops;
|
2013-07-11 16:55:08 +00:00
|
|
|
}
|
2013-06-29 17:01:32 +00:00
|
|
|
|
2013-07-01 09:10:13 +00:00
|
|
|
/* add a new pair with the initial string segment */
|
2018-01-10 10:01:41 +00:00
|
|
|
pair = qse_xli_insertpairwithstr(xli, parlist, QSE_NULL, key.ptr, name, keytag, QSE_STR_XSTR(xli->tok.name), strtag);
|
2013-07-01 09:10:13 +00:00
|
|
|
if (pair == QSE_NULL) goto oops;
|
2013-06-29 17:01:32 +00:00
|
|
|
|
2018-01-19 15:57:44 +00:00
|
|
|
if (xli->opt.cbs.pair_read) xli->opt.cbs.pair_read (xli, pair, &kloc);
|
|
|
|
|
2018-01-10 10:01:41 +00:00
|
|
|
if (MATCH(xli, QSE_XLI_TOK_NSTR))
|
|
|
|
{
|
|
|
|
((qse_xli_str_t*)pair->val)->flags |= QSE_XLI_STR_NSTR;
|
|
|
|
}
|
|
|
|
|
2013-07-11 16:55:08 +00:00
|
|
|
segcount++;
|
2013-06-29 17:01:32 +00:00
|
|
|
curstrseg = (qse_xli_str_t*)pair->val;
|
|
|
|
|
2013-02-09 13:31:31 +00:00
|
|
|
if (get_token (xli) <= -1) goto oops;
|
2015-08-30 03:11:54 +00:00
|
|
|
if ((xli->opt.trait & QSE_XLI_MULSEGSTR) && MATCH(xli, QSE_XLI_TOK_COMMA))
|
2013-02-18 13:45:50 +00:00
|
|
|
{
|
|
|
|
/* multi-segmented string */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (get_token (xli) <= -1) goto oops; /* skip the comma */
|
|
|
|
|
2013-09-25 06:40:40 +00:00
|
|
|
if (strtag)
|
2013-09-24 14:02:06 +00:00
|
|
|
{
|
2019-06-24 14:24:14 +00:00
|
|
|
qse_xli_freemem (xli, strtag);
|
2013-09-25 06:40:40 +00:00
|
|
|
strtag = QSE_NULL;
|
2013-09-24 14:02:06 +00:00
|
|
|
}
|
|
|
|
|
2018-01-09 10:45:43 +00:00
|
|
|
if ((xli->opt.trait & QSE_XLI_STRTAG) && MATCH(xli, QSE_XLI_TOK_TAG))
|
2013-09-24 14:02:06 +00:00
|
|
|
{
|
2019-06-24 14:24:14 +00:00
|
|
|
strtag = qse_strxdup (QSE_STR_PTR(xli->tok.name), QSE_STR_LEN(xli->tok.name), qse_xli_getmmgr(xli));
|
2013-09-25 06:40:40 +00:00
|
|
|
if (strtag == QSE_NULL)
|
2013-09-24 14:02:06 +00:00
|
|
|
{
|
|
|
|
qse_xli_seterrnum (xli, QSE_XLI_ENOMEM, QSE_NULL);
|
|
|
|
goto oops;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_token (xli) <= -1) goto oops;
|
|
|
|
}
|
|
|
|
|
2018-01-09 10:45:43 +00:00
|
|
|
if (!MATCH(xli, QSE_XLI_TOK_SQSTR) && !MATCH(xli, QSE_XLI_TOK_DQSTR) && !MATCH(xli, QSE_XLI_TOK_NSTR) && !MATCH(xli, QSE_XLI_TOK_IDENT))
|
2013-02-18 13:45:50 +00:00
|
|
|
{
|
|
|
|
qse_xli_seterror (xli, QSE_XLI_ESYNTAX, QSE_NULL, &xli->tok.loc);
|
|
|
|
goto oops;
|
|
|
|
}
|
|
|
|
|
2013-07-01 09:10:13 +00:00
|
|
|
/* add an additional segment to the string */
|
2014-07-02 12:28:58 +00:00
|
|
|
curstrseg = qse_xli_addsegtostr (xli, curstrseg, strtag, QSE_STR_XSTR(xli->tok.name));
|
2013-07-01 09:10:13 +00:00
|
|
|
if (curstrseg == QSE_NULL) goto oops;
|
2013-02-18 13:45:50 +00:00
|
|
|
|
2013-07-11 16:55:08 +00:00
|
|
|
segcount++;
|
2013-02-18 13:45:50 +00:00
|
|
|
if (get_token (xli) <= -1) goto oops; /* skip the value */
|
|
|
|
}
|
2018-01-09 10:45:43 +00:00
|
|
|
while (MATCH(xli, QSE_XLI_TOK_COMMA));
|
2013-02-18 13:45:50 +00:00
|
|
|
}
|
2013-02-09 13:31:31 +00:00
|
|
|
|
|
|
|
/* semicolon is mandatory for a string */
|
2018-01-09 10:45:43 +00:00
|
|
|
if (!MATCH(xli, QSE_XLI_TOK_SEMICOLON))
|
2013-02-09 13:31:31 +00:00
|
|
|
{
|
2014-07-02 12:28:58 +00:00
|
|
|
qse_xli_seterror (xli, QSE_XLI_ESCOLON, QSE_STR_XSTR(xli->tok.name), &xli->tok.loc);
|
2013-02-09 13:31:31 +00:00
|
|
|
goto oops;
|
|
|
|
}
|
|
|
|
|
2013-07-11 16:55:08 +00:00
|
|
|
if (scm && (segcount < scm->str_minseg || segcount > scm->str_maxseg))
|
|
|
|
{
|
|
|
|
/* too many string segments for the key */
|
2014-07-08 14:30:42 +00:00
|
|
|
qse_xli_seterror (xli, QSE_XLI_ESTRSEG, (const qse_cstr_t*)&key, &kloc);
|
2014-11-03 15:33:15 +00:00
|
|
|
goto oops;
|
2013-07-11 16:55:08 +00:00
|
|
|
}
|
|
|
|
|
2013-09-17 01:28:04 +00:00
|
|
|
/* semicolon read. turn off NSTR */
|
|
|
|
xli->tok_status &= ~TOK_STATUS_ENABLE_NSTR;
|
2018-01-10 10:01:41 +00:00
|
|
|
if (get_token(xli) <= -1) goto oops;
|
2013-02-09 13:31:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-01-10 10:01:41 +00:00
|
|
|
qse_xli_seterror (xli, QSE_XLI_EVALUE, QSE_STR_XSTR(xli->tok.name), &xli->tok.loc);
|
2014-11-03 15:33:15 +00:00
|
|
|
goto oops;
|
2013-02-09 13:31:31 +00:00
|
|
|
}
|
2013-07-11 16:55:08 +00:00
|
|
|
/* TODO: check against schema */
|
2018-01-08 08:25:49 +00:00
|
|
|
}
|
2018-01-09 10:45:43 +00:00
|
|
|
else if (!(xli->opt.trait & QSE_XLI_NOLIST) && MATCH(xli, QSE_XLI_TOK_LBRACE))
|
2013-02-06 14:31:32 +00:00
|
|
|
{
|
2013-07-12 15:37:29 +00:00
|
|
|
if (scm && !(scm->flags & QSE_XLI_SCM_VALLIST))
|
2013-07-11 16:55:08 +00:00
|
|
|
{
|
|
|
|
/* check the value type */
|
2014-07-08 14:30:42 +00:00
|
|
|
qse_xli_seterror (xli, QSE_XLI_EILVAL, (const qse_cstr_t*)&key, &kloc);
|
2014-10-14 12:55:00 +00:00
|
|
|
goto oops;
|
2013-07-11 16:55:08 +00:00
|
|
|
}
|
|
|
|
|
2013-07-01 15:16:19 +00:00
|
|
|
xli->tok_status &= ~TOK_STATUS_ENABLE_NSTR;
|
|
|
|
|
2013-02-06 14:31:32 +00:00
|
|
|
/* insert a pair with an empty list */
|
2018-01-09 10:45:43 +00:00
|
|
|
pair = qse_xli_insertpairwithemptylist(xli, parlist, QSE_NULL, key.ptr, name, keytag);
|
2013-02-06 14:31:32 +00:00
|
|
|
if (pair == QSE_NULL) goto oops;
|
2014-11-12 05:59:47 +00:00
|
|
|
|
2018-01-19 15:57:44 +00:00
|
|
|
if (xli->opt.cbs.pair_read) xli->opt.cbs.pair_read (xli, pair, &kloc);
|
|
|
|
|
2014-11-12 05:59:47 +00:00
|
|
|
/* skip validations of child pairs if the schema for the
|
2014-11-13 10:15:53 +00:00
|
|
|
* current pair is set with QSE_XLI_SCM_VALIFFY.
|
2014-11-12 05:59:47 +00:00
|
|
|
* the schema for the child pairs, if specified, must not
|
|
|
|
* take effect. */
|
2018-01-09 10:45:43 +00:00
|
|
|
if (read_list(xli, (qse_xli_list_t*)pair->val, (val_iffy? &scm_val_iffy: QSE_NULL)) <= -1) goto oops;
|
|
|
|
|
|
|
|
if (!MATCH(xli, QSE_XLI_TOK_RBRACE))
|
2013-02-06 14:31:32 +00:00
|
|
|
{
|
2018-01-09 10:45:43 +00:00
|
|
|
qse_xli_seterror (xli, QSE_XLI_ERBRACE, QSE_STR_XSTR(xli->tok.name), &xli->tok.loc);
|
2013-02-06 14:31:32 +00:00
|
|
|
goto oops;
|
|
|
|
}
|
|
|
|
|
2018-01-09 10:45:43 +00:00
|
|
|
if (get_token(xli) <= -1) goto oops;
|
2013-02-06 14:31:32 +00:00
|
|
|
|
|
|
|
/* semicolon is optional for a list */
|
2018-01-09 10:45:43 +00:00
|
|
|
if (MATCH(xli, QSE_XLI_TOK_SEMICOLON))
|
2013-02-06 14:31:32 +00:00
|
|
|
{
|
|
|
|
/* skip the semicolon */
|
|
|
|
if (get_token (xli) <= -1) goto oops;
|
|
|
|
}
|
2013-07-11 16:55:08 +00:00
|
|
|
|
|
|
|
/* TODO: check against schema */
|
2013-02-06 14:31:32 +00:00
|
|
|
}
|
2018-01-09 10:45:43 +00:00
|
|
|
else if (MATCH(xli, QSE_XLI_TOK_SEMICOLON))
|
2013-02-18 13:45:50 +00:00
|
|
|
{
|
2013-09-23 14:06:25 +00:00
|
|
|
if (xli->opt.trait & QSE_XLI_NONIL)
|
|
|
|
{
|
2014-07-08 14:30:42 +00:00
|
|
|
qse_xli_seterror (xli, QSE_XLI_ENOVAL, (const qse_cstr_t*)&key, &kloc);
|
2014-10-14 12:55:00 +00:00
|
|
|
goto oops;
|
2013-09-23 14:06:25 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 15:37:29 +00:00
|
|
|
if (scm && !(scm->flags & QSE_XLI_SCM_VALNIL) &&
|
|
|
|
!((scm->flags & QSE_XLI_SCM_VALSTR) && scm->str_minseg <= 0))
|
2013-07-11 16:55:08 +00:00
|
|
|
{
|
|
|
|
/* check the value type */
|
2014-07-08 14:30:42 +00:00
|
|
|
qse_xli_seterror (xli, QSE_XLI_ENOVAL, (const qse_cstr_t*)&key, &kloc);
|
2014-11-12 05:59:47 +00:00
|
|
|
goto oops;
|
2013-07-11 16:55:08 +00:00
|
|
|
}
|
|
|
|
|
2013-07-01 15:16:19 +00:00
|
|
|
xli->tok_status &= ~TOK_STATUS_ENABLE_NSTR;
|
|
|
|
|
2013-02-18 13:45:50 +00:00
|
|
|
/* no value has been specified for the pair */
|
2013-09-25 06:40:40 +00:00
|
|
|
pair = qse_xli_insertpair (xli, parlist, QSE_NULL, key.ptr, name, keytag, (qse_xli_val_t*)&xli->root->xnil);
|
2013-02-18 13:45:50 +00:00
|
|
|
if (pair == QSE_NULL) goto oops;
|
|
|
|
|
2018-01-19 15:57:44 +00:00
|
|
|
if (xli->opt.cbs.pair_read) xli->opt.cbs.pair_read (xli, pair, &kloc);
|
|
|
|
|
2013-02-18 13:45:50 +00:00
|
|
|
/* skip the semicolon */
|
|
|
|
if (get_token (xli) <= -1) goto oops;
|
2013-07-11 16:55:08 +00:00
|
|
|
|
|
|
|
/* TODO: check against schema */
|
2013-02-18 13:45:50 +00:00
|
|
|
}
|
2013-02-06 14:31:32 +00:00
|
|
|
else
|
|
|
|
{
|
2014-07-02 12:28:58 +00:00
|
|
|
qse_xli_seterror (xli, QSE_XLI_ELBREQ, QSE_STR_XSTR(xli->tok.name), &xli->tok.loc);
|
2014-10-14 12:55:00 +00:00
|
|
|
goto oops;
|
2013-02-06 14:31:32 +00:00
|
|
|
}
|
|
|
|
|
2019-06-24 14:24:14 +00:00
|
|
|
if (strtag) qse_xli_freemem (xli, strtag);
|
|
|
|
qse_xli_freemem (xli, name);
|
|
|
|
qse_xli_freemem (xli, key.ptr);
|
2013-07-11 16:55:08 +00:00
|
|
|
qse_str_setlen (xli->dotted_curkey, dotted_curkey_len);
|
2013-02-06 14:31:32 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
oops:
|
2013-07-01 15:16:19 +00:00
|
|
|
xli->tok_status &= ~TOK_STATUS_ENABLE_NSTR;
|
2019-06-24 14:24:14 +00:00
|
|
|
if (strtag) qse_xli_freemem (xli, strtag);
|
|
|
|
if (name) qse_xli_freemem (xli, name);
|
|
|
|
if (key.ptr) qse_xli_freemem (xli, key.ptr);
|
2013-07-11 16:55:08 +00:00
|
|
|
if (dotted_curkey_len != (qse_size_t)-1)
|
|
|
|
qse_str_setlen (xli->dotted_curkey, dotted_curkey_len);
|
2013-02-06 14:31:32 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-08-29 13:04:46 +00:00
|
|
|
qse_xli_list_link_t* qse_xli_makelistlink (qse_xli_t* xli, qse_xli_list_t* parlist)
|
2013-02-06 14:31:32 +00:00
|
|
|
{
|
2013-06-29 17:01:32 +00:00
|
|
|
qse_xli_list_link_t* link;
|
2013-06-23 14:44:29 +00:00
|
|
|
|
2019-06-24 14:24:14 +00:00
|
|
|
link = (qse_xli_list_link_t*)qse_xli_callocmem(xli, QSE_SIZEOF(*link));
|
2013-06-29 17:01:32 +00:00
|
|
|
if (link == QSE_NULL) return QSE_NULL;
|
2013-06-23 14:44:29 +00:00
|
|
|
|
|
|
|
link->list = parlist;
|
|
|
|
link->next = xli->parlink;
|
|
|
|
xli->parlink = link;
|
|
|
|
|
2014-10-14 12:55:00 +00:00
|
|
|
return link;
|
2013-06-29 17:01:32 +00:00
|
|
|
}
|
|
|
|
|
2015-08-29 13:04:46 +00:00
|
|
|
void qse_xli_freelistlink (qse_xli_t* xli, qse_xli_list_link_t* link)
|
2013-06-29 17:01:32 +00:00
|
|
|
{
|
2018-01-09 10:45:43 +00:00
|
|
|
QSE_ASSERT (xli->parlink == link);
|
2013-06-29 17:01:32 +00:00
|
|
|
xli->parlink = link->next;
|
|
|
|
qse_xli_freemem (xli, link);
|
|
|
|
}
|
|
|
|
|
2018-01-09 10:45:43 +00:00
|
|
|
static int __read_list (qse_xli_t* xli, const qse_xli_scm_t* override)
|
2018-01-08 08:25:49 +00:00
|
|
|
{
|
|
|
|
while (1)
|
|
|
|
{
|
2018-01-09 10:45:43 +00:00
|
|
|
if (MATCH(xli, QSE_XLI_TOK_XINCLUDE))
|
2018-01-08 08:25:49 +00:00
|
|
|
{
|
|
|
|
if (get_token(xli) <= -1) return -1;
|
|
|
|
|
|
|
|
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);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (begin_include (xli) <= -1) return -1;
|
|
|
|
}
|
2018-01-05 10:55:20 +00:00
|
|
|
else if ((xli->opt.trait & QSE_XLI_KEYTAG) && MATCH(xli, QSE_XLI_TOK_TAG))
|
2013-09-25 06:40:40 +00:00
|
|
|
{
|
|
|
|
qse_char_t* keytag;
|
|
|
|
int x;
|
|
|
|
|
2019-06-24 14:24:14 +00:00
|
|
|
keytag = qse_strxdup (QSE_STR_PTR(xli->tok.name), QSE_STR_LEN(xli->tok.name), qse_xli_getmmgr(xli));
|
2013-09-25 06:40:40 +00:00
|
|
|
if (keytag == QSE_NULL)
|
|
|
|
{
|
|
|
|
qse_xli_seterrnum (xli, QSE_XLI_ENOMEM, QSE_NULL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_token(xli) <= -1)
|
|
|
|
{
|
2019-06-24 14:24:14 +00:00
|
|
|
qse_xli_freemem (xli, keytag);
|
2013-09-25 06:40:40 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-01-09 10:45:43 +00:00
|
|
|
if (!MATCH(xli, QSE_XLI_TOK_IDENT) && !MATCH(xli, QSE_XLI_TOK_DQSTR) && !MATCH(xli, QSE_XLI_TOK_SQSTR))
|
2013-09-25 06:40:40 +00:00
|
|
|
{
|
2019-06-24 14:24:14 +00:00
|
|
|
qse_xli_freemem (xli, keytag);
|
2013-09-25 06:40:40 +00:00
|
|
|
qse_xli_seterror (xli, QSE_XLI_ENOKEY, QSE_NULL, &xli->tok.loc);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-01-05 10:55:20 +00:00
|
|
|
x = read_pair(xli, keytag, override);
|
2019-06-24 14:24:14 +00:00
|
|
|
qse_xli_freemem (xli, keytag);
|
2013-09-25 06:40:40 +00:00
|
|
|
if (x <= -1) return -1;
|
|
|
|
}
|
2018-01-09 10:45:43 +00:00
|
|
|
else if (MATCH(xli, QSE_XLI_TOK_IDENT) || MATCH(xli, QSE_XLI_TOK_DQSTR) || MATCH(xli, QSE_XLI_TOK_SQSTR))
|
2013-02-05 15:04:15 +00:00
|
|
|
{
|
2018-01-05 10:55:20 +00:00
|
|
|
if (read_pair(xli, QSE_NULL, override) <= -1) return -1;
|
2013-02-05 15:04:15 +00:00
|
|
|
}
|
2018-01-05 10:55:20 +00:00
|
|
|
else if (MATCH(xli, QSE_XLI_TOK_TEXT))
|
2013-02-05 15:04:15 +00:00
|
|
|
{
|
2013-06-29 17:01:32 +00:00
|
|
|
if (get_token(xli) <= -1) return -1;
|
2013-02-05 15:04:15 +00:00
|
|
|
}
|
2013-02-18 13:45:50 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2013-02-06 14:31:32 +00:00
|
|
|
}
|
|
|
|
|
2013-06-29 17:01:32 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-13 10:15:53 +00:00
|
|
|
static int read_list (qse_xli_t* xli, qse_xli_list_t* parlist, const qse_xli_scm_t* override)
|
2013-06-29 17:01:32 +00:00
|
|
|
{
|
|
|
|
qse_xli_list_link_t* link;
|
|
|
|
|
2018-01-05 10:55:20 +00:00
|
|
|
link = qse_xli_makelistlink(xli, parlist);
|
2013-06-29 17:01:32 +00:00
|
|
|
if (link == QSE_NULL) return -1;
|
|
|
|
|
2018-01-09 10:45:43 +00:00
|
|
|
QSE_ASSERT (link == xli->parlink);
|
|
|
|
|
2013-07-02 13:10:11 +00:00
|
|
|
/* get_token() here is to read the token after the left brace.
|
|
|
|
* it must be called after the xli->parlink has been updated
|
|
|
|
* in case there are comments at the beginning of the list */
|
2018-01-09 10:45:43 +00:00
|
|
|
if (get_token(xli) <= -1 || __read_list(xli, override) <= -1)
|
2013-06-29 17:01:32 +00:00
|
|
|
{
|
2015-08-29 13:04:46 +00:00
|
|
|
qse_xli_freelistlink (xli, link);
|
2013-06-29 17:01:32 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-06-23 14:44:29 +00:00
|
|
|
QSE_ASSERT (link == xli->parlink);
|
2018-01-09 10:45:43 +00:00
|
|
|
qse_xli_freelistlink (xli, link);
|
2013-06-23 14:44:29 +00:00
|
|
|
|
2013-02-06 14:31:32 +00:00
|
|
|
return 0;
|
2013-06-29 17:01:32 +00:00
|
|
|
}
|
2013-02-06 14:31:32 +00:00
|
|
|
|
2013-06-29 17:01:32 +00:00
|
|
|
static int read_root_list (qse_xli_t* xli)
|
|
|
|
{
|
|
|
|
qse_xli_list_link_t* link;
|
|
|
|
|
2018-01-09 10:45:43 +00:00
|
|
|
link = qse_xli_makelistlink (xli, &xli->root->list);
|
2015-08-29 13:04:46 +00:00
|
|
|
if (!link) return -1;
|
2013-06-29 17:01:32 +00:00
|
|
|
|
2018-01-09 10:45:43 +00:00
|
|
|
QSE_ASSERT (link == xli->parlink);
|
|
|
|
|
|
|
|
if (qse_xli_getchar(xli) <= -1 || get_token(xli) <= -1 || __read_list(xli, QSE_NULL) <= -1)
|
2013-06-23 14:44:29 +00:00
|
|
|
{
|
2015-08-29 13:04:46 +00:00
|
|
|
qse_xli_freelistlink (xli, link);
|
2013-06-29 17:01:32 +00:00
|
|
|
return -1;
|
2013-06-23 14:44:29 +00:00
|
|
|
}
|
2013-06-29 17:01:32 +00:00
|
|
|
|
|
|
|
QSE_ASSERT (link == xli->parlink);
|
2018-01-09 10:45:43 +00:00
|
|
|
qse_xli_freelistlink (xli, link);
|
2013-06-29 17:01:32 +00:00
|
|
|
|
|
|
|
return 0;
|
2013-02-06 14:31:32 +00:00
|
|
|
}
|
|
|
|
|
2013-06-29 17:01:32 +00:00
|
|
|
void qse_xli_clearrionames (qse_xli_t* xli)
|
2013-05-15 12:05:24 +00:00
|
|
|
{
|
|
|
|
qse_link_t* cur;
|
2013-06-29 17:01:32 +00:00
|
|
|
while (xli->rio_names)
|
2013-05-15 12:05:24 +00:00
|
|
|
{
|
2013-06-29 17:01:32 +00:00
|
|
|
cur = xli->rio_names;
|
|
|
|
xli->rio_names = cur->link;
|
2019-06-24 14:24:14 +00:00
|
|
|
qse_xli_freemem (xli, cur);
|
2013-05-15 12:05:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-06 14:31:32 +00:00
|
|
|
int qse_xli_read (qse_xli_t* xli, qse_xli_io_impl_t io)
|
|
|
|
{
|
2015-08-29 13:04:46 +00:00
|
|
|
if (!io)
|
2013-02-06 14:31:32 +00:00
|
|
|
{
|
2013-02-09 13:31:31 +00:00
|
|
|
qse_xli_seterrnum (xli, QSE_XLI_EINVAL, QSE_NULL);
|
2013-02-06 14:31:32 +00:00
|
|
|
return -1;
|
2013-02-05 15:04:15 +00:00
|
|
|
}
|
|
|
|
|
2013-06-29 17:01:32 +00:00
|
|
|
QSE_MEMSET (&xli->rio, 0, QSE_SIZEOF(xli->rio));
|
|
|
|
xli->rio.impl = io;
|
|
|
|
xli->rio.top.line = 1;
|
|
|
|
xli->rio.top.colm = 1;
|
|
|
|
xli->rio.inp = &xli->rio.top;
|
2013-07-01 09:29:08 +00:00
|
|
|
|
2015-08-30 03:11:54 +00:00
|
|
|
xli->tok_status = 0;
|
|
|
|
|
2013-07-01 09:29:08 +00:00
|
|
|
qse_xli_seterrnum (xli, QSE_XLI_ENOERR, QSE_NULL);
|
2013-06-29 17:01:32 +00:00
|
|
|
qse_xli_clearrionames (xli);
|
2013-02-06 14:31:32 +00:00
|
|
|
|
2013-07-11 16:55:08 +00:00
|
|
|
QSE_ASSERT (QSE_STR_LEN(xli->dotted_curkey) == 0);
|
|
|
|
|
2015-09-02 01:27:08 +00:00
|
|
|
if (qse_xli_openrstream (xli, xli->rio.inp) <= -1) return -1;
|
2013-02-06 14:31:32 +00:00
|
|
|
/* the input stream is open now */
|
|
|
|
|
2013-06-29 17:01:32 +00:00
|
|
|
if (read_root_list (xli) <= -1) goto oops;
|
2013-02-06 14:31:32 +00:00
|
|
|
|
2013-06-23 14:44:29 +00:00
|
|
|
QSE_ASSERT (xli->parlink == QSE_NULL);
|
|
|
|
|
2018-01-09 10:45:43 +00:00
|
|
|
if (!MATCH(xli, QSE_XLI_TOK_EOF))
|
2013-02-06 14:31:32 +00:00
|
|
|
{
|
2013-02-18 13:45:50 +00:00
|
|
|
qse_xli_seterror (xli, QSE_XLI_ESYNTAX, QSE_NULL, &xli->tok.loc);
|
2013-02-06 14:31:32 +00:00
|
|
|
goto oops;
|
|
|
|
}
|
|
|
|
|
2013-06-29 17:01:32 +00:00
|
|
|
QSE_ASSERT (xli->rio.inp == &xli->rio.top);
|
2015-09-02 01:27:08 +00:00
|
|
|
qse_xli_closeactiverstream (xli);
|
2013-07-11 16:55:08 +00:00
|
|
|
qse_str_clear (xli->tok.name);
|
2013-02-05 15:04:15 +00:00
|
|
|
return 0;
|
2013-02-06 14:31:32 +00:00
|
|
|
|
|
|
|
oops:
|
|
|
|
/* an error occurred and control has reached here
|
|
|
|
* probably, some included files might not have been
|
|
|
|
* closed. close them */
|
2013-06-29 17:01:32 +00:00
|
|
|
while (xli->rio.inp != &xli->rio.top)
|
2013-02-06 14:31:32 +00:00
|
|
|
{
|
2013-05-15 12:05:24 +00:00
|
|
|
qse_xli_io_arg_t* prev;
|
2013-02-06 14:31:32 +00:00
|
|
|
|
|
|
|
/* nothing much to do about a close error */
|
2015-09-02 01:27:08 +00:00
|
|
|
qse_xli_closeactiverstream (xli);
|
2013-02-06 14:31:32 +00:00
|
|
|
|
2013-06-29 17:01:32 +00:00
|
|
|
prev = xli->rio.inp->prev;
|
|
|
|
QSE_ASSERT (xli->rio.inp->name != QSE_NULL);
|
2019-06-24 14:24:14 +00:00
|
|
|
qse_xli_freemem (xli, xli->rio.inp);
|
2013-06-29 17:01:32 +00:00
|
|
|
xli->rio.inp = prev;
|
2013-02-06 14:31:32 +00:00
|
|
|
}
|
|
|
|
|
2015-09-02 01:27:08 +00:00
|
|
|
qse_xli_closeactiverstream (xli);
|
2013-07-11 16:55:08 +00:00
|
|
|
qse_str_clear (xli->tok.name);
|
2013-02-06 14:31:32 +00:00
|
|
|
return -1;
|
2013-02-05 15:04:15 +00:00
|
|
|
}
|