mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-11 14:01:49 +00:00
fixes
This commit is contained in:
parent
da190f3f7b
commit
84e8fd1af6
2 changed files with 29 additions and 3 deletions
|
|
@ -115,7 +115,7 @@ Parser::Parser(std::string filename, std::string source)
|
||||||
}
|
}
|
||||||
|
|
||||||
xmlelement Parser::parseOpenTag() {
|
xmlelement Parser::parseOpenTag() {
|
||||||
std::string tag = parseName();
|
std::string tag = parseXMLName();
|
||||||
auto node = std::make_shared<Node>(tag);
|
auto node = std::make_shared<Node>(tag);
|
||||||
|
|
||||||
char c;
|
char c;
|
||||||
|
|
@ -124,7 +124,7 @@ xmlelement Parser::parseOpenTag() {
|
||||||
c = peek();
|
c = peek();
|
||||||
if (c == '/' || c == '>' || c == '?')
|
if (c == '/' || c == '>' || c == '?')
|
||||||
break;
|
break;
|
||||||
std::string attrname = parseName();
|
std::string attrname = parseXMLName();
|
||||||
std::string attrtext = "";
|
std::string attrtext = "";
|
||||||
skipWhitespace();
|
skipWhitespace();
|
||||||
if (peek() == '=') {
|
if (peek() == '=') {
|
||||||
|
|
@ -181,6 +181,26 @@ std::string Parser::parseText() {
|
||||||
return source.substr(start, pos-start);
|
return source.substr(start, pos-start);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool is_xml_identifier_start(char c) {
|
||||||
|
return is_identifier_start(c) || c == ':';
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool is_xml_identifier_part(char c) {
|
||||||
|
return is_identifier_part(c) || c == '-' || c == '.' || c == ':';
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Parser::parseXMLName() {
|
||||||
|
char c = peek();
|
||||||
|
if (!is_xml_identifier_start(c)) {
|
||||||
|
throw error("identifier expected");
|
||||||
|
}
|
||||||
|
int start = pos;
|
||||||
|
while (hasNext() && is_xml_identifier_part(source[pos])) {
|
||||||
|
pos++;
|
||||||
|
}
|
||||||
|
return source.substr(start, pos-start);
|
||||||
|
}
|
||||||
|
|
||||||
xmlelement Parser::parseElement() {
|
xmlelement Parser::parseElement() {
|
||||||
// text element
|
// text element
|
||||||
if (peek() != '<') {
|
if (peek() != '<') {
|
||||||
|
|
@ -235,7 +255,12 @@ xmlelement Parser::parseElement() {
|
||||||
|
|
||||||
xmldocument Parser::parse() {
|
xmldocument Parser::parse() {
|
||||||
parseDeclaration();
|
parseDeclaration();
|
||||||
document->setRoot(parseElement());
|
|
||||||
|
xmlelement root = nullptr;
|
||||||
|
while (root == nullptr) {
|
||||||
|
root = parseElement();
|
||||||
|
}
|
||||||
|
document->setRoot(root);
|
||||||
return document;
|
return document;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,7 @@ namespace xml {
|
||||||
void parseDeclaration();
|
void parseDeclaration();
|
||||||
void parseComment();
|
void parseComment();
|
||||||
std::string parseText();
|
std::string parseText();
|
||||||
|
std::string parseXMLName();
|
||||||
public:
|
public:
|
||||||
Parser(std::string filename, std::string source);
|
Parser(std::string filename, std::string source);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue