From ebb11b0695d07f695b3d7064ecee6a2cc17b8d52 Mon Sep 17 00:00:00 2001 From: Andreas Zwinkau Date: Fri, 16 Jan 2015 22:02:59 +0100 Subject: [PATCH] Colon always needs space around Reverts 9284f1a which adds space around colons only in the case of ternary expressions. However, import bindings and class inheritance needs space as well. The overhead of the ast-list techniques seems unnecessary. --- src/dfmt.d | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/src/dfmt.d b/src/dfmt.d index 0631085..5603c08 100644 --- a/src/dfmt.d +++ b/src/dfmt.d @@ -313,17 +313,6 @@ private: case tok!"(": writeParens(true); break; - case tok!":": - if (!assumeSorted(astInformation.ternaryColonLocations) - .equalRange(current.index).empty) - { - write(" "); - writeToken(); - write(" "); - } - else - writeToken(); - break; case tok!"@": case tok!"!": case tok!"...": @@ -333,6 +322,10 @@ private: case tok!"$": writeToken(); break; + case tok!":": + write(" : "); + index += 1; + break; case tok!"]": writeToken(); if (current.type == tok!"identifier") @@ -811,9 +804,6 @@ struct ASTInformation /// Locations of unary operators size_t[] unaryLocations; - - /// Locations of ':' operators in ternary expressions - size_t[] ternaryColonLocations; } /// Collects information from the AST that is useful for the formatter @@ -886,13 +876,6 @@ final class FormatVisitor : ASTVisitor unary.accept(this); } - override void visit(const TernaryExpression ternary) - { - if (ternary.colon.type != tok!"") - astInformation.ternaryColonLocations ~= ternary.colon.index; - ternary.accept(this); - } - private: ASTInformation* astInformation; alias visit = ASTVisitor.visit;