Solved the mystery of the disappearing doc comments

This commit is contained in:
Hackerpilot 2014-01-30 20:00:20 -08:00
parent d5689dd1ac
commit 552d0bbb07
2 changed files with 8 additions and 7 deletions

5
main.d
View File

@ -109,12 +109,11 @@ int main(string[] args)
} }
else if (tokenDump) else if (tokenDump)
{ {
writeln("text blank\tindex\tline\tcolumn\tcomment"); writeln("text blank\tindex\tline\tcolumn");
foreach (token; tokens) foreach (token; tokens)
{ {
writefln("<<%20s>>%b\t%d\t%d\t%d", token.text is null ? str(token.type) : token.text, writefln("<<%20s>>%b\t%d\t%d\t%d", token.text is null ? str(token.type) : token.text,
token.text !is null, token.index, token.line, token.column, token.text !is null, token.index, token.line, token.column);
token.comment);
} }
return 0; return 0;
} }

View File

@ -412,13 +412,14 @@ public struct DLexer
private static bool isDocComment(string comment) pure nothrow @safe private static bool isDocComment(string comment) pure nothrow @safe
{ {
return comment.length >= 3 && (comment[0 .. 3] == "///" return comment.length >= 3 && (comment[2] == '/'
|| comment[0 .. 3] == "/**" || comment[0 .. 3] == "/++"); || comment[2] == '*' || comment[2] == '+');
} }
public void popFront() pure public void popFront() pure
{ {
_popFront(); _popFront();
string comment = null;
switch (front.type) switch (front.type)
{ {
case tok!"comment": case tok!"comment":
@ -427,9 +428,9 @@ public struct DLexer
import std.string; import std.string;
if (isDocComment(front.text)) if (isDocComment(front.text))
{ {
_front.comment = _front.comment == null comment = comment is null
? front.text ? front.text
: format("%s\n%s", _front.comment, front.text); : format("%s\n%s", comment, front.text);
} }
do _popFront(); while (front == tok!"comment"); do _popFront(); while (front == tok!"comment");
if (front == tok!"whitespace") goto case tok!"whitespace"; if (front == tok!"whitespace") goto case tok!"whitespace";
@ -445,6 +446,7 @@ public struct DLexer
default: default:
break; break;
} }
_front.comment = comment;
} }