fix #37
This commit is contained in:
parent
42ba457439
commit
514ec6d32f
32
src/dfmt.d
32
src/dfmt.d
|
@ -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--;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
class U
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
Label: int a = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
loop: while (true){
|
||||||
|
doStuff(); }
|
||||||
|
Label:{
|
||||||
|
}}
|
|
@ -0,0 +1,20 @@
|
||||||
|
class U
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
Label:
|
||||||
|
int a = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
loop: while (true)
|
||||||
|
{
|
||||||
|
doStuff();
|
||||||
|
}
|
||||||
|
Label:
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue