From 382258eb979c1489b30969e16c9220c1c9aceb4e Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Fri, 15 Jan 2016 16:29:00 -0800 Subject: [PATCH] Fix #208 --- src/dfmt/formatter.d | 10 +++++++--- tests/allman/issue0208.d.ref | 7 +++++++ tests/issue0208.d | 7 +++++++ tests/otbs/issue0208.d.ref | 5 +++++ 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 tests/allman/issue0208.d.ref create mode 100644 tests/issue0208.d create mode 100644 tests/otbs/issue0208.d.ref 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)) { + + } +}