#pragma once #include #include "Parsing/IParserValue.h" #include "AbstractMatcher.h" template class MatcherOptional final : public AbstractMatcher { // TokenType must inherit IParserValue static_assert(std::is_base_of::value); std::unique_ptr> m_matcher; protected: MatcherResult CanMatch(ILexer* lexer, unsigned tokenOffset) override { auto result = m_matcher->Match(lexer, tokenOffset); if (result.m_matches) return result; return MatcherResult::Match(0); } public: explicit MatcherOptional(std::unique_ptr> matcher) : m_matcher(std::move(matcher)) { } };