comparison trunk/src/cmd/DDoc.d @ 800:dcd30b0ba711

Added --xml option to command 'ddoc'.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sat, 01 Mar 2008 17:58:23 +0100
parents fd719161e743
children c39667f1e814
comparison
equal deleted inserted replaced
799:fd719161e743 800:dcd30b0ba711
34 import tango.io.File; 34 import tango.io.File;
35 import tango.io.FilePath; 35 import tango.io.FilePath;
36 36
37 /// Executes the doc generation command. 37 /// Executes the doc generation command.
38 void execute(string[] filePaths, string destDir, string[] macroPaths, 38 void execute(string[] filePaths, string destDir, string[] macroPaths,
39 bool incUndoc, bool verbose, CompilationContext context, 39 bool writeXML, bool incUndoc, bool verbose,
40 InfoManager infoMan) 40 CompilationContext context, InfoManager infoMan)
41 { 41 {
42 // Parse macro files. 42 // Parse macro files.
43 MacroTable mtable; 43 MacroTable mtable;
44 MacroParser mparser; 44 MacroParser mparser;
45 foreach (macroPath; macroPaths) 45 foreach (macroPath; macroPaths)
50 } 50 }
51 51
52 // foreach (k, v; mtable.table) 52 // foreach (k, v; mtable.table)
53 // Stdout(k)("=")(v.text); 53 // Stdout(k)("=")(v.text);
54 54
55 auto tokenHL = new TokenHighlighter(infoMan); // For DDoc code sections. 55 // For DDoc code sections.
56 auto tokenHL = new TokenHighlighter(infoMan, writeXML == false);
56 57
57 // Process D files. 58 // Process D files.
58 foreach (filePath; filePaths) 59 foreach (filePath; filePaths)
59 { 60 {
60 auto mod = new Module(filePath, infoMan); 61 auto mod = new Module(filePath, infoMan);
67 auto pass1 = new SemanticPass1(mod, context); 68 auto pass1 = new SemanticPass1(mod, context);
68 pass1.start(); 69 pass1.start();
69 70
70 // Generate documentation. 71 // Generate documentation.
71 auto dest = new FilePath(destDir); 72 auto dest = new FilePath(destDir);
72 dest.append(mod.getFQN() ~ ".html"); 73 dest.append(mod.getFQN() ~ (writeXML ? ".xml" : ".html"));
73 74
74 InfoManager infoMan2; // Collects warnings from the macro expander. 75 InfoManager infoMan2; // Collects warnings from the macro expander.
75 if (verbose) 76 if (verbose)
76 { 77 {
77 Stdout.formatln("{} > {}", mod.filePath, dest); 78 Stdout.formatln("{} > {}", mod.filePath, dest);
78 infoMan2 = new InfoManager(); 79 infoMan2 = new InfoManager();
79 } 80 }
80 81
81 writeDocFile(dest.toString(), mod, mtable, incUndoc, tokenHL, infoMan2); 82 writeDocFile(dest.toString(), mod, mtable, writeXML, incUndoc, tokenHL, infoMan2);
82 83
83 if (infoMan2) 84 if (infoMan2)
84 infoMan ~= infoMan2.info; 85 infoMan ~= infoMan2.info;
85 } 86 }
86 } 87 }
87 88
88 void writeDocFile(string dest, Module mod, MacroTable mtable, bool incUndoc, 89 void writeDocFile(string dest, Module mod, MacroTable mtable,
90 bool writeXML, bool incUndoc,
89 TokenHighlighter tokenHL, InfoManager infoMan) 91 TokenHighlighter tokenHL, InfoManager infoMan)
90 { 92 {
91 // Create a macro environment for this module. 93 // Create a macro environment for this module.
92 mtable = new MacroTable(mtable); 94 mtable = new MacroTable(mtable);
93 // Define runtime macros. 95 // Define runtime macros.
94 // MODPATH is not in the specs. 96 // MODPATH is not in the specs.
95 mtable.insert("MODPATH", mod.getFQNPath() ~ "." ~ mod.fileExtension()); 97 mtable.insert("MODPATH", mod.getFQNPath() ~ "." ~ mod.fileExtension());
96 mtable.insert("TITLE", mod.getFQN()); 98 mtable.insert("TITLE", mod.getFQN());
97 mtable.insert("DOCFILENAME", mod.getFQN() ~ ".html"); 99 mtable.insert("DOCFILENAME", mod.getFQN() ~ (writeXML ? ".xml" : ".html"));
98 auto timeStr = Time.toString(); 100 auto timeStr = Time.toString();
99 mtable.insert("DATETIME", timeStr); 101 mtable.insert("DATETIME", timeStr);
100 mtable.insert("YEAR", Time.year(timeStr)); 102 mtable.insert("YEAR", Time.year(timeStr));
101 103
102 auto doc = new DDocXMLEmitter(mod, mtable, incUndoc, tokenHL); 104 DDocEmitter docEmitter;
103 doc.emit(); 105 if (writeXML)
106 docEmitter = new DDocXMLEmitter(mod, mtable, incUndoc, tokenHL);
107 else
108 docEmitter = new DDocEmitter(mod, mtable, incUndoc, tokenHL);
109 docEmitter.emit();
104 // Set BODY macro to the text produced by the DDocEmitter. 110 // Set BODY macro to the text produced by the DDocEmitter.
105 mtable.insert("BODY", doc.text); 111 mtable.insert("BODY", docEmitter.text);
106 // Do the macro expansion pass. 112 // Do the macro expansion pass.
107 auto fileText = MacroExpander.expand(mtable, "$(DDOC)", mod.filePath, infoMan); 113 auto fileText = MacroExpander.expand(mtable, "$(DDOC)", mod.filePath, infoMan);
108 // fileText ~= "\n<pre>\n" ~ doc.text ~ "\n</pre>"; 114 // fileText ~= "\n<pre>\n" ~ doc.text ~ "\n</pre>";
109 // Finally write the file out to the harddisk. 115 // Finally write the file out to the harddisk.
110 auto file = new File(dest); 116 auto file = new File(dest);