Mercurial > projects > ddmd
view dmd/ddoc/Sections.d @ 153:560eaedcb7a2
added lots of ddoc code, still needs much care
added helpers functions in ddoc.Util
author | trass3r |
---|---|
date | Wed, 15 Sep 2010 04:18:46 +0200 |
parents | 78bf0fe43974 |
children |
line wrap: on
line source
module dmd.ddoc.Sections; import dmd.common; import dmd.ddoc.DocComment; import dmd.ddoc.Util; import dmd.Array; import dmd.Scope; import dmd.Dsymbol; import dmd.HdrGenState; import dmd.OutBuffer; //! alias Vector!Section Sections; //! class Section { string name; string body_; int nooutput; void write(DocComment dc, Scope sc, Dsymbol s, OutBuffer buf) { if (name.length) { static string[] table = [ "AUTHORS", "BUGS", "COPYRIGHT", "DATE", "DEPRECATED", "EXAMPLES", "HISTORY", "LICENSE", "RETURNS", "SEE_ALSO", "STANDARDS", "THROWS", "VERSION" ]; for (uint i = 0; i < table.length; i++) { if (icmp(table[i], name) == 0) { buf.printf("$(DDOC_%s ", table[i]); goto L1; } } buf.writestring("$(DDOC_SECTION "); // Replace _ characters with spaces buf.writestring("$(DDOC_SECTION_H "); size_t o = buf.offset; for (size_t u = 0; u < name.length; u++) { char c = name[u]; buf.writeByte((c == '_') ? ' ' : c); } escapeStrayParenthesis(buf, o, s.loc); buf.writestring(":)\n"); } else { buf.writestring("$(DDOC_DESCRIPTION "); } L1: uint o = buf.offset; buf.write(body_, body_.length); escapeStrayParenthesis(buf, o, s.loc); highlightText(sc, s, buf, o); buf.writestring(")\n"); } } //! class ParamSection : Section { override void write(DocComment dc, Scope sc, Dsymbol s, OutBuffer buf) { size_t i = 0; string p = body_; size_t tempstart, templen; size_t namestart, namelen = 0; // !=0 if line continuation size_t textstart, textlen; uint o; Parameter *arg; buf.writestring("$(DDOC_PARAMS \n"); while (i < _body.length) { // Skip to start of macro while (true) { switch (p[i]) { case ' ': case '\t': i++; continue; case '\n': i++; goto Lcont; default: if (isIdStart(p)) break; if (namelen) goto Ltext; // continuation of prev macro goto Lskipline; } break; } tempstart = i; while (isIdTail(body_[i .. $])) i += utfStride(body_[i .. $]); templen = i - tempstart; while (p[i] == ' ' || p[i] == '\t') i++; if (p[i] != '=') { if (namelen) goto Ltext; // continuation of prev macro goto Lskipline; } i++; if (namelen) { // Output existing param L1: // writef("param '%.*s' = '%.*s'\n", namelen, namestart, textlen, textstart); HdrGenState hgs; buf.writestring("$(DDOC_PARAM_ROW "); buf.writestring("$(DDOC_PARAM_ID "); o = buf.offset; arg = isFunctionParameter(s, namestart, namelen); if (arg && arg.type && arg.ident) arg.type.toCBuffer(buf, arg.ident, &hgs); else buf.write(namestart, namelen); escapeStrayParenthesis(buf, o, s.loc); highlightCode(sc, s, buf, o); buf.writestring(")\n"); buf.writestring("$(DDOC_PARAM_DESC "); o = buf.offset; buf.write(&p[textstart], textlen); escapeStrayParenthesis(buf, o, s.loc); highlightText(sc, s, buf, o); buf.writestring(")"); buf.writestring(")\n"); namelen = 0; if (i >= p.length) break; } namestart = tempstart; namelen = templen; while (p[i] == ' ' || p[i] == '\t') i++; textstart = i; Ltext: while (p[i] != '\n') i++; textlen = i - textstart; i++; Lcont: continue; Lskipline: // Ignore this line while (p[i++] != '\n') {} } if (namelen) goto L1; // write out last one buf.writestring(")\n"); } } //! class MacroSection : Section { override void write(DocComment dc, Scope sc, Dsymbol s, OutBuffer buf) { // writef("MacroSection.write()\n"); DocComment.parseMacros(dc.pescapetable, dc.pmacrotable, body_, body_.length); } }