return qdict_get_int(qobject_to_qdict(obj), "type");
}
-static int token_is_operator(QObject *obj, char op)
-{
- const char *val;
-
- if (token_get_type(obj) != JSON_OPERATOR) {
- return 0;
- }
-
- val = token_get_value(obj);
-
- return (val[0] == op) && (val[1] == 0);
-}
-
static int token_is_keyword(QObject *obj, const char *value)
{
if (token_get_type(obj) != JSON_KEYWORD) {
goto out;
}
- if (!token_is_operator(token, ':')) {
+ if (token_get_type(token) != JSON_COLON) {
parse_error(ctxt, token, "missing : in object pair");
goto out;
}
goto out;
}
- if (!token_is_operator(token, '{')) {
+ if (token_get_type(token) != JSON_LCURLY) {
goto out;
}
goto out;
}
- if (!token_is_operator(peek, '}')) {
+ if (token_get_type(peek) != JSON_RCURLY) {
if (parse_pair(ctxt, dict, ap) == -1) {
goto out;
}
goto out;
}
- while (!token_is_operator(token, '}')) {
- if (!token_is_operator(token, ',')) {
+ while (token_get_type(token) != JSON_RCURLY) {
+ if (token_get_type(token) != JSON_COMMA) {
parse_error(ctxt, token, "expected separator in dict");
goto out;
}
goto out;
}
- if (!token_is_operator(token, '[')) {
+ if (token_get_type(token) != JSON_LSQUARE) {
goto out;
}
goto out;
}
- if (!token_is_operator(peek, ']')) {
+ if (token_get_type(peek) != JSON_RSQUARE) {
QObject *obj;
obj = parse_value(ctxt, ap);
goto out;
}
- while (!token_is_operator(token, ']')) {
- if (!token_is_operator(token, ',')) {
+ while (token_get_type(token) != JSON_RSQUARE) {
+ if (token_get_type(token) != JSON_COMMA) {
parse_error(ctxt, token, "expected separator in list");
goto out;
}
JSONMessageParser *parser = container_of(lexer, JSONMessageParser, lexer);
QDict *dict;
- if (type == JSON_OPERATOR) {
- switch (qstring_get_str(token)[0]) {
- case '{':
- parser->brace_count++;
- break;
- case '}':
- parser->brace_count--;
- break;
- case '[':
- parser->bracket_count++;
- break;
- case ']':
- parser->bracket_count--;
- break;
- default:
- break;
- }
+ switch (type) {
+ case JSON_LCURLY:
+ parser->brace_count++;
+ break;
+ case JSON_RCURLY:
+ parser->brace_count--;
+ break;
+ case JSON_LSQUARE:
+ parser->bracket_count++;
+ break;
+ case JSON_RSQUARE:
+ parser->bracket_count--;
+ break;
+ default:
+ break;
}
dict = qdict_new();