summaryrefslogtreecommitdiff
path: root/core/variant_parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/variant_parser.cpp')
-rw-r--r--core/variant_parser.cpp97
1 files changed, 85 insertions, 12 deletions
diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp
index 9a494b4d57..3efa87de80 100644
--- a/core/variant_parser.cpp
+++ b/core/variant_parser.cpp
@@ -52,6 +52,7 @@ const char * VariantParser::tk_name[TK_MAX] = {
"color",
"':'",
"','",
+ "'.'",
"'='",
"EOF",
"ERROR"
@@ -140,6 +141,11 @@ Error VariantParser::get_token(Stream *p_stream, Token& r_token, int &line, Stri
r_token.type=TK_COMMA;
return OK;
};
+ case '.': {
+
+ r_token.type=TK_PERIOD;
+ return OK;
+ };
case '=': {
r_token.type=TK_EQUAL;
@@ -442,7 +448,7 @@ Error VariantParser::_parse_construct(Stream *p_stream,Vector<T>& r_construct,in
if (!first) {
get_token(p_stream,token,line,r_err_str);
if (token.type==TK_COMMA) {
- //do none
+ //do none
} else if (token.type==TK_PARENTHESIS_CLOSE) {
break;
} else {
@@ -452,7 +458,10 @@ Error VariantParser::_parse_construct(Stream *p_stream,Vector<T>& r_construct,in
}
}
get_token(p_stream,token,line,r_err_str);
- if (token.type!=TK_NUMBER) {
+
+ if (first && token.type==TK_PARENTHESIS_CLOSE) {
+ break;
+ } else if (token.type!=TK_NUMBER) {
r_err_str="Expected float in constructor";
return ERR_PARSE_ERROR;
}
@@ -1183,7 +1192,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
get_token(p_stream,token,line,r_err_str);
if (token.type==TK_COMMA) {
//do none
- } else if (token.type!=TK_PARENTHESIS_CLOSE) {
+ } else if (token.type==TK_PARENTHESIS_CLOSE) {
break;
} else {
r_err_str="Expected ',' or ')'";
@@ -1192,11 +1201,13 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
}
}
get_token(p_stream,token,line,r_err_str);
+
if (token.type!=TK_STRING) {
- r_err_str="Expected string";
+ r_err_str="Expected string";
return ERR_PARSE_ERROR;
}
+ first=false;
cs.push_back(token.value);
}
@@ -1362,6 +1373,28 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in
value= ie;
return OK;
+ } else if (id=="img") { // compatibility with engine.cfg
+
+ Token token;
+ get_token(p_stream,token,line,r_err_str);
+ if (token.type!=TK_PARENTHESIS_OPEN) {
+ r_err_str="Expected '(' in old-style engine.cfg construct";
+ return ERR_PARSE_ERROR;
+ }
+
+ while(true) {
+ CharType c = p_stream->get_char();
+ if (p_stream->is_eof()) {
+ r_err_str="Unexpected EOF in old style engine.cfg img()";
+ return ERR_PARSE_ERROR;
+ }
+ if (c==')')
+ break;
+ }
+
+ value=Image();
+
+ return OK;
} else {
r_err_str="Unexpected identifier: '"+id+"'.";
@@ -1552,7 +1585,7 @@ Error VariantParser::_parse_dictionary(Dictionary &object, Stream *p_stream, int
}
-Error VariantParser::_parse_tag(Token& token, Stream *p_stream, int &line, String &r_err_str, Tag& r_tag, ResourceParser *p_res_parser) {
+Error VariantParser::_parse_tag(Token& token, Stream *p_stream, int &line, String &r_err_str, Tag& r_tag, ResourceParser *p_res_parser,bool p_simple_tag) {
r_tag.fields.clear();
@@ -1562,6 +1595,29 @@ Error VariantParser::_parse_tag(Token& token, Stream *p_stream, int &line, Strin
}
+ if (p_simple_tag) {
+
+ r_tag.name="";
+ r_tag.fields.clear();
+
+ while(true) {
+
+ CharType c = p_stream->get_char();
+ if (p_stream->is_eof()) {
+ r_err_str="Unexpected EOF while parsing simple tag";
+ return ERR_PARSE_ERROR;
+ }
+ if (c==']')
+ break;
+ r_tag.name+=String::chr(c);
+ }
+
+ r_tag.name = r_tag.name.strip_edges();
+
+ return OK;
+
+ }
+
get_token(p_stream,token,line,r_err_str);
@@ -1571,6 +1627,7 @@ Error VariantParser::_parse_tag(Token& token, Stream *p_stream, int &line, Strin
}
r_tag.name=token.value;
+ bool parsing_tag=true;
while(true) {
@@ -1583,6 +1640,16 @@ Error VariantParser::_parse_tag(Token& token, Stream *p_stream, int &line, Strin
if (token.type==TK_BRACKET_CLOSE)
break;
+ if (parsing_tag && token.type==TK_PERIOD) {
+ r_tag.name+="."; //support tags such as [someprop.Anroid] for specific platforms
+ get_token(p_stream,token,line,r_err_str);
+ } else if (parsing_tag && token.type==TK_COLON) {
+ r_tag.name+=":"; //support tags such as [someprop.Anroid] for specific platforms
+ get_token(p_stream,token,line,r_err_str);
+ } else {
+ parsing_tag=false;
+ }
+
if (token.type!=TK_IDENTIFIER) {
r_err_str="Expected Identifier";
return ERR_PARSE_ERROR;
@@ -1590,10 +1657,13 @@ Error VariantParser::_parse_tag(Token& token, Stream *p_stream, int &line, Strin
String id=token.value;
+ if (parsing_tag) {
+ r_tag.name+=id;
+ continue;
+ }
get_token(p_stream,token,line,r_err_str);
if (token.type!=TK_EQUAL) {
- r_err_str="Expected '='";
return ERR_PARSE_ERROR;
}
@@ -1612,7 +1682,7 @@ Error VariantParser::_parse_tag(Token& token, Stream *p_stream, int &line, Strin
}
-Error VariantParser::parse_tag(Stream *p_stream, int &line, String &r_err_str, Tag& r_tag, ResourceParser *p_res_parser) {
+Error VariantParser::parse_tag(Stream *p_stream, int &line, String &r_err_str, Tag& r_tag, ResourceParser *p_res_parser, bool p_simple_tag) {
Token token;
get_token(p_stream,token,line,r_err_str);
@@ -1626,11 +1696,11 @@ Error VariantParser::parse_tag(Stream *p_stream, int &line, String &r_err_str, T
return ERR_PARSE_ERROR;
}
- return _parse_tag(token,p_stream,line,r_err_str,r_tag,p_res_parser);
+ return _parse_tag(token,p_stream,line,r_err_str,r_tag,p_res_parser,p_simple_tag);
}
-Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r_err_str, Tag& r_tag, String &r_assign, Variant &r_value, ResourceParser *p_res_parser) {
+Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r_err_str, Tag& r_tag, String &r_assign, Variant &r_value, ResourceParser *p_res_parser, bool p_simple_tag) {
//assign..
@@ -1668,7 +1738,7 @@ Error VariantParser::parse_tag_assign_eof(Stream *p_stream, int &line, String &r
//it's a tag!
p_stream->saved='['; //go back one
- Error err = parse_tag(p_stream,line,r_err_str,r_tag,p_res_parser);
+ Error err = parse_tag(p_stream,line,r_err_str,r_tag,p_res_parser,p_simple_tag);
return err;
}
@@ -1734,7 +1804,10 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
} break;
case Variant::REAL: {
- p_store_string_func(p_store_string_ud, rtoss(p_variant.operator real_t()) );
+ String s = rtoss(p_variant.operator real_t());
+ if (s.find(".")==-1 && s.find("e")==-1)
+ s+=".0";
+ p_store_string_func(p_store_string_ud, s );
} break;
case Variant::STRING: {
@@ -2053,7 +2126,7 @@ Error VariantWriter::write(const Variant& p_variant, StoreStringFunc p_store_str
if (i>0)
p_store_string_func(p_store_string_ud,", ");
String str=ptr[i];
- p_store_string_func(p_store_string_ud,""+str.c_escape()+"\"");
+ p_store_string_func(p_store_string_ud,"\""+str.c_escape()+"\"");
}
p_store_string_func(p_store_string_ud," )");