XMLParser: Implement support for short tag endings

This commit is contained in:
mrkubax10 2023-08-14 21:51:14 +02:00
parent 84d93d21ea
commit 7b6ac65d6a
2 changed files with 22 additions and 13 deletions

View File

@ -25,17 +25,17 @@ SOFTWARE.
<gui>
<box x="right" y="bottom" width="250" height="200" right_margin="8" bottom_margin="8" tr_text="Main Menu" layout="horizontal">
<container width="50%" height="100%" layout="vertical">
<label width="100%" height="25" tr_text="Nickname"></label>
<label width="100%" height="25" tr_text="Server"></label>
<label width="100%" height="25" tr_text="Port"></label>
<button width="50%" height="30" id="button_join" tr_text="Join"></button>
<label width="100%" height="25" tr_text="Nickname" />
<label width="100%" height="25" tr_text="Server" />
<label width="100%" height="25" tr_text="Port" />
<button width="50%" height="30" id="button_join" tr_text="Join" />
<!-- Note: Caption of button_host is set in code -->
<button width="50%" height="30" id="button_host"></button>
<button width="50%" height="30" id="button_host" />
</container>
<container width="45%" height="100%" layout="vertical">
<text_edit width="97%" height="25" id="text_edit_nickname"></text_edit>
<text_edit width="97%" height="25" id="text_edit_server"></text_edit>
<text_edit width="97%" height="25" id="text_edit_port"></text_edit>
<text_edit width="97%" height="25" id="text_edit_nickname" />
<text_edit width="97%" height="25" id="text_edit_server" />
<text_edit width="97%" height="25" id="text_edit_port" />
</container>
</box>
</gui>

View File

@ -48,13 +48,22 @@ bool polygun::xml::parse(std::istream& stream, XMLNode*& output) {
node_stack.push_back(temp_node);
node_stack.back()->set_name(tokens[offset].m_data);
while(++offset<tokens.size() && tokens[offset].m_type!=XMLToken::XML_TOKEN_TYPE_RBRACKET) {
const XMLToken& key = tokens[offset++];
const XMLToken& key_or_tag_end = tokens[offset++];
if(offset>=tokens.size()) {
LOG_ERROR("Unexpected end of input after %s token at %zu:%zu", key.get_string_name().c_str(), key.m_line, key.m_column);
LOG_ERROR("Unexpected end of input after %s token at %zu:%zu", key_or_tag_end.get_string_name().c_str(), key_or_tag_end.m_line, key_or_tag_end.m_column);
return false;
}
if(key.m_type!=XMLToken::XML_TOKEN_TYPE_IDENTIFIER){
LOG_ERROR("Expected IDENTIFIER at %zu:%zu", key.m_line, key.m_column);
if(key_or_tag_end.m_type==XMLToken::XML_TOKEN_TYPE_SLASH) {
const XMLToken& rbracket = tokens[offset];
if(rbracket.m_type!=XMLToken::XML_TOKEN_TYPE_RBRACKET) {
LOG_ERROR("Expected RBRACKET at %zu:%zu (found %s)", rbracket.m_line, rbracket.m_column, rbracket.get_string_name().c_str());
return false;
}
node_stack.pop_back();
break;
}
if(key_or_tag_end.m_type!=XMLToken::XML_TOKEN_TYPE_IDENTIFIER){
LOG_ERROR("Expected IDENTIFIER at %zu:%zu", key_or_tag_end.m_line, key_or_tag_end.m_column);
return false;
}
const XMLToken& equals = tokens[offset++];
@ -75,7 +84,7 @@ bool polygun::xml::parse(std::istream& stream, XMLNode*& output) {
LOG_ERROR("Expected STRING at %zu:%zu", str.m_line, str.m_column);
return false;
}
node_stack.back()->add_attribute(key.m_data, str.m_data);
node_stack.back()->add_attribute(key_or_tag_end.m_data, str.m_data);
}
offset++;
}