Fix #34
This commit is contained in:
parent
2a803bbde0
commit
cd5f5f644b
31
src/dfmt.d
31
src/dfmt.d
|
@ -189,8 +189,12 @@ private:
|
|||
write(" ");
|
||||
}
|
||||
writeToken();
|
||||
auto j = justAddedExtraNewline;
|
||||
if (tokens[index - 1].text[0 .. 2] == "//")
|
||||
{
|
||||
newline();
|
||||
justAddedExtraNewline = j;
|
||||
}
|
||||
else if (index < tokens.length)
|
||||
{
|
||||
if (tokens[index - 1].line == tokens[index].line)
|
||||
|
@ -231,10 +235,18 @@ private:
|
|||
break;
|
||||
}
|
||||
if (current.type == tok!"comment" && current.line == peekBack().line)
|
||||
{
|
||||
justAddedExtraNewline = true;
|
||||
break;
|
||||
if (!(t == tok!"import" && current.type == tok!"import"))
|
||||
}
|
||||
else if ((t == tok!"import" && current.type != tok!"import"))
|
||||
{
|
||||
write("\n");
|
||||
newline();
|
||||
justAddedExtraNewline = true;
|
||||
newline();
|
||||
}
|
||||
else
|
||||
newline();
|
||||
break;
|
||||
}
|
||||
else if (current.type == tok!",")
|
||||
|
@ -431,8 +443,6 @@ private:
|
|||
if (index >= tokens.length || current.type != tok!"comment"
|
||||
|| current.line != tokens[index - 1].line)
|
||||
newline();
|
||||
if (peekImplementation(tok!"class",0))
|
||||
newline();
|
||||
break;
|
||||
case tok!"{":
|
||||
writeBraces();
|
||||
|
@ -877,8 +887,15 @@ private:
|
|||
{
|
||||
import std.range:assumeSorted;
|
||||
output.put("\n");
|
||||
immutable bool hasCurrent = index + 1 < tokens.length;
|
||||
if (index > 0 && hasCurrent && tokens[index - 1].type != tok!"}"
|
||||
&& tokens[index].line - tokens[index - 1].line > 1 && !justAddedExtraNewline)
|
||||
{
|
||||
output.put("\n");
|
||||
}
|
||||
justAddedExtraNewline = false;
|
||||
currentLineLength = 0;
|
||||
if (index < tokens.length)
|
||||
if (hasCurrent)
|
||||
{
|
||||
if (current.type == tok!"}")
|
||||
indentLevel--;
|
||||
|
@ -950,6 +967,10 @@ private:
|
|||
|
||||
/// Configuration
|
||||
FormatterConfig* config;
|
||||
|
||||
/// Keep track of whether or not an extra newline was just added because of
|
||||
/// an import statement.
|
||||
bool justAddedExtraNewline;
|
||||
}
|
||||
|
||||
/// The only good brace styles
|
||||
|
|
|
@ -12,7 +12,6 @@ void main()
|
|||
}
|
||||
|
||||
const baz = 11;
|
||||
|
||||
class Foo2 : Foo
|
||||
{
|
||||
}
|
||||
|
|
|
@ -6,10 +6,12 @@ void main()
|
|||
writefln("Guess my target number that is between " ~ "%d and %d (inclusive).\n",
|
||||
interval[]);
|
||||
immutable target = uniform!"[]"(interval[]);
|
||||
|
||||
foreach (immutable i; sequence!q{n})
|
||||
{
|
||||
writef("Your guess #%d: ", i + 1);
|
||||
immutable txt = stdin.readln.strip;
|
||||
|
||||
Nullable!int answer;
|
||||
try
|
||||
{
|
||||
|
|
|
@ -14,10 +14,12 @@ void main()
|
|||
|
||||
int[] a = [10, 20];
|
||||
writeln(a);
|
||||
|
||||
// The std.algorithm standard library module
|
||||
// contains a generic swap:
|
||||
swap(a[0], a[1]);
|
||||
writeln(a);
|
||||
|
||||
// Using mySwap:
|
||||
mySwap(a[0], a[1]);
|
||||
writeln(a);
|
||||
|
|
Loading…
Reference in New Issue