mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-19 15:52:53 +00:00
Parse padding instructions for StructuredDataDef
This commit is contained in:
parent
73564cf0f0
commit
dff7912dbc
@ -218,6 +218,41 @@ namespace sdd::struct_scope_sequences
|
||||
}
|
||||
};
|
||||
|
||||
class SequencePadding final : public StructuredDataDefParser::sequence_t
|
||||
{
|
||||
static constexpr auto CAPTURE_PADDING_VALUE = 1;
|
||||
|
||||
public:
|
||||
SequencePadding()
|
||||
{
|
||||
const SimpleMatcherFactory create(this);
|
||||
|
||||
AddMatchers({
|
||||
create.Keyword("pad"),
|
||||
create.Char('('),
|
||||
create.Integer().Capture(CAPTURE_PADDING_VALUE),
|
||||
create.Char(')'),
|
||||
create.Char(';')
|
||||
});
|
||||
}
|
||||
|
||||
protected:
|
||||
void ProcessMatch(StructuredDataDefParserState* state, SequenceResult<SimpleParserValue>& result) const override
|
||||
{
|
||||
const auto& paddingValueToken = result.NextCapture(CAPTURE_PADDING_VALUE);
|
||||
const auto paddingValue = paddingValueToken.IntegerValue();
|
||||
|
||||
if (paddingValue <= 0)
|
||||
throw ParsingException(paddingValueToken.GetPos(), "Padding value must be greater than 0");
|
||||
|
||||
// Align to next byte
|
||||
state->m_current_struct_offset_in_bits = (state->m_current_struct_offset_in_bits + 7) / 8 * 8;
|
||||
|
||||
// Add padding value to current size
|
||||
state->m_current_struct_offset_in_bits += static_cast<size_t>(paddingValue);
|
||||
}
|
||||
};
|
||||
|
||||
class SequenceCloseStruct final : public StructuredDataDefParser::sequence_t
|
||||
{
|
||||
public:
|
||||
@ -267,5 +302,6 @@ StructuredDataStructScopeSequences::StructuredDataStructScopeSequences(std::vect
|
||||
void StructuredDataStructScopeSequences::AddSequences() const
|
||||
{
|
||||
AddSequence(std::make_unique<SequenceCloseStruct>());
|
||||
AddSequence(std::make_unique<SequencePadding>());
|
||||
AddSequence(std::make_unique<SequenceStructEntry>());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user