Run dfmt on itself and debug some wrapping calculations

This commit is contained in:
Hackerpilot 2016-01-19 05:20:31 -08:00
parent 7ec932a1e3
commit 24be6ddc2e
14 changed files with 333 additions and 196 deletions

View File

@ -96,7 +96,8 @@ final class FormatVisitor : ASTVisitor
auto condition = dec.compileCondition; auto condition = dec.compileCondition;
if (condition.versionCondition !is null) if (condition.versionCondition !is null)
{ {
astInformation.conditionalWithElseLocations ~= condition.versionCondition.versionIndex; astInformation.conditionalWithElseLocations
~= condition.versionCondition.versionIndex;
} }
else if (condition.debugCondition !is null) else if (condition.debugCondition !is null)
{ {
@ -151,8 +152,10 @@ final class FormatVisitor : ASTVisitor
{ {
if (functionBody.blockStatement !is null) if (functionBody.blockStatement !is null)
astInformation.doubleNewlineLocations ~= functionBody.blockStatement.endLocation; astInformation.doubleNewlineLocations ~= functionBody.blockStatement.endLocation;
if (functionBody.bodyStatement !is null && functionBody.bodyStatement.blockStatement !is null) if (functionBody.bodyStatement !is null && functionBody.bodyStatement
astInformation.doubleNewlineLocations ~= functionBody.bodyStatement.blockStatement.endLocation; .blockStatement !is null)
astInformation.doubleNewlineLocations
~= functionBody.bodyStatement.blockStatement.endLocation;
functionBody.accept(this); functionBody.accept(this);
} }
@ -203,8 +206,8 @@ final class FormatVisitor : ASTVisitor
override void visit(const UnaryExpression unary) override void visit(const UnaryExpression unary)
{ {
if (unary.prefix.type == tok!"~" || unary.prefix.type == tok!"&" if (unary.prefix.type == tok!"~" || unary.prefix.type == tok!"&"
|| unary.prefix.type == tok!"*" || unary.prefix.type == tok!"+" || unary.prefix.type == tok!"*"
|| unary.prefix.type == tok!"-") || unary.prefix.type == tok!"+" || unary.prefix.type == tok!"-")
{ {
astInformation.unaryLocations ~= unary.prefix.index; astInformation.unaryLocations ~= unary.prefix.index;
} }

View File

@ -54,7 +54,6 @@ struct Config
mixin StandardEditorConfigFields; mixin StandardEditorConfigFields;
/** /**
* Initializes the standard EditorConfig properties with default values that * Initializes the standard EditorConfig properties with default values that
* make sense for D code. * make sense for D code.
@ -89,7 +88,8 @@ struct Config
if (dfmt_soft_max_line_length > max_line_length) if (dfmt_soft_max_line_length > max_line_length)
{ {
stderr.writefln("Column hard limit (%d) must be greater than or equal to column soft limit (%d)", stderr.writefln(
"Column hard limit (%d) must be greater than or equal to column soft limit (%d)",
max_line_length, dfmt_soft_max_line_length); max_line_length, dfmt_soft_max_line_length);
return false; return false;
} }

View File

@ -73,11 +73,11 @@ mixin template StandardEditorConfigFields()
auto thisN = &mixin("this." ~ N); auto thisN = &mixin("this." ~ N);
static if (N == "pattern") static if (N == "pattern")
continue; continue;
else static if (is (T == enum)) else static if (is(T == enum))
*thisN = otherN != T.unspecified ? otherN : *thisN; *thisN = otherN != T.unspecified ? otherN : *thisN;
else static if (is (T == int)) else static if (is(T == int))
*thisN = otherN != -1 ? otherN : *thisN; *thisN = otherN != -1 ? otherN : *thisN;
else static if (is (T == string)) else static if (is(T == string))
*thisN = otherN !is null ? otherN : *thisN; *thisN = otherN !is null ? otherN : *thisN;
else else
static assert(false); static assert(false);
@ -143,6 +143,7 @@ EC getConfigFor(EC)(string path)
static if (__VERSION__ >= 2067) static if (__VERSION__ >= 2067)
{ {
import std.algorithm : each; import std.algorithm : each;
configs.each!(a => a.each!(b => result.merge(b, fileName)))(); configs.each!(a => a.each!(b => result.merge(b, fileName)))();
} }
else else

View File

@ -479,7 +479,6 @@ private:
body body
{ {
parenDepth--; parenDepth--;
if (parenDepth == 0)
indents.popWrapIndents(); indents.popWrapIndents();
if (indents.topIs(tok!"(")) if (indents.topIs(tok!"("))
indents.pop(); indents.pop();
@ -1279,6 +1278,7 @@ private:
} }
else if (currentIs(tok!"{")) else if (currentIs(tok!"{"))
{ {
indents.dump();
indents.popWrapIndents(); indents.popWrapIndents();
if (peekBackIsSlashSlash() && peekBack2Is(tok!";")) if (peekBackIsSlashSlash() && peekBack2Is(tok!";"))
{ {
@ -1329,10 +1329,12 @@ private:
} }
else else
{ {
indents.dump();
if (indents.topIsTemp() && (peekBackIsOneOf(true, tok!"}", if (indents.topIsTemp() && (peekBackIsOneOf(true, tok!"}",
tok!";") && indents.top != tok!";")) tok!";") && indents.top != tok!";"))
indents.popTempIndents(); indents.popTempIndents();
indentLevel = indents.indentLevel; indentLevel = indents.indentLevel;
indents.dump();
} }
indent(); indent();
} }

View File

@ -10,15 +10,15 @@ import std.path : filenameCharCmp, isDirSeparator;
// From std.path with changes: // From std.path with changes:
// * changes meaning to match all characters except '/' // * changes meaning to match all characters except '/'
// ** added to take over the old meaning of * // ** added to take over the old meaning of *
bool globMatchEditorConfig(CaseSensitive cs = CaseSensitive.osDefault, C, Range) bool globMatchEditorConfig(CaseSensitive cs = CaseSensitive.osDefault, C, Range)(
(Range path, const(C)[] pattern) Range path, const(C)[] pattern) @safe pure nothrow if (isForwardRange!Range
@safe pure nothrow && isSomeChar!(ElementEncodingType!Range) && isSomeChar!C
if (isForwardRange!Range && isSomeChar!(ElementEncodingType!Range) && && is(Unqual!C == Unqual!(ElementEncodingType!Range)))
isSomeChar!C && is(Unqual!C == Unqual!(ElementEncodingType!Range)))
in in
{ {
// Verify that pattern[] is valid // Verify that pattern[] is valid
import std.algorithm : balancedParens; import std.algorithm : balancedParens;
assert(balancedParens(pattern, '[', ']', 0)); assert(balancedParens(pattern, '[', ']', 0));
assert(balancedParens(pattern, '{', '}', 0)); assert(balancedParens(pattern, '{', '}', 0));
} }
@ -29,11 +29,13 @@ body
static if (RC.sizeof == 1 && isSomeString!Range) static if (RC.sizeof == 1 && isSomeString!Range)
{ {
import std.utf : byChar; import std.utf : byChar;
return globMatchEditorConfig!cs(path.byChar, pattern); return globMatchEditorConfig!cs(path.byChar, pattern);
} }
else static if (RC.sizeof == 2 && isSomeString!Range) else static if (RC.sizeof == 2 && isSomeString!Range)
{ {
import std.utf : byWchar; import std.utf : byWchar;
return globMatchEditorConfig!cs(path.byWchar, pattern); return globMatchEditorConfig!cs(path.byWchar, pattern);
} }
else else
@ -45,15 +47,14 @@ body
switch (pc) switch (pc)
{ {
case '*': case '*':
if (pi < pattern.length-1 && pattern[pi+1] == '*') if (pi < pattern.length - 1 && pattern[pi + 1] == '*')
{ {
if (pi + 2 == pattern.length) if (pi + 2 == pattern.length)
return true; return true;
for (; !path.empty; path.popFront()) for (; !path.empty; path.popFront())
{ {
auto p = path.save; auto p = path.save;
if (globMatchEditorConfig!(cs, C)(p, if (globMatchEditorConfig!(cs, C)(p, pattern[pi + 2 .. pattern.length]))
pattern[pi + 2 .. pattern.length]))
return true; return true;
} }
return false; return false;
@ -67,8 +68,7 @@ body
auto p = path.save; auto p = path.save;
//if (p[0].to!dchar.isDirSeparator() && !pattern[pi+1].isDirSeparator()) //if (p[0].to!dchar.isDirSeparator() && !pattern[pi+1].isDirSeparator())
// return false; // return false;
if (globMatchEditorConfig!(cs, C)(p, if (globMatchEditorConfig!(cs, C)(p, pattern[pi + 1 .. pattern.length]))
pattern[pi + 1 .. pattern.length]))
return true; return true;
if (p[0].to!dchar.isDirSeparator()) if (p[0].to!dchar.isDirSeparator())
return false; return false;
@ -110,9 +110,9 @@ body
case '{': case '{':
// find end of {} section // find end of {} section
auto piRemain = pi; auto piRemain = pi;
for (; piRemain < pattern.length for (; piRemain < pattern.length && pattern[piRemain] != '}'; ++piRemain)
&& pattern[piRemain] != '}'; ++piRemain) {
{ } }
if (piRemain < pattern.length) if (piRemain < pattern.length)
++piRemain; ++piRemain;
@ -131,7 +131,7 @@ body
auto p = path.save; auto p = path.save;
if (pi0 == pi) if (pi0 == pi)
{ {
if (globMatchEditorConfig!(cs, C)(p, pattern[piRemain..$])) if (globMatchEditorConfig!(cs, C)(p, pattern[piRemain .. $]))
{ {
return true; return true;
} }
@ -142,8 +142,7 @@ body
/* Match for: /* Match for:
* pattern[pi0..pi-1] ~ pattern[piRemain..$] * pattern[pi0..pi-1] ~ pattern[piRemain..$]
*/ */
if (pattmp.ptr == null) if (pattmp.ptr == null) // Allocate this only once per function invocation.
// Allocate this only once per function invocation.
// Should do it with malloc/free, but that would make it impure. // Should do it with malloc/free, but that would make it impure.
pattmp = new C[pattern.length]; pattmp = new C[pattern.length];
@ -180,8 +179,8 @@ body
unittest unittest
{ {
assert (globMatchEditorConfig!(CaseSensitive.no)("foo", "Foo")); assert(globMatchEditorConfig!(CaseSensitive.no)("foo", "Foo"));
assert (!globMatchEditorConfig!(CaseSensitive.yes)("foo", "Foo")); assert(!globMatchEditorConfig!(CaseSensitive.yes)("foo", "Foo"));
assert(globMatchEditorConfig("foo", "*")); assert(globMatchEditorConfig("foo", "*"));
assert(globMatchEditorConfig("foo.bar"w, "*"w)); assert(globMatchEditorConfig("foo.bar"w, "*"w));
@ -225,7 +224,7 @@ unittest
assert(!globMatchEditorConfig("foo", "foob")); assert(!globMatchEditorConfig("foo", "foob"));
assert(!globMatchEditorConfig("foo", "foo{b}")); assert(!globMatchEditorConfig("foo", "foo{b}"));
assert (globMatchEditorConfig(`foo/foo\bar`, "f**b**r")); assert(globMatchEditorConfig(`foo/foo\bar`, "f**b**r"));
assert(globMatchEditorConfig("foo", "**")); assert(globMatchEditorConfig("foo", "**"));
assert(globMatchEditorConfig("foo/bar", "foo/bar")); assert(globMatchEditorConfig("foo/bar", "foo/bar"));
assert(globMatchEditorConfig("foo/bar", "foo/*")); assert(globMatchEditorConfig("foo/bar", "foo/*"));
@ -235,6 +234,5 @@ unittest
assert(!globMatchEditorConfig("/foo/bar/gluu/sar.png", "*/sar.png")); assert(!globMatchEditorConfig("/foo/bar/gluu/sar.png", "*/sar.png"));
assert(!globMatchEditorConfig("/foo/bar/gluu/sar.png", "*/*.png")); assert(!globMatchEditorConfig("/foo/bar/gluu/sar.png", "*/*.png"));
static assert(globMatchEditorConfig("foo.bar", "[!gh]*bar")); static assert(globMatchEditorConfig("foo.bar", "[!gh]*bar"));
} }

View File

@ -151,6 +151,15 @@ struct IndentStack
return cast(int) index; return cast(int) index;
} }
void dump()
{
/+import std.stdio : stderr;
import dparse.lexer : str;
import std.algorithm.iteration : map;
stderr.writefln("\033[31m%(%s %)\033[0m", arr[0 .. index].map!(a => str(a)));+/
}
private: private:
size_t index; size_t index;
@ -163,12 +172,24 @@ private:
return 0; return 0;
immutable size_t j = k == size_t.max ? index : k; immutable size_t j = k == size_t.max ? index : k;
int size = 0; int size = 0;
int parenCount;
foreach (i; 0 .. j) foreach (i; 0 .. j)
{ {
if (i + 1 < index) if (i + 1 < index)
{ {
if (arr[i] == tok!"]") if (arr[i] == tok!"(")
parenCount++;
else if (arr[i] == tok!"]")
continue; continue;
else
{
if (isWrapIndent(arr[i]) && parenCount > 0)
{
parenCount = 0;
continue;
}
//parenCount = 0;
}
immutable currentIsNonWrapTemp = !isWrapIndent(arr[i]) && isTempIndent(arr[i]); immutable currentIsNonWrapTemp = !isWrapIndent(arr[i]) && isTempIndent(arr[i]);
immutable nextIsParenOrSwitch = arr[i + 1] == tok!"(" immutable nextIsParenOrSwitch = arr[i + 1] == tok!"("
|| arr[i + 1] == tok!"switch" || arr[i + 1] == tok!"{"; || arr[i + 1] == tok!"switch" || arr[i + 1] == tok!"{";

View File

@ -32,8 +32,10 @@ else
{ {
import dfmt.editorconfig : OptionalBoolean; import dfmt.editorconfig : OptionalBoolean;
import std.exception : enforceEx; import std.exception : enforceEx;
enforceEx!GetOptException(value == "true" || value == "false", "Invalid argument"); enforceEx!GetOptException(value == "true" || value == "false", "Invalid argument");
immutable OptionalBoolean optVal = value == "true" ? OptionalBoolean.t : OptionalBoolean.f; immutable OptionalBoolean optVal = value == "true" ? OptionalBoolean.t
: OptionalBoolean.f;
switch (option) switch (option)
{ {
case "align_switch_statements": case "align_switch_statements":
@ -54,7 +56,8 @@ else
case "compact_labeled_statements": case "compact_labeled_statements":
optConfig.dfmt_compact_labeled_statements = optVal; optConfig.dfmt_compact_labeled_statements = optVal;
break; break;
default: assert(false, "Invalid command-line switch"); default:
assert(false, "Invalid command-line switch");
} }
} }
@ -113,17 +116,19 @@ else
return 1; return 1;
File output = stdout; File output = stdout;
version(Windows) version (Windows)
{ {
// On Windows, set stdout to binary mode (needed for correct EOL writing) // On Windows, set stdout to binary mode (needed for correct EOL writing)
// See Phobos' stdio.File.rawWrite // See Phobos' stdio.File.rawWrite
{ {
import std.stdio; import std.stdio;
immutable fd = fileno(output.getFP()); immutable fd = fileno(output.getFP());
setmode(fd, _O_BINARY); setmode(fd, _O_BINARY);
version(CRuntime_DigitalMars) version (CRuntime_DigitalMars)
{ {
import core.atomic : atomicOp; import core.atomic : atomicOp;
atomicOp!"&="(__fhnd_info[fd], ~FHND_TEXT); atomicOp!"&="(__fhnd_info[fd], ~FHND_TEXT);
} }
} }
@ -176,14 +181,17 @@ else
} }
} }
private string optionsToString(E)() if(is(E == enum)) { private string optionsToString(E)() if (is(E == enum))
import std.traits:EnumMembers; {
import std.traits : EnumMembers;
import std.conv; import std.conv;
string result = "["; string result = "[";
foreach(i, option; EnumMembers!E) { foreach (i, option; EnumMembers!E)
{
result ~= to!string(option) ~ "|"; result ~= to!string(option) ~ "|";
} }
result = result[0 .. $-1] ~ "]"; result = result[0 .. $ - 1] ~ "]";
return result; return result;
} }
@ -199,11 +207,13 @@ Options:
Formatting Options: Formatting Options:
--align_switch_statements --align_switch_statements
--brace_style `, optionsToString!(typeof(Config.dfmt_brace_style))(), ` --brace_style `,
optionsToString!(typeof(Config.dfmt_brace_style))(), `
--end_of_line --end_of_line
--help|h --help|h
--indent_size --indent_size
--indent_style|t `, optionsToString!(typeof(Config.indent_style))(), ` --indent_style|t `,
optionsToString!(typeof(Config.indent_style))(), `
--soft_max_line_length --soft_max_line_length
--max_line_length --max_line_length
--outdent_attributes --outdent_attributes
@ -211,7 +221,8 @@ Formatting Options:
--selective_import_space --selective_import_space
--split_operator_at_line_end --split_operator_at_line_end
--compact_labeled_statements --compact_labeled_statements
--template_constraint_style `, optionsToString!(typeof(Config.dfmt_template_constraint_style))()); --template_constraint_style `,
optionsToString!(typeof(Config.dfmt_template_constraint_style))());
} }
private string createFilePath(bool readFromStdin, string fileName) private string createFilePath(bool readFromStdin, string fileName)

View File

@ -195,7 +195,6 @@ pure nothrow @safe @nogc unittest
assert(breakCost(tok!".", u) != 1000); assert(breakCost(tok!".", u) != 1000);
} }
private string generateFixedLengthCases() private string generateFixedLengthCases()
{ {
import std.algorithm : map; import std.algorithm : map;
@ -205,11 +204,11 @@ private string generateFixedLengthCases()
assert(__ctfe); assert(__ctfe);
string[] spacedOperatorTokens = [ string[] spacedOperatorTokens = [
",", "..", "...", "/", "/=", "!", "!<", "!<=", "!<>", "!<>=", "!=", "!>", ",", "..", "...", "/", "/=", "!", "!<", "!<=", "!<>", "!<>=", "!=",
"!>=", "%", "%=", "&", "&&", "&=", "*", "*=", "+", "+=", "-", "-=", ":", "!>", "!>=", "%", "%=", "&", "&&", "&=", "*", "*=", "+", "+=", "-",
";", "<", "<<", "<<=", "<=", "<>", "<>=", "=", "==", "=>", ">", ">=", "-=", ":", ";", "<", "<<", "<<=", "<=", "<>", "<>=", "=", "==", "=>",
">>", ">>=", ">>>", ">>>=", "?", "@", "^", "^=", "^^", "^^=", "|", "|=", "||", ">", ">=", ">>", ">>=", ">>>", ">>>=", "?", "@", "^", "^=", "^^",
"~", "~=" "^^=", "|", "|=", "||", "~", "~="
]; ];
immutable spacedOperatorTokenCases = spacedOperatorTokens.map!( immutable spacedOperatorTokenCases = spacedOperatorTokens.map!(
a => format(`case tok!"%s": return %d + 1;`, a, a.length)).join("\n\t"); a => format(`case tok!"%s": return %d + 1;`, a, a.length)).join("\n\t");
@ -219,20 +218,21 @@ private string generateFixedLengthCases()
"break", "byte", "case", "cast", "catch", "cdouble", "cent", "cfloat", "break", "byte", "case", "cast", "catch", "cdouble", "cent", "cfloat",
"char", "class", "const", "continue", "creal", "dchar", "debug", "char", "class", "const", "continue", "creal", "dchar", "debug",
"default", "delegate", "delete", "deprecated", "do", "double", "else", "default", "delegate", "delete", "deprecated", "do", "double", "else",
"enum", "export", "extern", "false", "final", "finally", "float", "for", "enum", "export", "extern", "false", "final", "finally", "float",
"foreach", "foreach_reverse", "function", "goto", "idouble", "if", "for", "foreach", "foreach_reverse", "function", "goto", "idouble",
"ifloat", "immutable", "import", "in", "inout", "int", "interface", "if", "ifloat", "immutable", "import", "in", "inout", "int",
"invariant", "ireal", "is", "lazy", "long", "macro", "mixin", "module", "interface", "invariant", "ireal", "is", "lazy", "long", "macro",
"new", "nothrow", "null", "out", "override", "package", "pragma", "mixin", "module", "new", "nothrow", "null", "out", "override",
"private", "protected", "public", "pure", "real", "ref", "return", "package", "pragma", "private", "protected", "public", "pure", "real",
"scope", "shared", "short", "static", "struct", "super", "switch", "ref", "return", "scope", "shared", "short", "static", "struct",
"synchronized", "template", "this", "throw", "true", "try", "typedef", "super", "switch", "synchronized", "template", "this", "throw", "true",
"typeid", "typeof", "ubyte", "ucent", "uint", "ulong", "union", "try", "typedef", "typeid", "typeof", "ubyte", "ucent", "uint",
"unittest", "ushort", "version", "void", "volatile", "wchar", "while", "ulong", "union", "unittest", "ushort", "version", "void", "volatile",
"with", "__DATE__", "__EOF__", "__FILE__", "__FUNCTION__", "__gshared", "wchar", "while", "with", "__DATE__", "__EOF__", "__FILE__",
"__LINE__", "__MODULE__", "__parameters", "__PRETTY_FUNCTION__", "__FUNCTION__", "__gshared", "__LINE__", "__MODULE__", "__parameters",
"__TIME__", "__TIMESTAMP__", "__traits", "__vector", "__VENDOR__", "__PRETTY_FUNCTION__", "__TIME__", "__TIMESTAMP__", "__traits",
"__VERSION__", "$", "++", "--", ".", "[", "]", "(", ")", "{", "}" "__vector", "__VENDOR__", "__VERSION__", "$", "++", "--", ".", "[",
"]", "(", ")", "{", "}"
]; ];
immutable identifierTokenCases = identifierTokens.map!( immutable identifierTokenCases = identifierTokens.map!(
a => format(`case tok!"%s": return %d;`, a, a.length)).join("\n\t"); a => format(`case tok!"%s": return %d;`, a, a.length)).join("\n\t");

