A few fixes for doc generation

This commit is contained in:
Hackerpilot 2014-06-18 17:02:14 -07:00
parent 870817ff3a
commit fc578105df
4 changed files with 54 additions and 48 deletions

View File

@ -107,9 +107,9 @@ class Formatter(Sink)
} }
else else
{ {
if (linkageAttribute) foreach (storageClass; storageClasses)
{ {
format(linkageAttribute); format(storageClass);
space(); space();
} }
@ -451,10 +451,8 @@ class Formatter(Sink)
with(att) with(att)
{ {
if (linkageAttribute) format(linkageAttribute);
if (alignAttribute) format(alignAttribute);
if (pragmaExpression) format(pragmaExpression);
if (storageClass) format(storageClass); if (storageClass) format(storageClass);
if (pragmaExpression) format(pragmaExpression);
if (attribute) put(tokenRep(attribute)); if (attribute) put(tokenRep(attribute));
} }
} }
@ -550,7 +548,7 @@ class Formatter(Sink)
void format(const BaseClassList baseClassList) void format(const BaseClassList baseClassList)
{ {
debug(verbose) writeln("BaseClassList"); debug(verbose) writeln("BaseClassList");
put(" : ");
foreach(count, item; baseClassList.items) foreach(count, item; baseClassList.items)
{ {
format(item); format(item);
@ -3595,6 +3593,8 @@ class Formatter(Sink)
mixin(binary("xorExpression", "^")); mixin(binary("xorExpression", "^"));
} }
Sink sink;
private: private:
import std.uni : isWhite; import std.uni : isWhite;
@ -3644,24 +3644,12 @@ private:
lastThing = currentThing; lastThing = currentThing;
currentThing = thing; currentThing = thing;
dchar last() {
auto r = sink.data;
while(!r.empty && r.back.isWhite) r.popBack();
return r.empty ? ' ' : r.back;
}
with(What) { with(What) {
if (last() == '{')
{
onNewline();
return;
}
if (lastThing == importDecl && thing != importDecl) if (lastThing == importDecl && thing != importDecl)
lineGap(1); lineGap(1);
if (lastThing == loop && last() == '}') if (lastThing == loop)
lineGap(1); lineGap(1);
switch(thing) switch(thing)
@ -3675,10 +3663,10 @@ private:
lineGap(1); lineGap(1);
break; break;
case conditionalDecl: case conditionalDecl:
if (last() == ';' || last() == '}') lineGap(1); lineGap(1);
break; break;
case variableDecl: case variableDecl:
if (last() == '}') lineGap(1); lineGap(1);
onNewline(); onNewline();
break; break;
case importDecl: case importDecl:
@ -3700,16 +3688,6 @@ private:
void lineGap(int gap) void lineGap(int gap)
{ {
int count;
auto r = sink.data;
while(!r.empty && r.back.isWhite)
{
if (r.back == '\n') count++;
r.popBack();
}
if (r.empty) return;
int need = gap - count + 1;
while(need--) newline();
} }
void newline() void newline()
@ -3728,19 +3706,10 @@ private:
void onNewline() void onNewline()
{ {
auto r = sink.data;
while(!r.empty && r.back.isWhite())
{
if (r.back == '\n') return;
r.popBack();
}
if (r.empty) return;
newline();
} }
void space() void space()
{ {
if (!sink.data.empty && !sink.data.back.isWhite() && sink.data.back != '(')
put(" "); put(" ");
} }
@ -3879,7 +3848,7 @@ private:
uint indentWidth; uint indentWidth;
uint indentLevel; uint indentLevel;
IndentStyle style; IndentStyle style;
Sink sink;
What lastThing, currentThing; What lastThing, currentThing;
uint lineLength; uint lineLength;

View File

@ -1987,6 +1987,7 @@ public:
/** */ IdentifierChain moduleName; /** */ IdentifierChain moduleName;
/** */ size_t startLocation; /** */ size_t startLocation;
/** */ size_t endLocation; /** */ size_t endLocation;
/** */ string comment;
mixin OpEquals; mixin OpEquals;
} }

View File

@ -1778,9 +1778,32 @@ body
{ {
case "///": case "///":
size_t i = 3; size_t i = 3;
while (comment[i] == ' ' || comment[i] == '\t') if (i < comment.length)
{
again:
while (i < comment.length && comment[i] == ' ' || comment[i] == '\t')
i++; i++;
outputRange.put(comment[i .. $]); size_t j = i + 1;
while (j < comment.length)
{
if (comment[j] == '\r')
j++;
if (j >= comment.length)
break;
if (comment[j] == '\n')
{
outputRange.put(comment[i .. j]);
j++;
while (j < comment.length && comment[j] == '/')
j++;
outputRange.put(' ');
i = j;
goto again;
}
j++;
}
outputRange.put(comment[i .. j]);
}
break; break;
case "/++": case "/++":
case "/**": case "/**":

View File

@ -2560,7 +2560,18 @@ body {} // six
node.attributes = attributes; node.attributes = attributes;
if (isAuto) if (isAuto)
{
foreach (a; node.attributes)
{
if (a.storageClass is null)
continue;
if (a.storageClass.token == tok!"auto")
node.hasAuto = true;
if (a.storageClass.token == tok!"ref")
node.hasRef = true;
}
goto functionName; goto functionName;
}
while (moreTokens() && currentIsMemberFunctionAttribute()) while (moreTokens() && currentIsMemberFunctionAttribute())
memberFunctionAttributes ~= parseMemberFunctionAttribute(); memberFunctionAttributes ~= parseMemberFunctionAttribute();
@ -3621,6 +3632,8 @@ invariant() foo();
auto node = allocate!ModuleDeclaration; auto node = allocate!ModuleDeclaration;
auto start = expect(tok!"module"); auto start = expect(tok!"module");
node.moduleName = parseIdentifierChain(); node.moduleName = parseIdentifierChain();
node.comment = start.comment;
comment = null;
auto end = expect(tok!";"); auto end = expect(tok!";");
node.startLocation = start.index; node.startLocation = start.index;
node.endLocation = end.index; node.endLocation = end.index;