Skip to content

Commit

Permalink
Fix #93
Browse files Browse the repository at this point in the history
  • Loading branch information
Hackerpilot committed Mar 12, 2015
1 parent c3cb505 commit 98d397c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
21 changes: 12 additions & 9 deletions src/dfmt.d
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,7 @@ private:
writeToken(); // switch
write(" ");
}
else if ((currentIs(tok!"version") || currentIs(tok!"extern"))
&& peekIs(tok!"("))
else if (currentIs(tok!"extern") && peekIs(tok!"("))
{
writeToken();
write(" ");
Expand All @@ -326,13 +325,13 @@ private:
if (currentIs(tok!"if") || (currentIs(tok!"static") && peekIs(tok!"if"))
|| currentIs(tok!"version"))
{
if (indents.top() == tok!"if")
if (indents.top() == tok!"if" || indents.top == tok!"version")
indents.pop();
write(" ");
}
else if (!currentIs(tok!"{") && !currentIs(tok!"comment"))
{
if (indents.top() == tok!"if")
if (indents.top() == tok!"if" || indents.top == tok!"version")
indents.pop();
indents.push(tok!"else");
newline();
Expand Down Expand Up @@ -941,13 +940,14 @@ private:
auto t = tokens[i + index].type;
return t == tok!"for" || t == tok!"foreach"
|| 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";
}

void newline()
{
import std.range : assumeSorted;
import std.algorithm : max;

if (currentIs(tok!"comment") && current.line == tokenEndLine(tokens[index - 1]))
return;
Expand Down Expand Up @@ -976,9 +976,11 @@ private:
bool switchLabel = false;
if (currentIs(tok!"else"))
{
auto l = indents.indentToMostRecent(tok!"if");
if (l != -1)
indentLevel = l;
auto i = indents.indentToMostRecent(tok!"if");
auto v = indents.indentToMostRecent(tok!"version");
auto mostRecent = max(i, v);
if (mostRecent != -1)
indentLevel = mostRecent;
}
else if (currentIs(tok!"identifier") && peekIs(tok!":"))
{
Expand Down Expand Up @@ -1037,7 +1039,8 @@ private:
indents.pop();
}
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();
}
Expand Down
3 changes: 2 additions & 1 deletion tests/issue0039.d.ref
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
version (AArch64) int x = 10;
version (AArch64)
int x = 10;
12 changes: 12 additions & 0 deletions tests/issue0093.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
unittest
{
if (x)
{
version (none)
{
}
else
{
}
}
}
12 changes: 12 additions & 0 deletions tests/issue0093.d.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
unittest
{
if (x)
{
version (none)
{
}
else
{
}
}
}

0 comments on commit 98d397c

Please sign in to comment.