From 4e367a4b7b5daea2f6586ee4192d2e5b813d75d8 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Thu, 7 Jan 2016 09:04:44 -0300 Subject: -fix bugs related to parsing config files with new variantparser, closes #3248 closes #3207 --- core/io/config_file.cpp | 4 ++++ core/variant_parser.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- core/variant_parser.h | 1 + 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index f32d006cba..a01e935baa 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -173,6 +173,10 @@ Error ConfigFile::load(const String& p_path) { while(true) { + assign=Variant(); + next_tag.fields.clear(); + next_tag.name=String(); + err = VariantParser::parse_tag_assign_eof(&stream,lines,error_text,next_tag,assign,value,NULL); if (err==ERR_FILE_EOF) return OK; diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp index 9a494b4d57..43140a672b 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; @@ -1361,6 +1367,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 { @@ -1571,6 +1599,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 +1612,13 @@ 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 { + parsing_tag=false; + } + if (token.type!=TK_IDENTIFIER) { r_err_str="Expected Identifier"; return ERR_PARSE_ERROR; @@ -1590,10 +1626,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; } diff --git a/core/variant_parser.h b/core/variant_parser.h index 16d576a6b4..0912271537 100644 --- a/core/variant_parser.h +++ b/core/variant_parser.h @@ -69,6 +69,7 @@ public: TK_COLOR, TK_COLON, TK_COMMA, + TK_PERIOD, TK_EQUAL, TK_EOF, TK_ERROR, -- cgit v1.2.3