#pragma once #include "AbstractMatcher.h" #include "Parsing/IParserValue.h" #include #include template class MatcherAnd final : public AbstractMatcher { // TokenType must inherit IParserValue static_assert(std::is_base_of::value); std::vector>> m_matchers; protected: MatcherResult CanMatch(ILexer* lexer, const unsigned tokenOffset) override { auto matchResult = MatcherResult::Match(0); for (const std::unique_ptr>& matcher : m_matchers) { MatcherResult result = matcher->Match(lexer, tokenOffset + matchResult.m_consumed_token_count); if (!result.m_matches) return MatcherResult::NoMatch(); matchResult.Absorb(std::move(result)); } return matchResult; } public: MatcherAnd(std::initializer_list>>> matchers) : m_matchers(std::make_move_iterator(matchers.begin()), std::make_move_iterator(matchers.end())) { } explicit MatcherAnd(std::vector>> matchers) : m_matchers(std::move(matchers)) { } };