mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-19 03:07:58 -05:00
Move item parsing sequences for different scopes into the same class
This commit is contained in:
@ -0,0 +1,27 @@
|
||||
#include "GenericBoolPropertySequence.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "Parsing/Menu/Matcher/MenuMatcherFactory.h"
|
||||
|
||||
using namespace menu;
|
||||
|
||||
GenericBoolPropertySequence::GenericBoolPropertySequence(std::string keywordName, callback_t setCallback)
|
||||
: m_set_callback(std::move(setCallback))
|
||||
{
|
||||
const MenuMatcherFactory create(this);
|
||||
|
||||
AddMatchers({
|
||||
create.KeywordIgnoreCase(std::move(keywordName)),
|
||||
create.Integer().Capture(CAPTURE_VALUE)
|
||||
});
|
||||
}
|
||||
|
||||
void GenericBoolPropertySequence::ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const
|
||||
{
|
||||
if (m_set_callback)
|
||||
{
|
||||
const auto value = result.NextCapture(CAPTURE_VALUE).IntegerValue();
|
||||
m_set_callback(state, value > 0);
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
#include "Parsing/Menu/MenuFileParser.h"
|
||||
|
||||
namespace menu
|
||||
{
|
||||
class GenericBoolPropertySequence final : public MenuFileParser::sequence_t
|
||||
{
|
||||
public:
|
||||
using callback_t = std::function<void(MenuFileParserState* state, bool value)>;
|
||||
|
||||
private:
|
||||
static constexpr auto CAPTURE_VALUE = 1;
|
||||
|
||||
const callback_t m_set_callback;
|
||||
|
||||
protected:
|
||||
void ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const override;
|
||||
|
||||
public:
|
||||
GenericBoolPropertySequence(std::string keywordName, callback_t setCallback);
|
||||
};
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
#include "GenericColorPropertySequence.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "Parsing/Menu/Matcher/MenuMatcherFactory.h"
|
||||
|
||||
using namespace menu;
|
||||
|
||||
GenericColorPropertySequence::GenericColorPropertySequence(std::string keywordName, callback_t setCallback)
|
||||
: m_set_callback(std::move(setCallback))
|
||||
{
|
||||
const MenuMatcherFactory create(this);
|
||||
|
||||
AddMatchers({
|
||||
create.KeywordIgnoreCase(std::move(keywordName)),
|
||||
create.Numeric().Capture(CAPTURE_R),
|
||||
create.Numeric().Capture(CAPTURE_G),
|
||||
create.Numeric().Capture(CAPTURE_B),
|
||||
create.Numeric().Capture(CAPTURE_A)
|
||||
});
|
||||
}
|
||||
|
||||
void GenericColorPropertySequence::ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const
|
||||
{
|
||||
if (m_set_callback)
|
||||
{
|
||||
CommonColor color{};
|
||||
color.r = MenuMatcherFactory::TokenNumericFloatingPointValue(result.NextCapture(CAPTURE_R));
|
||||
color.g = MenuMatcherFactory::TokenNumericFloatingPointValue(result.NextCapture(CAPTURE_G));
|
||||
color.b = MenuMatcherFactory::TokenNumericFloatingPointValue(result.NextCapture(CAPTURE_B));
|
||||
color.a = MenuMatcherFactory::TokenNumericFloatingPointValue(result.NextCapture(CAPTURE_A));
|
||||
|
||||
m_set_callback(state, color);
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
#include "Parsing/Menu/MenuFileParser.h"
|
||||
#include "Parsing/Menu/Domain/CommonMenuTypes.h"
|
||||
|
||||
namespace menu
|
||||
{
|
||||
class GenericColorPropertySequence final : public MenuFileParser::sequence_t
|
||||
{
|
||||
public:
|
||||
using callback_t = std::function<void(MenuFileParserState* state, CommonColor value)>;
|
||||
|
||||
private:
|
||||
static constexpr auto CAPTURE_R = 1;
|
||||
static constexpr auto CAPTURE_G = 2;
|
||||
static constexpr auto CAPTURE_B = 3;
|
||||
static constexpr auto CAPTURE_A = 4;
|
||||
|
||||
const callback_t m_set_callback;
|
||||
|
||||
protected:
|
||||
void ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const override;
|
||||
|
||||
public:
|
||||
GenericColorPropertySequence(std::string keywordName, callback_t setCallback);
|
||||
};
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
#include "GenericExpressionPropertySequence.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "Parsing/Menu/Matcher/MenuCommonMatchers.h"
|
||||
#include "Parsing/Menu/Matcher/MenuMatcherFactory.h"
|
||||
|
||||
using namespace menu;
|
||||
|
||||
GenericExpressionPropertySequence::GenericExpressionPropertySequence(callback_t setCallback)
|
||||
: m_set_callback(std::move(setCallback))
|
||||
{
|
||||
AddLabeledMatchers(MenuCommonMatchers::Expression(this), MenuCommonMatchers::LABEL_EXPRESSION);
|
||||
}
|
||||
|
||||
std::unique_ptr<GenericExpressionPropertySequence> GenericExpressionPropertySequence::WithKeyword(std::string keyword, callback_t setCallback)
|
||||
{
|
||||
auto result = std::unique_ptr<GenericExpressionPropertySequence>(new GenericExpressionPropertySequence(std::move(setCallback)));
|
||||
|
||||
const MenuMatcherFactory create(result.get());
|
||||
result->AddMatchers({
|
||||
create.KeywordIgnoreCase(std::move(keyword)),
|
||||
create.Label(MenuCommonMatchers::LABEL_EXPRESSION),
|
||||
create.Optional(create.Char(';'))
|
||||
});
|
||||
|
||||
return std::move(result);
|
||||
}
|
||||
|
||||
std::unique_ptr<GenericExpressionPropertySequence> GenericExpressionPropertySequence::WithKeywords(const std::initializer_list<std::string> keywords, callback_t setCallback)
|
||||
{
|
||||
auto result = std::unique_ptr<GenericExpressionPropertySequence>(new GenericExpressionPropertySequence(std::move(setCallback)));
|
||||
|
||||
const MenuMatcherFactory create(result.get());
|
||||
std::vector<std::unique_ptr<matcher_t>> keywordMatchers;
|
||||
for (auto keyword : keywords)
|
||||
keywordMatchers.emplace_back(create.KeywordIgnoreCase(std::move(keyword)));
|
||||
|
||||
result->AddMatchers({
|
||||
create.And(std::move(keywordMatchers)),
|
||||
create.Label(MenuCommonMatchers::LABEL_EXPRESSION),
|
||||
create.Optional(create.Char(';'))
|
||||
});
|
||||
|
||||
return std::move(result);
|
||||
}
|
||||
|
||||
std::unique_ptr<GenericExpressionPropertySequence> GenericExpressionPropertySequence::WithKeywordAndBool(std::string keyword, callback_t setCallback)
|
||||
{
|
||||
auto result = std::unique_ptr<GenericExpressionPropertySequence>(new GenericExpressionPropertySequence(std::move(setCallback)));
|
||||
|
||||
const MenuMatcherFactory create(result.get());
|
||||
result->AddMatchers({
|
||||
create.KeywordIgnoreCase(std::move(keyword)),
|
||||
create.Or({
|
||||
create.And({
|
||||
create.KeywordIgnoreCase("when"),
|
||||
create.Char('('),
|
||||
create.Label(MenuCommonMatchers::LABEL_EXPRESSION).Capture(CAPTURE_VALUE),
|
||||
create.Char(')')
|
||||
}),
|
||||
create.Label(MenuCommonMatchers::LABEL_EXPRESSION)
|
||||
}),
|
||||
create.Optional(create.Char(';'))
|
||||
});
|
||||
|
||||
return std::move(result);
|
||||
}
|
||||
|
||||
void GenericExpressionPropertySequence::ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const
|
||||
{
|
||||
if (m_set_callback)
|
||||
{
|
||||
auto expression = MenuCommonMatchers::ProcessExpression(state, result);
|
||||
m_set_callback(state, std::move(expression));
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
#include "Parsing/Menu/MenuFileParser.h"
|
||||
#include "Parsing/Menu/Domain/Expression/ICommonExpression.h"
|
||||
|
||||
namespace menu
|
||||
{
|
||||
class GenericExpressionPropertySequence final : public MenuFileParser::sequence_t
|
||||
{
|
||||
public:
|
||||
using callback_t = std::function<void(MenuFileParserState* state, std::unique_ptr<ICommonExpression> value)>;
|
||||
|
||||
private:
|
||||
static constexpr auto CAPTURE_VALUE = 1;
|
||||
|
||||
const callback_t m_set_callback;
|
||||
|
||||
protected:
|
||||
void ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const override;
|
||||
|
||||
private:
|
||||
explicit GenericExpressionPropertySequence(callback_t setCallback);
|
||||
|
||||
public:
|
||||
static std::unique_ptr<GenericExpressionPropertySequence> WithKeyword(std::string keyword, callback_t setCallback);
|
||||
static std::unique_ptr<GenericExpressionPropertySequence> WithKeywords(std::initializer_list<std::string> keywords, callback_t setCallback);
|
||||
static std::unique_ptr<GenericExpressionPropertySequence> WithKeywordAndBool(std::string keyword, callback_t setCallback);
|
||||
};
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
#include "GenericFloatingPointPropertySequence.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "Parsing/Menu/Matcher/MenuMatcherFactory.h"
|
||||
|
||||
using namespace menu;
|
||||
|
||||
GenericFloatingPointPropertySequence::GenericFloatingPointPropertySequence(std::string keywordName, callback_t setCallback)
|
||||
: m_set_callback(std::move(setCallback))
|
||||
{
|
||||
const MenuMatcherFactory create(this);
|
||||
|
||||
AddMatchers({
|
||||
create.KeywordIgnoreCase(std::move(keywordName)),
|
||||
create.Numeric().Capture(CAPTURE_VALUE)
|
||||
});
|
||||
}
|
||||
|
||||
void GenericFloatingPointPropertySequence::ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const
|
||||
{
|
||||
if (m_set_callback)
|
||||
{
|
||||
const auto value = MenuMatcherFactory::TokenNumericFloatingPointValue(result.NextCapture(CAPTURE_VALUE));
|
||||
m_set_callback(state, value);
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
#include "Parsing/Menu/MenuFileParser.h"
|
||||
|
||||
namespace menu
|
||||
{
|
||||
class GenericFloatingPointPropertySequence final : public MenuFileParser::sequence_t
|
||||
{
|
||||
public:
|
||||
using callback_t = std::function<void(MenuFileParserState* state, double value)>;
|
||||
|
||||
private:
|
||||
static constexpr auto CAPTURE_VALUE = 1;
|
||||
|
||||
const callback_t m_set_callback;
|
||||
|
||||
protected:
|
||||
void ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const override;
|
||||
|
||||
public:
|
||||
GenericFloatingPointPropertySequence(std::string keywordName, callback_t setCallback);
|
||||
};
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
#include "GenericIntPropertySequence.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "Parsing/Menu/Matcher/MenuMatcherFactory.h"
|
||||
|
||||
using namespace menu;
|
||||
|
||||
GenericIntPropertySequence::GenericIntPropertySequence(std::string keywordName, callback_t setCallback)
|
||||
: m_set_callback(std::move(setCallback))
|
||||
{
|
||||
const MenuMatcherFactory create(this);
|
||||
|
||||
AddMatchers({
|
||||
create.KeywordIgnoreCase(std::move(keywordName)),
|
||||
create.Integer().Capture(CAPTURE_VALUE)
|
||||
});
|
||||
}
|
||||
|
||||
void GenericIntPropertySequence::ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const
|
||||
{
|
||||
if (m_set_callback)
|
||||
{
|
||||
const auto value = result.NextCapture(CAPTURE_VALUE).IntegerValue();
|
||||
m_set_callback(state, value);
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
#include "Parsing/Menu/MenuFileParser.h"
|
||||
|
||||
namespace menu
|
||||
{
|
||||
class GenericIntPropertySequence final : public MenuFileParser::sequence_t
|
||||
{
|
||||
public:
|
||||
using callback_t = std::function<void(MenuFileParserState* state, int value)>;
|
||||
|
||||
private:
|
||||
static constexpr auto CAPTURE_VALUE = 1;
|
||||
|
||||
const callback_t m_set_callback;
|
||||
|
||||
protected:
|
||||
void ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const override;
|
||||
|
||||
public:
|
||||
GenericIntPropertySequence(std::string keywordName, callback_t setCallback);
|
||||
};
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
#include "GenericKeywordPropertySequence.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "Parsing/Menu/Matcher/MenuMatcherFactory.h"
|
||||
|
||||
using namespace menu;
|
||||
|
||||
GenericKeywordPropertySequence::GenericKeywordPropertySequence(std::string keywordName, callback_t setCallback)
|
||||
: m_set_callback(std::move(setCallback))
|
||||
{
|
||||
const MenuMatcherFactory create(this);
|
||||
|
||||
AddMatchers({
|
||||
create.KeywordIgnoreCase(std::move(keywordName)),
|
||||
});
|
||||
}
|
||||
|
||||
void GenericKeywordPropertySequence::ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const
|
||||
{
|
||||
if(m_set_callback)
|
||||
{
|
||||
m_set_callback(state);
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
#include "Parsing/Menu/MenuFileParser.h"
|
||||
|
||||
namespace menu
|
||||
{
|
||||
class GenericKeywordPropertySequence final : public MenuFileParser::sequence_t
|
||||
{
|
||||
public:
|
||||
using callback_t = std::function<void(MenuFileParserState* state)>;
|
||||
|
||||
private:
|
||||
const callback_t m_set_callback;
|
||||
|
||||
protected:
|
||||
void ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const override;
|
||||
|
||||
public:
|
||||
GenericKeywordPropertySequence(std::string keywordName, callback_t setCallback);
|
||||
};
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
#include "GenericStringPropertySequence.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "Parsing/Menu/Matcher/MenuMatcherFactory.h"
|
||||
|
||||
using namespace menu;
|
||||
|
||||
GenericStringPropertySequence::GenericStringPropertySequence(std::string keywordName, callback_t setCallback)
|
||||
: m_set_callback(std::move(setCallback))
|
||||
{
|
||||
const MenuMatcherFactory create(this);
|
||||
|
||||
AddMatchers({
|
||||
create.KeywordIgnoreCase(std::move(keywordName)),
|
||||
create.Text().Capture(CAPTURE_VALUE)
|
||||
});
|
||||
}
|
||||
|
||||
void GenericStringPropertySequence::ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const
|
||||
{
|
||||
if (m_set_callback)
|
||||
{
|
||||
const auto& value = MenuMatcherFactory::TokenTextValue(result.NextCapture(CAPTURE_VALUE));
|
||||
m_set_callback(state, value);
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <functional>
|
||||
|
||||
#include "Parsing/Menu/MenuFileParser.h"
|
||||
|
||||
namespace menu
|
||||
{
|
||||
class GenericStringPropertySequence final : public MenuFileParser::sequence_t
|
||||
{
|
||||
public:
|
||||
using callback_t = std::function<void(MenuFileParserState* state, const std::string& value)>;
|
||||
|
||||
private:
|
||||
static constexpr auto CAPTURE_VALUE = 1;
|
||||
|
||||
const callback_t m_set_callback;
|
||||
|
||||
protected:
|
||||
void ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const override;
|
||||
|
||||
public:
|
||||
GenericStringPropertySequence(std::string keywordName, callback_t setCallback);
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user