2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-09-01 22:47:26 +00:00

Add ZoneDefinition Lexer

This commit is contained in:
Jan
2021-03-10 14:58:02 +01:00
parent c47ea48b6b
commit 8798779b39
21 changed files with 232 additions and 14 deletions

View File

@@ -0,0 +1,14 @@
#include "SimpleMatcherAnyCharacterBesides.h"
SimpleMatcherAnyCharacterBesides::SimpleMatcherAnyCharacterBesides(std::vector<char> chars)
: m_chars(std::move(chars))
{
}
MatcherResult<SimpleParserValue> SimpleMatcherAnyCharacterBesides::CanMatch(ILexer<SimpleParserValue>* lexer, const unsigned tokenOffset)
{
const auto& token = lexer->GetToken(tokenOffset);
return token.m_type == SimpleParserValueType::CHARACTER && std::find(m_chars.begin(), m_chars.end(), token.CharacterValue()) == m_chars.end()
? MatcherResult<SimpleParserValue>::Match(1)
: MatcherResult<SimpleParserValue>::NoMatch();
}

View File

@@ -0,0 +1,17 @@
#pragma once
#include <vector>
#include "Parsing/Simple/SimpleParserValue.h"
#include "Parsing/Matcher/AbstractMatcher.h"
class SimpleMatcherAnyCharacterBesides final : public AbstractMatcher<SimpleParserValue>
{
std::vector<char> m_chars;
protected:
MatcherResult<SimpleParserValue> CanMatch(ILexer<SimpleParserValue>* lexer, unsigned tokenOffset) override;
public:
explicit SimpleMatcherAnyCharacterBesides(std::vector<char> chars);
};

View File

@@ -1,5 +1,7 @@
#include "SimpleMatcherFactory.h"
#include "SimpleMatcherAnyCharacterBesides.h"
#include "SimpleMatcherCharacter.h"
#include "SimpleMatcherKeyword.h"
#include "SimpleMatcherValueType.h"
@@ -38,3 +40,8 @@ MatcherFactoryWrapper<SimpleParserValue> SimpleMatcherFactory::Char(char c) cons
{
return MatcherFactoryWrapper<SimpleParserValue>(std::make_unique<SimpleMatcherCharacter>(c));
}
MatcherFactoryWrapper<SimpleParserValue> SimpleMatcherFactory::AnyCharBesides(std::vector<char> chars) const
{
return MatcherFactoryWrapper<SimpleParserValue>(std::make_unique<SimpleMatcherAnyCharacterBesides>(std::move(chars)));
}

View File

@@ -16,4 +16,5 @@ public:
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> Integer() const;
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> FloatingPoint() const;
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> Char(char c) const;
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> AnyCharBesides(std::vector<char> chars) const;
};