Import with comment behind must not output newlines
This commit is contained in:
parent
9e7d57af84
commit
cb9a4015e7
|
|
@ -159,7 +159,7 @@ private:
|
||||||
const i = index;
|
const i = index;
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
{
|
{
|
||||||
if (tokens[i-1].line < tokens[i].line)
|
if (tokens[i-1].line < current.line)
|
||||||
{
|
{
|
||||||
if (tokens[i-1].type != tok!"comment"
|
if (tokens[i-1].type != tok!"comment"
|
||||||
&& tokens[i-1].type != tok!"{")
|
&& tokens[i-1].type != tok!"{")
|
||||||
|
|
@ -192,6 +192,8 @@ private:
|
||||||
{
|
{
|
||||||
writeToken();
|
writeToken();
|
||||||
tempIndent = 0;
|
tempIndent = 0;
|
||||||
|
if (current.type == tok!"comment")
|
||||||
|
break;
|
||||||
if (!(t == tok!"import" && current.type == tok!"import"))
|
if (!(t == tok!"import" && current.type == tok!"import"))
|
||||||
write("\n");
|
write("\n");
|
||||||
newline();
|
newline();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
import std.algorithm: swap; // from Phobos standard library
|
||||||
|
|
||||||
|
// The D solution uses templates and it's similar to the C++ one:
|
||||||
|
void mySwap(T)(ref T left, ref T right) {
|
||||||
|
auto temp = left;
|
||||||
|
left = right;
|
||||||
|
right = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
import std.stdio;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
import std.algorithm : swap; // from Phobos standard library
|
||||||
|
|
||||||
|
// The D solution uses templates and it's similar to the C++ one:
|
||||||
|
void mySwap(T)(ref T left, ref T right)
|
||||||
|
{
|
||||||
|
auto temp = left;
|
||||||
|
left = right;
|
||||||
|
right = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
import std.stdio;
|
||||||
|
|
||||||
|
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