mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 00:02:55 +00:00
Discord menu function that have already been defined when parsing
This commit is contained in:
parent
245a2ed642
commit
f8c79d27d0
@ -27,18 +27,40 @@ namespace menu::function_scope_sequences
|
|||||||
protected:
|
protected:
|
||||||
void ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const override
|
void ProcessMatch(MenuFileParserState* state, SequenceResult<SimpleParserValue>& result) const override
|
||||||
{
|
{
|
||||||
|
if (!state->m_current_function->m_value)
|
||||||
|
{
|
||||||
|
std::ostringstream ss;
|
||||||
|
ss << "Cannot define function name \"" << state->m_current_function->m_name << "\" without a value";
|
||||||
|
throw ParsingException(result.NextCapture(CAPTURE_TOKEN).GetPos(), ss.str());
|
||||||
|
}
|
||||||
|
|
||||||
const auto existingFunction = state->m_functions_by_name.find(state->m_current_function->m_name);
|
const auto existingFunction = state->m_functions_by_name.find(state->m_current_function->m_name);
|
||||||
if (existingFunction == state->m_functions_by_name.end())
|
if (existingFunction == state->m_functions_by_name.end())
|
||||||
{
|
{
|
||||||
state->m_functions_by_name.emplace(std::make_pair(state->m_current_function->m_name, state->m_current_function));
|
state->m_functions_by_name.emplace(std::make_pair(state->m_current_function->m_name, state->m_current_function));
|
||||||
state->m_current_function = nullptr;
|
state->m_current_function = nullptr;
|
||||||
}
|
}
|
||||||
else
|
else if (!state->m_current_function->m_value->Equals(existingFunction->second->m_value.get()))
|
||||||
{
|
{
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
ss << "Function with name \"" << state->m_current_function->m_name << "\" already exists";
|
ss << "Function with name \"" << state->m_current_function->m_name << "\" already exists";
|
||||||
throw ParsingException(result.NextCapture(CAPTURE_TOKEN).GetPos(), ss.str());
|
throw ParsingException(result.NextCapture(CAPTURE_TOKEN).GetPos(), ss.str());
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Remove definition of function to not re-add it
|
||||||
|
const auto foundFunction = std::find_if(state->m_functions.rbegin(), state->m_functions.rend(), [state](const auto& element)
|
||||||
|
{
|
||||||
|
return element.get() == state->m_current_function;
|
||||||
|
});
|
||||||
|
|
||||||
|
assert(foundFunction != state->m_functions.rend());
|
||||||
|
assert((foundFunction + 1).base()->get() == state->m_current_function);
|
||||||
|
if (foundFunction != state->m_functions.rend())
|
||||||
|
state->m_functions.erase((foundFunction + 1).base());
|
||||||
|
|
||||||
|
state->m_current_function = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user