implement parsing of actions

This commit is contained in:
Jan 2021-02-19 17:39:35 +01:00
parent 524e188db1
commit 550eb1e4d3
3 changed files with 45 additions and 3 deletions

View File

@ -1,6 +1,7 @@
#include "CustomAction.h" #include "CustomAction.h"
CustomAction::CustomAction(std::string actionName) CustomAction::CustomAction(std::string actionName, std::vector<DataDefinition*> parameterTypes)
: m_action_name(std::move(actionName)) : m_action_name(std::move(actionName)),
m_parameter_types(std::move(parameterTypes))
{ {
} }

View File

@ -11,5 +11,5 @@ public:
std::string m_action_name; std::string m_action_name;
std::vector<DataDefinition*> m_parameter_types; std::vector<DataDefinition*> m_parameter_types;
explicit CustomAction(std::string actionName); CustomAction(std::string actionName, std::vector<DataDefinition*> parameterTypes);
}; };

View File

@ -38,4 +38,45 @@ SequenceAction::SequenceAction()
void SequenceAction::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const void SequenceAction::ProcessMatch(CommandsParserState* state, SequenceResult<CommandsParserValue>& result) const
{ {
StructureInformation* type;
const auto& actionNameToken = result.NextCapture(CAPTURE_ACTION_NAME);
// If a typename was specified then try to parse it
// Otherwise take the name that was specified with the last use command
if (result.HasNextCapture(CAPTURE_TYPE))
{
const auto& typeNameToken = result.NextCapture(CAPTURE_TYPE);
std::vector<MemberInformation*> memberChain;
if (!state->GetTypenameAndMembersFromTypename(typeNameToken.TypeNameValue(), type, memberChain))
throw ParsingException(typeNameToken.GetPos(), "Unknown type");
if (!memberChain.empty())
{
type = memberChain.back()->m_type;
if (type == nullptr)
throw ParsingException(typeNameToken.GetPos(), "Member is not a data type with members.");
}
}
else if (state->GetInUse() != nullptr)
{
type = state->GetInUse();
}
else
throw ParsingException(actionNameToken.GetPos(), "No type is used. Therefore one needs to be specified directly.");
// Extract all parameter types that were specified
std::vector<DataDefinition*> parameterTypes;
while(result.HasNextCapture(CAPTURE_ARG_TYPE))
{
const auto& argTypeToken = result.NextCapture(CAPTURE_ARG_TYPE);
auto* dataDefinition = state->GetRepository()->GetDataDefinitionByName(argTypeToken.TypeNameValue());
if (dataDefinition == nullptr)
throw ParsingException(argTypeToken.GetPos(), "Unknown type");
parameterTypes.push_back(dataDefinition);
}
type->m_post_load_action = std::make_unique<CustomAction>(actionNameToken.IdentifierValue(), std::move(parameterTypes));
} }