Skip to content

Commit cff6eb9

Browse files
Merge tag v0.7.2 into v0.8.x
2 parents c66fea0 + c58e54f commit cff6eb9

File tree

6 files changed

+72
-6
lines changed

6 files changed

+72
-6
lines changed

src/dfmt/formatter.d

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ private:
283283
{
284284
formatKeyword();
285285
}
286+
else if (current.text == "body" && peekBackIsFunctionDeclarationEnding())
287+
{
288+
formatKeyword();
289+
}
286290
else if (isBasicType(current.type))
287291
{
288292
writeToken();
@@ -596,8 +600,10 @@ private:
596600
indents.pop();
597601

598602
if (parenDepth == 0 && (peekIs(tok!"is") || peekIs(tok!"in")
599-
|| peekIs(tok!"out") || peekIs(tok!"body")))
603+
|| peekIs(tok!"out") || peekIs(tok!"do") || peekIsBody))
604+
{
600605
writeToken();
606+
}
601607
else if (peekIsLiteralOrIdent() || peekIsBasicType())
602608
{
603609
writeToken();
@@ -952,9 +958,11 @@ private:
952958
if (!currentIs(tok!"{") && !currentIs(tok!";"))
953959
write(" ");
954960
}
955-
else if (!currentIs(tok!"{") && !currentIs(tok!";")
956-
&& !currentIs(tok!"in") && !currentIs(tok!"out") && !currentIs(tok!"body"))
961+
else if (!currentIs(tok!"{") && !currentIs(tok!";") && !currentIs(tok!"in") &&
962+
!currentIs(tok!"out") && !currentIs(tok!"do") && current.text != "body")
963+
{
957964
newline();
965+
}
958966
else if (currentIs(tok!"{") && indents.topAre(tok!"static", tok!"if"))
959967
{
960968
// Hacks to format braced vs non-braced static if declarations.
@@ -1043,7 +1051,12 @@ private:
10431051
if (!currentIs(tok!"{"))
10441052
newline();
10451053
break;
1046-
case tok!"body":
1054+
case tok!"identifier":
1055+
if (current.text == "body")
1056+
goto case tok!"do";
1057+
else
1058+
goto default;
1059+
case tok!"do":
10471060
if (!peekBackIs(tok!"}"))
10481061
newline();
10491062
writeToken();
@@ -1843,6 +1856,18 @@ const pure @safe @nogc:
18431856
return peekImplementation(tokenType, 1, ignoreComments);
18441857
}
18451858

1859+
bool peekIsBody() nothrow
1860+
{
1861+
return index + 1 < tokens.length && tokens[index + 1].text == "body";
1862+
}
1863+
1864+
bool peekBackIsFunctionDeclarationEnding() nothrow
1865+
{
1866+
return peekBackIsOneOf(false, tok!")", tok!"const", tok!"immutable",
1867+
tok!"inout", tok!"shared", tok!"@", tok!"pure", tok!"nothrow",
1868+
tok!"return", tok!"scope");
1869+
}
1870+
18461871
bool peekBackIsSlashSlash() nothrow
18471872
{
18481873
return index > 0 && tokens[index - 1].type == tok!"comment"

src/dfmt/tokens.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ private string generateFixedLengthCases()
217217
a => format(`case tok!"%s": return %d + 1;`, a, a.length)).join("\n\t");
218218

219219
string[] identifierTokens = [
220-
"abstract", "alias", "align", "asm", "assert", "auto", "body", "bool",
220+
"abstract", "alias", "align", "asm", "assert", "auto", "bool",
221221
"break", "byte", "case", "cast", "catch", "cdouble", "cent", "cfloat", "char", "class",
222222
"const", "continue", "creal", "dchar", "debug", "default", "delegate", "delete", "deprecated",
223223
"do", "double", "else", "enum", "export", "extern", "false", "final", "finally", "float",

tests/allman/do_body.d.ref

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import character.body;
2+
3+
void body() @nogc
4+
in
5+
{
6+
}
7+
body
8+
{
9+
body = null;
10+
}
11+
12+
void body()
13+
in
14+
{
15+
}
16+
do
17+
{
18+
body = null;
19+
}

tests/do_body.d

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import character.body;
2+
3+
void body() @nogc
4+
in{} body{body = null;}
5+
6+
void body()
7+
in{} do{ body = null;}

tests/otbs/do_body.d.ref

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import character.body;
2+
3+
void body() @nogc
4+
in {
5+
}
6+
body {
7+
body = null;
8+
}
9+
10+
void body()
11+
in {
12+
}
13+
do {
14+
body = null;
15+
}

0 commit comments

Comments
 (0)