# HG changeset patch # User Aziz K?ksal # Date 1202595781 -3600 # Node ID 7299159c3a190b2251fa593a92f176bec90d1229 # Parent 7173ece1b6966fc114aa8a0f3858bc15f38ca3b6 Improved DDocParser. diff -r 7173ece1b696 -r 7299159c3a19 trunk/src/dil/doc/Doc.d --- a/trunk/src/dil/doc/Doc.d Sat Feb 09 22:54:31 2008 +0100 +++ b/trunk/src/dil/doc/Doc.d Sat Feb 09 23:23:01 2008 +0100 @@ -104,16 +104,16 @@ textEnd = p + text.length; char* summaryBegin; - char* idBegin, idEnd; - char* nextIdBegin, nextIdEnd; + string ident, nextIdent; + char* bodyBegin, nextBodyBegin; skipWhitespace(p); summaryBegin = p; - if (findNextIdColon(idBegin, idEnd)) + if (findNextIdColon(ident, bodyBegin)) { // Check that this is not an explicit section. - if (summaryBegin != idBegin) - scanSummaryAndDescription(summaryBegin, idBegin); + if (summaryBegin != ident.ptr) + scanSummaryAndDescription(summaryBegin, ident.ptr); } else // There are no explicit sections. { @@ -121,19 +121,35 @@ return sections; } - assert(idBegin && idEnd); + assert(ident.length); // Continue parsing. - while (findNextIdColon(nextIdBegin, nextIdEnd)) + while (findNextIdColon(nextIdent, nextBodyBegin)) { - sections ~= new Section(makeString(idBegin, idEnd), makeString(idEnd+1, nextIdBegin)); - idBegin = nextIdBegin; - idEnd = nextIdEnd; + sections ~= new Section(ident, textBody(bodyBegin, nextIdent.ptr)); + ident = nextIdent; + bodyBegin = nextBodyBegin; } // Add last section. - sections ~= new Section(makeString(idBegin, idEnd), makeString(idEnd+1, textEnd)); + sections ~= new Section(ident, textBody(bodyBegin, textEnd)); return sections; } + /// Removes trailing whitespace characters from the text body. + char[] textBody(char* begin, char* end) + { + // The body of A is empty, e.g.: + // A: + // B: some text + // ^- begin and end point to B (or to this.textEnd in the 2nd case.) + if (begin is end) + return ""; + // Remove trailing whitespace. + while (isspace(*--end) || *end == '\n') + {} + end++; + return makeString(begin, end); + } + void scanSummaryAndDescription(char* p, char* end) { assert(p < end); @@ -170,10 +186,10 @@ /// Find next "Identifier:". /// Params: - /// idBegin = set to the first character of the Identifier - /// idEnd = set to the colon following the Identifier + /// ident = set to the Identifier + /// bodyBegin = set to the beginning of the text body (whitespace skipped.) /// Returns: true if found - bool findNextIdColon(ref char* ref_idBegin, ref char* ref_idEnd) + bool findNextIdColon(ref char[] ident, ref char* bodyBegin) { while (p < textEnd) { @@ -187,10 +203,13 @@ do // IdChar* p++; while (p < textEnd && (isident(*p) || isUnicodeAlpha(p, textEnd))) + auto idEnd = p; if (p < textEnd && *p == ':') // : { - ref_idBegin = idBegin; - ref_idEnd = p; + p++; + skipWhitespace(p); + bodyBegin = p; + ident = makeString(idBegin, idEnd); return true; } } diff -r 7173ece1b696 -r 7299159c3a19 trunk/src/dil/doc/Parser.d --- a/trunk/src/dil/doc/Parser.d Sat Feb 09 22:54:31 2008 +0100 +++ b/trunk/src/dil/doc/Parser.d Sat Feb 09 23:23:01 2008 +0100 @@ -63,7 +63,7 @@ // B = some text // ^- begin and end point to B (or to this.textEnd in the 2nd case.) if (begin is end) - return null; + return ""; // Remove trailing whitespace. while (isspace(*--end) || *end == '\n') {}