Fix #93
This commit is contained in:
parent
c3cb505dfe
commit
98d397cd22
21
src/dfmt.d
21
src/dfmt.d
|
|
@ -300,8 +300,7 @@ private:
|
||||||
writeToken(); // switch
|
writeToken(); // switch
|
||||||
write(" ");
|
write(" ");
|
||||||
}
|
}
|
||||||
else if ((currentIs(tok!"version") || currentIs(tok!"extern"))
|
else if (currentIs(tok!"extern") && peekIs(tok!"("))
|
||||||
&& peekIs(tok!"("))
|
|
||||||
{
|
{
|
||||||
writeToken();
|
writeToken();
|
||||||
write(" ");
|
write(" ");
|
||||||
|
|
@ -326,13 +325,13 @@ private:
|
||||||
if (currentIs(tok!"if") || (currentIs(tok!"static") && peekIs(tok!"if"))
|
if (currentIs(tok!"if") || (currentIs(tok!"static") && peekIs(tok!"if"))
|
||||||
|| currentIs(tok!"version"))
|
|| currentIs(tok!"version"))
|
||||||
{
|
{
|
||||||
if (indents.top() == tok!"if")
|
if (indents.top() == tok!"if" || indents.top == tok!"version")
|
||||||
indents.pop();
|
indents.pop();
|
||||||
write(" ");
|
write(" ");
|
||||||
}
|
}
|
||||||
else if (!currentIs(tok!"{") && !currentIs(tok!"comment"))
|
else if (!currentIs(tok!"{") && !currentIs(tok!"comment"))
|
||||||
{
|
{
|
||||||
if (indents.top() == tok!"if")
|
if (indents.top() == tok!"if" || indents.top == tok!"version")
|
||||||
indents.pop();
|
indents.pop();
|
||||||
indents.push(tok!"else");
|
indents.push(tok!"else");
|
||||||
newline();
|
newline();
|
||||||
|
|
@ -941,13 +940,14 @@ private:
|
||||||
auto t = tokens[i + index].type;
|
auto t = tokens[i + index].type;
|
||||||
return t == tok!"for" || t == tok!"foreach"
|
return t == tok!"for" || t == tok!"foreach"
|
||||||
|| t == tok!"foreach_reverse" || t == tok!"while"
|
|| t == tok!"foreach_reverse" || t == tok!"while"
|
||||||
|| t == tok!"if" || t == tok!"out"
|
|| t == tok!"if" || t == tok!"out" || t == tok!"version"
|
||||||
|| t == tok!"catch" || t == tok!"with";
|
|| t == tok!"catch" || t == tok!"with";
|
||||||
}
|
}
|
||||||
|
|
||||||
void newline()
|
void newline()
|
||||||
{
|
{
|
||||||
import std.range : assumeSorted;
|
import std.range : assumeSorted;
|
||||||
|
import std.algorithm : max;
|
||||||
|
|
||||||
if (currentIs(tok!"comment") && current.line == tokenEndLine(tokens[index - 1]))
|
if (currentIs(tok!"comment") && current.line == tokenEndLine(tokens[index - 1]))
|
||||||
return;
|
return;
|
||||||
|
|
@ -976,9 +976,11 @@ private:
|
||||||
bool switchLabel = false;
|
bool switchLabel = false;
|
||||||
if (currentIs(tok!"else"))
|
if (currentIs(tok!"else"))
|
||||||
{
|
{
|
||||||
auto l = indents.indentToMostRecent(tok!"if");
|
auto i = indents.indentToMostRecent(tok!"if");
|
||||||
if (l != -1)
|
auto v = indents.indentToMostRecent(tok!"version");
|
||||||
indentLevel = l;
|
auto mostRecent = max(i, v);
|
||||||
|
if (mostRecent != -1)
|
||||||
|
indentLevel = mostRecent;
|
||||||
}
|
}
|
||||||
else if (currentIs(tok!"identifier") && peekIs(tok!":"))
|
else if (currentIs(tok!"identifier") && peekIs(tok!":"))
|
||||||
{
|
{
|
||||||
|
|
@ -1037,7 +1039,8 @@ private:
|
||||||
indents.pop();
|
indents.pop();
|
||||||
}
|
}
|
||||||
while (indents.length && isTempIndent(indents.top)
|
while (indents.length && isTempIndent(indents.top)
|
||||||
&& (indents.top != tok!"if" || !peekIs(tok!"else")))
|
&& ((indents.top != tok!"if" && indents.top != tok!"version")
|
||||||
|
|| !peekIs(tok!"else")))
|
||||||
{
|
{
|
||||||
indents.pop();
|
indents.pop();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
version (AArch64) int x = 10;
|
version (AArch64)
|
||||||
|
int x = 10;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
if (x)
|
||||||
|
{
|
||||||
|
version (none)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
if (x)
|
||||||
|
{
|
||||||
|
version (none)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue