#pragma once #include "Utils/ClassUtils.h" #include "Parsing/IParserValue.h" #include "AbstractMatcher.h" template class IMatcherForLabelSupplier { // TokenType must inherit IParserValue static_assert(std::is_base_of::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* GetMatcherForLabel(int label) const = 0; }; template class MatcherLabel final : public AbstractMatcher { // TokenType must inherit IParserValue static_assert(std::is_base_of::value); const IMatcherForLabelSupplier* m_supplier; int m_label; protected: MatcherResult CanMatch(ILexer* lexer, unsigned tokenOffset) override { AbstractMatcher* matcher = m_supplier->GetMatcherForLabel(m_label); if (matcher) return matcher->Match(lexer, tokenOffset); return MatcherResult::NoMatch(); } public: MatcherLabel(const IMatcherForLabelSupplier* supplier, const int label) : m_supplier(supplier), m_label(label) { } };