View File

@ -18,7 +18,8 @@ struct State
import core.bitop : popcnt, bsf; import core.bitop : popcnt, bsf;
import std.algorithm : min, map, sum; import std.algorithm : min, map, sum;
immutable int remainingCharsMultiplier = config.max_line_length - config.dfmt_soft_max_line_length; immutable int remainingCharsMultiplier = config.max_line_length
- config.dfmt_soft_max_line_length;
immutable int newlinePenalty = remainingCharsMultiplier * 20; immutable int newlinePenalty = remainingCharsMultiplier * 20;
this.breaks = breaks; this.breaks = breaks;
@ -152,7 +153,8 @@ size_t[] chooseLineBreakTokens(size_t index, const Token[] tokens,
return genRetVal(current.breaks, index); return genRetVal(current.breaks, index);
} }
validMoves!(typeof(open))(open, tokens[0 .. tokensEnd], validMoves!(typeof(open))(open, tokens[0 .. tokensEnd],
depths[0 .. tokensEnd], current.breaks, config, currentLineLength, indentLevel); depths[0 .. tokensEnd], current.breaks, config, currentLineLength,
indentLevel);
} }
if (open.empty) if (open.empty)
return genRetVal(lowest.breaks, index); return genRetVal(lowest.breaks, index);

View File

