I thought it was time to get serious about writing my syntax highlighting control, so I have finally made a proper start! So far all I have done is highlight the text when a file is loaded and I will be working on the re-colouring as text is typed in the coming weeks. Of course I am using lexertl for the lexing (the whole point of the project really) and I am sticking to C++ syntax highlighting (as in VC++ 6) for the moment, although I will provide a framework for using whatever lex spec you like.
So far the C++ lex spec looks like this:
try
{
lexertl::basic_rules Rules;
Rules.add_state (_T("MESSAGE_MAP"));
Rules.add (_T("INITIAL"), _T("//\\{\\{AFX[^/\r]*"),
RGB (0, 128, 0), _T("MESSAGE_MAP"));
Rules.add (_T("MESSAGE_MAP"), _T("//}}AFX[^/\r]*"),
RGB (0, 128, 0), _T("INITIAL"));
Rules.add (_T("MESSAGE_MAP"), _T("[^/]+|/"), RGB(128, 128, 128), _T("."));
Rules.add (_T("asm|auto|bool|false|true|break|case|catch|char|class|")
_T("const|const_cast|continue|default|delete|do|double|dynamic_cast|")
_T("else|enum|explicit|export|extern|float|for|friend|goto|if|inline|")
_T("int|long|mutable|namespace|new|operator|private|protected|public|")
_T("register|reinterpret_cast|return|short|signed|sizeof|static|")
_T("static_cast|struct|switch|template|this|throw|try|typedef|typeid|")
_T("typename|union|unsigned|using|virtual|void|wchar_t|while|#define|")
_T("#if|#ifdef|#ifndef|#else|#elif|#endif|#error|#include|#line|")
_T("#pragma|#undef|#warning|TRUE|FALSE"),
RGB (0, 0, 255));
Rules.add (_T("\\\"[^\"]*\\\""), RGB (0, 0, 1));
Rules.add (_T("[a-zA-Z_][a-zA-Z0-9_]*"), RGB (0, 0, 1));
Rules.add (_T("*"), _T("//.*?\r\n|/\\*.*?\\*/"), RGB (0, 128, 0), _T("."));
lexertl::basic_generator::build (Rules, m_sm);
}
catch (const std::exception &e)
{
AfxMessageBox (e.what ());
}
I will use proper
ids for the tokens and have a lookup array of RGB values as 0
and npos are already reserved by lexertl.
More updates soon...