More changes
This commit is contained in:
parent
32759fafae
commit
96501f7418
37
src/dfmt.d
37
src/dfmt.d
|
@ -851,19 +851,14 @@ struct FormatterConfig
|
|||
{
|
||||
/// Number of spaces used for indentation
|
||||
uint indentSize = 4;
|
||||
|
||||
/// Use tabs or spaces
|
||||
bool useTabs = false;
|
||||
|
||||
/// Size of a tab character
|
||||
uint tabSize = 8;
|
||||
|
||||
/// Soft line wrap limit
|
||||
uint columnSoftLimit = 80;
|
||||
|
||||
/// Hard line wrap limit
|
||||
uint columnHardLimit = 120;
|
||||
|
||||
/// Use the One True Brace Style
|
||||
BraceStyle braceStyle = BraceStyle.allman;
|
||||
}
|
||||
|
@ -1011,6 +1006,18 @@ int tokenLength(ref const Token t) pure @safe @nogc
|
|||
import std.algorithm : countUntil;
|
||||
switch (t.type)
|
||||
{
|
||||
case tok!"doubleLiteral":
|
||||
case tok!"floatLiteral":
|
||||
case tok!"idoubleLiteral":
|
||||
case tok!"ifloatLiteral":
|
||||
case tok!"intLiteral":
|
||||
case tok!"longLiteral":
|
||||
case tok!"realLiteral":
|
||||
case tok!"irealLiteral":
|
||||
case tok!"uintLiteral":
|
||||
case tok!"ulongLiteral":
|
||||
case tok!"characterLiteral":
|
||||
return cast(int) t.text.length;
|
||||
case tok!"identifier":
|
||||
case tok!"stringLiteral":
|
||||
case tok!"wstringLiteral":
|
||||
|
@ -1019,6 +1026,8 @@ int tokenLength(ref const Token t) pure @safe @nogc
|
|||
auto c = cast(int) t.text.countUntil('\n');
|
||||
if (c == -1)
|
||||
return cast(int) t.text.length;
|
||||
else
|
||||
return c;
|
||||
mixin (generateFixedLengthCases());
|
||||
default:
|
||||
return INVALID_TOKEN_LENGTH;
|
||||
|
@ -1072,6 +1081,9 @@ bool isBreakToken(IdType t)
|
|||
case tok!"%":
|
||||
case tok!"+=":
|
||||
case tok!".":
|
||||
case tok!"~":
|
||||
case tok!"+":
|
||||
case tok!"-":
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
@ -1084,10 +1096,10 @@ int breakCost(IdType t)
|
|||
{
|
||||
case tok!"||":
|
||||
case tok!"&&":
|
||||
return 21;
|
||||
return 0;
|
||||
case tok!"(":
|
||||
case tok!",":
|
||||
return 34;
|
||||
return 10;
|
||||
case tok!"^^":
|
||||
case tok!"^=":
|
||||
case tok!"^":
|
||||
|
@ -1125,6 +1137,9 @@ int breakCost(IdType t)
|
|||
case tok!"&=":
|
||||
case tok!"%=":
|
||||
case tok!"%":
|
||||
case tok!"+":
|
||||
case tok!"-":
|
||||
case tok!"~":
|
||||
case tok!"+=":
|
||||
return 55;
|
||||
case tok!".":
|
||||
|
@ -1151,7 +1166,7 @@ struct State
|
|||
if (breaks.length == 0)
|
||||
{
|
||||
_cost = int.max;
|
||||
s = false;
|
||||
s = tokens.map!(a => tokenLength(a)).sum() < formatterConfig.columnSoftLimit;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1212,8 +1227,7 @@ size_t[] chooseLineBreakTokens(size_t index, const Token[] tokens,
|
|||
|
||||
int depth = 0;
|
||||
auto open = new RedBlackTree!State;
|
||||
open.insert(State(cast(size_t[])[], tokens, depth, formatterConfig,
|
||||
currentLineLength, indentLevel));
|
||||
open.insert(State(cast(size_t[])[], tokens, depth, formatterConfig, currentLineLength, indentLevel));
|
||||
while (!open.empty)
|
||||
{
|
||||
State current = open.front();
|
||||
|
@ -1224,8 +1238,7 @@ size_t[] chooseLineBreakTokens(size_t index, const Token[] tokens,
|
|||
b += index;
|
||||
return current.breaks;
|
||||
}
|
||||
foreach (next; validMoves(tokens, current, formatterConfig,
|
||||
currentLineLength, indentLevel, depth))
|
||||
foreach (next; validMoves(tokens, current, formatterConfig, currentLineLength, indentLevel, depth))
|
||||
{
|
||||
open.insert(next);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue