This commit is contained in:
Hackerpilot 2015-03-08 19:02:15 -07:00
parent 401631b79d
commit 4590dd44b7
3 changed files with 55 additions and 14 deletions

View file

@ -443,8 +443,8 @@ private:
writeToken(); writeToken();
newline(); newline();
} }
else if (peekBackIs(tok!"identifier") && (peekBack2Is(tok!";") else if (peekBackIs(tok!"identifier") && (peekBack2Is(tok!";", true)
|| peekBack2Is(tok!"}") || peekBack2Is(tok!"{"))) || peekBack2Is(tok!"}", true) || peekBack2Is(tok!"{", true)))
{ {
if (tempIndent < 0) if (tempIndent < 0)
tempIndent = 0; tempIndent = 0;
@ -483,9 +483,7 @@ private:
} }
writeToken(); writeToken();
linebreakHints = []; linebreakHints = [];
if (index >= tokens.length || !currentIs(tok!"comment") newline();
|| current.line != tokens[index - 1].line)
newline();
break; break;
case tok!"{": case tok!"{":
writeBraces(); writeBraces();
@ -1003,28 +1001,28 @@ private:
} }
} }
bool peekBackIs(IdType tokenType) bool peekBackIs(IdType tokenType, bool ignoreComments = false)
{ {
return (index >= 1) && tokens[index - 1].type == tokenType; return peekImplementation(tokenType, -1, ignoreComments);
} }
bool peekBack2Is(IdType tokenType) bool peekBack2Is(IdType tokenType, bool ignoreComments = false)
{ {
return (index >= 2) && tokens[index - 2].type == tokenType; return peekImplementation(tokenType, -2, ignoreComments);
} }
bool peekImplementation(IdType tokenType, size_t n, bool ignoreComments = true) bool peekImplementation(IdType tokenType, int n, bool ignoreComments = true)
{ {
auto i = index + n; auto i = index + n;
if (ignoreComments) if (ignoreComments)
while (i < tokens.length && tokens[i].type == tok!"comment") while (n != 0 && i < tokens.length && tokens[i].type == tok!"comment")
i++; i = n > 0 ? i + 1 : i - 1;
return i < tokens.length && tokens[i].type == tokenType; return i < tokens.length && tokens[i].type == tokenType;
} }
bool peek2Is(IdType tokenType) bool peek2Is(IdType tokenType, bool ignoreComments = true)
{ {
return peekImplementation(tokenType, 2); return peekImplementation(tokenType, 2, ignoreComments);
} }
bool peekIsOperator() bool peekIsOperator()
@ -1073,6 +1071,9 @@ private:
{ {
import std.range : assumeSorted; import std.range : assumeSorted;
if (currentIs(tok!"comment") && current.line == tokenEndLine(tokens[index - 1]))
return;
output.put("\n"); output.put("\n");
immutable bool hasCurrent = index + 1 < tokens.length; immutable bool hasCurrent = index + 1 < tokens.length;
if (!justAddedExtraNewline && index > 0 if (!justAddedExtraNewline && index > 0

20
tests/issue0064.d Normal file
View file

@ -0,0 +1,20 @@
unittest
{
return true; //
Lnomatch:
//printf("nomatch\n");
return false; // nomatch;
}
unittest
{
if (x)
return true;
}
unittest
{
return true; // match
Lnomatch: //printf("nomatch\n");
return false; // nomatch;
}

20
tests/issue0064.d.ref Normal file
View file

@ -0,0 +1,20 @@
unittest
{
return true; //
Lnomatch:
//printf("nomatch\n");
return false; // nomatch;
}
unittest
{
if (x)
return true;
}
unittest
{
return true; // match
Lnomatch: //printf("nomatch\n");
return false; // nomatch;
}