diff --git a/src/cmd/DDoc.d b/src/cmd/DDoc.d index 1a78b4d5..7eb9bae7 100644 --- a/src/cmd/DDoc.d +++ b/src/cmd/DDoc.d @@ -118,7 +118,7 @@ class DDocCommand : Command auto mod = new Module(filePath, context); // Only parse if the file is not a "Ddoc"-file. - if (!DDocEmitter.isDDocFile(mod)) + if (!mod.isDDocFile) { if (mm.moduleByPath(mod.filePath())) continue; // The same file path was already loaded. TODO: warning? @@ -139,8 +139,13 @@ class DDocCommand : Command auto pass1 = new SemanticPass1(mod, context); pass1.run(); } - else // Normally done in mod.parse(). + else + { + // Normally done in mod.parse(). mod.setFQN(Path(filePath).name()); + if (writeHLFiles) + writeSyntaxHighlightedFile(mod); + } // Write the documentation file. writeDocumentationFile(mod, mtable); diff --git a/src/dil/Highlighter.d b/src/dil/Highlighter.d index 3c887b76..913d68a3 100644 --- a/src/dil/Highlighter.d +++ b/src/dil/Highlighter.d @@ -108,13 +108,41 @@ class Highlighter void highlightSyntax(string filePath, bool printHTML, bool opt_printLines) { auto modul = new Module(filePath, cc); - modul.parse(); + if (!modul.isDDocFile) + modul.parse(); highlightSyntax(modul, printHTML, opt_printLines); } /// ditto void highlightSyntax(Module modul, bool printHTML, bool opt_printLines) { + if (modul.isDDocFile) + { + print.format(tags["DocHead"], modul.getFQN()); + + auto text = modul.sourceText.text; + + if (opt_printLines) + { + size_t lineCount; + foreach (dchar c; text) + { + if (c == '\n') + ++lineCount; + } + + print(tags["LineNumberBegin"]); + printLines(lineCount); + print(tags["LineNumberEnd"]); + } + + print(tags["SourceBegin"]); + print(text); + print(tags["SourceEnd"]); + print(tags["DocEnd"]); + return; + } + auto parser = modul.parser; auto lx = parser.lexer; auto builder = new TokenExBuilder(); diff --git a/src/dil/doc/DDocEmitter.d b/src/dil/doc/DDocEmitter.d index 05a49833..fbc5bfdd 100644 --- a/src/dil/doc/DDocEmitter.d +++ b/src/dil/doc/DDocEmitter.d @@ -25,7 +25,7 @@ import dil.Highlighter, dil.Enums; import common; -import tango.text.Ascii : toUpper, icompare; +import tango.text.Ascii : toUpper; /// Traverses the syntax tree and writes DDoc macros to a string buffer. abstract class DDocEmitter : DefaultVisitor2 @@ -65,7 +65,7 @@ abstract class DDocEmitter : DefaultVisitor2 /// Entry method. char[] emit() { - if (isDDocFile(modul)) + if (modul.isDDocFile) { // The module is actually a DDoc text file. auto c = DDocUtils.getDDocComment(getDDocText(modul)); foreach (s; c.sections) @@ -75,7 +75,7 @@ abstract class DDocEmitter : DefaultVisitor2 mtable.insert(ms.macroNames, ms.macroTexts); } else - write(s.wholeText); + write(scanCommentText(s.wholeText)); return text; } @@ -189,18 +189,6 @@ abstract class DDocEmitter : DefaultVisitor2 } } - /// Returns true if the source text starts with "Ddoc\n" (ignores letter case.) - static bool isDDocFile(Module mod) - { - auto data = mod.sourceText.data; - // 5 = "ddoc\n".length; +1 = trailing '\0' in data. - if (data.length >= 5 + 1 && // Check for minimum length. - icompare(data[0..4], "ddoc") == 0 && // Check first four characters. - isNewline(data.ptr + 4)) // Check for a newline. - return true; - return false; - } - /// Returns the DDoc text of this module. static char[] getDDocText(Module mod) { diff --git a/src/dil/semantic/Module.d b/src/dil/semantic/Module.d index 0ddcdd95..66b014a1 100644 --- a/src/dil/semantic/Module.d +++ b/src/dil/semantic/Module.d @@ -6,7 +6,8 @@ module dil.semantic.Module; import dil.ast.Node, dil.ast.Declarations; import dil.parser.Parser; -import dil.lexer.Lexer, +import dil.lexer.Funcs, + dil.lexer.Lexer, dil.lexer.IdTable; import dil.semantic.Symbol, dil.semantic.Symbols; @@ -20,6 +21,7 @@ import common; import tango.io.model.IFile, tango.io.device.File; +import tango.text.Ascii : icompare; import tango.text.Util; alias FileConst.PathSeparatorChar dirSep; @@ -197,4 +199,16 @@ class Module : ModuleSymbol FQNPath[i] = dirSep; return FQNPath; } + + /// Returns true if the source text starts with "Ddoc\n" (ignores letter case.) + bool isDDocFile() + { + auto data = this.sourceText.data; + // 5 = "ddoc\n".length; +1 = trailing '\0' in data. + if (data.length >= 5 + 1 && // Check for minimum length. + icompare(data[0..4], "ddoc") == 0 && // Check first four characters. + isNewline(data.ptr + 4)) // Check for a newline. + return true; + return false; + } }