mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-09-09 23:47:07 +00:00
Reformat code with clang format
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
#include "MenuExpressionMatchers.h"
|
||||
|
||||
#include "MenuMatcherFactory.h"
|
||||
#include "Game/IW4/IW4.h"
|
||||
#include "Game/IW5/IW5.h"
|
||||
#include "Game/IW4/MenuConstantsIW4.h"
|
||||
#include "Game/IW5/IW5.h"
|
||||
#include "Game/IW5/MenuConstantsIW5.h"
|
||||
#include "MenuMatcherFactory.h"
|
||||
#include "Parsing/Menu/Domain/Expression/CommonExpressionBaseFunctionCall.h"
|
||||
#include "Parsing/Menu/Domain/Expression/CommonExpressionCustomFunctionCall.h"
|
||||
|
||||
@@ -30,45 +30,40 @@ std::unique_ptr<SimpleExpressionMatchers::matcher_t> MenuExpressionMatchers::Par
|
||||
{
|
||||
const MenuMatcherFactory create(labelSupplier);
|
||||
|
||||
return create.Or({
|
||||
create.And({
|
||||
create.Identifier().Capture(CAPTURE_FUNCTION_NAME),
|
||||
create.Char('('),
|
||||
create.Optional(create.And({
|
||||
create.Label(LABEL_EXPRESSION),
|
||||
create.OptionalLoop(create.And({
|
||||
create.Char(','),
|
||||
create.Label(LABEL_EXPRESSION)
|
||||
})),
|
||||
})),
|
||||
create.Char(')').Tag(TAG_EXPRESSION_FUNCTION_CALL_END)
|
||||
}).Tag(TAG_EXPRESSION_FUNCTION_CALL)
|
||||
});
|
||||
return create.Or({create
|
||||
.And({create.Identifier().Capture(CAPTURE_FUNCTION_NAME),
|
||||
create.Char('('),
|
||||
create.Optional(create.And({
|
||||
create.Label(LABEL_EXPRESSION),
|
||||
create.OptionalLoop(create.And({create.Char(','), create.Label(LABEL_EXPRESSION)})),
|
||||
})),
|
||||
create.Char(')').Tag(TAG_EXPRESSION_FUNCTION_CALL_END)})
|
||||
.Tag(TAG_EXPRESSION_FUNCTION_CALL)});
|
||||
}
|
||||
|
||||
const std::map<std::string, size_t>& MenuExpressionMatchers::GetBaseFunctionMapForFeatureLevel(const FeatureLevel featureLevel)
|
||||
{
|
||||
if(featureLevel == FeatureLevel::IW4)
|
||||
if (featureLevel == FeatureLevel::IW4)
|
||||
{
|
||||
static std::map<std::string, size_t> iw4FunctionMap;
|
||||
static bool iw4FunctionMapInitialized = false;
|
||||
|
||||
if(!iw4FunctionMapInitialized)
|
||||
if (!iw4FunctionMapInitialized)
|
||||
{
|
||||
for(size_t i = IW4::expressionFunction_e::EXP_FUNC_DYN_START; i < std::extent_v<decltype(IW4::g_expFunctionNames)>; i++)
|
||||
for (size_t i = IW4::expressionFunction_e::EXP_FUNC_DYN_START; i < std::extent_v<decltype(IW4::g_expFunctionNames)>; i++)
|
||||
iw4FunctionMap.emplace(std::make_pair(IW4::g_expFunctionNames[i], i));
|
||||
}
|
||||
|
||||
return iw4FunctionMap;
|
||||
}
|
||||
if(featureLevel == FeatureLevel::IW5)
|
||||
if (featureLevel == FeatureLevel::IW5)
|
||||
{
|
||||
static std::map<std::string, size_t> iw5FunctionMap;
|
||||
static bool iw5FunctionMapInitialized = false;
|
||||
|
||||
if(!iw5FunctionMapInitialized)
|
||||
if (!iw5FunctionMapInitialized)
|
||||
{
|
||||
for(size_t i = IW5::expressionFunction_e::EXP_FUNC_DYN_START; i < std::extent_v<decltype(IW5::g_expFunctionNames)>; i++)
|
||||
for (size_t i = IW5::expressionFunction_e::EXP_FUNC_DYN_START; i < std::extent_v<decltype(IW5::g_expFunctionNames)>; i++)
|
||||
iw5FunctionMap.emplace(std::make_pair(IW5::g_expFunctionNames[i], i));
|
||||
}
|
||||
|
||||
@@ -82,7 +77,7 @@ const std::map<std::string, size_t>& MenuExpressionMatchers::GetBaseFunctionMapF
|
||||
std::unique_ptr<ISimpleExpression> MenuExpressionMatchers::ProcessOperandExtension(SequenceResult<SimpleParserValue>& result) const
|
||||
{
|
||||
assert(m_state);
|
||||
if(m_state == nullptr)
|
||||
if (m_state == nullptr)
|
||||
throw ParsingException(TokenPos(), "No state when processing menu operand extension!!");
|
||||
|
||||
if (result.PeekAndRemoveIfTag(TAG_EXPRESSION_FUNCTION_CALL) != TAG_EXPRESSION_FUNCTION_CALL)
|
||||
@@ -93,7 +88,7 @@ std::unique_ptr<ISimpleExpression> MenuExpressionMatchers::ProcessOperandExtensi
|
||||
|
||||
const auto& baseFunctionMap = GetBaseFunctionMapForFeatureLevel(m_state->m_feature_level);
|
||||
const auto foundBaseFunction = baseFunctionMap.find(functionCallName);
|
||||
if(foundBaseFunction != baseFunctionMap.end())
|
||||
if (foundBaseFunction != baseFunctionMap.end())
|
||||
{
|
||||
auto functionCall = std::make_unique<CommonExpressionBaseFunctionCall>(std::move(functionCallName), foundBaseFunction->second);
|
||||
while (result.PeekAndRemoveIfTag(TAG_EXPRESSION_FUNCTION_CALL_END) != TAG_EXPRESSION_FUNCTION_CALL_END)
|
||||
@@ -104,11 +99,11 @@ std::unique_ptr<ISimpleExpression> MenuExpressionMatchers::ProcessOperandExtensi
|
||||
}
|
||||
|
||||
const auto foundCustomFunction = m_state->m_functions_by_name.find(functionCallName);
|
||||
if(foundCustomFunction != m_state->m_functions_by_name.end())
|
||||
if (foundCustomFunction != m_state->m_functions_by_name.end())
|
||||
{
|
||||
auto functionCall = std::make_unique<CommonExpressionCustomFunctionCall>(std::move(functionCallName));
|
||||
|
||||
if(result.PeekAndRemoveIfTag(TAG_EXPRESSION_FUNCTION_CALL_END) != TAG_EXPRESSION_FUNCTION_CALL_END)
|
||||
if (result.PeekAndRemoveIfTag(TAG_EXPRESSION_FUNCTION_CALL_END) != TAG_EXPRESSION_FUNCTION_CALL_END)
|
||||
throw ParsingException(functionCallToken.GetPos(), "Custom functions cannot be called with arguments");
|
||||
|
||||
return std::move(functionCall);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "Parsing/Menu/MenuFileParserState.h"
|
||||
#include "Parsing/Simple/Expression/SimpleExpressionMatchers.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace menu
|
||||
{
|
||||
class MenuExpressionMatchers final : public SimpleExpressionMatchers
|
||||
@@ -21,4 +21,4 @@ namespace menu
|
||||
std::unique_ptr<matcher_t> ParseOperandExtension(const supplier_t* labelSupplier) const override;
|
||||
std::unique_ptr<ISimpleExpression> ProcessOperandExtension(SequenceResult<SimpleParserValue>& result) const override;
|
||||
};
|
||||
}
|
||||
} // namespace menu
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "MenuMatcherFactory.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "MenuExpressionMatchers.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
using namespace menu;
|
||||
|
||||
MenuMatcherFactory::MenuMatcherFactory(const IMatcherForLabelSupplier<SimpleParserValue>* labelSupplier)
|
||||
@@ -13,23 +13,20 @@ MenuMatcherFactory::MenuMatcherFactory(const IMatcherForLabelSupplier<SimplePars
|
||||
|
||||
MatcherFactoryWrapper<SimpleParserValue> MenuMatcherFactory::StringChain() const
|
||||
{
|
||||
return Or({
|
||||
And({
|
||||
String(),
|
||||
Loop(String())
|
||||
}).Transform([](const token_list_t& tokens) -> SimpleParserValue
|
||||
{
|
||||
std::ostringstream ss;
|
||||
return Or({And({String(), Loop(String())})
|
||||
.Transform(
|
||||
[](const token_list_t& tokens) -> SimpleParserValue
|
||||
{
|
||||
std::ostringstream ss;
|
||||
|
||||
for (const auto& token : tokens)
|
||||
{
|
||||
ss << token.get().StringValue();
|
||||
}
|
||||
for (const auto& token : tokens)
|
||||
{
|
||||
ss << token.get().StringValue();
|
||||
}
|
||||
|
||||
return SimpleParserValue::String(tokens[0].get().GetPos(), new std::string(ss.str()));
|
||||
}),
|
||||
String()
|
||||
});
|
||||
return SimpleParserValue::String(tokens[0].get().GetPos(), new std::string(ss.str()));
|
||||
}),
|
||||
String()});
|
||||
}
|
||||
|
||||
MatcherFactoryWrapper<SimpleParserValue> MenuMatcherFactory::Text() const
|
||||
@@ -49,26 +46,24 @@ MatcherFactoryWrapper<SimpleParserValue> MenuMatcherFactory::Numeric() const
|
||||
|
||||
MatcherFactoryWrapper<SimpleParserValue> MenuMatcherFactory::IntExpression() const
|
||||
{
|
||||
return MatcherFactoryWrapper(Or({
|
||||
Integer().Tag(TAG_INT).Capture(CAPTURE_INT),
|
||||
And({
|
||||
Char('(').Capture(CAPTURE_FIRST_TOKEN),
|
||||
Label(MenuExpressionMatchers::LABEL_EXPRESSION),
|
||||
Char(')'),
|
||||
}).Tag(TAG_EXPRESSION)
|
||||
}));
|
||||
return MatcherFactoryWrapper(Or({Integer().Tag(TAG_INT).Capture(CAPTURE_INT),
|
||||
And({
|
||||
Char('(').Capture(CAPTURE_FIRST_TOKEN),
|
||||
Label(MenuExpressionMatchers::LABEL_EXPRESSION),
|
||||
Char(')'),
|
||||
})
|
||||
.Tag(TAG_EXPRESSION)}));
|
||||
}
|
||||
|
||||
MatcherFactoryWrapper<SimpleParserValue> MenuMatcherFactory::NumericExpression() const
|
||||
{
|
||||
return MatcherFactoryWrapper(Or({
|
||||
Numeric().Tag(TAG_NUMERIC).Capture(CAPTURE_NUMERIC),
|
||||
And({
|
||||
Char('(').Capture(CAPTURE_FIRST_TOKEN),
|
||||
Label(MenuExpressionMatchers::LABEL_EXPRESSION),
|
||||
Char(')'),
|
||||
}).Tag(TAG_EXPRESSION)
|
||||
}));
|
||||
return MatcherFactoryWrapper(Or({Numeric().Tag(TAG_NUMERIC).Capture(CAPTURE_NUMERIC),
|
||||
And({
|
||||
Char('(').Capture(CAPTURE_FIRST_TOKEN),
|
||||
Label(MenuExpressionMatchers::LABEL_EXPRESSION),
|
||||
Char(')'),
|
||||
})
|
||||
.Tag(TAG_EXPRESSION)}));
|
||||
}
|
||||
|
||||
int MenuMatcherFactory::TokenNumericIntValue(const SimpleParserValue& value)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "Parsing/Menu/MenuFileParserState.h"
|
||||
#include "Parsing/Sequence/SequenceResult.h"
|
||||
#include "Parsing/Simple/Matcher/SimpleMatcherFactory.h"
|
||||
#include "Parsing/Menu/MenuFileParserState.h"
|
||||
|
||||
namespace menu
|
||||
{
|
||||
@@ -34,4 +34,4 @@ namespace menu
|
||||
_NODISCARD static int TokenIntExpressionValue(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result);
|
||||
_NODISCARD static double TokenNumericExpressionValue(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result);
|
||||
};
|
||||
}
|
||||
} // namespace menu
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "MenuMatcherScriptInt.h"
|
||||
|
||||
MenuMatcherScriptInt::MenuMatcherScriptInt()
|
||||
= default;
|
||||
MenuMatcherScriptInt::MenuMatcherScriptInt() = default;
|
||||
|
||||
MatcherResult<SimpleParserValue> MenuMatcherScriptInt::CanMatch(ILexer<SimpleParserValue>* lexer, const unsigned tokenOffset)
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Parsing/Simple/SimpleParserValue.h"
|
||||
#include "Parsing/Matcher/AbstractMatcher.h"
|
||||
#include "Parsing/Simple/SimpleParserValue.h"
|
||||
|
||||
class MenuMatcherScriptInt final : public AbstractMatcher<SimpleParserValue>
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "MenuMatcherScriptNumeric.h"
|
||||
|
||||
MenuMatcherScriptNumeric::MenuMatcherScriptNumeric()
|
||||
= default;
|
||||
MenuMatcherScriptNumeric::MenuMatcherScriptNumeric() = default;
|
||||
|
||||
MatcherResult<SimpleParserValue> MenuMatcherScriptNumeric::CanMatch(ILexer<SimpleParserValue>* lexer, const unsigned tokenOffset)
|
||||
{
|
||||
@@ -34,7 +33,7 @@ MatcherResult<SimpleParserValue> MenuMatcherScriptNumeric::CanMatch(ILexer<Simpl
|
||||
// The return result does not matter here
|
||||
const auto _ = strtod(stringValue.data(), &endPtr);
|
||||
|
||||
if(endPtr != &stringValue[stringValue.size()])
|
||||
if (endPtr != &stringValue[stringValue.size()])
|
||||
return MatcherResult<SimpleParserValue>::NoMatch();
|
||||
|
||||
return MatcherResult<SimpleParserValue>::Match(1);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Parsing/Simple/SimpleParserValue.h"
|
||||
#include "Parsing/Matcher/AbstractMatcher.h"
|
||||
#include "Parsing/Simple/SimpleParserValue.h"
|
||||
|
||||
class MenuMatcherScriptNumeric final : public AbstractMatcher<SimpleParserValue>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user