From 7109c5b4f27ae8fe9d5e5ebc84472bebf2bfadb1 Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Fri, 24 Apr 2015 13:15:53 -0700 Subject: [PATCH] Fix #138 --- src/dfmt/formatter.d | 9 +++++---- tests/allman/issue0138.d.ref | 8 ++++++++ tests/issue0138.d | 8 ++++++++ tests/otbs/issue0138.d.ref | 6 ++++++ 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 tests/allman/issue0138.d.ref create mode 100644 tests/issue0138.d create mode 100644 tests/otbs/issue0138.d.ref diff --git a/src/dfmt/formatter.d b/src/dfmt/formatter.d index 669f3a3..3e4a763 100644 --- a/src/dfmt/formatter.d +++ b/src/dfmt/formatter.d @@ -154,8 +154,7 @@ private: { immutable t = tokens[index].type; if (t == tok!"identifier" || isStringLiteral(t) - || isNumberLiteral(t) || t == tok!"characterLiteral" - || isKeyword(t)) + || isNumberLiteral(t) || t == tok!"characterLiteral") write(" "); } } @@ -221,7 +220,7 @@ private: { writeToken(); if (index < tokens.length && (currentIs(tok!"identifier") - || isKeyword(current.type) || isBasicType(current.type) || currentIs(tok!"@"))) + || isBasicType(current.type) || currentIs(tok!"@"))) { write(" "); } @@ -377,7 +376,7 @@ private: newline(); writeToken(); // in/out/body } - else if (peekIsLiteralOrIdent() || peekIsBasicType() || peekIsKeyword()) + else if (peekIsLiteralOrIdent() || peekIsBasicType()) { writeToken(); if (spaceAfterParens || parenDepth > 0) @@ -676,6 +675,8 @@ private: break; case tok!"in": case tok!"is": + if (!peekBackIsOneOf(false, tok!"!", tok!"(", tok!",")) + write(" "); writeToken(); if (!currentIs(tok!"(") && !currentIs(tok!"{")) write(" "); diff --git a/tests/allman/issue0138.d.ref b/tests/allman/issue0138.d.ref new file mode 100644 index 0000000..7dacc3a --- /dev/null +++ b/tests/allman/issue0138.d.ref @@ -0,0 +1,8 @@ +unittest +{ + auto result = a[0] in aa; +} + +void doStuff(in int a, in int b) +{ +} diff --git a/tests/issue0138.d b/tests/issue0138.d new file mode 100644 index 0000000..d976fe6 --- /dev/null +++ b/tests/issue0138.d @@ -0,0 +1,8 @@ +unittest +{ + auto result = a[0] in aa; +} + +void doStuff(in int a, in int b) +{ +} diff --git a/tests/otbs/issue0138.d.ref b/tests/otbs/issue0138.d.ref new file mode 100644 index 0000000..b6abc82 --- /dev/null +++ b/tests/otbs/issue0138.d.ref @@ -0,0 +1,6 @@ +unittest { + auto result = a[0] in aa; +} + +void doStuff(in int a, in int b) { +}