2016-06-18 12:46:12 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* variant_construct_string.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 21:01:57 +00:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-07 22:45:00 +00:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2016-06-18 12:46:12 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2015-02-15 04:19:46 +00:00
|
|
|
#include "variant.h"
|
|
|
|
|
|
|
|
class VariantConstruct {
|
|
|
|
|
|
|
|
enum TokenType {
|
|
|
|
TK_CURLY_BRACKET_OPEN,
|
|
|
|
TK_CURLY_BRACKET_CLOSE,
|
|
|
|
TK_BRACKET_OPEN,
|
|
|
|
TK_BRACKET_CLOSE,
|
|
|
|
TK_IDENTIFIER,
|
|
|
|
TK_STRING,
|
|
|
|
TK_NUMBER,
|
|
|
|
TK_COLON,
|
|
|
|
TK_COMMA,
|
|
|
|
TK_EOF,
|
|
|
|
TK_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Expecting {
|
|
|
|
|
|
|
|
EXPECT_OBJECT,
|
|
|
|
EXPECT_OBJECT_KEY,
|
|
|
|
EXPECT_COLON,
|
|
|
|
EXPECT_OBJECT_VALUE,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Token {
|
|
|
|
|
|
|
|
TokenType type;
|
|
|
|
Variant value;
|
|
|
|
};
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
static const char *tk_name[TK_MAX];
|
2015-02-15 04:19:46 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
static String _print_var(const Variant &p_var);
|
2015-02-15 04:19:46 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
static Error _get_token(const CharType *p_str, int &index, int p_len, Token &r_token, int &line, String &r_err_str);
|
|
|
|
static Error _parse_value(Variant &value, Token &token, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str, Variant::ObjectConstruct *p_construct, void *p_ud);
|
|
|
|
static Error _parse_array(Array &array, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str, Variant::ObjectConstruct *p_construct, void *p_ud);
|
|
|
|
static Error _parse_dict(Dictionary &object, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str, Variant::ObjectConstruct *p_construct, void *p_ud);
|
2015-02-15 04:19:46 +00:00
|
|
|
|
|
|
|
public:
|
2017-03-18 23:36:26 +00:00
|
|
|
static Error parse(const String &p_string, Variant &r_ret, String &r_err_str, int &r_err_line, Variant::ObjectConstruct *p_construct, void *p_ud);
|
2015-02-15 04:19:46 +00:00
|
|
|
};
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const char *VariantConstruct::tk_name[TK_MAX] = {
|
2015-02-15 04:19:46 +00:00
|
|
|
"'{'",
|
|
|
|
"'}'",
|
|
|
|
"'['",
|
|
|
|
"']'",
|
|
|
|
"identifier",
|
|
|
|
"string",
|
|
|
|
"number",
|
|
|
|
"':'",
|
|
|
|
"','",
|
|
|
|
"EOF",
|
|
|
|
};
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error VariantConstruct::_get_token(const CharType *p_str, int &idx, int p_len, Token &r_token, int &line, String &r_err_str) {
|
2015-02-15 04:19:46 +00:00
|
|
|
|
|
|
|
while (true) {
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (p_str[idx]) {
|
2015-02-15 04:19:46 +00:00
|
|
|
|
|
|
|
case '\n': {
|
|
|
|
|
|
|
|
line++;
|
|
|
|
idx++;
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
case 0: {
|
2017-03-18 23:36:26 +00:00
|
|
|
r_token.type = TK_EOF;
|
2015-02-15 04:19:46 +00:00
|
|
|
return OK;
|
|
|
|
} break;
|
|
|
|
case '{': {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_token.type = TK_CURLY_BRACKET_OPEN;
|
2015-02-15 04:19:46 +00:00
|
|
|
idx++;
|
|
|
|
return OK;
|
|
|
|
};
|
|
|
|
case '}': {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_token.type = TK_CURLY_BRACKET_CLOSE;
|
2015-02-15 04:19:46 +00:00
|
|
|
idx++;
|
|
|
|
return OK;
|
|
|
|
};
|
|
|
|
case '[': {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_token.type = TK_BRACKET_OPEN;
|
2015-02-15 04:19:46 +00:00
|
|
|
idx++;
|
|
|
|
return OK;
|
|
|
|
};
|
|
|
|
case ']': {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_token.type = TK_BRACKET_CLOSE;
|
2015-02-15 04:19:46 +00:00
|
|
|
idx++;
|
|
|
|
return OK;
|
|
|
|
};
|
|
|
|
case ':': {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_token.type = TK_COLON;
|
2015-02-15 04:19:46 +00:00
|
|
|
idx++;
|
|
|
|
return OK;
|
|
|
|
};
|
|
|
|
case ',': {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_token.type = TK_COMMA;
|
2015-02-15 04:19:46 +00:00
|
|
|
idx++;
|
|
|
|
return OK;
|
|
|
|
};
|
|
|
|
case '"': {
|
|
|
|
|
|
|
|
idx++;
|
|
|
|
String str;
|
2017-03-18 23:36:26 +00:00
|
|
|
while (true) {
|
|
|
|
if (p_str[idx] == 0) {
|
|
|
|
r_err_str = "Unterminated String";
|
2015-02-15 04:19:46 +00:00
|
|
|
return ERR_PARSE_ERROR;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (p_str[idx] == '"') {
|
2015-02-15 04:19:46 +00:00
|
|
|
idx++;
|
|
|
|
break;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (p_str[idx] == '\\') {
|
2015-02-15 04:19:46 +00:00
|
|
|
//escaped characters...
|
|
|
|
idx++;
|
|
|
|
CharType next = p_str[idx];
|
2017-03-18 23:36:26 +00:00
|
|
|
if (next == 0) {
|
|
|
|
r_err_str = "Unterminated String";
|
|
|
|
return ERR_PARSE_ERROR;
|
2015-02-15 04:19:46 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
CharType res = 0;
|
|
|
|
|
|
|
|
switch (next) {
|
|
|
|
|
|
|
|
case 'b': res = 8; break;
|
|
|
|
case 't': res = 9; break;
|
|
|
|
case 'n': res = 10; break;
|
|
|
|
case 'f': res = 12; break;
|
|
|
|
case 'r': res = 13; break;
|
|
|
|
case '\"': res = '\"'; break;
|
|
|
|
case '\\': res = '\\'; break;
|
|
|
|
case '/': res = '/'; break;
|
2015-02-15 04:19:46 +00:00
|
|
|
case 'u': {
|
|
|
|
//hexnumbarh - oct is deprecated
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int j = 0; j < 4; j++) {
|
|
|
|
CharType c = p_str[idx + j + 1];
|
|
|
|
if (c == 0) {
|
|
|
|
r_err_str = "Unterminated String";
|
2015-02-15 04:19:46 +00:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) {
|
2015-02-15 04:19:46 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_err_str = "Malformed hex constant in string";
|
2015-02-15 04:19:46 +00:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
CharType v;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (c >= '0' && c <= '9') {
|
|
|
|
v = c - '0';
|
|
|
|
} else if (c >= 'a' && c <= 'f') {
|
|
|
|
v = c - 'a';
|
|
|
|
v += 10;
|
|
|
|
} else if (c >= 'A' && c <= 'F') {
|
|
|
|
v = c - 'A';
|
|
|
|
v += 10;
|
2015-02-15 04:19:46 +00:00
|
|
|
} else {
|
|
|
|
ERR_PRINT("BUG");
|
2017-03-18 23:36:26 +00:00
|
|
|
v = 0;
|
2015-02-15 04:19:46 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
res <<= 4;
|
|
|
|
res |= v;
|
2015-02-15 04:19:46 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
idx += 4; //will add at the end anyway
|
2015-02-15 04:19:46 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
default: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_err_str = "Invalid escape sequence";
|
2015-02-15 04:19:46 +00:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
str += res;
|
2015-02-15 04:19:46 +00:00
|
|
|
|
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_str[idx] == '\n')
|
2015-02-15 04:19:46 +00:00
|
|
|
line++;
|
2017-03-18 23:36:26 +00:00
|
|
|
str += p_str[idx];
|
2015-02-15 04:19:46 +00:00
|
|
|
}
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_token.type = TK_STRING;
|
|
|
|
r_token.value = str;
|
2015-02-15 04:19:46 +00:00
|
|
|
return OK;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
default: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_str[idx] <= 32) {
|
2015-02-15 04:19:46 +00:00
|
|
|
idx++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_str[idx] == '-' || (p_str[idx] >= '0' && p_str[idx] <= '9')) {
|
2015-02-15 04:19:46 +00:00
|
|
|
//a number
|
|
|
|
const CharType *rptr;
|
2017-03-18 23:36:26 +00:00
|
|
|
double number = String::to_double(&p_str[idx], &rptr);
|
|
|
|
idx += (rptr - &p_str[idx]);
|
|
|
|
r_token.type = TK_NUMBER;
|
|
|
|
r_token.value = number;
|
2015-02-15 04:19:46 +00:00
|
|
|
return OK;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if ((p_str[idx] >= 'A' && p_str[idx] <= 'Z') || (p_str[idx] >= 'a' && p_str[idx] <= 'z')) {
|
2015-02-15 04:19:46 +00:00
|
|
|
|
|
|
|
String id;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while ((p_str[idx] >= 'A' && p_str[idx] <= 'Z') || (p_str[idx] >= 'a' && p_str[idx] <= 'z')) {
|
2015-02-15 04:19:46 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
id += p_str[idx];
|
2015-02-15 04:19:46 +00:00
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_token.type = TK_IDENTIFIER;
|
|
|
|
r_token.value = id;
|
2015-02-15 04:19:46 +00:00
|
|
|
return OK;
|
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
r_err_str = "Unexpected character.";
|
2015-02-15 04:19:46 +00:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error VariantConstruct::_parse_value(Variant &value, Token &token, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str, Variant::ObjectConstruct *p_construct, void *p_ud) {
|
2015-02-15 04:19:46 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (token.type == TK_CURLY_BRACKET_OPEN) {
|
2015-02-15 04:19:46 +00:00
|
|
|
|
|
|
|
Dictionary d;
|
2017-03-18 23:36:26 +00:00
|
|
|
Error err = _parse_dict(d, p_str, index, p_len, line, r_err_str, p_construct, p_ud);
|
2015-02-15 04:19:46 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
2017-03-18 23:36:26 +00:00
|
|
|
value = d;
|
2015-02-15 04:19:46 +00:00
|
|
|
return OK;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (token.type == TK_BRACKET_OPEN) {
|
2015-02-15 04:19:46 +00:00
|
|
|
|
|
|
|
Array a;
|
2017-03-18 23:36:26 +00:00
|
|
|
Error err = _parse_array(a, p_str, index, p_len, line, r_err_str, p_construct, p_ud);
|
2015-02-15 04:19:46 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
2017-03-18 23:36:26 +00:00
|
|
|
value = a;
|
2015-02-15 04:19:46 +00:00
|
|
|
return OK;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (token.type == TK_IDENTIFIER) {
|
2015-02-15 04:19:46 +00:00
|
|
|
|
|
|
|
String id = token.value;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (id == "true")
|
|
|
|
value = true;
|
|
|
|
else if (id == "false")
|
|
|
|
value = false;
|
|
|
|
else if (id == "null")
|
|
|
|
value = Variant();
|
2015-02-15 04:19:46 +00:00
|
|
|
else {
|
2017-03-18 23:36:26 +00:00
|
|
|
r_err_str = "Expected 'true','false' or 'null', got '" + id + "'.";
|
2015-02-15 04:19:46 +00:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
return OK;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (token.type == TK_NUMBER) {
|
2015-02-15 04:19:46 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
value = token.value;
|
2015-02-15 04:19:46 +00:00
|
|
|
return OK;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (token.type == TK_STRING) {
|
2015-02-15 04:19:46 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
value = token.value;
|
2015-02-15 04:19:46 +00:00
|
|
|
return OK;
|
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
r_err_str = "Expected value, got " + String(tk_name[token.type]) + ".";
|
2015-02-15 04:19:46 +00:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error VariantConstruct::_parse_array(Array &array, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str, Variant::ObjectConstruct *p_construct, void *p_ud) {
|
2015-02-15 04:19:46 +00:00
|
|
|
|
|
|
|
Token token;
|
2017-03-18 23:36:26 +00:00
|
|
|
bool need_comma = false;
|
2015-02-15 04:19:46 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (index < p_len) {
|
2015-02-15 04:19:46 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error err = _get_token(p_str, index, p_len, token, line, r_err_str);
|
|
|
|
if (err != OK)
|
2015-02-15 04:19:46 +00:00
|
|
|
return err;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (token.type == TK_BRACKET_CLOSE) {
|
2015-02-15 04:19:46 +00:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_comma) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (token.type != TK_COMMA) {
|
2015-02-15 04:19:46 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_err_str = "Expected ','";
|
2015-02-15 04:19:46 +00:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
need_comma = false;
|
2015-02-15 04:19:46 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Variant v;
|
2017-03-18 23:36:26 +00:00
|
|
|
err = _parse_value(v, token, p_str, index, p_len, line, r_err_str, p_construct, p_ud);
|
2015-02-15 04:19:46 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
array.push_back(v);
|
2017-03-18 23:36:26 +00:00
|
|
|
need_comma = true;
|
2015-02-15 04:19:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error VariantConstruct::_parse_dict(Dictionary &dict, const CharType *p_str, int &index, int p_len, int &line, String &r_err_str, Variant::ObjectConstruct *p_construct, void *p_ud) {
|
2015-02-15 04:19:46 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool at_key = true;
|
2015-02-15 04:19:46 +00:00
|
|
|
Variant key;
|
|
|
|
Token token;
|
2017-03-18 23:36:26 +00:00
|
|
|
bool need_comma = false;
|
2015-02-15 04:19:46 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (index < p_len) {
|
2015-02-15 04:19:46 +00:00
|
|
|
|
|
|
|
if (at_key) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error err = _get_token(p_str, index, p_len, token, line, r_err_str);
|
|
|
|
if (err != OK)
|
2015-02-15 04:19:46 +00:00
|
|
|
return err;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (token.type == TK_CURLY_BRACKET_CLOSE) {
|
2015-02-15 04:19:46 +00:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_comma) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (token.type != TK_COMMA) {
|
2015-02-15 04:19:46 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_err_str = "Expected '}' or ','";
|
2015-02-15 04:19:46 +00:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
need_comma = false;
|
2015-02-15 04:19:46 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
err = _parse_value(key, token, p_str, index, p_len, line, r_err_str, p_construct, p_ud);
|
2015-02-15 04:19:46 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (err != OK)
|
2015-02-15 04:19:46 +00:00
|
|
|
return err;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
err = _get_token(p_str, index, p_len, token, line, r_err_str);
|
2015-02-15 04:19:46 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (err != OK)
|
2015-02-15 04:19:46 +00:00
|
|
|
return err;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (token.type != TK_COLON) {
|
2015-02-15 04:19:46 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_err_str = "Expected ':'";
|
2015-02-15 04:19:46 +00:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
at_key = false;
|
2015-02-15 04:19:46 +00:00
|
|
|
} else {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error err = _get_token(p_str, index, p_len, token, line, r_err_str);
|
|
|
|
if (err != OK)
|
2015-02-15 04:19:46 +00:00
|
|
|
return err;
|
|
|
|
|
|
|
|
Variant v;
|
2017-03-18 23:36:26 +00:00
|
|
|
err = _parse_value(v, token, p_str, index, p_len, line, r_err_str, p_construct, p_ud);
|
2015-02-15 04:19:46 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
2017-03-18 23:36:26 +00:00
|
|
|
dict[key] = v;
|
|
|
|
need_comma = true;
|
|
|
|
at_key = true;
|
2015-02-15 04:19:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error VariantConstruct::parse(const String &p_string, Variant &r_ret, String &r_err_str, int &r_err_line, Variant::ObjectConstruct *p_construct, void *p_ud) {
|
2015-02-15 04:19:46 +00:00
|
|
|
|
|
|
|
const CharType *str = p_string.ptr();
|
|
|
|
int idx = 0;
|
|
|
|
int len = p_string.length();
|
|
|
|
Token token;
|
2017-03-18 23:36:26 +00:00
|
|
|
r_err_line = 0;
|
2015-02-15 04:19:46 +00:00
|
|
|
String aux_key;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Error err = _get_token(str, idx, len, token, r_err_line, r_err_str);
|
2015-02-15 04:19:46 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return _parse_value(r_ret, token, str, idx, len, r_err_line, r_err_str, p_construct, p_ud);
|
2015-02-15 04:19:46 +00:00
|
|
|
}
|