Mercurial > projects > dil
diff trunk/src/dil/ast/Node.d @ 612:c65b11c2074c
Added getDocComments() to class Node.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Mon, 07 Jan 2008 20:36:08 +0100 |
parents | 39fac5531b85 |
children | 7034d3f9e40c |
line wrap: on
line diff
--- a/trunk/src/dil/ast/Node.d Sun Jan 06 22:58:49 2008 +0100 +++ b/trunk/src/dil/ast/Node.d Mon Jan 07 20:36:08 2008 +0100 @@ -288,4 +288,54 @@ { children is null || addChildren(children); } + + static bool isDoxygenComment(Token* token) + { // Doxygen: '/+!' '/*!' '//!' + return token.type == TOK.Comment && token.start[2] == '!'; + } + + static bool isDDocComment(Token* token) + { // DDOC: '/++' '/**' '///' + return token.type == TOK.Comment && token.start[1] == token.start[2]; + } + + /++ + Returns the surrounding documentation comment tokens. + Note: this function works correctly only if + the source text is syntactically correct. + +/ + Token*[] getDocComments(bool function(Token*) isDocComment = &isDDocComment) + { + Token*[] comments; + // Get comment to the right. + auto token = end.next; + if (token.type == TOK.Comment && + isDocComment(token)) + comments ~= token; + // Get preceding comments. + token = begin; + // Scan backwards until we hit another declaration. + while (1) + { + token = token.prev; + if (token.type == TOK.LBrace || + token.type == TOK.RBrace || + token.type == TOK.Semicolon || + token.type == TOK.HEAD) + break; + if (token.type == TOK.Comment) + { + // Check that this comment doesn't belong to the previous declaration. + switch (token.prev.type) + { + case TOK.Semicolon, TOK.RBrace: + break; + default: + if (isDocComment(token)) + comments ~= token; + } + } + } + return comments; + } }