comparison dmd/ddoc/DocComment.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 4092a614a9f3
children
comparison
equal deleted inserted replaced
152:4092a614a9f3 153:560eaedcb7a2
1 module dmd.ddoc.DocComment; 1 module dmd.ddoc.DocComment;
2 2
3 import dmd.ddoc.Escape; 3 import dmd.ddoc.Escape;
4 import dmd.ddoc.Macro; 4 import dmd.ddoc.Macro;
5 import dmd.ddoc.Sections; 5 import dmd.ddoc.Sections;
6 import dmd.ddoc.Util;
7
6 import dmd.Array; 8 import dmd.Array;
7 import dmd.Scope; 9 import dmd.Scope;
8 import dmd.Dsymbol; 10 import dmd.Dsymbol;
9 import dmd.OutBuffer; 11 import dmd.OutBuffer;
10 12
24 // TODO: memset(this, 0, sizeof(DocComment)); 26 // TODO: memset(this, 0, sizeof(DocComment));
25 } 27 }
26 28
27 static DocComment parse(Scope sc, Dsymbol s, string comment) 29 static DocComment parse(Scope sc, Dsymbol s, string comment)
28 { 30 {
29 unsigned idlen; 31 uint idlen;
30 32
31 // writef("parse(%s): '%s'\n", s.toChars(), comment); 33 // writef("parse(%s): '%s'\n", s.toChars(), comment);
32 if (sc.lastdc && isDitto(comment)) 34 if (sc.lastdc && isDitto(comment))
33 return null; 35 return null;
34 36
60 * name1 = value1 62 * name1 = value1
61 * 63 *
62 * name2 = value2 64 * name2 = value2
63 */ 65 */
64 static void parseMacros(Escape** pescapetable, Macro** pmacrotable, ubyte* m, uint mlen) 66 static void parseMacros(Escape** pescapetable, Macro** pmacrotable, ubyte* m, uint mlen)
65 { 67 {/+
66 assert(false); 68 unsigned char *p = m;
67 } 69 unsigned len = mlen;
70 unsigned char *pend = p + len;
71
72 unsigned char *tempstart;
73 unsigned templen;
74
75 unsigned char *namestart;
76 unsigned namelen = 0; // !=0 if line continuation
77
78 unsigned char *textstart;
79 unsigned textlen;
80
81 while (p < pend)
82 {
83 // Skip to start of macro
84 while (1)
85 {
86 if (p >= pend)
87 goto Ldone;
88 switch (*p)
89 {
90 case ' ':
91 case '\t':
92 p++;
93 continue;
94
95 case '\n':
96 p++;
97 goto Lcont;
98
99 default:
100 if (isIdStart(p))
101 break;
102 if (namelen)
103 goto Ltext; // continuation of prev macro
104 goto Lskipline;
105 }
106 break;
107 }
108 tempstart = p;
109
110 while (1)
111 {
112 if (p >= pend)
113 goto Ldone;
114 if (!isIdTail(p))
115 break;
116 p += utfStride(p);
117 }
118 templen = p - tempstart;
119
120 while (1)
121 {
122 if (p >= pend)
123 goto Ldone;
124 if (!(*p == ' ' || *p == '\t'))
125 break;
126 p++;
127 }
128
129 if (*p != '=')
130 { if (namelen)
131 goto Ltext; // continuation of prev macro
132 goto Lskipline;
133 }
134 p++;
135 if (p >= pend)
136 goto Ldone;
137
138 if (namelen)
139 { // Output existing macro
140 L1:
141 //printf("macro '%.*s' = '%.*s'\n", namelen, namestart, textlen, textstart);
142 if (icmp("ESCAPES", namestart, namelen) == 0)
143 parseEscapes(pescapetable, textstart, textlen);
144 else
145 Macro.define(pmacrotable, namestart, namelen, textstart, textlen);
146 namelen = 0;
147 if (p >= pend)
148 break;
149 }
150
151 namestart = tempstart;
152 namelen = templen;
153
154 while (p < pend && (*p == ' ' || *p == '\t'))
155 p++;
156 textstart = p;
157
158 Ltext:
159 while (p < pend && *p != '\n')
160 p++;
161 textlen = p - textstart;
162
163 // Remove trailing \r if there is one
164 if (p > m && p[-1] == '\r')
165 textlen--;
166
167 p++;
168 //printf("p = %p, pend = %p\n", p, pend);
169
170 Lcont:
171 continue;
172
173 Lskipline:
174 // Ignore this line
175 while (p < pend && *p++ != '\n') {}
176 }
177 Ldone:
178 if (namelen)
179 goto L1; // write out last one
180 +/}
68 181
69 /************************************** 182 /**************************************
70 * Parse escapes of the form: 183 * Parse escapes of the form:
71 * /c/string/ 184 * /c/string/
72 * where c is a single character. 185 * where c is a single character.
73 * Multiple escapes can be separated 186 * Multiple escapes can be separated
74 * by whitespace and/or commas. 187 * by whitespace and/or commas.
75 */ 188 */
76 static void parseEscapes(Escape** pescapetable, ubyte* textstart, uint textlen) 189 static void parseEscapes(Escape** pescapetable, ubyte* textstart, uint textlen)
77 { 190 {/+
78 assert(false); 191 Escape *escapetable = *pescapetable;
79 } 192
193 if (!escapetable)
194 { escapetable = new Escape;
195 *pescapetable = escapetable;
196 }
197 unsigned char *p = textstart;
198 unsigned char *pend = p + textlen;
199
200 while (1)
201 {
202 while (1)
203 {
204 if (p + 4 >= pend)
205 return;
206 if (!(*p == ' ' || *p == '\t' || *p == '\n' || *p == ','))
207 break;
208 p++;
209 }
210 if (p[0] != '/' || p[2] != '/')
211 return;
212 unsigned char c = p[1];
213 p += 3;
214 unsigned char *start = p;
215 while (1)
216 {
217 if (p >= pend)
218 return;
219 if (*p == '/')
220 break;
221 p++;
222 }
223 size_t len = p - start;
224 char *s = (char *)memcpy(mem.malloc(len + 1), start, len);
225 s[len] = 0;
226 escapetable.strings[c] = s;
227 //printf("%c = '%s'\n", c, s);
228 p++;
229 }
230 +/}
231
80 /***************************************** 232 /*****************************************
81 * Parse next paragraph out of *pcomment. 233 * Parse next paragraph out of *pcomment.
82 * Update *pcomment to point past paragraph. 234 * Update *pcomment to point past paragraph.
83 * Returns null if no more paragraphs. 235 * Returns null if no more paragraphs.
84 * If paragraph ends in 'identifier:', 236 * If paragraph ends in 'identifier:',
88 { 240 {
89 ubyte*p; 241 ubyte*p;
90 ubyte*pstart; 242 ubyte*pstart;
91 ubyte*pend; 243 ubyte*pend;
92 ubyte*idstart; 244 ubyte*idstart;
93 unsigned idlen; 245 uint idlen;
94 246
95 ubyte*name = null; 247 ubyte*name = null;
96 unsigned namelen = 0; 248 size_t namelen = 0;
97 249
98 //printf("parseSections('%s')\n", comment); 250 //printf("parseSections('%s')\n", comment);
99 p = comment; 251 p = comment;
100 while (*p) 252 while (*p)
101 { 253 {
216 if (sec.namelen || i) 368 if (sec.namelen || i)
217 sec.write(this, sc, s, buf); 369 sec.write(this, sc, s, buf);
218 else 370 else
219 { 371 {
220 buf.writestring("$(DDOC_SUMMARY "); 372 buf.writestring("$(DDOC_SUMMARY ");
221 unsigned o = buf.offset; 373 uint o = buf.offset;
222 buf.write(sec.body_, sec.bodylen); 374 buf.write(sec.body_, sec.bodylen);
223 highlightText(sc, s, buf, o); 375 highlightText(sc, s, buf, o);
224 buf.writestring(")\n"); 376 buf.writestring(")\n");
225 } 377 }
226 } 378 }