// Copyright Brian Schott (Sir Alaran) 2012. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) module highlighter; import std.stdio; import std.array; import std.d.lexer; void writeSpan(string cssClass, string value) { stdout.write(``, value.replace("&", "&").replace("<", "<"), ``); } // http://ethanschoonover.com/solarized void highlight(R)(R tokens) { stdout.writeln(q"[
]");
foreach (Token t; tokens)
{
if (isType(t.type))
writeSpan("type", t.value);
else if (isKeyword(t.type))
writeSpan("kwrd", t.value);
else if (t.type == TokenType.Comment)
writeSpan("com", t.value);
else if (isStringLiteral(t.type))
writeSpan("str", t.value);
else if (isNumberLiteral(t.type))
writeSpan("num", t.value);
else if (isOperator(t.type))
writeSpan("op", t.value);
else
stdout.write(t.value.replace("<", "<"));
}
stdout.writeln("\n");
}