mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-07-01 08:41:52 +00:00
Add sequences for commands
This commit is contained in:
@ -7,5 +7,142 @@ CommandsLexer::CommandsLexer(IParserLineStream* stream)
|
||||
|
||||
CommandsParserValue CommandsLexer::GetNextToken()
|
||||
{
|
||||
return CommandsParserValue::Invalid(TokenPos());
|
||||
auto c = NextChar();
|
||||
|
||||
while (c != EOF)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case '\"':
|
||||
{
|
||||
return CommandsParserValue::String(GetPreviousCharacterPos(), new std::string(ReadString()));
|
||||
}
|
||||
|
||||
case '<':
|
||||
{
|
||||
if (!IsLineEnd())
|
||||
{
|
||||
const auto pos = GetPreviousCharacterPos();
|
||||
const auto nextChar = PeekChar();
|
||||
|
||||
if (nextChar == '=')
|
||||
{
|
||||
NextChar();
|
||||
return CommandsParserValue::LessEqual(pos);
|
||||
}
|
||||
if (nextChar == '<')
|
||||
{
|
||||
NextChar();
|
||||
return CommandsParserValue::ShiftLeft(pos);
|
||||
}
|
||||
}
|
||||
|
||||
return CommandsParserValue::Character(GetPreviousCharacterPos(), static_cast<char>(c));
|
||||
}
|
||||
|
||||
case '>':
|
||||
{
|
||||
if (!IsLineEnd())
|
||||
{
|
||||
const auto pos = GetPreviousCharacterPos();
|
||||
const auto nextChar = PeekChar();
|
||||
|
||||
if (nextChar == '=')
|
||||
{
|
||||
NextChar();
|
||||
return CommandsParserValue::GreaterEqual(pos);
|
||||
}
|
||||
if (nextChar == '>')
|
||||
{
|
||||
NextChar();
|
||||
return CommandsParserValue::ShiftRight(pos);
|
||||
}
|
||||
}
|
||||
|
||||
return CommandsParserValue::Character(GetPreviousCharacterPos(), static_cast<char>(c));
|
||||
}
|
||||
|
||||
case '=':
|
||||
{
|
||||
if (NextCharInLineIs('='))
|
||||
{
|
||||
const auto pos = GetPreviousCharacterPos();
|
||||
NextChar();
|
||||
return CommandsParserValue::Equals(pos);
|
||||
}
|
||||
|
||||
return CommandsParserValue::Character(GetPreviousCharacterPos(), static_cast<char>(c));
|
||||
}
|
||||
|
||||
case '&':
|
||||
{
|
||||
if (NextCharInLineIs('&'))
|
||||
{
|
||||
const auto pos = GetPreviousCharacterPos();
|
||||
NextChar();
|
||||
return CommandsParserValue::LogicalAnd(pos);
|
||||
}
|
||||
|
||||
return CommandsParserValue::Character(GetPreviousCharacterPos(), static_cast<char>(c));
|
||||
}
|
||||
|
||||
case '|':
|
||||
{
|
||||
if (NextCharInLineIs('|'))
|
||||
{
|
||||
const auto pos = GetPreviousCharacterPos();
|
||||
NextChar();
|
||||
return CommandsParserValue::LogicalOr(pos);
|
||||
}
|
||||
|
||||
return CommandsParserValue::Character(GetPreviousCharacterPos(), static_cast<char>(c));
|
||||
}
|
||||
|
||||
case '!':
|
||||
{
|
||||
if (NextCharInLineIs('='))
|
||||
{
|
||||
const auto pos = GetPreviousCharacterPos();
|
||||
NextChar();
|
||||
return CommandsParserValue::NotEqual(pos);
|
||||
}
|
||||
|
||||
return CommandsParserValue::Character(GetPreviousCharacterPos(), static_cast<char>(c));
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
if (isspace(c))
|
||||
break;
|
||||
|
||||
const auto pos = GetPreviousCharacterPos();
|
||||
if (isdigit(c))
|
||||
{
|
||||
bool isFloatingPointValue;
|
||||
double doubleValue;
|
||||
int integerValue;
|
||||
|
||||
ReadNumber(isFloatingPointValue, doubleValue, integerValue);
|
||||
|
||||
if (isFloatingPointValue)
|
||||
return CommandsParserValue::FloatingPoint(pos, doubleValue);
|
||||
|
||||
return CommandsParserValue::Integer(pos, integerValue);
|
||||
}
|
||||
|
||||
if (isalpha(c) || c == '_')
|
||||
{
|
||||
auto identifier = ReadIdentifier();
|
||||
|
||||
return CommandsParserValue::Identifier(pos, new std::string(std::move(identifier)));
|
||||
}
|
||||
|
||||
return CommandsParserValue::Character(pos, static_cast<char>(c));
|
||||
}
|
||||
}
|
||||
|
||||
c = NextChar();
|
||||
}
|
||||
|
||||
return CommandsParserValue::EndOfFile(TokenPos());
|
||||
}
|
||||
|
@ -0,0 +1,46 @@
|
||||
#include "CommandsParser.h"
|
||||
|
||||
#include "Parsing/Commands/Sequence/SequenceAction.h"
|
||||
#include "Parsing/Commands/Sequence/SequenceArrayCount.h"
|
||||
#include "Parsing/Commands/Sequence/SequenceArraySize.h"
|
||||
#include "Parsing/Commands/Sequence/SequenceAsset.h"
|
||||
#include "Parsing/Commands/Sequence/SequenceBlock.h"
|
||||
#include "Parsing/Commands/Sequence/SequenceCondition.h"
|
||||
#include "Parsing/Commands/Sequence/SequenceCount.h"
|
||||
#include "Parsing/Commands/Sequence/SequenceGame.h"
|
||||
#include "Parsing/Commands/Sequence/SequenceName.h"
|
||||
#include "Parsing/Commands/Sequence/SequenceReorder.h"
|
||||
#include "Parsing/Commands/Sequence/SequenceReusable.h"
|
||||
#include "Parsing/Commands/Sequence/SequenceScriptString.h"
|
||||
#include "Parsing/Commands/Sequence/SequenceSetBlock.h"
|
||||
#include "Parsing/Commands/Sequence/SequenceString.h"
|
||||
#include "Parsing/Commands/Sequence/SequenceUse.h"
|
||||
|
||||
CommandsParser::CommandsParser(CommandsLexer* lexer, IDataRepository* targetRepository)
|
||||
: AbstractParser(lexer, std::make_unique<CommandsParserState>()),
|
||||
m_repository(targetRepository)
|
||||
{
|
||||
}
|
||||
|
||||
const std::vector<CommandsParser::sequence_t*>& CommandsParser::GetTestsForState()
|
||||
{
|
||||
static std::vector<sequence_t*> tests({
|
||||
new SequenceAction(),
|
||||
new SequenceArrayCount(),
|
||||
new SequenceArraySize(),
|
||||
new SequenceAsset(),
|
||||
new SequenceBlock(),
|
||||
new SequenceCondition(),
|
||||
new SequenceCount(),
|
||||
new SequenceGame(),
|
||||
new SequenceName(),
|
||||
new SequenceReorder(),
|
||||
new SequenceReusable(),
|
||||
new SequenceScriptString(),
|
||||
new SequenceSetBlock(),
|
||||
new SequenceString(),
|
||||
new SequenceUse()
|
||||
});
|
||||
|
||||
return tests;
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
class CommandsParser
|
||||
#include "CommandsLexer.h"
|
||||
#include "CommandsParserState.h"
|
||||
#include "CommandsParserValue.h"
|
||||
#include "Parsing/Impl/AbstractParser.h"
|
||||
#include "Persistence/IDataRepository.h"
|
||||
|
||||
class CommandsParser final : public AbstractParser<CommandsParserValue, CommandsParserState>
|
||||
{
|
||||
|
||||
};
|
||||
IDataRepository* m_repository;
|
||||
|
||||
protected:
|
||||
const std::vector<sequence_t*>& GetTestsForState() override;
|
||||
|
||||
public:
|
||||
CommandsParser(CommandsLexer* lexer, IDataRepository* targetRepository);
|
||||
};
|
||||
|
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
class CommandsParserState
|
||||
{
|
||||
public:
|
||||
};
|
@ -131,7 +131,8 @@ CommandsParserValue::~CommandsParserValue()
|
||||
}
|
||||
|
||||
CommandsParserValue::CommandsParserValue(CommandsParserValue&& other) noexcept
|
||||
: m_type(other.m_type),
|
||||
: m_pos(other.m_pos),
|
||||
m_type(other.m_type),
|
||||
m_hash(other.m_hash),
|
||||
m_value(other.m_value)
|
||||
{
|
||||
@ -140,6 +141,7 @@ CommandsParserValue::CommandsParserValue(CommandsParserValue&& other) noexcept
|
||||
|
||||
CommandsParserValue& CommandsParserValue::operator=(CommandsParserValue&& other) noexcept
|
||||
{
|
||||
m_pos = other.m_pos;
|
||||
m_type = other.m_type;
|
||||
m_value = other.m_value;
|
||||
m_hash = other.m_hash;
|
||||
|
@ -26,6 +26,15 @@ enum class CommandsParserValueType
|
||||
LOGICAL_AND,
|
||||
LOGICAL_OR,
|
||||
|
||||
// Built-in types
|
||||
BUILT_IN_FIRST,
|
||||
UNSIGNED = BUILT_IN_FIRST,
|
||||
CHAR,
|
||||
SHORT,
|
||||
INT,
|
||||
LONG,
|
||||
BUILT_IN_LAST = LONG,
|
||||
|
||||
// Generic token types
|
||||
INTEGER,
|
||||
FLOATING_POINT,
|
||||
|
Reference in New Issue
Block a user