Mercurial > projects > dil
changeset 807:a2880c95eda3
Refactored ddoc command.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Sun, 09 Mar 2008 15:28:24 +0100 |
parents | bcb74c9b895c |
children | 28e1ff1dcfcf |
files | release.py src/cmd/DDoc.d src/cmd/DDocXML.d src/main.d |
diffstat | 4 files changed, 106 insertions(+), 101 deletions(-) [+] |
line wrap: on
line diff
--- a/release.py Sun Mar 09 00:12:19 2008 +0100 +++ b/release.py Sun Mar 09 15:28:24 2008 +0100 @@ -1,8 +1,12 @@ +#! /usr/bin/python # -*- coding: utf-8 -*- # Author: Aziz Köksal # TODO: port release.sh to Python +if __name__ == '__main__': + print "DIL" + # TODO: write subcommand that creates a Makefile def writeMakefile(): pass
--- a/src/cmd/DDoc.d Sun Mar 09 00:12:19 2008 +0100 +++ b/src/cmd/DDoc.d Sun Mar 09 15:28:24 2008 +0100 @@ -34,96 +34,102 @@ import tango.io.File; import tango.io.FilePath; -/// Executes the doc generation command. -void execute(string[] filePaths, string destDir, string[] macroPaths, - bool writeXML, bool incUndoc, bool verbose, - CompilationContext context, InfoManager infoMan) +/// The ddoc command. +struct DDocCommand { - // Parse macro files. - MacroTable mtable; - MacroParser mparser; - foreach (macroPath; macroPaths) - { - auto macros = mparser.parse(loadMacroFile(macroPath, infoMan)); - mtable = new MacroTable(mtable); - mtable.insert(macros); - } - -// foreach (k, v; mtable.table) -// Stdout(k)("=")(v.text); - - // For DDoc code sections. - auto tokenHL = new TokenHighlighter(infoMan, writeXML == false); + string destDirPath; /// Destination directory. + string[] macroPaths; /// Macro file paths. + string[] filePaths; /// Module file paths. + bool includeUndocumented; /// Whether to include undocumented symbols. + bool writeXML; /// Whether to write XML instead of HTML docs. + bool verbose; /// Whether to be verbose. - // Process D files. - foreach (filePath; filePaths) - { - auto mod = new Module(filePath, infoMan); - // Parse the file. - mod.parse(); - if (mod.hasErrors) - continue; + CompilationContext context; + InfoManager infoMan; + TokenHighlighter tokenHL; /// For DDoc code sections. - // Start semantic analysis. - auto pass1 = new SemanticPass1(mod, context); - pass1.start(); - - // Generate documentation. - auto dest = new FilePath(destDir); - dest.append(mod.getFQN() ~ (writeXML ? ".xml" : ".html")); - - InfoManager infoMan2; // Collects warnings from the macro expander. - if (verbose) + /// Executes the doc generation command. + void run() + { + // Parse macro files and build macro table hierarchy. + MacroTable mtable; + MacroParser mparser; + foreach (macroPath; macroPaths) { - Stdout.formatln("{} > {}", mod.filePath, dest); - infoMan2 = new InfoManager(); + auto macros = mparser.parse(loadMacroFile(macroPath, infoMan)); + mtable = new MacroTable(mtable); + mtable.insert(macros); } - writeDocFile(dest.toString(), mod, mtable, writeXML, incUndoc, tokenHL, infoMan2); + // For DDoc code sections. + tokenHL = new TokenHighlighter(infoMan, writeXML == false); - if (infoMan2) - infoMan ~= infoMan2.info; - } -} + // Process D files. + foreach (filePath; filePaths) + { + auto mod = new Module(filePath, infoMan); + // Parse the file. + mod.parse(); + if (mod.hasErrors) + continue; -void writeDocFile(string dest, Module mod, MacroTable mtable, - bool writeXML, bool incUndoc, - TokenHighlighter tokenHL, InfoManager infoMan) -{ - // Create a macro environment for this module. - mtable = new MacroTable(mtable); - // Define runtime macros. - // MODPATH is not in the specs. - mtable.insert("MODPATH", mod.getFQNPath() ~ "." ~ mod.fileExtension()); - mtable.insert("TITLE", mod.getFQN()); - mtable.insert("DOCFILENAME", mod.getFQN() ~ (writeXML ? ".xml" : ".html")); - auto timeStr = Time.toString(); - mtable.insert("DATETIME", timeStr); - mtable.insert("YEAR", Time.year(timeStr)); + // Start semantic analysis. + auto pass1 = new SemanticPass1(mod, context); + pass1.start(); + + // Build destination file path. + auto destPath = new FilePath(destDirPath); + destPath.append(mod.getFQN() ~ (writeXML ? ".xml" : ".html")); + + if (verbose) + Stdout.formatln("{} > {}", mod.filePath, destPath); + + // Write the document file. + writeDocFile(destPath.toString(), mod, mtable); + } + } - DDocEmitter docEmitter; - if (writeXML) - docEmitter = new DDocXMLEmitter(mod, mtable, incUndoc, tokenHL); - else - docEmitter = new DDocEmitter(mod, mtable, incUndoc, tokenHL); - docEmitter.emit(); - // Set BODY macro to the text produced by the DDocEmitter. - mtable.insert("BODY", docEmitter.text); - // Do the macro expansion pass. - auto fileText = MacroExpander.expand(mtable, "$(DDOC)", mod.filePath, infoMan); -// fileText ~= "\n<pre>\n" ~ doc.text ~ "\n</pre>"; - // Finally write the file out to the harddisk. - auto file = new File(dest); - file.write(fileText); -} + void writeDocFile(string destPath, Module mod, MacroTable mtable) + { + // Create this module's own macro environment. + mtable = new MacroTable(mtable); + // Define runtime macros. + // MODPATH is an extension by dil. + mtable.insert("MODPATH", mod.getFQNPath() ~ "." ~ mod.fileExtension()); + mtable.insert("TITLE", mod.getFQN()); + mtable.insert("DOCFILENAME", mod.getFQN() ~ (writeXML ? ".xml" : ".html")); + auto timeStr = Time.toString(); + mtable.insert("DATETIME", timeStr); + mtable.insert("YEAR", Time.year(timeStr)); + + DDocEmitter docEmitter; + if (writeXML) + docEmitter = new DDocXMLEmitter(mod, mtable, includeUndocumented, tokenHL); + else + docEmitter = new DDocEmitter(mod, mtable, includeUndocumented, tokenHL); + docEmitter.emit(); -/// Loads a macro file. Converts any Unicode encoding to UTF-8. -string loadMacroFile(string filePath, InfoManager infoMan) -{ - auto src = new SourceText(filePath); - src.load(infoMan); - auto text = src.data[0..$-1]; // Exclude '\0'. - return sanitizeText(text); + // Set BODY macro to the text produced by the emitter. + mtable.insert("BODY", docEmitter.text); + // Do the macro expansion pass. + auto fileText = MacroExpander.expand(mtable, "$(DDOC)", + mod.filePath, + verbose ? infoMan : null); + // fileText ~= "\n<pre>\n" ~ doc.text ~ "\n</pre>"; + + // Finally write the file out to the harddisk. + scope file = new File(destPath); + file.write(fileText); + } + + /// Loads a macro file. Converts any Unicode encoding to UTF-8. + static string loadMacroFile(string filePath, InfoManager infoMan) + { + auto src = new SourceText(filePath); + src.load(infoMan); + auto text = src.data[0..$-1]; // Exclude '\0'. + return sanitizeText(text); + } } /// Traverses the syntax tree and writes DDoc macros to a string buffer. @@ -583,7 +589,7 @@ writeStructOrUnion(d); } - /// Writes an union declaration. + /// Writes a union declaration. void writeUnion(UnionDeclaration d) { writeStructOrUnion(d); }
--- a/src/cmd/DDocXML.d Sun Mar 09 00:12:19 2008 +0100 +++ b/src/cmd/DDocXML.d Sun Mar 09 15:28:24 2008 +0100 @@ -190,7 +190,7 @@ writeStructOrUnion(d); } - /// Writes an union declaration. + /// Writes a union declaration. void writeUnion(UnionDeclaration d) { writeStructOrUnion(d); }
--- a/src/main.d Sun Mar 09 00:12:19 2008 +0100 +++ b/src/main.d Sun Mar 09 15:28:24 2008 +0100 @@ -68,7 +68,7 @@ else filePaths ~= arg; } - infoMan = new InfoManager(); + foreach (filePath; filePaths) { auto mod = new Module(filePath, infoMan); @@ -104,34 +104,29 @@ if (args.length < 4) return printHelp("ddoc"); - auto destination = args[2]; - auto macroPaths = GlobalSettings.ddocFilePaths; - char[][] filePaths; - bool incUndoc; - bool writeXML; - bool verbose; + DDocCommand cmd; + cmd.destDirPath = args[2]; + cmd.macroPaths = GlobalSettings.ddocFilePaths; + cmd.context = newCompilationContext(); + cmd.infoMan = infoMan; + // Parse arguments. - auto context = newCompilationContext(); foreach (arg; args[3..$]) { - if (parseDebugOrVersion(arg, context)) + if (parseDebugOrVersion(arg, cmd.context)) {} else if (arg == "--xml") - writeXML = true; + cmd.writeXML = true; else if (arg == "-i") - incUndoc = true; + cmd.includeUndocumented = true; else if (arg == "-v") - verbose = true; + cmd.verbose = true; else if (arg.length > 5 && icompare(arg[$-4..$], "ddoc") == 0) - macroPaths ~= arg; + cmd.macroPaths ~= arg; else - filePaths ~= arg; + cmd.filePaths ~= arg; } - - infoMan = new InfoManager(); - // Execute command. - cmd.DDoc.execute(filePaths, destination, macroPaths, writeXML, - incUndoc, verbose, context, infoMan); + cmd.run(); infoMan.hasInfo && printErrors(infoMan); break; case "gen", "generate":