Fixed some bugs and added parsing

This commit is contained in:
2023-06-16 15:48:33 -07:00
parent 2964aa4a95
commit e6350d99e9
17 changed files with 157 additions and 42 deletions

View File

@@ -66,5 +66,15 @@ int32_t SceneItemComponentParser::onParse(
++itOptional;
}
auto itInnerXml = ruleset.innerXml.begin();
while(itInnerXml != ruleset.innerXml.end()) {
auto name = itInnerXml->first;
auto type = itInnerXml->second;
out->values[name] = stringParser(node->innerXml, error);
if(error->size() != 0) return 1;
++itInnerXml;
}
return 0;
}

View File

@@ -76,14 +76,23 @@ struct SceneItemComponentRuleset SceneItemComponentRegistry::parseFile(
// Find each instance of "@optional" when it's used within a comment
// e.g. // @optional or /* @optional */ in the string data.1
std::regex regex("^\\s*(?:\\/\\/|\\/\\*){1}\\s*\\@optional\\s*(?:\\*\\/)?\\s*$", regexFlags);
std::regex regex("^\\s*(?:\\/\\/|\\/\\*){1}\\s*\\@(optional|innerXml)\\s*(?:\\*\\/)?\\s*$", regexFlags);
std::sregex_iterator it(data.begin(), data.end(), regex);
std::sregex_iterator end;
while(it != end) {
// Extract the kind of parameter this is
std::smatch match;
if(!std::regex_search(data, match, regex)) {
std::cout << "Failed to determine parameter type!" << std::endl;
return { .name = "" };
}
std::string paramType = match[1].str();
// Find the next ";"
auto endPos = data.find(";", it->position() + it->length());
if(endPos == std::string::npos) {
std::cout << "Failed to find end of line for optional attribute!" << std::endl;
std::cout << "Failed to find end of line for attribute!" << std::endl;
return { .name = "" };
}
@@ -105,16 +114,24 @@ struct SceneItemComponentRuleset SceneItemComponentRegistry::parseFile(
// Now (should) be able to extract the type;
std::regex regex2("^\\s*(?:[\\S]+<)?([\\w*:_\\s]+)(?:[\\S]+)? (\\**[\\w]+)\\s*$", regexFlags);
std::smatch match;
if(!std::regex_search(variableString, match, regex2)) {
std::smatch match2;
if(!std::regex_search(variableString, match2, regex2)) {
std::cout << "Failed to extract type and name from variable string! " << variableString << std::endl;
return { .name = "" };
}
// Now we have our type and name
auto type = match[1].str();
auto name = match[2].str();
ruleset.selfOptional[name] = type;
auto type = match2[1].str();
auto name = match2[2].str();
// Now store depending on the type
if(paramType == "optional") {
ruleset.selfOptional[name] = type;
} else if(paramType == "innerXml") {
ruleset.innerXml[name] = type;
} else {
assertUnreachable();
}
++it;
}
return ruleset;

View File

@@ -16,6 +16,7 @@ namespace Dawn {
std::string name;
std::string include;
std::map<std::string, std::string> selfOptional;
std::map<std::string, std::string> innerXml;
std::map<std::string, std::string> optional;
std::vector<std::string> extends;
};