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