This commit is contained in:
Hackerpilot 2015-03-05 19:33:19 -08:00
parent 42ba457439
commit 514ec6d32f
3 changed files with 59 additions and 10 deletions

View File

@ -290,12 +290,12 @@ private:
write(" "); write(" ");
writeParens(true); writeParens(true);
} }
else if (currentIsBlockHeader()) else if (isBlockHeader())
{ {
writeToken(); writeToken();
write(" "); write(" ");
writeParens(false); writeParens(false);
if (currentIsBlockHeader() || current.type == tok!"switch") if (isBlockHeader() || current.type == tok!"switch")
{ {
write(" "); write(" ");
} }
@ -430,8 +430,12 @@ private:
else if (peekBackIs(tok!"identifier") && (peekBack2Is(tok!";") else if (peekBackIs(tok!"identifier") && (peekBack2Is(tok!";")
|| peekBack2Is(tok!"}") || peekBack2Is(tok!"{"))) || peekBack2Is(tok!"}") || peekBack2Is(tok!"{")))
{ {
tempIndent = 0;
writeToken(); writeToken();
if (isBlockHeader())
write(" "); write(" ");
else if (!currentIs(tok!"{"))
newline();
} }
else else
{ {
@ -883,12 +887,20 @@ private:
return peekImplementation(tokenType, 1); return peekImplementation(tokenType, 1);
} }
bool currentIsBlockHeader() bool currentIs(IdType tokenType)
{ {
return current.type == tok!"for" || current.type == tok!"foreach" return peekImplementation(tokenType, 0);
|| current.type == tok!"foreach_reverse" || current.type == tok!"while" }
|| current.type == tok!"if" || current.type == tok!"out"
|| current.type == tok!"catch" || current.type == tok!"with"; bool isBlockHeader(int i = 0)
{
if (i + index < 0 || i + index >= tokens.length)
return false;
auto t = tokens[i + index].type;
return t == tok!"for" || t == tok!"foreach"
|| t == tok!"foreach_reverse" || t == tok!"while"
|| t == tok!"if" || t == tok!"out"
|| t == tok!"catch" || t == tok!"with";
} }
void newline() void newline()
@ -907,8 +919,10 @@ private:
{ {
if (current.type == tok!"}") if (current.type == tok!"}")
indentLevel--; indentLevel--;
else if (!assumeSorted(astInformation.attributeDeclarationLines) else if ((current.type == tok!"identifier" && peekIs(tok!":")
.equalRange(current.line).empty) && !isBlockHeader(2))
|| (!assumeSorted(astInformation.attributeDeclarationLines)
.equalRange(current.line).empty))
{ {
tempIndent--; tempIndent--;
} }

15
tests/issue0037.d Normal file
View File

@ -0,0 +1,15 @@
class U
{
private:
unittest
{
Label: int a = 0;
}
}
unittest
{
loop: while (true){
doStuff(); }
Label:{
}}

20
tests/issue0037.d.ref Normal file
View File

@ -0,0 +1,20 @@
class U
{
private:
unittest
{
Label:
int a = 0;
}
}
unittest
{
loop: while (true)
{
doStuff();
}
Label:
{
}
}