mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-21 00:25:44 +00:00
implement parsing of actions
This commit is contained in:
parent
524e188db1
commit
550eb1e4d3
@ -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))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
};
|
};
|
||||||
|
@ -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));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user