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