mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 00:02:55 +00:00
Skip unnecessary outer parenthesis for if clauses and expressions
This commit is contained in:
parent
601b683f8a
commit
a89492d636
@ -593,6 +593,32 @@ class MenuDumperIw4 : public MenuDumper
|
|||||||
WriteStatementEntryRange(statement, 0, static_cast<size_t>(statement->numEntries));
|
WriteStatementEntryRange(statement, 0, static_cast<size_t>(statement->numEntries));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WriteStatementSkipInitialUnnecessaryParenthesis(const Statement_s* statementValue) const
|
||||||
|
{
|
||||||
|
if (statementValue == nullptr || statementValue->numEntries < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const auto statementEnd = static_cast<size_t>(statementValue->numEntries);
|
||||||
|
|
||||||
|
if (statementValue->numEntries >= 1
|
||||||
|
&& statementValue->entries[0].type == EET_OPERATOR
|
||||||
|
&& statementValue->entries[0].data.op == OP_LEFTPAREN)
|
||||||
|
{
|
||||||
|
const auto parenthesisEnd = FindStatementClosingParenthesis(statementValue, 0);
|
||||||
|
|
||||||
|
if (parenthesisEnd >= statementEnd)
|
||||||
|
WriteStatementEntryRange(statementValue, 1, statementEnd);
|
||||||
|
else if (parenthesisEnd == statementEnd - 1)
|
||||||
|
WriteStatementEntryRange(statementValue, 1, statementEnd - 1);
|
||||||
|
else
|
||||||
|
WriteStatementEntryRange(statementValue, 0, statementEnd);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
WriteStatementEntryRange(statementValue, 0, statementEnd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void WriteStatementProperty(const std::string& propertyKey, const Statement_s* statementValue, const bool isBooleanStatement) const
|
void WriteStatementProperty(const std::string& propertyKey, const Statement_s* statementValue, const bool isBooleanStatement) const
|
||||||
{
|
{
|
||||||
if (statementValue == nullptr || statementValue->numEntries < 0)
|
if (statementValue == nullptr || statementValue->numEntries < 0)
|
||||||
@ -601,24 +627,17 @@ class MenuDumperIw4 : public MenuDumper
|
|||||||
Indent();
|
Indent();
|
||||||
WriteKey(propertyKey);
|
WriteKey(propertyKey);
|
||||||
|
|
||||||
const auto statementEnd = static_cast<size_t>(statementValue->numEntries);
|
|
||||||
|
|
||||||
if (isBooleanStatement)
|
if (isBooleanStatement)
|
||||||
{
|
{
|
||||||
m_stream << "when";
|
m_stream << "when(";
|
||||||
|
WriteStatementSkipInitialUnnecessaryParenthesis(statementValue);
|
||||||
// Add a space when first entry is not (
|
m_stream << ");\n";
|
||||||
if (statementEnd < 1
|
}
|
||||||
|| statementValue->entries[0].type != EET_OPERATOR
|
else
|
||||||
|| statementValue->entries[0].data.op != OP_LEFTPAREN)
|
{
|
||||||
{
|
WriteStatementSkipInitialUnnecessaryParenthesis(statementValue);
|
||||||
m_stream << " ";
|
m_stream << ";\n";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteStatementEntryRange(statementValue, 0, statementEnd);
|
|
||||||
|
|
||||||
m_stream << ";\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteSetLocalVarData(const std::string& setFunction, const SetLocalVarData* setLocalVarData) const
|
void WriteSetLocalVarData(const std::string& setFunction, const SetLocalVarData* setLocalVarData) const
|
||||||
@ -637,14 +656,14 @@ class MenuDumperIw4 : public MenuDumper
|
|||||||
const std::string scriptString(script);
|
const std::string scriptString(script);
|
||||||
std::istringstream stringStream(scriptString);
|
std::istringstream stringStream(scriptString);
|
||||||
ParserInputStream inputStream(stringStream, "MenuScript");
|
ParserInputStream inputStream(stringStream, "MenuScript");
|
||||||
SimpleLexer lexer(&inputStream, SimpleLexer::Config{ false, true, false });
|
SimpleLexer lexer(&inputStream, SimpleLexer::Config{false, true, false});
|
||||||
|
|
||||||
std::vector<std::string> result;
|
std::vector<std::string> result;
|
||||||
auto hasLexerTokens = true;
|
auto hasLexerTokens = true;
|
||||||
while(hasLexerTokens)
|
while (hasLexerTokens)
|
||||||
{
|
{
|
||||||
const auto& token = lexer.GetToken(0);
|
const auto& token = lexer.GetToken(0);
|
||||||
switch(token.m_type)
|
switch (token.m_type)
|
||||||
{
|
{
|
||||||
case SimpleParserValueType::IDENTIFIER:
|
case SimpleParserValueType::IDENTIFIER:
|
||||||
result.emplace_back(token.IdentifierValue());
|
result.emplace_back(token.IdentifierValue());
|
||||||
@ -714,7 +733,7 @@ class MenuDumperIw4 : public MenuDumper
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isNewStatement)
|
if (!isNewStatement)
|
||||||
m_stream << " ";
|
m_stream << " ";
|
||||||
else
|
else
|
||||||
isNewStatement = false;
|
isNewStatement = false;
|
||||||
@ -757,7 +776,7 @@ class MenuDumperIw4 : public MenuDumper
|
|||||||
|
|
||||||
Indent();
|
Indent();
|
||||||
m_stream << "if (";
|
m_stream << "if (";
|
||||||
WriteStatement(eventHandler->eventData.conditionalScript->eventExpression);
|
WriteStatementSkipInitialUnnecessaryParenthesis(eventHandler->eventData.conditionalScript->eventExpression);
|
||||||
m_stream << ")\n";
|
m_stream << ")\n";
|
||||||
WriteMenuEventHandlerSet(eventHandler->eventData.conditionalScript->eventHandlerSet);
|
WriteMenuEventHandlerSet(eventHandler->eventData.conditionalScript->eventHandlerSet);
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user