Mercurial > projects > dil
comparison 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 |
comparison
equal
deleted
inserted
replaced
746:32a8ddd330f8 | 747:00f872d949ea |
---|---|
13 dil.ast.Expression, | 13 dil.ast.Expression, |
14 dil.ast.Parameters, | 14 dil.ast.Parameters, |
15 dil.ast.Types; | 15 dil.ast.Types; |
16 import dil.ast.DefaultVisitor; | 16 import dil.ast.DefaultVisitor; |
17 import dil.lexer.Token; | 17 import dil.lexer.Token; |
18 import dil.lexer.Funcs; | |
18 import dil.semantic.Module; | 19 import dil.semantic.Module; |
19 import dil.semantic.Pass1; | 20 import dil.semantic.Pass1; |
20 import dil.semantic.Symbol; | 21 import dil.semantic.Symbol; |
21 import dil.semantic.Symbols; | 22 import dil.semantic.Symbols; |
22 import dil.Information; | 23 import dil.Information; |
93 doc.emit(mod); | 94 doc.emit(mod); |
94 // Set BODY macro to the text produced by the DDocEmitter. | 95 // Set BODY macro to the text produced by the DDocEmitter. |
95 mtable.insert("BODY", doc.text); | 96 mtable.insert("BODY", doc.text); |
96 // Do the macro expansion pass. | 97 // Do the macro expansion pass. |
97 auto fileText = MacroExpander.expand(mtable, "$(DDOC)", mod.filePath, infoMan); | 98 auto fileText = MacroExpander.expand(mtable, "$(DDOC)", mod.filePath, infoMan); |
99 // fileText ~= "\n<pre>\n" ~ doc.text ~ "\n</pre>"; | |
98 // Finally write the file out to the harddisk. | 100 // Finally write the file out to the harddisk. |
99 auto file = new File(dest); | 101 auto file = new File(dest); |
100 file.write(fileText); | 102 file.write(fileText); |
101 } | 103 } |
102 | 104 |
234 mtable.insert(ms.macroNames, ms.macroTexts); | 236 mtable.insert(ms.macroNames, ms.macroTexts); |
235 continue; | 237 continue; |
236 } | 238 } |
237 else | 239 else |
238 write("\n$(DDOC_SECTION $(DDOC_SECTION_H " ~ s.name ~ ":)"); | 240 write("\n$(DDOC_SECTION $(DDOC_SECTION_H " ~ s.name ~ ":)"); |
239 write(s.text, ")"); | 241 write(scanCommentText(s.text), ")"); |
240 } | 242 } |
241 write(")"); | 243 write(")"); |
242 } | 244 } |
243 | 245 |
246 char[] scanCommentText(char[] text) | |
247 { | |
248 char* p = text.ptr; | |
249 char* end = p + text.length; | |
250 char[] result = new char[text.length]; // Reserve space. | |
251 result.length = 0; | |
252 | |
253 while (p < end) | |
254 { | |
255 switch (*p) | |
256 { | |
257 case '$': | |
258 if (auto macroEnd = MacroParser.scanMacro(p, end)) | |
259 { | |
260 result ~= makeString(p, macroEnd); // Copy macro invocation as is. | |
261 p = macroEnd; | |
262 continue; | |
263 } | |
264 goto default; | |
265 case '<': | |
266 auto begin = p; | |
267 p++; | |
268 if (p+2 < end && *p == '!' && p[1] == '-' && p[2] == '-') // <!-- | |
269 { | |
270 p += 2; // Point to 2nd '-'. | |
271 // Scan to closing "-->". | |
272 while (++p < end) | |
273 if (p+2 < end && *p == '-' && p[1] == '-' && p[2] == '>') | |
274 { | |
275 p += 3; // Point one past '>'. | |
276 break; | |
277 } | |
278 result ~= makeString(begin, p); | |
279 } // <tag ...> or </tag> | |
280 else if (p < end && (isalpha(*p) || *p == '/')) | |
281 { | |
282 while (++p < end && *p != '>') // Skip to closing '>'. | |
283 {} | |
284 p != end && p++; // Skip '>'. | |
285 result ~= makeString(begin, p); | |
286 } | |
287 else | |
288 result ~= "<"; | |
289 continue; | |
290 case '(': result ~= "("; break; | |
291 case ')': result ~= ")"; break; | |
292 case '\'': result ~= "'"; break; // ' | |
293 case '"': result ~= """; break; | |
294 case '>': result ~= ">"; break; | |
295 case '&': | |
296 if (p+1 < end && (isalpha(p[1]) || p[1] == '#')) | |
297 goto default; | |
298 result ~= "&"; | |
299 break; | |
300 case '-': | |
301 if (p+2 < end && p[1] == '-' && p[2] == '-') | |
302 { | |
303 p += 2; // Point to 3rd '-'. | |
304 auto codeBegin = p + 1; | |
305 while (++p < end) | |
306 if (p+2 < end && *p == '-' && p[1] == '-' && p[2] == '-') | |
307 { | |
308 result ~= "$(D_CODE " ~ scanCodeSection(makeString(codeBegin, p)) ~ ")"; | |
309 p += 3; | |
310 break; | |
311 } | |
312 continue; | |
313 } | |
314 //goto default; | |
315 default: | |
316 result ~= *p; | |
317 } | |
318 p++; | |
319 } | |
320 return result; | |
321 } | |
322 | |
323 char[] scanCodeSection(char[] text) | |
324 { | |
325 return text; | |
326 } | |
327 | |
328 void writeParams(Parameters params) | |
329 { | |
330 if (!params.items.length) | |
331 return write("()"); | |
332 write("("); | |
333 auto lastParam = params.items[$-1]; | |
334 foreach (param; params.items) | |
335 { | |
336 if (param.isCVariadic) | |
337 write("..."); | |
338 else | |
339 { | |
340 assert(param.type); | |
341 // Write storage classes. | |
342 auto typeBegin = param.type.baseType.begin; | |
343 if (typeBegin !is param.begin) | |
344 write(textSpan(param.begin, typeBegin.prevNWS), " "); | |
345 write(textSpan(typeBegin, param.type.end)); | |
346 write(" $(DDOC_PARAM ", param.name.str, ")"); | |
347 if (param.isDVariadic) | |
348 write("..."); | |
349 } | |
350 if (param !is lastParam) | |
351 write(", "); | |
352 } | |
353 write(")"); | |
354 } | |
355 | |
244 void writeTemplateParams() | 356 void writeTemplateParams() |
245 { | 357 { |
246 if (!isTemplatized) | 358 if (!isTemplatized) |
247 return; | 359 return; |
248 text ~= "(" ~ (tparams ? textSpan(tparams.begin, tparams.end) : "") ~ ")"; | 360 write("(", (tparams ? textSpan(tparams.begin, tparams.end) : ""), ")"); |
249 isTemplatized = false; | 361 isTemplatized = false; |
250 tparams = null; | 362 tparams = null; |
251 } | 363 } |
252 | 364 |
253 void writeInheritanceList(BaseClassType[] bases) | 365 void writeInheritanceList(BaseClassType[] bases) |
438 | 550 |
439 D visit(ConstructorDeclaration d) | 551 D visit(ConstructorDeclaration d) |
440 { | 552 { |
441 if (!ddoc(d)) | 553 if (!ddoc(d)) |
442 return d; | 554 return d; |
555 DECL({ write("this"); writeParams(d.params); }); | |
556 DESC({ writeComment(); }); | |
557 return d; | |
558 } | |
559 | |
560 D visit(StaticConstructorDeclaration d) | |
561 { | |
562 if (!ddoc(d)) | |
563 return d; | |
443 DECL({ writeFuncHeader(d, d.funcBody); }); | 564 DECL({ writeFuncHeader(d, d.funcBody); }); |
444 DESC({ writeComment(); }); | 565 DESC({ writeComment(); }); |
445 return d; | 566 return d; |
446 } | 567 } |
447 | 568 |
448 D visit(StaticConstructorDeclaration d) | 569 D visit(DestructorDeclaration d) |
449 { | 570 { |
450 if (!ddoc(d)) | 571 if (!ddoc(d)) |
451 return d; | 572 return d; |
452 DECL({ writeFuncHeader(d, d.funcBody); }); | 573 DECL({ writeFuncHeader(d, d.funcBody); }); |
453 DESC({ writeComment(); }); | 574 DESC({ writeComment(); }); |
454 return d; | 575 return d; |
455 } | 576 } |
456 | 577 |
457 D visit(DestructorDeclaration d) | 578 D visit(StaticDestructorDeclaration d) |
458 { | 579 { |
459 if (!ddoc(d)) | 580 if (!ddoc(d)) |
460 return d; | 581 return d; |
461 DECL({ writeFuncHeader(d, d.funcBody); }); | 582 DECL({ writeFuncHeader(d, d.funcBody); }); |
462 DESC({ writeComment(); }); | 583 DESC({ writeComment(); }); |
463 return d; | 584 return d; |
464 } | 585 } |
465 | 586 |
466 D visit(StaticDestructorDeclaration d) | |
467 { | |
468 if (!ddoc(d)) | |
469 return d; | |
470 DECL({ writeFuncHeader(d, d.funcBody); }); | |
471 DESC({ writeComment(); }); | |
472 return d; | |
473 } | |
474 | |
475 D visit(FunctionDeclaration d) | 587 D visit(FunctionDeclaration d) |
476 { | 588 { |
477 if (!ddoc(d)) | 589 if (!ddoc(d)) |
478 return d; | 590 return d; |
479 DECL({ writeFuncHeader(d, d.funcBody); }); | 591 auto type = textSpan(d.returnType.baseType.begin, d.returnType.end); |
592 DECL({ write(type, " "); SYMBOL(d.name.str); writeParams(d.params); }); | |
480 DESC({ writeComment(); }); | 593 DESC({ writeComment(); }); |
481 return d; | 594 return d; |
482 } | 595 } |
483 | 596 |
484 D visit(NewDeclaration d) | 597 D visit(NewDeclaration d) |
485 { | 598 { |
486 if (!ddoc(d)) | 599 if (!ddoc(d)) |
487 return d; | 600 return d; |
488 DECL({ writeFuncHeader(d, d.funcBody); }); | 601 DECL({ write("new"); writeParams(d.params); }); |
489 DESC({ writeComment(); }); | 602 DESC({ writeComment(); }); |
490 return d; | 603 return d; |
491 } | 604 } |
492 | 605 |
493 D visit(DeleteDeclaration d) | 606 D visit(DeleteDeclaration d) |