diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index cdc941b..004c0d5 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -949,8 +949,7 @@ private: formatAt(); break; case tok!"!": - if ((peekIs(tok!"is") || peekIs(tok!"in")) - && !peekBackIsOneOf(false, tok!"(", tok!"=")) + if ((peekIs(tok!"is") || peekIs(tok!"in")) && !peekBackIsOperator()) write(" "); goto case; case tok!"...": @@ -1488,7 +1487,7 @@ const pure @safe @nogc: return peekImplementation(tokenType, -1, ignoreComments); } - bool peekBackIsKeyword(bool ignoreComments = true) + bool peekBackIsKeyword(bool ignoreComments = true) pure nothrow const @nogc @safe { if (index == 0) return false; @@ -1503,6 +1502,11 @@ const pure @safe @nogc: return isKeyword(tokens[i].type); } + bool peekBackIsOperator() pure nothrow const @nogc @safe + { + return index == 0 ? false : isOperator(tokens[index - 1].type); + } + bool peekBackIsOneOf(bool ignoreComments, IdType[] tokenTypes...) { if (index == 0) diff --git a/tests/allman/issue0208.d.ref b/tests/allman/issue0208.d.ref new file mode 100644 index 0000000..7ee7fab --- /dev/null +++ b/tests/allman/issue0208.d.ref @@ -0,0 +1,7 @@ +unittest +{ + if (a && !is(b == q)) + { + + } +} diff --git a/tests/issue0208.d b/tests/issue0208.d new file mode 100644 index 0000000..b318881 --- /dev/null +++ b/tests/issue0208.d @@ -0,0 +1,7 @@ +unittest +{ + if (a && !is(b == q)) + { + + } +} diff --git a/tests/otbs/issue0208.d.ref b/tests/otbs/issue0208.d.ref new file mode 100644 index 0000000..379e02c --- /dev/null +++ b/tests/otbs/issue0208.d.ref @@ -0,0 +1,5 @@ +unittest { + if (a && !is(b == q)) { + + } +}