diff --git a/src/ObjLoading/Parsing/Menu/Domain/Expression/CommonExpressionUnaryOperation.cpp b/src/ObjLoading/Parsing/Menu/Domain/Expression/CommonExpressionUnaryOperation.cpp index 275b7c00..c2e3dce9 100644 --- a/src/ObjLoading/Parsing/Menu/Domain/Expression/CommonExpressionUnaryOperation.cpp +++ b/src/ObjLoading/Parsing/Menu/Domain/Expression/CommonExpressionUnaryOperation.cpp @@ -31,10 +31,24 @@ const CommonExpressionUnaryOperationType CommonExpressionUnaryOperationType::OPE } ); +const CommonExpressionUnaryOperationType CommonExpressionUnaryOperationType::OPERATION_NEGATIVE( + "-", + [](const CommonExpressionValue& operand) -> CommonExpressionValue + { + if(operand.m_type == CommonExpressionValue::Type::INT) + return CommonExpressionValue(-operand.m_int_value); + if (operand.m_type == CommonExpressionValue::Type::DOUBLE) + return CommonExpressionValue(-operand.m_double_value); + + return CommonExpressionValue(0); + } +); + const CommonExpressionUnaryOperationType* const CommonExpressionUnaryOperationType::ALL_OPERATION_TYPES[static_cast(UnaryOperationId::COUNT)] { &OPERATION_NOT, &OPERATION_BITWISE_NOT, + &OPERATION_NEGATIVE, }; CommonExpressionUnaryOperation::CommonExpressionUnaryOperation(const CommonExpressionUnaryOperationType* operationType, std::unique_ptr operand) diff --git a/src/ObjLoading/Parsing/Menu/Domain/Expression/CommonExpressionUnaryOperation.h b/src/ObjLoading/Parsing/Menu/Domain/Expression/CommonExpressionUnaryOperation.h index 1debd289..6ad3916f 100644 --- a/src/ObjLoading/Parsing/Menu/Domain/Expression/CommonExpressionUnaryOperation.h +++ b/src/ObjLoading/Parsing/Menu/Domain/Expression/CommonExpressionUnaryOperation.h @@ -13,6 +13,7 @@ namespace menu { NOT, BITWISE_NOT, + NEGATIVE, COUNT }; @@ -31,6 +32,7 @@ namespace menu public: static const CommonExpressionUnaryOperationType OPERATION_NOT; static const CommonExpressionUnaryOperationType OPERATION_BITWISE_NOT; + static const CommonExpressionUnaryOperationType OPERATION_NEGATIVE; static const CommonExpressionUnaryOperationType* const ALL_OPERATION_TYPES[static_cast(UnaryOperationId::COUNT)]; }; diff --git a/src/ObjLoading/Parsing/Menu/Matcher/MenuCommonMatchers.cpp b/src/ObjLoading/Parsing/Menu/Matcher/MenuCommonMatchers.cpp index 2afa715a..4cac4301 100644 --- a/src/ObjLoading/Parsing/Menu/Matcher/MenuCommonMatchers.cpp +++ b/src/ObjLoading/Parsing/Menu/Matcher/MenuCommonMatchers.cpp @@ -276,6 +276,10 @@ std::unique_ptr MenuCommonMatchers::ParseUnaryOpe { return SimpleParserValue::Integer(values[0].get().GetPos(), static_cast(UnaryOperationId::BITWISE_NOT)); }), + create.Char('-').Transform([](const MenuMatcherFactory::token_list_t& values) + { + return SimpleParserValue::Integer(values[0].get().GetPos(), static_cast(UnaryOperationId::NEGATIVE)); + }), }).Tag(TAG_EXPRESSION_UNARY_OPERATION).Capture(CAPTURE_UNARY_OPERATION_TYPE); }