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:
33
src/ZoneCodeGeneratorLib/Parsing/Matcher/MatcherOptional.h
Normal file
33
src/ZoneCodeGeneratorLib/Parsing/Matcher/MatcherOptional.h
Normal 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))
|
||||
{
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user