2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-06-26 14:21:49 +00:00

Implement sequence matcher and parser magic

This commit is contained in:
Jan
2021-02-13 00:12:26 +01:00
parent fe1f391bcc
commit 0f70f9586c
48 changed files with 1061 additions and 141 deletions

View File

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