pattern: Add attribute to format array entries (#435)

Co-authored-by: Dmitry Polshakov <dmitry.polshakov@dsr-corporation.com>
This commit is contained in:
Polshakov Dmitry 2022-02-12 17:40:42 +03:00 committed by GitHub
parent 63455ce2be
commit 9399cf873f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 0 deletions

View File

@ -803,6 +803,24 @@ namespace hex::pl {
else
inlinable->setInlined(true);
}
if (auto value = attributable->getAttributeValue("format_entries"); value) {
auto functions = evaluator->getCustomFunctions();
if (!functions.contains(*value))
LogConsole::abortEvaluation(hex::format("cannot find formatter function '{}'", *value), node);
const auto &function = functions[*value];
if (function.parameterCount != 1)
LogConsole::abortEvaluation("formatter function needs exactly one parameter", node);
auto array = dynamic_cast<PatternDataDynamicArray *>(pattern);
if (array == nullptr)
LogConsole::abortEvaluation("inline_array attribute can only be applied to array types", node);
for (const auto& entry : array->getEntries()) {
entry->setFormatterFunction(function);
}
}
}
class ASTNodeVariableDecl : public ASTNode,