mirror of
https://github.com/dlang-community/dfmt.git
synced 2025-04-29 06:39:55 +03:00
Fix #81
This commit is contained in:
parent
62d0378740
commit
cb5ca659b1
3 changed files with 43 additions and 10 deletions
22
src/dfmt.d
22
src/dfmt.d
|
@ -292,7 +292,7 @@ private:
|
||||||
}
|
}
|
||||||
else if (isBlockHeader() && peekIs(tok!"(", false))
|
else if (isBlockHeader() && peekIs(tok!"(", false))
|
||||||
{
|
{
|
||||||
if (currentIs(tok!"if"))
|
if (currentIs(tok!"if") && !peekBackIs(tok!"else"))
|
||||||
ifIndents.push(tempIndent);
|
ifIndents.push(tempIndent);
|
||||||
writeToken();
|
writeToken();
|
||||||
write(" ");
|
write(" ");
|
||||||
|
@ -728,14 +728,16 @@ private:
|
||||||
output.put("\n");
|
output.put("\n");
|
||||||
justAddedExtraNewline = true;
|
justAddedExtraNewline = true;
|
||||||
}
|
}
|
||||||
if (config.braceStyle == BraceStyle.otbs)
|
if (config.braceStyle == BraceStyle.otbs && currentIs(tok!"else"))
|
||||||
{
|
write(" ");
|
||||||
if (index < tokens.length && currentIs(tok!"else"))
|
|
||||||
write(" ");
|
|
||||||
}
|
|
||||||
index++;
|
index++;
|
||||||
if (peekIs(tok!"case") || peekIs(tok!"default"))
|
if (peekIs(tok!"case") || peekIs(tok!"default"))
|
||||||
indentLevel--;
|
indentLevel--;
|
||||||
|
if (ifIndents.length >= 2 && ifIndents.top == tempIndent && !currentIs(tok!"else"))
|
||||||
|
{
|
||||||
|
ifIndents.pop();
|
||||||
|
tempIndent = ifIndents.top();
|
||||||
|
}
|
||||||
newline();
|
newline();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1675,23 +1677,23 @@ State[] validMoves(const Token[] tokens, ref const State current,
|
||||||
|
|
||||||
struct FixedStack
|
struct FixedStack
|
||||||
{
|
{
|
||||||
void push(int i)
|
void push(int i) pure nothrow
|
||||||
{
|
{
|
||||||
index = index == 255 ? index : index + 1;
|
index = index == 255 ? index : index + 1;
|
||||||
arr[index] = i;
|
arr[index] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pop()
|
void pop() pure nothrow
|
||||||
{
|
{
|
||||||
index = index == 0 ? index : index - 1;
|
index = index == 0 ? index : index - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int top()
|
int top() const pure nothrow @property
|
||||||
{
|
{
|
||||||
return arr[index];
|
return arr[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t length()
|
size_t length() const pure nothrow @property
|
||||||
{
|
{
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
23
tests/issue0081.d
Normal file
23
tests/issue0081.d
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
if (0)
|
||||||
|
if (0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else if (0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
}
|
||||||
|
doSomething();
|
||||||
|
}
|
||||||
|
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
if (0)
|
||||||
|
if (0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
doSomething();
|
||||||
|
}
|
8
tests/issue0081.d.ref
Normal file
8
tests/issue0081.d.ref
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
if (0)
|
||||||
|
if (0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
doSomething();
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue