mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-21 00:25:44 +00:00
Parse game and block commands
This commit is contained in:
parent
2747e1f0f2
commit
1264be4274
@ -17,7 +17,7 @@
|
|||||||
#include "Parsing/Commands/Sequence/SequenceUse.h"
|
#include "Parsing/Commands/Sequence/SequenceUse.h"
|
||||||
|
|
||||||
CommandsParser::CommandsParser(CommandsLexer* lexer, IDataRepository* targetRepository)
|
CommandsParser::CommandsParser(CommandsLexer* lexer, IDataRepository* targetRepository)
|
||||||
: AbstractParser(lexer, std::make_unique<CommandsParserState>()),
|
: AbstractParser(lexer, std::make_unique<CommandsParserState>(targetRepository)),
|
||||||
m_repository(targetRepository)
|
m_repository(targetRepository)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
#include "CommandsParserState.h"
|
||||||
|
|
||||||
|
CommandsParserState::CommandsParserState(IDataRepository* repository)
|
||||||
|
: m_repository(repository),
|
||||||
|
m_in_use(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const IDataRepository* CommandsParserState::GetRepository() const
|
||||||
|
{
|
||||||
|
return m_repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CommandsParserState::AddBlock(std::unique_ptr<FastFileBlock> block) const
|
||||||
|
{
|
||||||
|
m_repository->Add(std::move(block));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CommandsParserState::SetGame(std::string gameName) const
|
||||||
|
{
|
||||||
|
m_repository->SetGame(std::move(gameName));
|
||||||
|
}
|
||||||
|
|
||||||
|
StructureInformation* CommandsParserState::GetInUse() const
|
||||||
|
{
|
||||||
|
return m_in_use;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CommandsParserState::SetInUse(StructureInformation* structure)
|
||||||
|
{
|
||||||
|
m_in_use = structure;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CommandsParserState::GetMembersFromParts(const std::string& typeNameValue, StructureInformation* baseType, std::vector<MemberInformation*>& members)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CommandsParserState::GetTypenameAndMembersFromParts(const std::string& typeNameValue, StructureInformation*& structure, std::vector<MemberInformation*>& members)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
@ -1,6 +1,27 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "Utils/ClassUtils.h"
|
||||||
|
#include "Persistence/IDataRepository.h"
|
||||||
|
|
||||||
class CommandsParserState
|
class CommandsParserState
|
||||||
{
|
{
|
||||||
|
IDataRepository* m_repository;
|
||||||
|
StructureInformation* m_in_use;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
explicit CommandsParserState(IDataRepository* repository);
|
||||||
|
|
||||||
|
_NODISCARD const IDataRepository* GetRepository() const;
|
||||||
|
|
||||||
|
void AddBlock(std::unique_ptr<FastFileBlock> block) const;
|
||||||
|
void SetGame(std::string gameName) const;
|
||||||
|
|
||||||
|
_NODISCARD StructureInformation* GetInUse() const;
|
||||||
|
void SetInUse(StructureInformation* structure);
|
||||||
|
|
||||||
|
bool GetMembersFromParts(const std::string& typeNameValue, StructureInformation* baseType, std::vector<MemberInformation*>& members);
|
||||||
|
bool GetTypenameAndMembersFromParts(const std::string& typeNameValue, StructureInformation*& structure, std::vector<MemberInformation*>& members);
|
||||||
};
|
};
|
@ -194,7 +194,12 @@ std::unique_ptr<CommandsCommonMatchers::matcher_t> CommandsCommonMatchers::Evalu
|
|||||||
}).Tag(TAG_EVALUATION);
|
}).Tag(TAG_EVALUATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<IEvaluation> CommandsCommonMatchers::ParseEvaluation(SequenceResult<CommandsParserValue>& result)
|
std::unique_ptr<IEvaluation> CommandsCommonMatchers::ParseEvaluation(CommandsParserState* state, SequenceResult<CommandsParserValue>& result)
|
||||||
{
|
{
|
||||||
|
if (result.PeekAndRemoveIfTag(TAG_EVALUATION) != TAG_EVALUATION)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "Domain/Evaluation/IEvaluation.h"
|
#include "Domain/Evaluation/IEvaluation.h"
|
||||||
|
#include "Parsing/Commands/Impl/CommandsParserState.h"
|
||||||
#include "Parsing/Commands/Impl/CommandsParserValue.h"
|
#include "Parsing/Commands/Impl/CommandsParserValue.h"
|
||||||
#include "Parsing/Matcher/AbstractMatcher.h"
|
#include "Parsing/Matcher/AbstractMatcher.h"
|
||||||
#include "Parsing/Matcher/MatcherLabel.h"
|
#include "Parsing/Matcher/MatcherLabel.h"
|
||||||
@ -29,5 +30,5 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
static std::unique_ptr<matcher_t> Evaluation(const supplier_t* labelSupplier);
|
static std::unique_ptr<matcher_t> Evaluation(const supplier_t* labelSupplier);
|
||||||
static std::unique_ptr<IEvaluation> ParseEvaluation(SequenceResult<CommandsParserValue>& result);
|
static std::unique_ptr<IEvaluation> ParseEvaluation(CommandsParserState* state, SequenceResult<CommandsParserValue>& result);
|
||||||
};
|
};
|
||||||
|
@ -7,15 +7,53 @@ SequenceBlock::SequenceBlock()
|
|||||||
{
|
{
|
||||||
const CommandsMatcherFactory create(this);
|
const CommandsMatcherFactory create(this);
|
||||||
|
|
||||||
|
#define DEFINE_FAST_FILE_BLOCK_TYPE(type) AddFastFileBlockToLookup(#type, FastFileBlockType::type)
|
||||||
|
DEFINE_FAST_FILE_BLOCK_TYPE(TEMP);
|
||||||
|
DEFINE_FAST_FILE_BLOCK_TYPE(RUNTIME);
|
||||||
|
DEFINE_FAST_FILE_BLOCK_TYPE(DELAY);
|
||||||
|
DEFINE_FAST_FILE_BLOCK_TYPE(NORMAL);
|
||||||
|
#undef DEFINE_FAST_FILE_BLOCK_TYPE
|
||||||
|
|
||||||
AddMatchers({
|
AddMatchers({
|
||||||
create.Keyword("block"),
|
create.Keyword("block"),
|
||||||
create.Identifier().Capture(CAPTURE_BLOCK_ENUM_ENTRY),
|
|
||||||
create.Identifier().Capture(CAPTURE_BLOCK_TYPE),
|
create.Identifier().Capture(CAPTURE_BLOCK_TYPE),
|
||||||
|
create.Identifier().Capture(CAPTURE_BLOCK_ENUM_ENTRY),
|
||||||
create.Optional(create.Keyword("default").Tag(TAG_DEFAULT)),
|
create.Optional(create.Keyword("default").Tag(TAG_DEFAULT)),
|
||||||
create.Char(';')
|
create.Char(';')
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SequenceBlock::AddFastFileBlockToLookup(std::string name, const FastFileBlockType type)
|
||||||
|
{
|
||||||
|
for (auto& c : name)
|
||||||
|
c = static_cast<char>(tolower(c));
|
||||||
|
|
||||||
|
m_type_lookup[name] = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SequenceBlock::GetFastFileBlockNameByType(const std::string& name, FastFileBlockType& type) const
|
||||||
|
{
|
||||||
|
const auto foundEntry = m_type_lookup.find(name);
|
||||||
|
if (foundEntry == m_type_lookup.end())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
type = foundEntry->second;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void SequenceBlock::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
|
void SequenceBlock::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
|
||||||
{
|
{
|
||||||
|
const auto& enumEntryToken = result.NextCapture(CAPTURE_BLOCK_ENUM_ENTRY);
|
||||||
|
auto* enumMember = state->GetRepository()->GetEnumMemberByName(enumEntryToken.IdentifierValue());
|
||||||
|
if (enumMember == nullptr)
|
||||||
|
throw ParsingException(enumEntryToken.GetPos(), "Unknown block enum entry");
|
||||||
|
|
||||||
|
const auto& typeToken = result.NextCapture(CAPTURE_BLOCK_TYPE);
|
||||||
|
FastFileBlockType type;
|
||||||
|
if (!GetFastFileBlockNameByType(typeToken.IdentifierValue(), type))
|
||||||
|
throw ParsingException(typeToken.GetPos(), "Unknown fastfile block type");
|
||||||
|
|
||||||
|
auto isDefault = result.PeekAndRemoveIfTag(TAG_DEFAULT) == TAG_DEFAULT;
|
||||||
|
|
||||||
|
state->AddBlock(std::make_unique<FastFileBlock>(enumMember->m_name, static_cast<int>(enumMember->m_value), type, isDefault));
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
#include "Utils/ClassUtils.h"
|
||||||
#include "Parsing/Commands/Impl/CommandsParser.h"
|
#include "Parsing/Commands/Impl/CommandsParser.h"
|
||||||
|
|
||||||
class SequenceBlock final : public CommandsParser::sequence_t
|
class SequenceBlock final : public CommandsParser::sequence_t
|
||||||
@ -9,6 +12,11 @@ class SequenceBlock final : public CommandsParser::sequence_t
|
|||||||
static constexpr auto CAPTURE_BLOCK_ENUM_ENTRY = 1;
|
static constexpr auto CAPTURE_BLOCK_ENUM_ENTRY = 1;
|
||||||
static constexpr auto CAPTURE_BLOCK_TYPE = 2;
|
static constexpr auto CAPTURE_BLOCK_TYPE = 2;
|
||||||
|
|
||||||
|
std::unordered_map<std::string, FastFileBlockType> m_type_lookup;
|
||||||
|
|
||||||
|
void AddFastFileBlockToLookup(std::string name, FastFileBlockType type);
|
||||||
|
_NODISCARD bool GetFastFileBlockNameByType(const std::string& name, FastFileBlockType& type) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;
|
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;
|
||||||
|
|
||||||
|
@ -16,4 +16,5 @@ SequenceGame::SequenceGame()
|
|||||||
|
|
||||||
void SequenceGame::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
|
void SequenceGame::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
|
||||||
{
|
{
|
||||||
|
state->SetGame(result.NextCapture(CAPTURE_GAME).IdentifierValue());
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,9 @@ public:
|
|||||||
virtual void Add(std::unique_ptr<StructureInformation> structureInformation) = 0;
|
virtual void Add(std::unique_ptr<StructureInformation> structureInformation) = 0;
|
||||||
virtual void Add(std::unique_ptr<FastFileBlock> fastFileBlock) = 0;
|
virtual void Add(std::unique_ptr<FastFileBlock> fastFileBlock) = 0;
|
||||||
|
|
||||||
|
_NODISCARD virtual const std::string& GetGameName() const = 0;
|
||||||
|
virtual void SetGame(std::string gameName) = 0;
|
||||||
|
|
||||||
_NODISCARD virtual const std::vector<EnumDefinition*>& GetAllEnums() const = 0;
|
_NODISCARD virtual const std::vector<EnumDefinition*>& GetAllEnums() const = 0;
|
||||||
_NODISCARD virtual const std::vector<StructDefinition*>& GetAllStructs() const = 0;
|
_NODISCARD virtual const std::vector<StructDefinition*>& GetAllStructs() const = 0;
|
||||||
_NODISCARD virtual const std::vector<UnionDefinition*>& GetAllUnions() const = 0;
|
_NODISCARD virtual const std::vector<UnionDefinition*>& GetAllUnions() const = 0;
|
||||||
@ -36,4 +39,5 @@ public:
|
|||||||
|
|
||||||
_NODISCARD virtual DataDefinition* GetDataDefinitionByName(const std::string& name) const = 0;
|
_NODISCARD virtual DataDefinition* GetDataDefinitionByName(const std::string& name) const = 0;
|
||||||
_NODISCARD virtual StructureInformation* GetInformationFor(DefinitionWithMembers* definitionWithMembers) const = 0;
|
_NODISCARD virtual StructureInformation* GetInformationFor(DefinitionWithMembers* definitionWithMembers) const = 0;
|
||||||
|
_NODISCARD virtual EnumMember* GetEnumMemberByName(const std::string& name) const = 0;
|
||||||
};
|
};
|
||||||
|
@ -1,10 +1,29 @@
|
|||||||
#include "InMemoryRepository.h"
|
#include "InMemoryRepository.h"
|
||||||
|
|
||||||
|
InMemoryRepository::~InMemoryRepository()
|
||||||
|
{
|
||||||
|
for (auto* enumDefinition : m_enums)
|
||||||
|
delete enumDefinition;
|
||||||
|
for (auto* structDefinition : m_structs)
|
||||||
|
delete structDefinition;
|
||||||
|
for (auto* unionDefinition : m_unions)
|
||||||
|
delete unionDefinition;
|
||||||
|
for (auto* typedefDefinition : m_typedefs)
|
||||||
|
delete typedefDefinition;
|
||||||
|
for (auto* structureInformation : m_structures_information)
|
||||||
|
delete structureInformation;
|
||||||
|
for (auto* fastFileBlock : m_fast_file_blocks)
|
||||||
|
delete fastFileBlock;
|
||||||
|
}
|
||||||
|
|
||||||
void InMemoryRepository::Add(std::unique_ptr<EnumDefinition> enumsDefinition)
|
void InMemoryRepository::Add(std::unique_ptr<EnumDefinition> enumsDefinition)
|
||||||
{
|
{
|
||||||
auto* raw = enumsDefinition.release();
|
auto* raw = enumsDefinition.release();
|
||||||
m_enums.push_back(raw);
|
m_enums.push_back(raw);
|
||||||
m_data_definitions_by_name[raw->m_name] = raw;
|
m_data_definitions_by_name[raw->m_name] = raw;
|
||||||
|
|
||||||
|
for(const auto& enumMember : raw->m_members)
|
||||||
|
m_enum_members_by_name[enumMember->m_name] = enumMember.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InMemoryRepository::Add(std::unique_ptr<StructDefinition> structDefinition)
|
void InMemoryRepository::Add(std::unique_ptr<StructDefinition> structDefinition)
|
||||||
@ -40,6 +59,16 @@ void InMemoryRepository::Add(std::unique_ptr<FastFileBlock> fastFileBlock)
|
|||||||
m_fast_file_blocks.push_back(fastFileBlock.release());
|
m_fast_file_blocks.push_back(fastFileBlock.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string& InMemoryRepository::GetGameName() const
|
||||||
|
{
|
||||||
|
return m_game_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void InMemoryRepository::SetGame(std::string gameName)
|
||||||
|
{
|
||||||
|
m_game_name = std::move(gameName);
|
||||||
|
}
|
||||||
|
|
||||||
const std::vector<EnumDefinition*>& InMemoryRepository::GetAllEnums() const
|
const std::vector<EnumDefinition*>& InMemoryRepository::GetAllEnums() const
|
||||||
{
|
{
|
||||||
return m_enums;
|
return m_enums;
|
||||||
@ -89,3 +118,13 @@ StructureInformation* InMemoryRepository::GetInformationFor(DefinitionWithMember
|
|||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EnumMember* InMemoryRepository::GetEnumMemberByName(const std::string& name) const
|
||||||
|
{
|
||||||
|
const auto foundEntry = m_enum_members_by_name.find(name);
|
||||||
|
|
||||||
|
if (foundEntry != m_enum_members_by_name.end())
|
||||||
|
return foundEntry->second;
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
@ -13,9 +13,18 @@ class InMemoryRepository final : public IDataRepository
|
|||||||
std::vector<StructureInformation*> m_structures_information;
|
std::vector<StructureInformation*> m_structures_information;
|
||||||
std::vector<FastFileBlock*> m_fast_file_blocks;
|
std::vector<FastFileBlock*> m_fast_file_blocks;
|
||||||
std::map<std::string, DataDefinition*> m_data_definitions_by_name;
|
std::map<std::string, DataDefinition*> m_data_definitions_by_name;
|
||||||
|
std::map<std::string, EnumMember*> m_enum_members_by_name;
|
||||||
std::map<DefinitionWithMembers*, StructureInformation*> m_structure_information_by_definition;
|
std::map<DefinitionWithMembers*, StructureInformation*> m_structure_information_by_definition;
|
||||||
|
std::string m_game_name;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
InMemoryRepository() = default;
|
||||||
|
~InMemoryRepository() override;
|
||||||
|
InMemoryRepository(const InMemoryRepository& other) = delete;
|
||||||
|
InMemoryRepository(InMemoryRepository&& other) noexcept = default;
|
||||||
|
InMemoryRepository& operator=(const InMemoryRepository& other) = delete;
|
||||||
|
InMemoryRepository& operator=(InMemoryRepository&& other) noexcept = default;
|
||||||
|
|
||||||
void Add(std::unique_ptr<EnumDefinition> enumsDefinition) override;
|
void Add(std::unique_ptr<EnumDefinition> enumsDefinition) override;
|
||||||
void Add(std::unique_ptr<StructDefinition> structDefinition) override;
|
void Add(std::unique_ptr<StructDefinition> structDefinition) override;
|
||||||
void Add(std::unique_ptr<UnionDefinition> unionDefinition) override;
|
void Add(std::unique_ptr<UnionDefinition> unionDefinition) override;
|
||||||
@ -23,6 +32,9 @@ public:
|
|||||||
void Add(std::unique_ptr<StructureInformation> structureInformation) override;
|
void Add(std::unique_ptr<StructureInformation> structureInformation) override;
|
||||||
void Add(std::unique_ptr<FastFileBlock> fastFileBlock) override;
|
void Add(std::unique_ptr<FastFileBlock> fastFileBlock) override;
|
||||||
|
|
||||||
|
_NODISCARD const std::string& GetGameName() const override;
|
||||||
|
void SetGame(std::string gameName) override;
|
||||||
|
|
||||||
_NODISCARD const std::vector<EnumDefinition*>& GetAllEnums() const override;
|
_NODISCARD const std::vector<EnumDefinition*>& GetAllEnums() const override;
|
||||||
_NODISCARD const std::vector<StructDefinition*>& GetAllStructs() const override;
|
_NODISCARD const std::vector<StructDefinition*>& GetAllStructs() const override;
|
||||||
_NODISCARD const std::vector<UnionDefinition*>& GetAllUnions() const override;
|
_NODISCARD const std::vector<UnionDefinition*>& GetAllUnions() const override;
|
||||||
@ -32,4 +44,5 @@ public:
|
|||||||
|
|
||||||
_NODISCARD DataDefinition* GetDataDefinitionByName(const std::string& name) const override;
|
_NODISCARD DataDefinition* GetDataDefinitionByName(const std::string& name) const override;
|
||||||
_NODISCARD StructureInformation* GetInformationFor(DefinitionWithMembers* definitionWithMembers) const override;
|
_NODISCARD StructureInformation* GetInformationFor(DefinitionWithMembers* definitionWithMembers) const override;
|
||||||
|
_NODISCARD EnumMember* GetEnumMemberByName(const std::string& name) const override;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user