summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2016-01-08 19:00:45 -0300
committerJuan Linietsky <reduzio@gmail.com>2016-01-08 19:03:17 -0300
commit176afb2feb7ed235bf9d7528ee3e8af092f12f90 (patch)
tree8519cfbd86626bbdb4969f6893e2ab1d6debab61 /core
parente291294c7981f108dbb8658976b109df1850d303 (diff)
-Use simpler methods for parsing simple tags, fixes #3274
Diffstat (limited to 'core')
-rw-r--r--core/io/config_file.cpp2
-rw-r--r--core/variant_parser.cpp33
-rw-r--r--core/variant_parser.h6
3 files changed, 32 insertions, 9 deletions
diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp
index a01e935baa..d79a3d1288 100644
--- a/core/io/config_file.cpp
+++ b/core/io/config_file.cpp
@@ -177,7 +177,7 @@ Error ConfigFile::load(const String& p_path) {
next_tag.fields.clear();
next_tag.name=String();
- err = VariantParser::parse_tag_assign_eof(&stream,lines,error_text,next_tag,assign,value,NULL);
+ err = VariantParser::parse_tag_assign_eof(&stream,lines,error_text,next_tag,assign,value,NULL,true);
if (err==ERR_FILE_EOF)
return OK;
else if (err!=OK) {
diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp
index 5ca0984103..e7fbbba548 100644
--- a/core/variant_parser.cpp
+++ b/core/variant_parser.cpp
@@ -1580,7 +1580,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();
@@ -1590,6 +1590,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);
@@ -1654,7 +1677,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);
@@ -1668,11 +1691,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..
@@ -1710,7 +1733,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;
}
diff --git a/core/variant_parser.h b/core/variant_parser.h
index 0912271537..00f6910b29 100644
--- a/core/variant_parser.h
+++ b/core/variant_parser.h
@@ -104,12 +104,12 @@ private:
static Error _parse_enginecfg(Stream *p_stream, Vector<String>& strings, int &line, String &r_err_str);
static Error _parse_dictionary(Dictionary &object, Stream *p_stream, int &line, String &r_err_str,ResourceParser *p_res_parser=NULL);
static Error _parse_array(Array &array, Stream *p_stream, int &line, String &r_err_str,ResourceParser *p_res_parser=NULL);
- static Error _parse_tag(Token& token,Stream *p_stream, int &line, String &r_err_str,Tag& r_tag,ResourceParser *p_res_parser=NULL);
+ static Error _parse_tag(Token& token,Stream *p_stream, int &line, String &r_err_str,Tag& r_tag,ResourceParser *p_res_parser=NULL,bool p_simple_tag=false);
public:
- static Error parse_tag(Stream *p_stream, int &line, String &r_err_str,Tag& r_tag,ResourceParser *p_res_parser=NULL);
- static Error 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=NULL);
+ static Error parse_tag(Stream *p_stream, int &line, String &r_err_str,Tag& r_tag,ResourceParser *p_res_parser=NULL,bool p_simple_tag=false);
+ static Error 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=NULL,bool p_simple_tag=false);
static Error parse_value(Token& token,Variant &value, Stream *p_stream, int &line, String &r_err_str,ResourceParser *p_res_parser=NULL);
static Error get_token(Stream *p_stream,Token& r_token,int &line,String &r_err_str);