@ -0,0 +1,36 @@
unittest
{
if (a)
{
while (sBraceDepth == 0 && indents.topIsTemp()
&& ((indents.top != tok!"if" && indents.top != tok!"version")
|| !peekIs(tok!"else")))
{
a();
}
}
if (parenDepth == 0 && (peekIs(tok!"is") || peekIs(tok!"in")
|| peekIs(tok!"out") || peekIs(tok!"body")))
writeToken();
{
{
while (sBraceDepth == 0 && indents.topIsTemp()
&& ((indents.top != tok!"if"
&& indents.top != tok!"version") || !peekIs(tok!"else")))
{
indents.pop();
}
}
}
{
while (sBraceDepth == 0 && indents.topIsTemp()
&& ((indents.top != tok!"if" && indents.top != tok!"version")
|| !peekIs(tok!"else")))
{
indents.pop();
}
}
}

View File

@ -0,0 +1,31 @@
unittest {
if (a) {
while (sBraceDepth == 0 && indents.topIsTemp()
&& ((indents.top != tok!"if" && indents.top != tok!"version")
|| !peekIs(tok!"else"))) {
a();
}
}
if (parenDepth == 0 && (peekIs(tok!"is") || peekIs(tok!"in")
|| peekIs(tok!"out") || peekIs(tok!"body")))
writeToken();
{
{
while (sBraceDepth == 0 && indents.topIsTemp()
&& ((indents.top != tok!"if"
&& indents.top != tok!"version") || !peekIs(tok!"else"))) {
indents.pop();
}
}
}
{
while (sBraceDepth == 0 && indents.topIsTemp()
&& ((indents.top != tok!"if" && indents.top != tok!"version")
|| !peekIs(tok!"else"))) {
indents.pop();
}
}
}

32
tests/parenIndent.d Normal file
View File

@ -0,0 +1,32 @@
unittest
{
if (a)
{
while (sBraceDepth == 0 && indents.topIsTemp()
&& ((indents.top != tok!"if" && indents.top != tok!"version")|| !peekIs(tok!"else")))
{
a();
}
}
if (parenDepth == 0 && (peekIs(tok!"is") || peekIs(tok!"in")
|| peekIs(tok!"out") || peekIs(tok!"body")))
writeToken();
{
{
while (sBraceDepth == 0 && indents.topIsTemp()&& ((indents.top != tok!"if"
&& indents.top != tok!"version") || !peekIs(tok!"else")))
{
indents.pop();
}
}
}
{
while (sBraceDepth == 0 && indents.topIsTemp()&& ((indents.top != tok!"if" && indents.top != tok!"version") || !peekIs(tok!"else")))
{
indents.pop();
}
}
}