Mercurial > projects > dil
changeset 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 | 6d449e777f5d |
children | 7034d3f9e40c |
files | trunk/src/dil/ast/Node.d trunk/src/dil/lexer/Token.d |
diffstat | 2 files changed, 54 insertions(+), 3 deletions(-) [+] |
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; + } }
--- a/trunk/src/dil/lexer/Token.d Sun Jan 06 22:58:49 2008 +0100 +++ b/trunk/src/dil/lexer/Token.d Mon Jan 07 20:36:08 2008 +0100 @@ -50,9 +50,10 @@ string str; char pf; /// Postfix 'c', 'w', 'd' or 0 for none. version(D2) - Token* tok_str; /// Points to the contents of a token string stored as a - /// doubly linked list. The last token is always '}' or - /// EOF in case end of source text is "q{" EOF. + Token* tok_str; /++ Points to the contents of a token string stored as a + doubly linked list. The last token is always '}' or + EOF in case end of source text is "q{" EOF. + +/ } Identifier* ident; dchar dchar_;