SynLight - Lua Syntax Highlighting

http://henrys-hub.googlecode.com/svn/trunk/synlight/synlight.lua
( place this in: lua/includes/module/synlight.lua of your addon folder )

This module was designed to be easy to use and optimized for syntax highlighting.
It isn’t really used to parse Lua, since it jumbles up words of the same colors together.

The highlighting is practically done, now all that’s left is for the database of words, enums, and libraries to be put in.

I made the top area of the module to be easily customized in case you wanted to add any of your own defines.

The only function you really need to know from the module is:
[lua]synlight.parse( str )[/lua]
Str being the big string of lua that you want to parse.
It will return a table containing a chunk of code and what type the chunk is defined as.

To better understand it, check out this example:
[lua]
require “synlight”

if g_MultiLine then
	g_MultiLine:Remove()
end
g_MultiLine = vgui.Create( "DTextEntry" )
g_MultiLine:MakePopup()
g_MultiLine:Center()
g_MultiLine:SetSize( 500, 100)
g_MultiLine:SetMultiline( true )

function PAINTFUNC()
	surface.SetDrawColor( Color( 0,0,0,255 ) )
	surface.DrawRect( 0, 0, ScrW(), ScrH() )
	local str = g_MultiLine:GetValue()
	local final = synlight.parse( str )
	local line = 1
	local x = 0
	for k,chunk_data in pairs( final ) do
		if chunk_data[2] == CHUNK_SPECIALWORD then
			draw.SimpleText( chunk_data[1], "ConsoleText", x, line*15, Color( 0,89,223,255 ), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
		elseif chunk_data[2] == CHUNK_OPERATOR then
			draw.SimpleText( chunk_data[1], "ConsoleText", x, line*15, Color( 255,0,128,255 ), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
		elseif chunk_data[2] == CHUNK_COMMENT then
			draw.SimpleText( chunk_data[1], "ConsoleText", x, line*15, Color( 58,208,15,255 ), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
		elseif chunk_data[2] == CHUNK_NUMBER then
			draw.SimpleText( chunk_data[1], "ConsoleText", x, line*15, Color( 204,149,19,255 ), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
		elseif chunk_data[2] == CHUNK_GLOBALVARIABLES or chunk_data[2] == CHUNK_BRACKET then
			draw.SimpleText( chunk_data[1], "ConsoleText", x, line*15, Color( 200,23,165,255 ), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
		elseif chunk_data[2] == CHUNK_STRING then
			draw.SimpleText( chunk_data[1], "ConsoleText", x, line*15, Color( 222,230,89,255 ), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
		elseif chunk_data[2] == CHUNK_LIBRARY then
			draw.SimpleText( chunk_data[1], "ConsoleText", x, line*15, Color( 104,21,242,255 ), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
		elseif chunk_data[2] == CHUNK_HOOK then
			draw.SimpleText( chunk_data[1], "ConsoleText", x, line*15, Color( 128,255,0,255 ), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
		elseif chunk_data[2] == CHUNK_CLASSFUNCTION then
			draw.SimpleText( chunk_data[1], "ConsoleText", x, line*15, Color( 86,209,231,255 ), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
		else
			draw.SimpleText( chunk_data[1], "ConsoleText", x, line*15, Color( 255,255,255,255 ), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP )
		end
		local w, h = surface.GetTextSize( chunk_data[1] )
		if chunk_data[2] == CHUNK_NEWLINE then
			line = line + string.len(chunk_data[1]) * 1
			x = 0
		elseif chunk_data[2] == CHUNK_WHITESPACE then
			x = x + string.len(chunk_data[1]) * 50
		else
			x = x + w
		end
	end
end
hook.Add( "HUDPaint", "T_T", PAINTFUNC )

[/lua]

Which outputs: