Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/cmd/DDoc.d
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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);
Expand Down
30 changes: 29 additions & 1 deletion src/dil/Highlighter.d
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
18 changes: 3 additions & 15 deletions src/dil/doc/DDocEmitter.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -75,7 +75,7 @@ abstract class DDocEmitter : DefaultVisitor2
mtable.insert(ms.macroNames, ms.macroTexts);
}
else
write(s.wholeText);
write(scanCommentText(s.wholeText));
return text;
}

Expand Down Expand Up @@ -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)
{
Expand Down
16 changes: 15 additions & 1 deletion src/dil/semantic/Module.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}