Indentation rework
This commit is contained in:
parent
bf0843f321
commit
7ec932a1e3
|
@ -445,7 +445,7 @@ private:
|
|||
writeToken();
|
||||
if (p == tok!"(")
|
||||
{
|
||||
indents.push(p);
|
||||
indents.push(p);
|
||||
spaceAfterParens = true;
|
||||
parenDepth++;
|
||||
}
|
||||
|
@ -481,8 +481,8 @@ private:
|
|||
parenDepth--;
|
||||
if (parenDepth == 0)
|
||||
indents.popWrapIndents();
|
||||
if (indents.topIs(tok!"("))
|
||||
indents.pop();
|
||||
if (indents.topIs(tok!"("))
|
||||
indents.pop();
|
||||
|
||||
if (parenDepth == 0 && (peekIs(tok!"is") || peekIs(tok!"in")
|
||||
|| peekIs(tok!"out") || peekIs(tok!"body")))
|
||||
|
@ -1271,6 +1271,12 @@ private:
|
|||
indentLevel = config.dfmt_align_switch_statements
|
||||
== OptionalBoolean.t ? l : indents.indentLevel;
|
||||
}
|
||||
else if (currentIs(tok!")"))
|
||||
{
|
||||
if (indents.topIs(tok!"("))
|
||||
indents.pop();
|
||||
indentLevel = indents.indentLevel;
|
||||
}
|
||||
else if (currentIs(tok!"{"))
|
||||
{
|
||||
indents.popWrapIndents();
|
||||
|
@ -1326,7 +1332,7 @@ private:
|
|||
if (indents.topIsTemp() && (peekBackIsOneOf(true, tok!"}",
|
||||
tok!";") && indents.top != tok!";"))
|
||||
indents.popTempIndents();
|
||||
indentLevel = indents.indentLevel + parenDepth;
|
||||
indentLevel = indents.indentLevel;
|
||||
}
|
||||
indent();
|
||||
}
|
||||
|
|
|
@ -169,13 +169,14 @@ private:
|
|||
{
|
||||
if (arr[i] == tok!"]")
|
||||
continue;
|
||||
immutable bool currentIsTemp = isTempIndent(arr[i]);
|
||||
immutable bool nextIsTemp = isTempIndent(arr[i + 1]);
|
||||
immutable bool nextIsSwitch = arr[i + 1] == tok!"switch";
|
||||
immutable bool nextIsWrap = isWrapIndent(arr[i + 1]);
|
||||
if (((nextIsSwitch || nextIsWrap) && currentIsTemp))
|
||||
immutable currentIsNonWrapTemp = !isWrapIndent(arr[i]) && isTempIndent(arr[i]);
|
||||
immutable nextIsParenOrSwitch = arr[i + 1] == tok!"("
|
||||
|| arr[i + 1] == tok!"switch" || arr[i + 1] == tok!"{";
|
||||
if (currentIsNonWrapTemp && nextIsParenOrSwitch)
|
||||
continue;
|
||||
}
|
||||
if (arr[i] == tok!"!")
|
||||
size++;
|
||||
size++;
|
||||
}
|
||||
return size;
|
||||
|
|
|
@ -4,7 +4,7 @@ void main()
|
|||
{
|
||||
immutable interval = tuple(1, 100);
|
||||
writefln("Guess my target number that is between " ~ "%d and %d (inclusive).\n",
|
||||
interval[]);
|
||||
interval[]);
|
||||
immutable target = uniform!"[]"(interval[]);
|
||||
|
||||
foreach (immutable i; sequence!q{n})
|
||||
|
|
|
@ -6,7 +6,7 @@ unittest
|
|||
{
|
||||
auto dd = new DtorDeclaration(declLoc, Loc(), stc, Identifier.idPool("__fieldDtor"));
|
||||
auto dd = new DtorDeclaration(declLoc, Loc(), stc, extraParam,
|
||||
midLengthFun(param, param), longIdentifier, Identifier.idPool("__fieldDtor"));
|
||||
midLengthFun(param, param), longIdentifier, Identifier.idPool("__fieldDtor"));
|
||||
|
||||
memcpy(&saved_idents, &rvl.saved_idents, (const(char)*).sizeof * VC_SAVED_IDENT_CNT);
|
||||
memcpy(&saved_types, &rvl.saved_types, (Type).sizeof * VC_SAVED_TYPE_CNT);
|
||||
|
@ -16,8 +16,8 @@ unittest
|
|||
}
|
||||
|
||||
void doStuff(const Token[] tokens, ref const State current,
|
||||
const FormatterConfig* formatterConfig, int currentLineLength, int indentLevel,
|
||||
int depth)
|
||||
const FormatterConfig* formatterConfig, int currentLineLength, int indentLevel,
|
||||
int depth)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
struct Test
|
||||
{
|
||||
this(string name, string[] aliasList, string briefDescription, string examDesc,
|
||||
string onOpenDesc, string openDesc, string onCloseDesc, string closeDesc,
|
||||
Flag!"canOpen" canOpen, Flag!"canClose" canClose, Flag!"isOpen" isOpen)
|
||||
string onOpenDesc, string openDesc, string onCloseDesc,
|
||||
string closeDesc, Flag!"canOpen" canOpen, Flag!"canClose" canClose,
|
||||
Flag!"isOpen" isOpen)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@ unittest
|
|||
callFunc({
|
||||
int i = 10;
|
||||
foo(alpha_longVarName, bravo_longVarName, charlie_longVarName,
|
||||
delta_longVarName, echo_longVarName, foxtrot_longVarName,
|
||||
golf_longVarName, echo_longVarName);
|
||||
delta_longVarName, echo_longVarName, foxtrot_longVarName,
|
||||
golf_longVarName, echo_longVarName);
|
||||
doStuff(withThings, andOtherStuff);
|
||||
return i;
|
||||
}, more_stuff);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
struct State
|
||||
{
|
||||
this(uint breaks, const Token[] tokens, immutable short[] depths,
|
||||
const Config* config, int currentLineLength, int indentLevel) pure @safe
|
||||
const Config* config, int currentLineLength, int indentLevel) pure @safe
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
void foo(int foobarbazqux1, /* */
|
||||
int foobarbazqux2, /* */
|
||||
int foobarbazqux3, /* */
|
||||
int foobarbazqux4, /* */
|
||||
int foobarbazqux5, /* */
|
||||
int foobarbazqux6, /* */
|
||||
int foobarbazqux7 /* */
|
||||
int foobarbazqux2, /* */
|
||||
int foobarbazqux3, /* */
|
||||
int foobarbazqux4, /* */
|
||||
int foobarbazqux5, /* */
|
||||
int foobarbazqux6, /* */
|
||||
int foobarbazqux7 /* */
|
||||
);
|
||||
|
|
|
@ -8,9 +8,9 @@ unittest
|
|||
{
|
||||
{
|
||||
bool anotherTemplatedFunction(One, Two, Three)(One alpha, Two bravo,
|
||||
Three charlie, double delta)
|
||||
if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo
|
||||
&& foxtrot && golf && hotel && india && juliet)
|
||||
Three charlie, double delta)
|
||||
if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo
|
||||
&& foxtrot && golf && hotel && india && juliet)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ unittest
|
|||
{
|
||||
{
|
||||
bool anotherTemplatedFunction(One, Two, Three)(One alpha, Two bravo,
|
||||
Three charlie, double delta)
|
||||
Three charlie, double delta)
|
||||
if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo
|
||||
&& foxtrot && golf && hotel && india && juliet)
|
||||
&& foxtrot && golf && hotel && india && juliet)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -9,9 +9,9 @@ unittest
|
|||
{
|
||||
{
|
||||
bool anotherTemplatedFunction(One, Two, Three)(One alpha, Two bravo,
|
||||
Three charlie, double delta)
|
||||
Three charlie, double delta)
|
||||
if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo
|
||||
&& foxtrot && golf && hotel && india && juliet)
|
||||
&& foxtrot && golf && hotel && india && juliet)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module example;
|
||||
|
||||
bool aTemplatedFunction(One)(One alpha)
|
||||
if (isNumeric!One)
|
||||
if (isNumeric!One)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -9,9 +9,9 @@ unittest
|
|||
{
|
||||
{
|
||||
bool anotherTemplatedFunction(One, Two, Three)(One alpha, Two bravo,
|
||||
Three charlie, double delta)
|
||||
if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo
|
||||
&& foxtrot && golf && hotel && india && juliet)
|
||||
Three charlie, double delta)
|
||||
if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo
|
||||
&& foxtrot && golf && hotel && india && juliet)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ version (AArch64)
|
|||
public:
|
||||
|
||||
double javaStyleFunctionName(double alpha, double bravo, double charlie,
|
||||
double delta, double echo, double foxtrot, double golf, double hotel)
|
||||
double delta, double echo, double foxtrot, double golf, double hotel)
|
||||
{
|
||||
if (alpha < beta && alpha > golf && hotel < alpha && bravo >= charlie && echo < delta)
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@ void main(string[] args)
|
|||
if (prevLocation != size_t.max)
|
||||
{
|
||||
addErrorMessage(line, column, KEY,
|
||||
"Expression %s is true: already checked on line %d.".format(
|
||||
expressions[prevLocation].formatted, expressions[prevLocation].line));
|
||||
"Expression %s is true: already checked on line %d.".format(
|
||||
expressions[prevLocation].formatted, expressions[prevLocation].line));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import std.stdio, std.random, std.typecons, std.conv, std.string, std.range;
|
|||
void main() {
|
||||
immutable interval = tuple(1, 100);
|
||||
writefln("Guess my target number that is between " ~ "%d and %d (inclusive).\n",
|
||||
interval[]);
|
||||
interval[]);
|
||||
immutable target = uniform!"[]"(interval[]);
|
||||
|
||||
foreach (immutable i; sequence!q{n}) {
|
||||
|
|
|
@ -5,7 +5,7 @@ unittest {
|
|||
{
|
||||
auto dd = new DtorDeclaration(declLoc, Loc(), stc, Identifier.idPool("__fieldDtor"));
|
||||
auto dd = new DtorDeclaration(declLoc, Loc(), stc, extraParam,
|
||||
midLengthFun(param, param), longIdentifier, Identifier.idPool("__fieldDtor"));
|
||||
midLengthFun(param, param), longIdentifier, Identifier.idPool("__fieldDtor"));
|
||||
|
||||
memcpy(&saved_idents, &rvl.saved_idents, (const(char)*).sizeof * VC_SAVED_IDENT_CNT);
|
||||
memcpy(&saved_types, &rvl.saved_types, (Type).sizeof * VC_SAVED_TYPE_CNT);
|
||||
|
@ -15,8 +15,8 @@ unittest {
|
|||
}
|
||||
|
||||
void doStuff(const Token[] tokens, ref const State current,
|
||||
const FormatterConfig* formatterConfig, int currentLineLength, int indentLevel,
|
||||
int depth) {
|
||||
const FormatterConfig* formatterConfig, int currentLineLength, int indentLevel,
|
||||
int depth) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
struct Test {
|
||||
this(string name, string[] aliasList, string briefDescription, string examDesc,
|
||||
string onOpenDesc, string openDesc, string onCloseDesc, string closeDesc,
|
||||
Flag!"canOpen" canOpen, Flag!"canClose" canClose, Flag!"isOpen" isOpen) {
|
||||
string onOpenDesc, string openDesc, string onCloseDesc,
|
||||
string closeDesc, Flag!"canOpen" canOpen, Flag!"canClose" canClose,
|
||||
Flag!"isOpen" isOpen) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ unittest {
|
|||
callFunc({
|
||||
int i = 10;
|
||||
foo(alpha_longVarName, bravo_longVarName, charlie_longVarName,
|
||||
delta_longVarName, echo_longVarName, foxtrot_longVarName,
|
||||
golf_longVarName, echo_longVarName);
|
||||
delta_longVarName, echo_longVarName, foxtrot_longVarName,
|
||||
golf_longVarName, echo_longVarName);
|
||||
doStuff(withThings, andOtherStuff);
|
||||
return i;
|
||||
}, more_stuff);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
struct State {
|
||||
this(uint breaks, const Token[] tokens, immutable short[] depths,
|
||||
const Config* config, int currentLineLength, int indentLevel) pure @safe {
|
||||
const Config* config, int currentLineLength, int indentLevel) pure @safe {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
void foo(int foobarbazqux1, /* */
|
||||
int foobarbazqux2, /* */
|
||||
int foobarbazqux3, /* */
|
||||
int foobarbazqux4, /* */
|
||||
int foobarbazqux5, /* */
|
||||
int foobarbazqux6, /* */
|
||||
int foobarbazqux7 /* */
|
||||
int foobarbazqux2, /* */
|
||||
int foobarbazqux3, /* */
|
||||
int foobarbazqux4, /* */
|
||||
int foobarbazqux5, /* */
|
||||
int foobarbazqux6, /* */
|
||||
int foobarbazqux7 /* */
|
||||
);
|
||||
|
|
|
@ -6,9 +6,9 @@ bool aTemplatedFunction(One)(One alpha) if (isNumeric!One) {
|
|||
unittest {
|
||||
{
|
||||
bool anotherTemplatedFunction(One, Two, Three)(One alpha, Two bravo,
|
||||
Three charlie, double delta)
|
||||
if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo
|
||||
&& foxtrot && golf && hotel && india && juliet) {
|
||||
Three charlie, double delta)
|
||||
if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo
|
||||
&& foxtrot && golf && hotel && india && juliet) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@ bool aTemplatedFunction(One)(One alpha) if (isNumeric!One) {
|
|||
unittest {
|
||||
{
|
||||
bool anotherTemplatedFunction(One, Two, Three)(One alpha, Two bravo,
|
||||
Three charlie, double delta)
|
||||
Three charlie, double delta)
|
||||
if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo
|
||||
&& foxtrot && golf && hotel && india && juliet) {
|
||||
&& foxtrot && golf && hotel && india && juliet) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,9 +7,9 @@ if (isNumeric!One) {
|
|||
unittest {
|
||||
{
|
||||
bool anotherTemplatedFunction(One, Two, Three)(One alpha, Two bravo,
|
||||
Three charlie, double delta)
|
||||
Three charlie, double delta)
|
||||
if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo
|
||||
&& foxtrot && golf && hotel && india && juliet) {
|
||||
&& foxtrot && golf && hotel && india && juliet) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
module example;
|
||||
|
||||
bool aTemplatedFunction(One)(One alpha)
|
||||
if (isNumeric!One) {
|
||||
if (isNumeric!One) {
|
||||
}
|
||||
|
||||
unittest {
|
||||
{
|
||||
bool anotherTemplatedFunction(One, Two, Three)(One alpha, Two bravo,
|
||||
Three charlie, double delta)
|
||||
if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo
|
||||
&& foxtrot && golf && hotel && india && juliet) {
|
||||
Three charlie, double delta)
|
||||
if (isNumeric!One && isNumeric!Two && isNumeric!Three && echo
|
||||
&& foxtrot && golf && hotel && india && juliet) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ version (AArch64) {
|
|||
public:
|
||||
|
||||
double javaStyleFunctionName(double alpha, double bravo, double charlie,
|
||||
double delta, double echo, double foxtrot, double golf, double hotel) {
|
||||
double delta, double echo, double foxtrot, double golf, double hotel) {
|
||||
if (alpha < beta && alpha > golf && hotel < alpha && bravo >= charlie && echo < delta) {
|
||||
if (alpha < beta && alpha > golf && hotel < alpha && bravo >= charlie && echo < delta) {
|
||||
if (alpha < beta && alpha > golf && hotel < alpha
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
void main(string[] args) {
|
||||
if (prevLocation != size_t.max) {
|
||||
addErrorMessage(line, column, KEY,
|
||||
"Expression %s is true: already checked on line %d.".format(
|
||||
expressions[prevLocation].formatted, expressions[prevLocation].line));
|
||||
"Expression %s is true: already checked on line %d.".format(
|
||||
expressions[prevLocation].formatted, expressions[prevLocation].line));
|
||||
}
|
||||
}
|
||||
|
|
18
tests/test
18
tests/test
|
@ -1,18 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
for braceStyle in allman otbs
|
||||
do
|
||||
for source in *.d
|
||||
do
|
||||
echo "${source}.ref" "${braceStyle}/${source}.out"
|
||||
argsFile=$(basename ${source} .d).args
|
||||
if [ -e ${argsFile} ]; then
|
||||
args=$(cat ${argsFile})
|
||||
else
|
||||
args=
|
||||
fi
|
||||
../bin/dfmt --brace_style=${braceStyle} ${args} "${source}" > "${braceStyle}/${source}.out"
|
||||
diff -u "${braceStyle}/${source}.ref" "${braceStyle}/${source}.out"
|
||||
done
|
||||
done
|
Loading…
Reference in New Issue