// 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 langutils; import std.array; void writeSpan(string cssClass, string value) { stdout.write(``, value.replace("<", "<"), ``); } void highlight(Token[] tokens) { stdout.writeln(q"[
]");

	foreach (Token t; tokens)
	{
		switch (t.type)
		{
		case TokenType.KEYWORDS_BEGIN: .. case TokenType.KEYWORDS_END:
			writeSpan("keyword", t.value);
			break;
		case TokenType.TYPES_BEGIN: .. case TokenType.TYPES_END:
			writeSpan("type", t.value);
			break;
		case TokenType.comment:
			writeSpan("comment", t.value);
			break;
		case TokenType.stringLiteral:
			writeSpan("string", t.value);
			break;
		case TokenType.numberLiteral:
			writeSpan("number", t.value);
			break;
		case TokenType.OPERATORS_BEGIN: .. case TokenType.OPERATORS_END:
			writeSpan("operator", t.value);
			break;
		case TokenType.PROPERTIES_BEGIN: .. case TokenType.PROPERTIES_END:
			writeSpan("property", t.value);
			break;
		default:
			stdout.write(t.value.replace("<", "<"));
			break;
		}
	}
	stdout.writeln("
\n"); }