2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-01-11 19:21:50 +00:00

Correctly parse binary operations that can be interpreted as sign prefixes for numbers

This commit is contained in:
Jan
2021-11-28 15:16:43 +01:00
parent c3a44f60d3
commit e7eb43a955
12 changed files with 211 additions and 12 deletions

View File

@@ -1,5 +1,6 @@
#include "SimpleExpressionMatchers.h"
#include <algorithm>
#include <list>
#include "SimpleExpressionConditionalOperator.h"
@@ -273,6 +274,30 @@ std::unique_ptr<SimpleExpressionMatchers::matcher_t> SimpleExpressionMatchers::P
}
}
const auto hasAddOperation = std::any_of(enabledBinaryOperations.begin(), enabledBinaryOperations.end(), [](const SimpleExpressionBinaryOperationType* type)
{
return type == &SimpleExpressionBinaryOperationType::OPERATION_ADD;
});
const auto hasSubtractOperation = std::any_of(enabledBinaryOperations.begin(), enabledBinaryOperations.end(), [](const SimpleExpressionBinaryOperationType* type)
{
return type == &SimpleExpressionBinaryOperationType::OPERATION_SUBTRACT;
});
if (hasAddOperation && hasSubtractOperation)
{
binaryOperationsMatchers.emplace_back(
create.Or({
create.IntegerWithSign(),
create.FloatingPointWithSign()
})
.NoConsume()
.Transform([](const SimpleMatcherFactory::token_list_t& values)
{
return SimpleParserValue::Integer(values[0].get().GetPos(), static_cast<int>(SimpleBinaryOperationId::ADD));
}));
}
return create.Or(std::move(binaryOperationsMatchers)).Capture(CAPTURE_BINARY_OPERATION_TYPE);
}