mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-05-02 08:29:36 +00:00
Extract commonly used Parser code to new Parser component
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Parsing/IParserValue.h"
|
||||
#include "AbstractMatcher.h"
|
||||
|
||||
template <typename TokenType>
|
||||
class IMatcherForLabelSupplier
|
||||
{
|
||||
// TokenType must inherit IParserValue
|
||||
static_assert(std::is_base_of<IParserValue, TokenType>::value);
|
||||
|
||||
public:
|
||||
IMatcherForLabelSupplier() = default;
|
||||
virtual ~IMatcherForLabelSupplier() = default;
|
||||
IMatcherForLabelSupplier(const IMatcherForLabelSupplier& other) = default;
|
||||
IMatcherForLabelSupplier(IMatcherForLabelSupplier&& other) noexcept = default;
|
||||
IMatcherForLabelSupplier& operator=(const IMatcherForLabelSupplier& other) = default;
|
||||
IMatcherForLabelSupplier& operator=(IMatcherForLabelSupplier&& other) noexcept = default;
|
||||
|
||||
_NODISCARD virtual AbstractMatcher<TokenType>* GetMatcherForLabel(int label) const = 0;
|
||||
};
|
||||
|
||||
template <typename TokenType>
|
||||
class MatcherLabel final : public AbstractMatcher<TokenType>
|
||||
{
|
||||
// TokenType must inherit IParserValue
|
||||
static_assert(std::is_base_of<IParserValue, TokenType>::value);
|
||||
|
||||
const IMatcherForLabelSupplier<TokenType>* m_supplier;
|
||||
int m_label;
|
||||
|
||||
protected:
|
||||
MatcherResult<TokenType> CanMatch(ILexer<TokenType>* lexer, unsigned tokenOffset) override
|
||||
{
|
||||
AbstractMatcher<TokenType>* matcher = m_supplier->GetMatcherForLabel(m_label);
|
||||
|
||||
if (matcher)
|
||||
return matcher->Match(lexer, tokenOffset);
|
||||
|
||||
return MatcherResult<TokenType>::NoMatch();
|
||||
}
|
||||
|
||||
public:
|
||||
MatcherLabel(const IMatcherForLabelSupplier<TokenType>* supplier, const int label)
|
||||
: m_supplier(supplier),
|
||||
m_label(label)
|
||||
{
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user