Mercurial > projects > dil
changeset 456:de2675bc9afa
Dependency lists, minor cleanup.
author | Jari-Matti M?kel? <jmjm@iki.fi> |
---|---|
date | Tue, 30 Oct 2007 02:35:56 +0200 |
parents | f92505ad18ab |
children | 33a4cb255fcc |
files | trunk/src/docgen/docgen.d trunk/src/docgen/document/htmlwriter.d trunk/src/docgen/document/latexwriter.d trunk/src/docgen/document/plaintextwriter.d trunk/src/docgen/document/writer.d trunk/src/docgen/document/xmlwriter.d trunk/src/docgen/graphutils/modulenamewriter.d trunk/src/docgen/graphutils/modulepathwriter.d trunk/src/docgen/modulegraph/writer.d |
diffstat | 9 files changed, 232 insertions(+), 160 deletions(-) [+] |
line wrap: on
line diff
--- a/trunk/src/docgen/docgen.d Mon Oct 29 21:27:02 2007 +0200 +++ b/trunk/src/docgen/docgen.d Tue Oct 30 02:35:56 2007 +0200 @@ -15,7 +15,8 @@ import tango.text.Ascii; import tango.text.Util : replace; import tango.io.FilePath; -debug import tango.io.Stdout; + +import tango.io.Stdout; template DefaultDocGenerator(char[] genDir) { abstract class DefaultDocGenerator : DocGenerator { @@ -37,7 +38,7 @@ // TODO: constructor for situations where parsing has happened elsewhere - char[] outPath(char[] file) { + protected char[] outPath(char[] file) { return options.outputDir ~ "/" ~ genDir ~ "/" ~ file; } @@ -91,6 +92,25 @@ } } +class HTMLDocGenerator : DefaultDocGenerator!("html") { + this(DocGeneratorOptions options) { + super(options); + } + public void generate() { /* TODO */ } +} +class XMLDocGenerator : DefaultDocGenerator!("xml") { + this(DocGeneratorOptions options) { + super(options); + } + public void generate() { /* TODO */ } +} +class PlainTextDocGenerator : DefaultDocGenerator!("txt") { + this(DocGeneratorOptions options) { + super(options); + } + public void generate() { /* TODO */ } +} + /** * Main routine for LaTeX doc generation. */ @@ -214,15 +234,53 @@ } } +void usage() { + Stdout( + "Usage: docgen rootpath importpath_1 ... importpath_n outputdir" + ).newline; +} + void main(char[][] args) { + Stdout(docgen_version).newline.newline; + + if (args.length<3) { + usage(); + return; + } + Configurator config = new DefaultConfigurator(); auto options = config.getConfiguration(); options.parser.rootPaths = [ args[1] ]; - options.parser.importPaths = [ args[2] ]; - options.outputDir = args[3]; + options.parser.importPaths = args[2..$-1]; + options.outputDir = args[$-1]; - auto generator = new LaTeXDocGenerator(*options); - - generator.generate(); + foreach(format; options.outputFormats) { + switch(format) { + case DocFormat.LaTeX: + auto generator = new LaTeXDocGenerator(*options); + Stdout("Generating LaTeX docs.."); + generator.generate(); + Stdout("done.").newline; + break; + case DocFormat.HTML: + auto generator = new HTMLDocGenerator(*options); + Stdout("Generating HTML docs.."); + generator.generate(); + Stdout("done.").newline; + break; + case DocFormat.XML: + auto generator = new XMLDocGenerator(*options); + Stdout("Generating XML docs.."); + generator.generate(); + Stdout("done.").newline; + break; + case DocFormat.PlainText: + auto generator = new PlainTextDocGenerator(*options); + Stdout("Generating plain text docs.."); + generator.generate(); + Stdout("done.").newline; + break; + } + } }
--- a/trunk/src/docgen/document/htmlwriter.d Mon Oct 29 21:27:02 2007 +0200 +++ b/trunk/src/docgen/document/htmlwriter.d Tue Oct 30 02:35:56 2007 +0200 @@ -5,9 +5,8 @@ module docgen.document.htmlwriter; import docgen.document.writer; +import docgen.misc.textutils; import tango.io.FileConduit : FileConduit; -import tango.io.Print: Print; -import tango.text.convert.Layout : Layout; // TODO: this is mostly broken now @@ -21,29 +20,21 @@ void generateTOC(Module[] modules) { // TODO - auto print = new Print!(char)(new Layout!(char), outputs[0]); - print.format(templates["toc"]); } void generateModuleSection() { // TODO - auto print = new Print!(char)(new Layout!(char), outputs[0]); - print.format(templates["modules"]); } void generateListingSection() { // TODO - auto print = new Print!(char)(new Layout!(char), outputs[0]); - print.format(templates["listings"]); } void generateDepGraphSection() { // TODO - auto print = new Print!(char)(new Layout!(char), outputs[0]); - print.format(templates["dependencies"]); } @@ -52,9 +43,7 @@ void generateLastPage() { } void generateFirstPage() { - auto output = new Print!(char)(new Layout!(char), outputs[0]); - - output.format( + print.format( templates["firstpage"], factory.options.templates.title, factory.options.templates.copyright, @@ -62,4 +51,14 @@ docgen_version ); } + + void addList(char[][] contents, bool ordered) { + foreach(item; contents) { + switch(item) { + case "(": print(ordered ? "<ol>" : "<ul>"); continue; + case ")": print(ordered ? "</ol>" : "</ul>"); continue; + default: print("<li>")(xml_escape(item))("</li>"); + } + } + } }
--- a/trunk/src/docgen/document/latexwriter.d Mon Oct 29 21:27:02 2007 +0200 +++ b/trunk/src/docgen/document/latexwriter.d Tue Oct 30 02:35:56 2007 +0200 @@ -6,8 +6,6 @@ import docgen.document.writer; import tango.io.FileConduit : FileConduit; -import tango.io.Print: Print; -import tango.text.convert.Layout : Layout; /** * Writes a LaTeX document skeleton. @@ -18,8 +16,6 @@ } void generateFirstPage() { - auto print = new Print!(char)(new Layout!(char), outputs[0]); - print.format( templates["firstpage"], factory.options.templates.paperSize, @@ -30,4 +26,14 @@ factory.options.listing.literateStyle ? "" : "%" ); } + + void addList(char[][] contents, bool ordered) { + foreach(item; contents) { + switch(item) { + case "(": print(ordered ? "\\begin{enumerate}" : "\\begin{itemize}"); continue; + case ")": print(ordered ? "\\end{enumerate}" : "\\end{itemize}"); continue; + default: print("\\item")(item)(\n); + } + } + } }
--- a/trunk/src/docgen/document/plaintextwriter.d Mon Oct 29 21:27:02 2007 +0200 +++ b/trunk/src/docgen/document/plaintextwriter.d Tue Oct 30 02:35:56 2007 +0200 @@ -7,8 +7,6 @@ import docgen.document.writer; import docgen.misc.textutils; import tango.io.FileConduit : FileConduit; -import tango.io.Print: Print; -import tango.text.convert.Layout : Layout; //TODO: this is mostly broken now @@ -22,29 +20,21 @@ void generateTOC(Module[] modules) { // TODO - auto print = new Print!(char)(new Layout!(char), outputs[0]); - print.format(templates["toc"]); } void generateModuleSection() { // TODO - auto print = new Print!(char)(new Layout!(char), outputs[0]); - print.format(templates["modules"]); } void generateListingSection() { // TODO - auto print = new Print!(char)(new Layout!(char), outputs[0]); - print.format(templates["listings"]); } void generateDepGraphSection() { // TODO - auto print = new Print!(char)(new Layout!(char), outputs[0]); - print.format(templates["dependencies"]); } @@ -53,9 +43,7 @@ void generateLastPage() { } void generateFirstPage() { - auto output = new Print!(char)(new Layout!(char), outputs[0]); - - output( + print( plainTextHeading(factory.options.templates.title ~ " Reference Manual") ~ factory.options.templates.versionString ~ \n ~ "Generated by " ~ docgen_version ~ \n ~ @@ -67,4 +55,22 @@ plainTextHeading("Dependency diagram") ~ \n ); } + + void addList(char[][] contents, bool ordered) { + uint[] counters; + foreach(item; contents) { + switch(item) { + case "(": counters ~= 1; continue; + case ")": counters.length = counters.length - 1; continue; + default: + if (counters.length>0) + for (int i=0; i <= counters.length; i++) + print(" "); + if (ordered) + print(++counters[$-1])(". ")(item)(\n); + else + print("* ")(item)(\n); + } + } + } }
--- a/trunk/src/docgen/document/writer.d Mon Oct 29 21:27:02 2007 +0200 +++ b/trunk/src/docgen/document/writer.d Tue Oct 30 02:35:56 2007 +0200 @@ -15,6 +15,95 @@ import tango.text.convert.Layout : Layout; public import docgen.misc.parser; +const templateDir = "docgen/templates/"; + +// template file names +const templateNames = [ + "firstpage"[], "toc"[], "modules"[], + "listings"[], "dependencies"[], "index"[], + "lastpage"[], "langdef"[], "makefile"[], + "graphics"[], "listing"[] +]; + +/** + * Writes the logical subcomponents of a document, + * e.g. sections, embedded graphics, lists + */ +interface DocumentWriter { + /** + * Updates the outputstreams. + */ + void setOutput(OutputStream[] outputs); + + /** + * Generates the first page(s). + */ + void generateFirstPage(); + + /** + * Generates table of contents. + */ + void generateTOC(Module[] modules); + + /** + * Generates module documentation section. + */ + void generateModuleSection(); + + /** + * Generates source code listing section. + */ + void generateListingSection(); + + /** + * Generates dependency graph section. + */ + void generateDepGraphSection(); + + /** + * Generates an index section. + */ + void generateIndexSection(); + + /** + * Generates the last page(s). + */ + void generateLastPage(); + + /** + * Generates a language definition file [LaTeX]. + * Could be used for DTD too, I suppose. + */ + void generateLangDef(); + + /** + * Generates a makefile used for document post-processing. + */ + void generateMakeFile(); + + // --- page components + // + /* + * Adds an external graphics file. + */ + void addGraphics(char[] imageFile); + + /** + * Adds a source code listing. + */ + void addListing(char[] moduleName, char[] contents, bool inline = true); + + /** + * Adds a list of items. + */ + void addList(char[][] contents, bool ordered); +} + +interface DocumentWriterFactory : WriterFactory { + DocumentWriter createDocumentWriter(OutputStream[] outputs, DocFormat outputFormat); +} + + char[] timeNow() { auto date = Clock.toDate; auto sprint = new Sprint!(char); @@ -26,7 +115,7 @@ } char[] loadTemplate(char[] style, char[] format, char[] templateName) { - char[] fn = "docgen/templates/"~style~"/"~format~"/"~templateName~".tpl"; + char[] fn = templateDir~style~"/"~format~"/"~templateName~".tpl"; scope(failure) { Stderr("Warning: error opening template "~fn~"."); @@ -44,55 +133,14 @@ return content; } -const templateNames = [ - "firstpage"[], "toc"[], "modules"[], - "listings"[], "dependencies"[], "index"[], - "lastpage"[], "langdef"[], "makefile"[], - "graphics"[], "listing"[] -]; - -interface DocumentWriter { - void setOutput(OutputStream[] outputs); - - void generateFirstPage(); - - void generateTOC(Module[] modules); - - void generateModuleSection(); - - void generateListingSection(); - - void generateDepGraphSection(); - - void generateIndexSection(); - - void generateLastPage(); - - void generateLangDef(); - - void generateMakeFile(); - - /** - * Writes a tag for the given image to the output stream - */ - void addGraphics(char[] imageFile); - - /** - * Writes a tag for the given source listing to the output stream; - */ - void addListing(char[] moduleName, char[] contents, bool inline = true); -} - -interface DocumentWriterFactory : WriterFactory { - DocumentWriter createDocumentWriter(OutputStream[] outputs, DocFormat outputFormat); -} - template AbstractDocumentWriter(int n, char[] format) { abstract class AbstractDocumentWriter : AbstractWriter!(DocumentWriterFactory, n), DocumentWriter { protected char[][char[]] templates; + protected Print!(char) print; this(DocumentWriterFactory factory, OutputStream[] outputs) { super(factory, outputs); + setOutput(outputs); foreach(tpl; templateNames) { templates[tpl] = loadTemplate(factory.options.templates.templateStyle, format, tpl); @@ -101,67 +149,48 @@ void setOutput(OutputStream[] outputs) { this.outputs = outputs; + + print = new Print!(char)(new Layout!(char), outputs[0]); } void generateTOC(Module[] modules) { - auto print = new Print!(char)(new Layout!(char), outputs[0]); - print.format(templates["toc"]); } void generateModuleSection() { - auto print = new Print!(char)(new Layout!(char), outputs[0]); - print.format(templates["modules"]); } void generateListingSection() { - auto print = new Print!(char)(new Layout!(char), outputs[0]); - print.format(templates["listings"]); } void generateDepGraphSection() { - auto print = new Print!(char)(new Layout!(char), outputs[0]); - print.format(templates["dependencies"]); } void generateIndexSection() { - auto print = new Print!(char)(new Layout!(char), outputs[0]); - print.format(templates["index"]); } void generateLastPage() { - auto print = new Print!(char)(new Layout!(char), outputs[0]); - print.format(templates["lastpage"]); } void generateLangDef() { - auto print = new Print!(char)(new Layout!(char), outputs[0]); - print(templates["langdef"]); } void generateMakeFile() { - auto print = new Print!(char)(new Layout!(char), outputs[0]); - print(templates["makefile"]); } - // --- page components void addGraphics(char[] imageFile) { - auto print = new Print!(char)(new Layout!(char), outputs[0]); - print.format(templates["graphics"], imageFile); } void addListing(char[] moduleName, char[] contents, bool inline) { - auto print = new Print!(char)(new Layout!(char), outputs[0]); - print.format(templates["listing"], moduleName, contents); } }
--- a/trunk/src/docgen/document/xmlwriter.d Mon Oct 29 21:27:02 2007 +0200 +++ b/trunk/src/docgen/document/xmlwriter.d Tue Oct 30 02:35:56 2007 +0200 @@ -5,9 +5,8 @@ module docgen.document.xmlwriter; import docgen.document.writer; +import docgen.misc.textutils; import tango.io.FileConduit : FileConduit; -import tango.io.Print: Print; -import tango.text.convert.Layout : Layout; //TODO: this is mostly broken now @@ -21,29 +20,21 @@ void generateTOC(Module[] modules) { // TODO - auto print = new Print!(char)(new Layout!(char), outputs[0]); - print.format(templates["toc"]); } void generateModuleSection() { // TODO - auto print = new Print!(char)(new Layout!(char), outputs[0]); - print.format(templates["modules"]); } void generateListingSection() { // TODO - auto print = new Print!(char)(new Layout!(char), outputs[0]); - print.format(templates["listings"]); } void generateDepGraphSection() { // TODO - auto print = new Print!(char)(new Layout!(char), outputs[0]); - print.format(templates["dependencies"]); } @@ -52,4 +43,14 @@ void generateLastPage() { } void generateFirstPage() { } + + void addList(char[][] contents, bool ordered) { + foreach(item; contents) { + switch(item) { + case "(": print(ordered ? "<ol>" : "<ul>"); continue; + case ")": print(ordered ? "</ol>" : "</ul>"); continue; + default: print("<li>")(xml_escape(item))("</li>"); + } + } + } }
--- a/trunk/src/docgen/graphutils/modulenamewriter.d Mon Oct 29 21:27:02 2007 +0200 +++ b/trunk/src/docgen/graphutils/modulenamewriter.d Tue Oct 30 02:35:56 2007 +0200 @@ -14,17 +14,24 @@ } void generateDepGraph(Vertex[] vertices, Edge[] edges, OutputStream imageFile) { + char[][] contents; - void doList(Vertex[] v, uint level, char[] indent = "") { + void doList(Vertex[] v, uint level) { if (!level) return; + contents ~= "("; + foreach (vertex; v) { - // TODO: output(indent)(vertex.name).newline; + contents ~= vertex.name; if (vertex.outgoing.length) - doList(vertex.outgoing, level-1, indent ~ " "); + doList(vertex.outgoing, level-1); } + + contents ~= ")"; } doList(vertices, factory.options.graph.depth); + + writer.addList(contents, false); } }
--- a/trunk/src/docgen/graphutils/modulepathwriter.d Mon Oct 29 21:27:02 2007 +0200 +++ b/trunk/src/docgen/graphutils/modulepathwriter.d Tue Oct 30 02:35:56 2007 +0200 @@ -14,17 +14,24 @@ } void generateDepGraph(Vertex[] vertices, Edge[] edges, OutputStream imageFile) { + char[][] contents; - void doPaths(Vertex[] v, uint level, char[] indent = "") { + void doList(Vertex[] v, uint level) { if (!level) return; + contents ~= "("; + foreach (vertex; v) { - // TODO: output(indent)(vertex.location).newline; + contents ~= vertex.location; if (vertex.outgoing.length) - doPaths(vertex.outgoing, level-1, indent ~ " "); + doList(vertex.outgoing, level-1); } + + contents ~= ")"; } - doPaths(vertices, factory.options.graph.depth); + doList(vertices, factory.options.graph.depth); + + writer.addList(contents, false); } }
--- a/trunk/src/docgen/modulegraph/writer.d Mon Oct 29 21:27:02 2007 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -/** - * Author: Aziz Köksal & Jari-Matti Mäkelä - * License: GPL3 - */ -module docgen.modulegraph.writer; - -import docgen.graphutils.writers; - -import dil.Parser; -import dil.Module; -import dil.Settings; -import tango.text.Regex : RegExp = Regex; -import tango.io.FilePath; -import tango.io.FileConst; -import tango.text.Util; -import common; - -alias FileConst.PathSeparatorChar dirSep; -/+ -class ModuleGraphGenerator { - - /** - * TODO - */ - static void generateGraph(GraphOptions *options) { - auto gwf = new DefaultGraphWriterFactory(*options); - - auto writer = gwf.createGraphWriter([Stdout.stream]); - - Edge[] edges; - Vertex[] vertices; - /* - loadModules(null, null, null, - gwf.options.IncludeUnlocatableModules, - vertices, edges); - - writer(vertices, edges); - */ - } -} -+/