This commit is contained in:
parent
91ae2d4fc3
commit
47bf248e95
86
src/dfmt.d
86
src/dfmt.d
|
@ -594,52 +594,69 @@ private:
|
||||||
if (current.type == tok!"{")
|
if (current.type == tok!"{")
|
||||||
{
|
{
|
||||||
depth++;
|
depth++;
|
||||||
if (config.braceStyle == BraceStyle.otbs)
|
if (assumeSorted(astInformation.structInitStartLocations)
|
||||||
|
.equalRange(tokens[index].index).length)
|
||||||
{
|
{
|
||||||
write(" ");
|
writeToken();
|
||||||
write("{");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (config.braceStyle == BraceStyle.otbs)
|
||||||
|
{
|
||||||
|
write(" ");
|
||||||
|
write("{");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newline();
|
||||||
|
write("{");
|
||||||
|
}
|
||||||
|
indentLevel++;
|
||||||
|
index++;
|
||||||
newline();
|
newline();
|
||||||
write("{");
|
|
||||||
}
|
}
|
||||||
indentLevel++;
|
|
||||||
index++;
|
|
||||||
newline();
|
|
||||||
}
|
}
|
||||||
else if (current.type == tok!"}")
|
else if (current.type == tok!"}")
|
||||||
{
|
{
|
||||||
// Silly hack to format enums better.
|
if (assumeSorted(astInformation.structInitEndLocations)
|
||||||
if (peekBackIs(tok!"identifier"))
|
.equalRange(tokens[index].index).length)
|
||||||
newline();
|
|
||||||
write("}");
|
|
||||||
depth--;
|
|
||||||
if (index < tokens.length - 1 &&
|
|
||||||
assumeSorted(astInformation.doubleNewlineLocations)
|
|
||||||
.equalRange(tokens[index].index).length && !peekIs(tok!"}"))
|
|
||||||
{
|
{
|
||||||
output.put("\n");
|
writeToken();
|
||||||
|
depth--;
|
||||||
}
|
}
|
||||||
if (config.braceStyle == BraceStyle.otbs)
|
else
|
||||||
{
|
{
|
||||||
index++;
|
// Silly hack to format enums better.
|
||||||
if (index < tokens.length && current.type == tok!"else")
|
if (peekBackIs(tok!"identifier"))
|
||||||
write(" ");
|
newline();
|
||||||
|
write("}");
|
||||||
|
depth--;
|
||||||
|
if (index < tokens.length - 1 &&
|
||||||
|
assumeSorted(astInformation.doubleNewlineLocations)
|
||||||
|
.equalRange(tokens[index].index).length && !peekIs(tok!"}"))
|
||||||
|
{
|
||||||
|
output.put("\n");
|
||||||
|
}
|
||||||
|
if (config.braceStyle == BraceStyle.otbs)
|
||||||
|
{
|
||||||
|
index++;
|
||||||
|
if (index < tokens.length && current.type == tok!"else")
|
||||||
|
write(" ");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (peekIs(tok!"case") || peekIs(tok!"default"))
|
||||||
|
indentLevel--;
|
||||||
|
newline();
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
index++;
|
||||||
if (peekIs(tok!"case") || peekIs(tok!"default"))
|
if (peekIs(tok!"case") || peekIs(tok!"default"))
|
||||||
indentLevel--;
|
indentLevel--;
|
||||||
newline();
|
newline();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
index++;
|
|
||||||
if (peekIs(tok!"case") || peekIs(tok!"default"))
|
|
||||||
indentLevel--;
|
|
||||||
newline();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
formatStep();
|
formatStep();
|
||||||
|
@ -950,6 +967,8 @@ struct ASTInformation
|
||||||
sort(unaryLocations);
|
sort(unaryLocations);
|
||||||
sort(attributeDeclarationLines);
|
sort(attributeDeclarationLines);
|
||||||
sort(caseEndLocations);
|
sort(caseEndLocations);
|
||||||
|
sort(structInitStartLocations);
|
||||||
|
sort(structInitEndLocations);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Locations of end braces for struct bodies
|
/// Locations of end braces for struct bodies
|
||||||
|
@ -966,6 +985,12 @@ struct ASTInformation
|
||||||
|
|
||||||
/// Case statement colon locations
|
/// Case statement colon locations
|
||||||
size_t[] caseEndLocations;
|
size_t[] caseEndLocations;
|
||||||
|
|
||||||
|
/// Opening braces of struct initializers
|
||||||
|
size_t[] structInitStartLocations;
|
||||||
|
|
||||||
|
/// Closing braces of struct initializers
|
||||||
|
size_t[] structInitEndLocations;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Collects information from the AST that is useful for the formatter
|
/// Collects information from the AST that is useful for the formatter
|
||||||
|
@ -1004,6 +1029,13 @@ final class FormatVisitor : ASTVisitor
|
||||||
functionBody.accept(this);
|
functionBody.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override void visit(const StructInitializer structInitializer)
|
||||||
|
{
|
||||||
|
astInformation.structInitStartLocations ~= structInitializer.startLocation;
|
||||||
|
astInformation.structInitEndLocations ~= structInitializer.endLocation;
|
||||||
|
structInitializer.accept(this);
|
||||||
|
}
|
||||||
|
|
||||||
override void visit(const EnumBody enumBody)
|
override void visit(const EnumBody enumBody)
|
||||||
{
|
{
|
||||||
astInformation.doubleNewlineLocations ~= enumBody.endLocation;
|
astInformation.doubleNewlineLocations ~= enumBody.endLocation;
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
immutable NameId[] namesA =
|
||||||
|
[
|
||||||
|
{"Aacgr", 0x00386}, // GREEK CAPITAL LETTER ALPHA WITH TONOS
|
||||||
|
{"aacgr", 0x003AC}, // GREEK SMALL LETTER ALPHA WITH TONOS
|
||||||
|
];
|
|
@ -0,0 +1,3 @@
|
||||||
|
immutable NameId[] namesA = [{"Aacgr", 0x00386}, // GREEK CAPITAL LETTER ALPHA WITH TONOS
|
||||||
|
{"aacgr", 0x003AC}, // GREEK SMALL LETTER ALPHA WITH TONOS
|
||||||
|
];
|
Loading…
Reference in New Issue