This commit is contained in:
Hackerpilot 2015-03-18 16:15:51 -07:00
parent 0c0bcf3bf3
commit 5b68b60877
4 changed files with 1756 additions and 1741 deletions

View File

@ -207,8 +207,8 @@ private:
if (index < tokens.length)
{
immutable t = tokens[index].type;
if (t == tok!"identifier" || isStringLiteral(t) || isNumberLiteral(t)
|| t == tok!"characterLiteral")
if (t == tok!"identifier" || isStringLiteral(t)
|| isNumberLiteral(t) || t == tok!"characterLiteral")
write(" ");
}
}
@ -579,13 +579,21 @@ private:
}
}
bool peekBackIsSlashSlash()
{
return index > 0 && tokens[index - 1].type == tok!"comment"
&& tokens[index - 1].text[0 .. 2] == "//";
}
void formatRightBrace()
{
if (astInformation.structInitEndLocations.canFindIndex(tokens[index].index))
if (!peekBackIsSlashSlash()
&& astInformation.structInitEndLocations.canFindIndex(tokens[index].index))
{
writeToken();
}
else if (astInformation.funLitEndLocations.canFindIndex(tokens[index].index))
else if (!peekBackIsSlashSlash()
&& astInformation.funLitEndLocations.canFindIndex(tokens[index].index))
{
write(" ");
writeToken();
@ -593,12 +601,12 @@ private:
else
{
// Silly hack to format enums better.
if (peekBackIsLiteralOrIdent() || peekBackIs(tok!","))
if (peekBackIsLiteralOrIdent() || peekBackIs(tok!",", true))
newline();
write("}");
if (index < tokens.length - 1
&& astInformation.doubleNewlineLocations.canFindIndex(tokens[index].index)
&& !peekIs(tok!"}"))
&& !peekIs(tok!"}") && !peekIs(tok!";"))
{
write("\n");
currentLineLength = 0;
@ -606,7 +614,7 @@ private:
}
if (config.braceStyle == BraceStyle.otbs && currentIs(tok!"else"))
write(" ");
if (!peekIs(tok!",") && !peekIs(tok!")"))
if (!peekIs(tok!",") && !peekIs(tok!")") && !peekIs(tok!";"))
{
index++;
newline();
@ -1105,7 +1113,7 @@ private:
immutable bool hasCurrent = index + 1 < tokens.length;
if (hasCurrent && tokens[index].type == tok!"}"
if (!peekBackIsSlashSlash() && hasCurrent && tokens[index].type == tok!"}"
&& !assumeSorted(astInformation.funLitEndLocations).equalRange(tokens[index].index).empty)
{
write(" ");

View File

@ -0,0 +1,2 @@
auto fun = { int i; // Comment
};

3
tests/issue0120.d Normal file
View File

@ -0,0 +1,3 @@
auto fun = {
int i; // Comment
};

View File

@ -0,0 +1,2 @@
auto fun = { int i; // Comment
};