comparison trunk/src/cmd/DDoc.d @ 731:ca7607226caa

Added new module cmd.DDoc. Added command 'ddoc'. Fixed scanArguments() in dil.doc.Macro.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sun, 03 Feb 2008 19:56:47 +0100
parents
children f88b5285b86b
comparison
equal deleted inserted replaced
730:5cb236c6fe52 731:ca7607226caa
1 /++
2 Author: Aziz Köksal
3 License: GPL3
4 +/
5 module cmd.DDoc;
6
7 import dil.doc.Parser;
8 import dil.doc.Macro;
9 import dil.doc.Doc;
10 import dil.ast.DefaultVisitor;
11 import dil.semantic.Module;
12 import dil.semantic.Pass1;
13 import dil.semantic.Symbol;
14 import dil.semantic.Symbols;
15 import dil.Information;
16 import dil.File;
17 import common;
18
19 import tango.stdc.time : time_t, time, ctime;
20 import tango.stdc.string : strlen;
21
22 void execute(string[] filePaths, string destDir, string[] macroPaths,
23 bool incUndoc, InfoManager infoMan)
24 {
25 // Parse macro files.
26 MacroTable mtable;
27 MacroParser mparser;
28 foreach (macroPath; macroPaths)
29 {
30 auto macros = mparser.parse(loadFile(macroPath));
31 mtable = new MacroTable(mtable);
32 mtable.insert(macros);
33 }
34
35 // foreach (k, v; mtable.table)
36 // Stdout(k)("=")(v.text);
37
38 Module[] modules;
39 foreach (filePath; filePaths)
40 {
41 auto mod = new Module(filePath, infoMan);
42 modules ~= mod;
43 // Parse the file.
44 mod.parse();
45 if (mod.hasErrors)
46 continue;
47
48 // Start semantic analysis.
49 auto pass1 = new SemanticPass1(mod);
50 pass1.start();
51 }
52
53 foreach (mod; modules)
54 generateDocumentation(mod, mtable);
55 }
56
57 void generateDocumentation(Module mod, MacroTable mtable)
58 {
59 // Create a macro environment for this module.
60 mtable = new MacroTable(mtable);
61 // Define runtime macros.
62 mtable.insert(new Macro("TITLE", mod.getFQN()));
63 mtable.insert(new Macro("DOCFILENAME", mod.getFQN()));
64
65 time_t time_val;
66 time(&time_val);
67 char* str = ctime(&time_val);
68 char[] time_str = str[0 .. strlen(str)];
69 mtable.insert(new Macro("DATETIME", time_str.dup));
70 mtable.insert(new Macro("YEAR", time_str[20..24].dup));
71
72 if (mod.moduleDecl)
73 {
74 auto ddocComment = getDDocComment(mod.moduleDecl);
75 if (auto copyright = ddocComment.getCopyright())
76 mtable.insert(new Macro("COPYRIGHT", copyright.text));
77 }
78
79 auto docEmitter = new DDocEmitter();
80 docEmitter.emit(mod);
81
82 mtable.insert(new Macro("BODY", docEmitter.text));
83 expandMacros(mtable, "$(DDOC)");
84 }
85
86 class DDocEmitter : DefaultVisitor
87 {
88 char[] text;
89
90 char[] emit(Module mod)
91 {
92 return text;
93 }
94 }