Mercurial > projects > dil
diff trunk/src/cmd/DDoc.d @ 747:00f872d949ea
Added method scanCommentText() to DDocEmitter.
Added method writeParams() and scanCodeSection().
Added method scanMacro() to MacroParser.
Made fixes and improvements to the MacroExpander.
Applied other minor fixes.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Mon, 11 Feb 2008 03:15:45 +0100 |
parents | 7173ece1b696 |
children | 8caf18892c1b |
line wrap: on
line diff
--- a/trunk/src/cmd/DDoc.d Sun Feb 10 02:14:08 2008 +0100 +++ b/trunk/src/cmd/DDoc.d Mon Feb 11 03:15:45 2008 +0100 @@ -15,6 +15,7 @@ dil.ast.Types; import dil.ast.DefaultVisitor; import dil.lexer.Token; +import dil.lexer.Funcs; import dil.semantic.Module; import dil.semantic.Pass1; import dil.semantic.Symbol; @@ -95,6 +96,7 @@ mtable.insert("BODY", doc.text); // Do the macro expansion pass. auto fileText = MacroExpander.expand(mtable, "$(DDOC)", mod.filePath, infoMan); +// fileText ~= "\n<pre>\n" ~ doc.text ~ "\n</pre>"; // Finally write the file out to the harddisk. auto file = new File(dest); file.write(fileText); @@ -236,16 +238,126 @@ } else write("\n$(DDOC_SECTION $(DDOC_SECTION_H " ~ s.name ~ ":)"); - write(s.text, ")"); + write(scanCommentText(s.text), ")"); } write(")"); } + char[] scanCommentText(char[] text) + { + char* p = text.ptr; + char* end = p + text.length; + char[] result = new char[text.length]; // Reserve space. + result.length = 0; + + while (p < end) + { + switch (*p) + { + case '$': + if (auto macroEnd = MacroParser.scanMacro(p, end)) + { + result ~= makeString(p, macroEnd); // Copy macro invocation as is. + p = macroEnd; + continue; + } + goto default; + case '<': + auto begin = p; + p++; + if (p+2 < end && *p == '!' && p[1] == '-' && p[2] == '-') // <!-- + { + p += 2; // Point to 2nd '-'. + // Scan to closing "-->". + while (++p < end) + if (p+2 < end && *p == '-' && p[1] == '-' && p[2] == '>') + { + p += 3; // Point one past '>'. + break; + } + result ~= makeString(begin, p); + } // <tag ...> or </tag> + else if (p < end && (isalpha(*p) || *p == '/')) + { + while (++p < end && *p != '>') // Skip to closing '>'. + {} + p != end && p++; // Skip '>'. + result ~= makeString(begin, p); + } + else + result ~= "<"; + continue; + case '(': result ~= "("; break; + case ')': result ~= ")"; break; + case '\'': result ~= "'"; break; // ' + case '"': result ~= """; break; + case '>': result ~= ">"; break; + case '&': + if (p+1 < end && (isalpha(p[1]) || p[1] == '#')) + goto default; + result ~= "&"; + break; + case '-': + if (p+2 < end && p[1] == '-' && p[2] == '-') + { + p += 2; // Point to 3rd '-'. + auto codeBegin = p + 1; + while (++p < end) + if (p+2 < end && *p == '-' && p[1] == '-' && p[2] == '-') + { + result ~= "$(D_CODE " ~ scanCodeSection(makeString(codeBegin, p)) ~ ")"; + p += 3; + break; + } + continue; + } + //goto default; + default: + result ~= *p; + } + p++; + } + return result; + } + + char[] scanCodeSection(char[] text) + { + return text; + } + + void writeParams(Parameters params) + { + if (!params.items.length) + return write("()"); + write("("); + auto lastParam = params.items[$-1]; + foreach (param; params.items) + { + if (param.isCVariadic) + write("..."); + else + { + assert(param.type); + // Write storage classes. + auto typeBegin = param.type.baseType.begin; + if (typeBegin !is param.begin) + write(textSpan(param.begin, typeBegin.prevNWS), " "); + write(textSpan(typeBegin, param.type.end)); + write(" $(DDOC_PARAM ", param.name.str, ")"); + if (param.isDVariadic) + write("..."); + } + if (param !is lastParam) + write(", "); + } + write(")"); + } + void writeTemplateParams() { if (!isTemplatized) return; - text ~= "(" ~ (tparams ? textSpan(tparams.begin, tparams.end) : "") ~ ")"; + write("(", (tparams ? textSpan(tparams.begin, tparams.end) : ""), ")"); isTemplatized = false; tparams = null; } @@ -440,7 +552,7 @@ { if (!ddoc(d)) return d; - DECL({ writeFuncHeader(d, d.funcBody); }); + DECL({ write("this"); writeParams(d.params); }); DESC({ writeComment(); }); return d; } @@ -476,7 +588,8 @@ { if (!ddoc(d)) return d; - DECL({ writeFuncHeader(d, d.funcBody); }); + auto type = textSpan(d.returnType.baseType.begin, d.returnType.end); + DECL({ write(type, " "); SYMBOL(d.name.str); writeParams(d.params); }); DESC({ writeComment(); }); return d; } @@ -485,7 +598,7 @@ { if (!ddoc(d)) return d; - DECL({ writeFuncHeader(d, d.funcBody); }); + DECL({ write("new"); writeParams(d.params); }); DESC({ writeComment(); }); return d; }