text
stringlengths 0
14.1k
|
---|
[T_CLOSE_LIST] = S_PARENT }, |
[S_DICT_KEY] = { |
[T_STRING] = S_DICT_COLON }, |
[S_DICT_KEY_OR_CLOSE] = { |
[T_STRING] = S_DICT_COLON, |
[T_CLOSE_DICT] = S_PARENT }, |
[S_DICT_COLON] = { |
[T_COLON] = S_DICT_VALUE }, |
[S_DICT_VALUE] = { |
[T_OPEN_LIST] = S_LIST_VALUE_OR_CLOSE, |
[T_OPEN_DICT] = S_DICT_KEY_OR_CLOSE, |
[T_STRING] = S_DICT_COMMA_OR_CLOSE, |
[T_OTHER] = S_DICT_COMMA_OR_CLOSE }, |
[S_DICT_COMMA_OR_CLOSE] = { |
[T_COMMA] = S_DICT_KEY, |
[T_CLOSE_DICT] = S_PARENT }, |
}; |
#define MAPSTATE(state, tok) do { \ |
int newstate = STATE_STEPS[state][tok]; \ |
if (!newstate) \ |
return err_false(ctx, ""Unexpected symbol: '%c'"", c); \ |
state = newstate; \ |
} while (0) |
/* actual parser */ |
static bool parse_tokens(struct JsonContext *ctx, const char *src, const char *end) |
{ |
char c; |
enum ParseState state = S_INITIAL_VALUE; |
bool relaxed = ctx->options & JSON_PARSE_RELAXED; |
while (src < end) { |
c = *src++; |
switch (c) { |
case '\n': |
ctx->linenr++; |
case ' ': case '\t': case '\r': case '\f': case '\v': |
/* common case - many spaces */ |
while (src < end && *src == ' ') src++; |
break; |
case '""': |
MAPSTATE(state, T_STRING); |
if (!parse_string(ctx, &src, end)) |
goto failed; |
break; |
case 'n': |
MAPSTATE(state, T_OTHER); |
src--; |
if (!parse_char4(ctx, &src, end, C_NULL, JSON_NULL, 0)) |
goto failed; |
continue; |
case 't': |
MAPSTATE(state, T_OTHER); |
src--; |
if (!parse_char4(ctx, &src, end, C_TRUE, JSON_BOOL, 1)) |
goto failed; |
break; |
case 'f': |
MAPSTATE(state, T_OTHER); |
if (!parse_char4(ctx, &src, end, C_ALSE, JSON_BOOL, 0)) |
goto failed; |
break; |
case '-': |
case '0': case '1': case '2': case '3': case '4': |
case '5': case '6': case '7': case '8': case '9': |
MAPSTATE(state, T_OTHER); |
src--; |
if (!parse_number(ctx, &src, end)) |
goto failed; |
break; |
case '[': |
MAPSTATE(state, T_OPEN_LIST); |
if (!open_container(ctx, JSON_LIST, LIST_EXTRA)) |
goto failed; |
break; |
case '{': |
MAPSTATE(state, T_OPEN_DICT); |
if (!open_container(ctx, JSON_DICT, DICT_EXTRA)) |
goto failed; |
break; |
case ']': |
MAPSTATE(state, T_CLOSE_LIST); |
state = close_container(ctx, state); |
if (!state) |
goto failed; |
break; |
case '}': |
MAPSTATE(state, T_CLOSE_DICT); |
state = close_container(ctx, state); |
if (!state) |
goto failed; |
break; |
case ':': |
MAPSTATE(state, T_COLON); |
if (!real_dict_add_key(ctx, ctx->parent, ctx->cur_key)) |
goto failed; |
break; |
case ',': |
if (relaxed && skip_extra_comma(ctx, &src, end, state)) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.