Added comments attribute

This commit is contained in:
WerWolv
2021-01-21 20:55:10 +01:00
parent 9a97c6c328
commit b6e2bbc434
5 changed files with 47 additions and 13 deletions

View File

@@ -338,10 +338,12 @@ namespace hex::lang {
auto handleVariableAttributes = [this, &currPattern](auto attribute, auto value) {
if (attribute == "color")
currPattern->setColor(hex::changeEndianess(u32(strtoul(value.data(), nullptr, 0)) << 8, std::endian::big));
else if (attribute == "name")
currPattern->setVariableName(value.data());
if (attribute == "color" && value.has_value())
currPattern->setColor(hex::changeEndianess(u32(strtoul(value->data(), nullptr, 0)) << 8, std::endian::big));
else if (attribute == "name" && value.has_value())
currPattern->setVariableName(value->data());
else if (attribute == "comment" && value.has_value())
currPattern->setComment(value->data());
else
this->getConsole().abortEvaluation("unknown or invalid attribute");
@@ -349,6 +351,9 @@ namespace hex::lang {
auto &attributes = attributableNode->getAttributes();
if (attributes.empty())
return currPattern;
if (auto variableDeclNode = dynamic_cast<ASTNodeVariableDecl*>(currNode); variableDeclNode != nullptr) {
for (auto &attribute : attributes)
handleVariableAttributes(attribute->getAttribute(), attribute->getValue());

View File

@@ -420,7 +420,7 @@ namespace hex::lang {
if (MATCHES(sequence(VALUETYPE_PADDING, SEPARATOR_SQUAREBRACKETOPEN)))
member = parsePadding();
else if (MATCHES((optional(KEYWORD_BE), optional(KEYWORD_LE)) && variant(IDENTIFIER, VALUETYPE_ANY) && sequence(IDENTIFIER, SEPARATOR_SQUAREBRACKETOPEN)))
else if (MATCHES((optional(KEYWORD_BE), optional(KEYWORD_LE)) && variant(IDENTIFIER, VALUETYPE_ANY) && sequence(IDENTIFIER, SEPARATOR_SQUAREBRACKETOPEN) && none(sequence(SEPARATOR_SQUAREBRACKETOPEN))))
member = parseMemberArrayVariable();
else if (MATCHES((optional(KEYWORD_BE), optional(KEYWORD_LE)) && variant(IDENTIFIER, VALUETYPE_ANY) && sequence(IDENTIFIER)))
member = parseMemberVariable();