diff --git a/src/dfmt.d b/src/dfmt.d index bf5b95d..780222d 100644 --- a/src/dfmt.d +++ b/src/dfmt.d @@ -1,30 +1,9 @@ -/******************************************************************************* - * Boost Software License - Version 1.0 - August 17th, 2003 - * - * Permission is hereby granted, free of charge, to any person or organization - * obtaining a copy of the software and accompanying documentation covered by - * this license (the "Software") to use, reproduce, display, distribute, - * execute, and transmit the Software, and to prepare derivative works of the - * Software, and to permit third-parties to whom the Software is furnished to - * do so, all subject to the following: - * - * The copyright notices in the Software and this entire statement, including - * the above license grant, this restriction and the following disclaimer, - * must be included in all copies of the Software, in whole or in part, and - * all derivative works of the Software, unless such copies or derivative - * works are solely in the form of machine-executable object code generated by - * a source language processor. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT - * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE - * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - ******************************************************************************/ +// Copyright Brian Schott 2015. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) -module dfmt; +module dfmt.main; import std.stdio; @@ -631,7 +610,7 @@ private: { // Silly hack to format enums better. if (peekBackIsLiteralOrIdent() || peekBackIs(tok!")", true) - ||(peekBackIs(tok!",", true) && !peekBackIsSlashSlash)) + || (peekBackIs(tok!",", true) && !peekBackIsSlashSlash)) newline(); write("}"); if (index < tokens.length - 1 @@ -940,8 +919,8 @@ private: void regenLineBreakHints(immutable size_t i) { immutable size_t j = expressionEndIndex(i); - linebreakHints = chooseLineBreakTokens(i, tokens[i .. j], - depths[i .. j], config, currentLineLength, indentLevel); + linebreakHints = chooseLineBreakTokens(i, tokens[i .. j], depths[i .. j], + config, currentLineLength, indentLevel); } void regenLineBreakHintsIfNecessary(immutable size_t i) @@ -1163,9 +1142,8 @@ private: immutable bool hasCurrent = index + 1 < tokens.length; if (niBraceDepth > 0 && !peekBackIsSlashSlash() && hasCurrent - && tokens[index].type == tok!"}" - && !assumeSorted(astInformation.funLitEndLocations).equalRange( - tokens[index].index).empty) + && tokens[index].type == tok!"}" && !assumeSorted( + astInformation.funLitEndLocations).equalRange(tokens[index].index).empty) { write(" "); return; @@ -1225,8 +1203,8 @@ private: if (l != -1) indentLevel = l; } - else if (currentIs(tok!"{") && !astInformation.structInitStartLocations.canFindIndex( - tokens[index].index) + else if (currentIs(tok!"{") + && !astInformation.structInitStartLocations.canFindIndex(tokens[index].index) && !astInformation.funLitStartLocations.canFindIndex(tokens[index].index)) { while (indents.length && isWrapIndent(indents.top)) @@ -1856,7 +1834,7 @@ struct State int ll = currentLineLength; size_t breakIndex = 0; size_t i = 0; - bool s = true; + this._solved = true; if (breaks.length == 0) { immutable int l = currentLineLength + tokens.map!(a => tokenLength(a)).sum(); @@ -1865,10 +1843,10 @@ struct State { immutable longPenalty = (l - formatterConfig.columnSoftLimit) * remainingCharsMultiplier; _cost += longPenalty; - s = longPenalty < newlinePenalty; + this._solved = longPenalty < newlinePenalty; } else - s = true; + this._solved = true; } else { @@ -1878,7 +1856,7 @@ struct State ll += tokens[i .. j].map!(a => tokenLength(a)).sum(); if (ll > formatterConfig.columnHardLimit) { - s = false; + this._solved = false; break; } else if (ll > formatterConfig.columnSoftLimit) @@ -1890,7 +1868,6 @@ struct State while (i + 1 < tokens.length); } this._cost += breaks.length * newlinePenalty; - this._solved = s; } int cost() const pure nothrow @safe @property @@ -1991,7 +1968,7 @@ State[] validMoves(const Token[] tokens, immutable short[] depths, ref const Sta State[] states; foreach (i, token; tokens) { - if (current.breaks.canFind(i) || !isBreakToken(token.type)) + if (!isBreakToken(token.type) || current.breaks.canFind(i)) continue; size_t[] breaks; breaks ~= current.breaks;