# HG changeset patch # User Aziz K?ksal # Date 1200680917 -3600 # Node ID c4e3a34e40f1d8dd6bafb9bb3a91980ed3f24a5d # Parent e7811328e6c70961f1add9ab1c770578c5b66e1f Added new module dil.doc.Doc. Moved some doc related methods in dil.ast.Node to dil.doc.Doc. diff -r e7811328e6c7 -r c4e3a34e40f1 trunk/src/dil/ast/Node.d --- a/trunk/src/dil/ast/Node.d Fri Jan 18 18:18:14 2008 +0100 +++ b/trunk/src/dil/ast/Node.d Fri Jan 18 19:28:37 2008 +0100 @@ -76,67 +76,4 @@ { return cast(Class)cast(void*)this; } - - 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 preceding comments. - auto 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 || - (kind == NodeKind.EnumMember && token.type == TOK.Comma)) - break; - - if (token.type == TOK.Comment) - { - // Check that this comment doesn't belong to the previous declaration. - if (kind == NodeKind.EnumMember && token.type == TOK.Comma) - break; - switch (token.prev.type) - { - case TOK.Semicolon, TOK.RBrace: - break; - default: - if (isDocComment(token)) - comments ~= token; - } - } - } - // Get single comment to the right. - token = end.next; - if (token.type == TOK.Comment && isDocComment(token)) - comments ~= token; - else if (kind == NodeKind.EnumMember) - { - token = end.nextNWS; - if (token.type == TOK.Comma) - { - token = token.next; - if (token.type == TOK.Comment && isDocComment(token)) - comments ~= token; - } - } - return comments; - } } diff -r e7811328e6c7 -r c4e3a34e40f1 trunk/src/dil/doc/Doc.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/dil/doc/Doc.d Fri Jan 18 19:28:37 2008 +0100 @@ -0,0 +1,70 @@ +/++ + Author: Aziz Köksal + License: GPL3 ++/ +module dil.doc.Doc; + +import dil.ast.Node; + +bool isDoxygenComment(Token* token) +{ // Doxygen: '/+!' '/*!' '//!' + return token.type == TOK.Comment && token.start[2] == '!'; +} + +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(Node node, bool function(Token*) isDocComment = &isDDocComment) +{ + Token*[] comments; + // Get preceding comments. + auto token = node.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 || + (node.kind == NodeKind.EnumMember && token.type == TOK.Comma)) + break; + + if (token.type == TOK.Comment) + { + // Check that this comment doesn't belong to the previous declaration. + if (node.kind == NodeKind.EnumMember && token.type == TOK.Comma) + break; + switch (token.prev.type) + { + case TOK.Semicolon, TOK.RBrace: + break; + default: + if (isDocComment(token)) + comments ~= token; + } + } + } + // Get single comment to the right. + token = node.end.next; + if (token.type == TOK.Comment && isDocComment(token)) + comments ~= token; + else if (node.kind == NodeKind.EnumMember) + { + token = node.end.nextNWS; + if (token.type == TOK.Comma) + { + token = token.next; + if (token.type == TOK.Comment && isDocComment(token)) + comments ~= token; + } + } + return comments; +} diff -r e7811328e6c7 -r c4e3a34e40f1 trunk/src/main.d --- a/trunk/src/main.d Fri Jan 18 18:18:14 2008 +0100 +++ b/trunk/src/main.d Fri Jan 18 19:28:37 2008 +0100 @@ -16,6 +16,7 @@ import dil.semantic.Symbols; import dil.semantic.Pass1; import dil.translator.German; +import dil.doc.Doc; import dil.Messages; import dil.Settings; import dil.SettingsLoader; @@ -65,7 +66,7 @@ { foreach (member; scopeSym.members) { - auto tokens = member.node.getDocComments(); + auto tokens = getDocComments(member.node); char[] docText; foreach (token; tokens) docText ~= token.srcText;