Fix #28
This commit is contained in:
parent
fbdb908832
commit
2a803bbde0
56
src/dfmt.d
56
src/dfmt.d
|
|
@ -198,7 +198,7 @@ private:
|
||||||
if (tokens[index].type != tok!"{")
|
if (tokens[index].type != tok!"{")
|
||||||
write(" ");
|
write(" ");
|
||||||
}
|
}
|
||||||
else
|
else if (current.type != tok!"{")
|
||||||
newline();
|
newline();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -277,15 +277,22 @@ private:
|
||||||
write(" ");
|
write(" ");
|
||||||
writeParens(false);
|
writeParens(false);
|
||||||
}
|
}
|
||||||
else if (current.type == tok!"for" || current.type == tok!"foreach"
|
else if (currentIsBlockHeader())
|
||||||
|| current.type == tok!"foreach_reverse" || current.type == tok!"while"
|
|
||||||
|| current.type == tok!"if" || current.type == tok!"out"
|
|
||||||
|| current.type == tok!"catch")
|
|
||||||
{
|
{
|
||||||
writeToken();
|
writeToken();
|
||||||
write(" ");
|
write(" ");
|
||||||
writeParens(false);
|
writeParens(false);
|
||||||
if (current.type != tok!"{" && current.type != tok!";")
|
if (currentIsBlockHeader() || current.type == tok!"switch")
|
||||||
|
{
|
||||||
|
write(" ");
|
||||||
|
}
|
||||||
|
else if (current.type == tok!"comment")
|
||||||
|
{
|
||||||
|
if (!peekIs(tok!"{") && !peekIs(tok!";"))
|
||||||
|
pushIndent();
|
||||||
|
formatStep();
|
||||||
|
}
|
||||||
|
else if (current.type != tok!"{" && current.type != tok!";")
|
||||||
{
|
{
|
||||||
pushIndent();
|
pushIndent();
|
||||||
newline();
|
newline();
|
||||||
|
|
@ -761,7 +768,15 @@ private:
|
||||||
newline();
|
newline();
|
||||||
while (index < tokens.length)
|
while (index < tokens.length)
|
||||||
{
|
{
|
||||||
if (current.type == tok!"case")
|
if (current.type == tok!"}")
|
||||||
|
{
|
||||||
|
indentLevel = l;
|
||||||
|
indent();
|
||||||
|
writeToken();
|
||||||
|
newline();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (current.type == tok!"case")
|
||||||
{
|
{
|
||||||
writeToken();
|
writeToken();
|
||||||
write(" ");
|
write(" ");
|
||||||
|
|
@ -773,21 +788,14 @@ private:
|
||||||
writeToken();
|
writeToken();
|
||||||
write(" ");
|
write(" ");
|
||||||
}
|
}
|
||||||
else
|
else if (peekIs(tok!"case") || peekIs(tok!"default")
|
||||||
|
|| peekIs(tok!"}") || peekIsLabel())
|
||||||
{
|
{
|
||||||
assert (current.type != tok!"}");
|
indentLevel = l;
|
||||||
if (peekIs(tok!"case") || peekIs(tok!"default") || peekIsLabel())
|
formatStep();
|
||||||
{
|
|
||||||
indentLevel = l;
|
|
||||||
formatStep();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
formatStep();
|
|
||||||
if (current.type == tok!"}")
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
formatStep();
|
||||||
}
|
}
|
||||||
indentLevel = l;
|
indentLevel = l;
|
||||||
assert (current.type == tok!"}");
|
assert (current.type == tok!"}");
|
||||||
|
|
@ -857,6 +865,14 @@ private:
|
||||||
return peekImplementation(tokenType, 1);
|
return peekImplementation(tokenType, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool currentIsBlockHeader()
|
||||||
|
{
|
||||||
|
return current.type == tok!"for" || current.type == tok!"foreach"
|
||||||
|
|| 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";
|
||||||
|
}
|
||||||
|
|
||||||
void newline()
|
void newline()
|
||||||
{
|
{
|
||||||
import std.range:assumeSorted;
|
import std.range:assumeSorted;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
if (imin.value > 0x10FFFFUL) // ??
|
||||||
|
imin.value = 0x10FFFFUL; // ??
|
||||||
|
with (stuff) switch (a)
|
||||||
|
{
|
||||||
|
case a: doStuff(); break;
|
||||||
|
} switch (a)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
if (something) /** whatever */
|
||||||
|
doStuff();
|
||||||
|
if (something) /+ comment +/
|
||||||
|
{doStuff();}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
if (imin.value > 0x10FFFFUL) // ??
|
||||||
|
imin.value = 0x10FFFFUL; // ??
|
||||||
|
with (stuff) switch (a)
|
||||||
|
{
|
||||||
|
case a:
|
||||||
|
doStuff();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch (a)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
if (something) /** whatever */
|
||||||
|
doStuff();
|
||||||
|
if (something) /+ comment +/
|
||||||
|
{
|
||||||
|
doStuff();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue