mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-27 23:37:05 -05:00
patterns: Use standalone pattern language library instead of built-in one
This commit is contained in:
@@ -20,7 +20,7 @@ namespace hex::test {
|
||||
second->setEntries(create<PatternUnsigned>("u8", "", 0x4, sizeof(u8)), 4);
|
||||
|
||||
auto testStruct = create<PatternStruct>("Signature", "sign", 0x0, sizeof(u8[8]));
|
||||
std::vector<std::shared_ptr<hex::pl::Pattern>> structMembers;
|
||||
std::vector<std::shared_ptr<pl::Pattern>> structMembers;
|
||||
{
|
||||
structMembers.push_back(std::move(first));
|
||||
structMembers.push_back(std::move(second));
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace hex::test {
|
||||
auto testBitfield = create<PatternBitfield>("TestBitfield", "testBitfield", 0x12, (4 * 4) / 8);
|
||||
testBitfield->setEndian(std::endian::big);
|
||||
|
||||
std::vector<std::shared_ptr<hex::pl::Pattern>> bitfieldFields;
|
||||
std::vector<std::shared_ptr<pl::Pattern>> bitfieldFields;
|
||||
{
|
||||
bitfieldFields.push_back(create<PatternBitfieldField>("", "a", 0x12, 0, 4, testBitfield.get()));
|
||||
bitfieldFields.push_back(create<PatternBitfieldField>("", "b", 0x12, 4, 4, testBitfield.get()));
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace hex::test {
|
||||
{
|
||||
auto hdr = create<PatternStruct>("Header", "hdr", HEADER_START, HEADER_SIZE);
|
||||
{
|
||||
std::vector<std::shared_ptr<hex::pl::Pattern>> hdrMembers {
|
||||
std::vector<std::shared_ptr<pl::Pattern>> hdrMembers {
|
||||
std::shared_ptr(create<PatternUnsigned>("u8", "len", HEADER_START, sizeof(u8)))
|
||||
};
|
||||
hdr->setMembers(std::move(hdrMembers));
|
||||
@@ -32,13 +32,13 @@ namespace hex::test {
|
||||
{
|
||||
auto bodyArray = create<PatternArrayStatic>("u8", "arr", BODY_START, BODY_SIZE);
|
||||
bodyArray->setEntries(create<PatternUnsigned>("u8", "", BODY_START, sizeof(u8)), BODY_SIZE);
|
||||
std::vector<std::shared_ptr<hex::pl::Pattern>> bodyMembers {
|
||||
std::vector<std::shared_ptr<pl::Pattern>> bodyMembers {
|
||||
std::shared_ptr(std::move(bodyArray))
|
||||
};
|
||||
body->setMembers(std::move(bodyMembers));
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<hex::pl::Pattern>> dataMembers {
|
||||
std::vector<std::shared_ptr<pl::Pattern>> dataMembers {
|
||||
std::shared_ptr(std::move(hdr)),
|
||||
std::shared_ptr(std::move(body))
|
||||
};
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace hex::test {
|
||||
auto array = create<PatternArrayStatic>("u8", "array", 0x100 + sizeof(i32) + 20, sizeof(u8[0x10]));
|
||||
array->setEntries(create<PatternUnsigned>("u8", "", 0x100 + sizeof(i32) + 20, sizeof(u8)), 0x10);
|
||||
|
||||
std::vector<std::shared_ptr<hex::pl::Pattern>> structMembers;
|
||||
std::vector<std::shared_ptr<pl::Pattern>> structMembers;
|
||||
{
|
||||
structMembers.push_back(std::move(variable));
|
||||
structMembers.push_back(std::move(padding));
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace hex::test {
|
||||
auto array = create<PatternArrayStatic>("u8", "array", 0x100 + sizeof(i32), sizeof(u8[0x10]));
|
||||
array->setEntries(create<PatternUnsigned>("u8", "", 0x100 + sizeof(i32), sizeof(u8)), 0x10);
|
||||
|
||||
std::vector<std::shared_ptr<hex::pl::Pattern>> structMembers;
|
||||
std::vector<std::shared_ptr<pl::Pattern>> structMembers;
|
||||
{
|
||||
structMembers.push_back(std::move(variable));
|
||||
structMembers.push_back(std::move(array));
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace hex::test {
|
||||
array->setEntries(create<PatternSigned>("s32", "", 0x200, sizeof(i32)), 2);
|
||||
auto variable = create<PatternUnsigned>("u128", "variable", 0x200, sizeof(u128));
|
||||
|
||||
std::vector<std::shared_ptr<hex::pl::Pattern>> unionMembers;
|
||||
std::vector<std::shared_ptr<pl::Pattern>> unionMembers;
|
||||
{
|
||||
unionMembers.push_back(std::move(array));
|
||||
unionMembers.push_back(std::move(variable));
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
using namespace hex::test;
|
||||
|
||||
static std::string format(hex::pl::Evaluator *ctx, const auto ¶ms) {
|
||||
auto format = hex::pl::Token::literalToString(params[0], true);
|
||||
static std::string format(pl::Evaluator *ctx, const auto ¶ms) {
|
||||
auto format = pl::Token::literalToString(params[0], true);
|
||||
std::string message;
|
||||
|
||||
fmt::dynamic_format_arg_store<fmt::format_context> formatArgs;
|
||||
@@ -28,7 +28,7 @@ static std::string format(hex::pl::Evaluator *ctx, const auto ¶ms) {
|
||||
auto ¶m = params[i];
|
||||
|
||||
std::visit(hex::overloaded {
|
||||
[&](hex::pl::Pattern *value) {
|
||||
[&](pl::Pattern *value) {
|
||||
formatArgs.push_back(value->toString(ctx->getProvider()));
|
||||
},
|
||||
[&](auto &&value) {
|
||||
@@ -40,7 +40,7 @@ static std::string format(hex::pl::Evaluator *ctx, const auto ¶ms) {
|
||||
try {
|
||||
return fmt::vformat(format, formatArgs);
|
||||
} catch (fmt::format_error &error) {
|
||||
hex::pl::LogConsole::abortEvaluation(hex::format("format error: {}", error.what()));
|
||||
pl::LogConsole::abortEvaluation(hex::format("format error: {}", error.what()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ int test(int argc, char **argv) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
hex::pl::PatternLanguage language;
|
||||
pl::PatternLanguage language;
|
||||
|
||||
// Check if compilation succeeded
|
||||
auto result = language.executeString(provider, testPatterns[testName]->getSourceCode());
|
||||
|
||||
Reference in New Issue
Block a user