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