mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-09-01 22:47:26 +00:00
Correctly parse binary operations that can be interpreted as sign prefixes for numbers
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "SimpleMatcherKeywordPrefix.h"
|
||||
#include "SimpleMatcherMultiCharacter.h"
|
||||
#include "SimpleMatcherValueType.h"
|
||||
#include "SimpleMatcherValueTypeAndHasSignPrefix.h"
|
||||
|
||||
SimpleMatcherFactory::SimpleMatcherFactory(const IMatcherForLabelSupplier<SimpleParserValue>* labelSupplier)
|
||||
: AbstractMatcherFactory(labelSupplier)
|
||||
@@ -48,11 +49,21 @@ MatcherFactoryWrapper<SimpleParserValue> SimpleMatcherFactory::Integer() const
|
||||
return MatcherFactoryWrapper<SimpleParserValue>(std::make_unique<SimpleMatcherValueType>(SimpleParserValueType::INTEGER));
|
||||
}
|
||||
|
||||
MatcherFactoryWrapper<SimpleParserValue> SimpleMatcherFactory::IntegerWithSign() const
|
||||
{
|
||||
return MatcherFactoryWrapper<SimpleParserValue>(std::make_unique<SimpleMatcherValueTypeAndHasSignPrefix>(SimpleParserValueType::INTEGER, true));
|
||||
}
|
||||
|
||||
MatcherFactoryWrapper<SimpleParserValue> SimpleMatcherFactory::FloatingPoint() const
|
||||
{
|
||||
return MatcherFactoryWrapper<SimpleParserValue>(std::make_unique<SimpleMatcherValueType>(SimpleParserValueType::FLOATING_POINT));
|
||||
}
|
||||
|
||||
MatcherFactoryWrapper<SimpleParserValue> SimpleMatcherFactory::FloatingPointWithSign() const
|
||||
{
|
||||
return MatcherFactoryWrapper<SimpleParserValue>(std::make_unique<SimpleMatcherValueTypeAndHasSignPrefix>(SimpleParserValueType::FLOATING_POINT, true));
|
||||
}
|
||||
|
||||
MatcherFactoryWrapper<SimpleParserValue> SimpleMatcherFactory::Char(char c) const
|
||||
{
|
||||
return MatcherFactoryWrapper<SimpleParserValue>(std::make_unique<SimpleMatcherCharacter>(c));
|
||||
|
@@ -17,7 +17,9 @@ public:
|
||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> Identifier() const;
|
||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> String() const;
|
||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> Integer() const;
|
||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> IntegerWithSign() const;
|
||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> FloatingPoint() const;
|
||||
_NODISCARD MatcherFactoryWrapper<SimpleParserValue> FloatingPointWithSign() 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,15 @@
|
||||
#include "SimpleMatcherValueTypeAndHasSignPrefix.h"
|
||||
|
||||
SimpleMatcherValueTypeAndHasSignPrefix::SimpleMatcherValueTypeAndHasSignPrefix(const SimpleParserValueType type, bool hasSignPrefix)
|
||||
: m_type(type),
|
||||
m_has_sign_prefix(hasSignPrefix)
|
||||
{
|
||||
}
|
||||
|
||||
MatcherResult<SimpleParserValue> SimpleMatcherValueTypeAndHasSignPrefix::CanMatch(ILexer<SimpleParserValue>* lexer, const unsigned tokenOffset)
|
||||
{
|
||||
const auto& token = lexer->GetToken(tokenOffset);
|
||||
return token.m_type == m_type && token.m_has_sign_prefix == m_has_sign_prefix
|
||||
? MatcherResult<SimpleParserValue>::Match(1)
|
||||
: MatcherResult<SimpleParserValue>::NoMatch();
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "Parsing/Simple/SimpleParserValue.h"
|
||||
#include "Parsing/Matcher/AbstractMatcher.h"
|
||||
|
||||
class SimpleMatcherValueTypeAndHasSignPrefix final : public AbstractMatcher<SimpleParserValue>
|
||||
{
|
||||
SimpleParserValueType m_type;
|
||||
bool m_has_sign_prefix;
|
||||
|
||||
protected:
|
||||
MatcherResult<SimpleParserValue> CanMatch(ILexer<SimpleParserValue>* lexer, unsigned tokenOffset) override;
|
||||
|
||||
public:
|
||||
explicit SimpleMatcherValueTypeAndHasSignPrefix(SimpleParserValueType type, bool hasSignPrefix);
|
||||
};
|
Reference in New Issue
Block a user