diff --git a/src/ZoneCodeGeneratorLib/Domain/Extension/CustomAction.cpp b/src/ZoneCodeGeneratorLib/Domain/Extension/CustomAction.cpp index e02166c8..a433428b 100644 --- a/src/ZoneCodeGeneratorLib/Domain/Extension/CustomAction.cpp +++ b/src/ZoneCodeGeneratorLib/Domain/Extension/CustomAction.cpp @@ -1,6 +1,7 @@ #include "CustomAction.h" -CustomAction::CustomAction(std::string actionName) - : m_action_name(std::move(actionName)) +CustomAction::CustomAction(std::string actionName, std::vector parameterTypes) + : m_action_name(std::move(actionName)), + m_parameter_types(std::move(parameterTypes)) { } diff --git a/src/ZoneCodeGeneratorLib/Domain/Extension/CustomAction.h b/src/ZoneCodeGeneratorLib/Domain/Extension/CustomAction.h index 615ea9e5..b5fa5d79 100644 --- a/src/ZoneCodeGeneratorLib/Domain/Extension/CustomAction.h +++ b/src/ZoneCodeGeneratorLib/Domain/Extension/CustomAction.h @@ -11,5 +11,5 @@ public: std::string m_action_name; std::vector m_parameter_types; - explicit CustomAction(std::string actionName); + CustomAction(std::string actionName, std::vector parameterTypes); }; diff --git a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceAction.cpp b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceAction.cpp index 1e3475f4..59ad7231 100644 --- a/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceAction.cpp +++ b/src/ZoneCodeGeneratorLib/Parsing/Commands/Sequence/SequenceAction.cpp @@ -38,4 +38,45 @@ SequenceAction::SequenceAction() void SequenceAction::ProcessMatch(CommandsParserState* state, SequenceResult& 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 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 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(actionNameToken.IdentifierValue(), std::move(parameterTypes)); }