mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-09-01 22:47:26 +00:00
Add multicharacter tokens to simple lexer
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "SimpleMatcherKeyword.h"
|
||||
#include "SimpleMatcherKeywordIgnoreCase.h"
|
||||
#include "SimpleMatcherKeywordPrefix.h"
|
||||
#include "SimpleMatcherMultiCharacter.h"
|
||||
#include "SimpleMatcherValueType.h"
|
||||
|
||||
SimpleMatcherFactory::SimpleMatcherFactory(const IMatcherForLabelSupplier<SimpleParserValue>* labelSupplier)
|
||||
@@ -57,6 +58,11 @@ MatcherFactoryWrapper<SimpleParserValue> SimpleMatcherFactory::Char(char c) cons
|
||||
return MatcherFactoryWrapper<SimpleParserValue>(std::make_unique<SimpleMatcherCharacter>(c));
|
||||
}
|
||||
|
||||
MatcherFactoryWrapper<SimpleParserValue> SimpleMatcherFactory::MultiChar(int multiCharacterSequenceId) const
|
||||
{
|
||||
return MatcherFactoryWrapper<SimpleParserValue>(std::make_unique<SimpleMatcherMultiCharacter>(multiCharacterSequenceId));
|
||||
}
|
||||
|
||||
MatcherFactoryWrapper<SimpleParserValue> SimpleMatcherFactory::AnyCharBesides(std::vector<char> chars) const
|
||||
{
|
||||
return MatcherFactoryWrapper<SimpleParserValue>(std::make_unique<SimpleMatcherAnyCharacterBesides>(std::move(chars)));
|
||||
|
@@ -19,5 +19,6 @@ public:
|
||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> Integer() const;
|
||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> FloatingPoint() const;
|
||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> Char(char c) const;
|
||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> MultiChar(int multiCharacterSequenceId) const;
|
||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> AnyCharBesides(std::vector<char> chars) const;
|
||||
};
|
||||
|
@@ -0,0 +1,14 @@
|
||||
#include "SimpleMatcherMultiCharacter.h"
|
||||
|
||||
SimpleMatcherMultiCharacter::SimpleMatcherMultiCharacter(const int multiCharacterSequenceId)
|
||||
: m_multi_character_sequence_id(multiCharacterSequenceId)
|
||||
{
|
||||
}
|
||||
|
||||
MatcherResult<SimpleParserValue> SimpleMatcherMultiCharacter::CanMatch(ILexer<SimpleParserValue>* lexer, const unsigned tokenOffset)
|
||||
{
|
||||
const auto& token = lexer->GetToken(tokenOffset);
|
||||
return token.m_type == SimpleParserValueType::MULTI_CHARACTER && token.MultiCharacterValue() == m_multi_character_sequence_id
|
||||
? MatcherResult<SimpleParserValue>::Match(1)
|
||||
: MatcherResult<SimpleParserValue>::NoMatch();
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "Parsing/Simple/SimpleParserValue.h"
|
||||
#include "Parsing/Matcher/AbstractMatcher.h"
|
||||
|
||||
class SimpleMatcherMultiCharacter final : public AbstractMatcher<SimpleParserValue>
|
||||
{
|
||||
int m_multi_character_sequence_id;
|
||||
|
||||
protected:
|
||||
MatcherResult<SimpleParserValue> CanMatch(ILexer<SimpleParserValue>* lexer, unsigned tokenOffset) override;
|
||||
|
||||
public:
|
||||
explicit SimpleMatcherMultiCharacter(int multiCharacterSequenceId);
|
||||
};
|
Reference in New Issue
Block a user