implement set block sequence

This commit is contained in:
Jan
2021-02-19 20:44:46 +01:00
parent 48e3738c05
commit 0cafabc44e
7 changed files with 48 additions and 7 deletions

View File

@ -9,7 +9,7 @@ SequenceSetBlock::SequenceSetBlock()
AddLabeledMatchers(CommandsCommonMatchers::Typename(this), CommandsCommonMatchers::LABEL_TYPENAME);
AddMatchers({
create.Keyword("set"),
create.Keyword("set").Capture(CAPTURE_START),
create.Keyword("block"),
create.Or({
create.And({
@ -24,4 +24,29 @@ SequenceSetBlock::SequenceSetBlock()
void SequenceSetBlock::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
{
StructureInformation* information;
std::vector<MemberInformation*> memberChain;
if (result.HasNextCapture(CAPTURE_TYPE))
{
const auto& typeNameToken = result.NextCapture(CAPTURE_TYPE);
if (!state->GetTypenameAndMembersFromTypename(typeNameToken.TypeNameValue(), information, memberChain))
throw ParsingException(typeNameToken.GetPos(), "Unknown type");
}
else if (state->GetInUse() != nullptr)
{
information = state->GetInUse();
}
else
throw ParsingException(result.NextCapture(CAPTURE_START).GetPos(), "No type is used. Therefore one needs to be specified directly.");
const auto& blockNameToken = result.NextCapture(CAPTURE_BLOCK_ENUM_ENTRY);
auto* fastFileBlock = state->GetRepository()->GetFastFileBlockByName(blockNameToken.IdentifierValue());
if (fastFileBlock == nullptr)
throw ParsingException(blockNameToken.GetPos(), "Unknown block");
if (!memberChain.empty())
memberChain.back()->m_fast_file_block = fastFileBlock;
else
information->m_block = fastFileBlock;
}

View File

@ -4,8 +4,9 @@
class SequenceSetBlock final : public CommandsParser::sequence_t
{
static constexpr auto CAPTURE_TYPE = 1;
static constexpr auto CAPTURE_BLOCK_ENUM_ENTRY = 2;
static constexpr auto CAPTURE_START = 1;
static constexpr auto CAPTURE_TYPE = 2;
static constexpr auto CAPTURE_BLOCK_ENUM_ENTRY = 3;
protected:
void ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const override;