This commit is contained in:
Hackerpilot 2015-03-08 18:23:01 -07:00
parent 4b7e37c1da
commit d5eed6a9b0
2 changed files with 23 additions and 8 deletions

View File

@ -468,10 +468,13 @@ private:
if (ifIndents.length) if (ifIndents.length)
ifIndents.pop(); ifIndents.pop();
} }
else if (!peekIs(tok!"}")) else if (braceIndents.top() < tempIndent)
{
if (!peekIs(tok!"}"))
tempIndent = 0; tempIndent = 0;
else else
popIndent(); popIndent();
}
writeToken(); writeToken();
linebreakHints = []; linebreakHints = [];
if (index >= tokens.length || current.type != tok!"comment" if (index >= tokens.length || current.type != tok!"comment"
@ -604,12 +607,17 @@ private:
/// Pushes a temporary indent level /// Pushes a temporary indent level
void pushIndent() void pushIndent()
{ {
// stderr.writeln("pushIndent: ", current.line, ",", current.column);
tempIndent++; tempIndent++;
} }
/// Pops a temporary indent level /// Pops a temporary indent level
void popIndent() void popIndent()
{ {
// if (index < tokens.length)
// stderr.writeln("popIndent: ", current.line, ",", current.column);
// else
// stderr.writeln("popIndent: EOF");
if (tempIndent > 0) if (tempIndent > 0)
tempIndent--; tempIndent--;
} }
@ -697,11 +705,11 @@ private:
else if (current.type == tok!"}") else if (current.type == tok!"}")
{ {
braceIndents.pop(); braceIndents.pop();
depth--;
if (assumeSorted(astInformation.structInitEndLocations) if (assumeSorted(astInformation.structInitEndLocations)
.equalRange(tokens[index].index).length) .equalRange(tokens[index].index).length)
{ {
writeToken(); writeToken();
depth--;
} }
else else
{ {
@ -709,7 +717,6 @@ private:
if (peekBackIsLiteralOrIdent() || peekBackIs(tok!",")) if (peekBackIsLiteralOrIdent() || peekBackIs(tok!","))
newline(); newline();
write("}"); write("}");
depth--;
if (index < tokens.length - 1 && if (index < tokens.length - 1 &&
assumeSorted(astInformation.doubleNewlineLocations) assumeSorted(astInformation.doubleNewlineLocations)
.equalRange(tokens[index].index).length && !peekIs(tok!"}")) .equalRange(tokens[index].index).length && !peekIs(tok!"}"))
@ -732,7 +739,6 @@ private:
formatStep(); formatStep();
} }
while (index < tokens.length && depth > 0); while (index < tokens.length && depth > 0);
popIndent();
} }
void writeParens(bool space_afterwards) void writeParens(bool space_afterwards)
@ -801,7 +807,7 @@ private:
formatStep(); formatStep();
} }
while (index < tokens.length && depth > 0); while (index < tokens.length && depth > 0);
popIndent(); // popIndent();
tempIndent = t; tempIndent = t;
linebreakHints = []; linebreakHints = [];
} }

9
tests/issue0070.d Normal file
View File

@ -0,0 +1,9 @@
unittest
{
if (0)
if (0)
{
something();
something_else();
}
}