mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-22 00:55:45 +00:00
Parse structured data def reserved enum count
This commit is contained in:
parent
040f945009
commit
b894a524e8
@ -12,9 +12,18 @@ CommonStructuredDataDefEnumEntry::CommonStructuredDataDefEnumEntry(std::string n
|
||||
}
|
||||
|
||||
CommonStructuredDataDefEnum::CommonStructuredDataDefEnum()
|
||||
= default;
|
||||
|
||||
CommonStructuredDataDefEnum::CommonStructuredDataDefEnum(std::string name)
|
||||
: m_name(std::move(name))
|
||||
: m_reserved_entry_count(-1)
|
||||
{
|
||||
}
|
||||
|
||||
CommonStructuredDataDefEnum::CommonStructuredDataDefEnum(std::string name)
|
||||
: m_name(std::move(name)),
|
||||
m_reserved_entry_count(-1)
|
||||
{
|
||||
}
|
||||
|
||||
CommonStructuredDataDefEnum::CommonStructuredDataDefEnum(std::string name, const int reservedEntryCount)
|
||||
: m_name(std::move(name)),
|
||||
m_reserved_entry_count(reservedEntryCount)
|
||||
{
|
||||
}
|
||||
|
@ -14,8 +14,10 @@ struct CommonStructuredDataDefEnumEntry
|
||||
struct CommonStructuredDataDefEnum
|
||||
{
|
||||
std::string m_name;
|
||||
int m_reserved_entry_count;
|
||||
std::vector<CommonStructuredDataDefEnumEntry> m_entries;
|
||||
|
||||
CommonStructuredDataDefEnum();
|
||||
explicit CommonStructuredDataDefEnum(std::string name);
|
||||
CommonStructuredDataDefEnum(std::string name, int reservedEntryCount);
|
||||
};
|
@ -7,6 +7,7 @@ namespace sdd::def_scope_sequences
|
||||
class SequenceEnum final : public StructuredDataDefParser::sequence_t
|
||||
{
|
||||
static constexpr auto CAPTURE_NAME = 1;
|
||||
static constexpr auto CAPTURE_RESERVED_COUNT = 2;
|
||||
|
||||
public:
|
||||
SequenceEnum()
|
||||
@ -15,6 +16,11 @@ namespace sdd::def_scope_sequences
|
||||
|
||||
AddMatchers({
|
||||
create.Keyword("enum"),
|
||||
create.Optional(create.And({
|
||||
create.Char('('),
|
||||
create.Integer().Capture(CAPTURE_RESERVED_COUNT),
|
||||
create.Char(')')
|
||||
})),
|
||||
create.Identifier().Capture(CAPTURE_NAME),
|
||||
create.Char('{')
|
||||
});
|
||||
@ -26,6 +32,15 @@ namespace sdd::def_scope_sequences
|
||||
assert(state->m_current_def);
|
||||
|
||||
auto newEnum = std::make_unique<CommonStructuredDataDefEnum>(result.NextCapture(CAPTURE_NAME).IdentifierValue());
|
||||
if (result.HasNextCapture(CAPTURE_RESERVED_COUNT))
|
||||
{
|
||||
const auto& reservedCountToken = result.NextCapture(CAPTURE_RESERVED_COUNT);
|
||||
newEnum->m_reserved_entry_count = reservedCountToken.IntegerValue();
|
||||
|
||||
if (newEnum->m_reserved_entry_count <= 0)
|
||||
throw ParsingException(reservedCountToken.GetPos(), "Reserved enum entry count must be greater than zero");
|
||||
}
|
||||
|
||||
state->m_current_enum = newEnum.get();
|
||||
state->m_def_types_by_name.emplace(newEnum->m_name, CommonStructuredDataDefType(CommonStructuredDataDefTypeCategory::ENUM, state->m_current_def->m_enums.size()));
|
||||
state->m_current_def->m_enums.emplace_back(std::move(newEnum));
|
||||
|
@ -29,7 +29,11 @@ namespace sdd::enum_scope_sequences
|
||||
{
|
||||
assert(state->m_current_enum);
|
||||
|
||||
state->m_current_enum->m_entries.emplace_back(result.NextCapture(CAPTURE_ENTRY_VALUE).StringValue(), state->m_current_enum->m_entries.size());
|
||||
const auto& entryValueToken = result.NextCapture(CAPTURE_ENTRY_VALUE);
|
||||
if (state->m_current_enum->m_reserved_entry_count > 0 && static_cast<size_t>(state->m_current_enum->m_reserved_entry_count) <= state->m_current_enum->m_entries.size())
|
||||
throw ParsingException(entryValueToken.GetPos(), "Enum entry count exceeds reserved count");
|
||||
|
||||
state->m_current_enum->m_entries.emplace_back(entryValueToken.StringValue(), state->m_current_enum->m_entries.size());
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user