mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-30 05:05:19 -05:00
Added attributes syntax to pattern language
This comes with two experimental attributes for variables called `name` and `color`
This commit is contained in:
@@ -262,6 +262,29 @@ namespace hex::lang {
|
||||
return this->parseTernaryConditional();
|
||||
}
|
||||
|
||||
// [[ <Identifier[( (parseStringLiteral) )], ...> ]]
|
||||
void Parser::parseAttribute(Attributable *currNode) {
|
||||
if (currNode == nullptr)
|
||||
throwParseError("tried to apply attribute to invalid statement");
|
||||
|
||||
do {
|
||||
if (!MATCHES(sequence(IDENTIFIER)))
|
||||
throwParseError("expected attribute expression");
|
||||
|
||||
auto attribute = this->getValue<std::string>(-1);
|
||||
|
||||
if (MATCHES(sequence(SEPARATOR_ROUNDBRACKETOPEN, STRING, SEPARATOR_ROUNDBRACKETCLOSE))) {
|
||||
auto value = this->getValue<std::string>(-2);
|
||||
currNode->addAttribute(new ASTNodeAttribute(attribute, value));
|
||||
}
|
||||
else
|
||||
currNode->addAttribute(new ASTNodeAttribute(attribute));
|
||||
|
||||
} while (MATCHES(sequence(SEPARATOR_COMMA)));
|
||||
|
||||
if (!MATCHES(sequence(SEPARATOR_SQUAREBRACKETCLOSE, SEPARATOR_SQUAREBRACKETCLOSE)))
|
||||
throwParseError("unfinished attribute. Expected ']]'");
|
||||
}
|
||||
|
||||
/* Control flow */
|
||||
|
||||
@@ -410,6 +433,9 @@ namespace hex::lang {
|
||||
else
|
||||
throwParseError("invalid struct member", 0);
|
||||
|
||||
if (MATCHES(sequence(SEPARATOR_SQUAREBRACKETOPEN, SEPARATOR_SQUAREBRACKETOPEN)))
|
||||
parseAttribute(dynamic_cast<Attributable *>(member));
|
||||
|
||||
if (!MATCHES(sequence(SEPARATOR_ENDOFEXPRESSION)))
|
||||
throwParseError("missing ';' at end of expression", -1);
|
||||
|
||||
@@ -605,6 +631,9 @@ namespace hex::lang {
|
||||
statement = parseFunctionCall();
|
||||
else throwParseError("invalid sequence", 0);
|
||||
|
||||
if (MATCHES(sequence(SEPARATOR_SQUAREBRACKETOPEN, SEPARATOR_SQUAREBRACKETOPEN)))
|
||||
parseAttribute(dynamic_cast<Attributable *>(statement));
|
||||
|
||||
if (!MATCHES(sequence(SEPARATOR_ENDOFEXPRESSION)))
|
||||
throwParseError("missing ';' at end of expression", -1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user