diff --git a/dub.json b/dub.json index d257652..0c3badc 100644 --- a/dub.json +++ b/dub.json @@ -4,6 +4,6 @@ "targetType": "autodetect", "license": "BSL-1.0", "dependencies": { - "libdparse": "~>0.7.1-beta.7" + "libdparse": "~>0.7.2-alpha.3" } } diff --git a/libdparse b/libdparse index 4229f11..a2b492d 160000 --- a/libdparse +++ b/libdparse @@ -1 +1 @@ -Subproject commit 4229f11828a901ea5379409015f14a033e742906 +Subproject commit a2b492d8c7a84881657de85939d9c6b14f867d5b diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index 932955a..fc8753d 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -898,6 +898,20 @@ private: indents.push(tok!"if"); formatLeftBrace(); } + else if (currentIs(tok!"{") && indents.topAre(tok!"static", tok!"foreach")) + { + indents.pop(); + indents.pop(); + indents.push(tok!"foreach"); + formatLeftBrace(); + } + else if (currentIs(tok!"{") && indents.topAre(tok!"static", tok!"foreach_reverse")) + { + indents.pop(); + indents.pop(); + indents.push(tok!"foreach_reverse"); + formatLeftBrace(); + } } void formatElse() diff --git a/src/dfmt/indentation.d b/src/dfmt/indentation.d index 9c0b275..f065945 100644 --- a/src/dfmt/indentation.d +++ b/src/dfmt/indentation.d @@ -176,6 +176,7 @@ private: int indentSize(const size_t k = size_t.max) const pure nothrow @safe @nogc { + import std.algorithm : among; if (index == 0 || k == 0) return 0; immutable size_t j = k == size_t.max ? index : k; @@ -196,8 +197,9 @@ private: continue; immutable currentIsNonWrapTemp = !isWrapIndent(arr[i]) && isTempIndent(arr[i]) && arr[i] != tok!")" && arr[i] != tok!"!"; - if (arr[i] == tok!"static" && (arr[i + 1] == tok!"if" - || arr[i + 1] == tok!"else") && (i + 2 >= index || arr[i + 2] != tok!"{")) + if (arr[i] == tok!"static" + && arr[i + 1].among!(tok!"if", tok!"else", tok!"foreach", tok!"foreach_reverse") + && (i + 2 >= index || arr[i + 2] != tok!"{")) { parenCount = pc; continue; diff --git a/tests/allman/issue0303.d.ref b/tests/allman/issue0303.d.ref new file mode 100644 index 0000000..807cc28 --- /dev/null +++ b/tests/allman/issue0303.d.ref @@ -0,0 +1,12 @@ +static foreach (thing; things) +{ + pragma(msg, thing); +} +static foreach_reverse (thing; things) +{ + pragma(msg, thing); +} +static foreach (thing; things) + pragma(msg, thing); +static foreach_reverse (thing; things) + pragma(msg, thing); diff --git a/tests/issue0303.d b/tests/issue0303.d new file mode 100644 index 0000000..3fcab0e --- /dev/null +++ b/tests/issue0303.d @@ -0,0 +1,4 @@ +static foreach (thing; things){pragma(msg,thing);} +static foreach_reverse (thing; things){pragma(msg,thing);} +static foreach (thing; things) pragma(msg,thing); +static foreach_reverse (thing; things) pragma(msg,thing); \ No newline at end of file diff --git a/tests/otbs/issue0303.d.ref b/tests/otbs/issue0303.d.ref new file mode 100644 index 0000000..4f11f69 --- /dev/null +++ b/tests/otbs/issue0303.d.ref @@ -0,0 +1,10 @@ +static foreach (thing; things) { + pragma(msg, thing); +} +static foreach_reverse (thing; things) { + pragma(msg, thing); +} +static foreach (thing; things) + pragma(msg, thing); +static foreach_reverse (thing; things) + pragma(msg, thing);