--- /dev/null
+#include "TscSyntax.hxx"
+
+// --- internal constants ---
+
+const QString preprocs("include");
+const QString structs("BUTTON DATACONTROLBOX EDITBOX FRAME HEADER_BOX LEFT LISTBOX SCROLLBAR TEXT TEXTBUTTON");
+const QString functions("Alpha Background ChangePage Color DataColumn DataFunctionColumn Document FunctionText "
+ "GetControlText GetEnv Image Layout LineHeight MaxBuffer OnAccess OnAccessError OnData OnLoad "
+ "OnMouse PlaySound Pos ReceiveDB RenderHeader Resource SelectionColumn ServerMessage Set "
+ "SetContent SetEnv SetFunctionContent Settings ShowLineNumbers Size SubImage Target UpdateDB "
+ "TryAccess Width");
+
+// --- constructors and deconstructors ---
+
+TscSyntax::TscSyntax(QObject *parent)
+: QSyntaxHighlighter(parent)
+{
+ setup();
+}
+
+TscSyntax::TscSyntax(QTextDocument *parent)
+: QSyntaxHighlighter(parent)
+{
+ setup();
+}
+
+TscSyntax::~TscSyntax()
+{
+}
+
+// --- protected methods ---
+
+void TscSyntax::highlightBlock(const QString& text)
+{
+ qint32 index = 0;
+
+ setCurrentBlockState(0);
+
+ // structs
+ index = text.indexOf(_structs_re);
+ while (index >= 0)
+ {
+ auto len = _structs_re.matchedLength();
+
+ setFormat(index, len, _structs_f);
+ index = text.indexOf(_structs_re, index + len);
+ }
+
+ // functions
+ index = text.indexOf(_functions_re);
+ while (index >= 0)
+ {
+ auto len = _functions_re.matchedLength();
+
+ setFormat(index, len, _functions_f);
+ index = text.indexOf(_functions_re, index + len);
+ }
+
+ // ints
+ index = text.indexOf(_ints_re);
+ while (index >= 0)
+ {
+ auto len = _ints_re.matchedLength();
+
+ setFormat(index, len, _ints_f);
+ index = text.indexOf(_ints_re, index + len);
+ }
+
+ // floats
+ index = text.indexOf(_floats_re);
+ while (index >= 0)
+ {
+ auto len = _floats_re.matchedLength();
+
+ setFormat(index, len, _floats_f);
+ index = text.indexOf(_floats_re, index + len);
+ }
+
+ // strings
+ index = text.indexOf(_strings_re);
+ while (index >= 0)
+ {
+ auto len = _strings_re.matchedLength();
+
+ setFormat(index, len, _strings_f);
+ index = text.indexOf(_strings_re, index + len);
+ }
+
+ // single line comments
+ index = text.indexOf(_comment_re);
+ if (index >= 0)
+ setFormat(index, _comment_re.matchedLength(), _comment_f);
+
+ // preprocessor
+ index = text.indexOf(_preprocs_re);
+ if (index >= 0)
+ setFormat(index, _preprocs_re.matchedLength(), _preprocs_f);
+}
+
+void TscSyntax::setup()
+{
+ QString pattern;
+
+ // format
+ _structs_f.setFontWeight(QFont::Bold);
+ _structs_f.setForeground(Qt::green);
+
+ _functions_f.setFontWeight(QFont::Bold);
+ _functions_f.setForeground(Qt::darkGreen);
+
+ _ints_f.setFontWeight(QFont::Bold);
+ _ints_f.setForeground(Qt::darkBlue);
+
+ _floats_f.setFontWeight(QFont::Bold);
+ _floats_f.setForeground(Qt::darkRed);
+
+ _strings_f.setFontItalic(true);
+ _strings_f.setForeground(Qt::darkYellow);
+
+ _comment_f.setFontItalic(true);
+ _comment_f.setForeground(Qt::darkGray);
+
+ _preprocs_f.setFontWeight(QFont::Bold);
+ _preprocs_f.setForeground(Qt::magenta);
+
+ // regexp
+ pattern.append("\\b(");
+ pattern.append(structs.split(" ").join("|"));
+ pattern.append(")\\b");
+ _structs_re.setPattern(pattern);
+
+ pattern.clear();
+ pattern.append("\\b(");
+ pattern.append(functions.split(" ").join("|"));
+ pattern.append(")\\b");
+ _functions_re.setPattern(pattern);
+
+ _ints_re.setPattern("\\b[0-9]+\\b");
+
+ _floats_re.setPattern("\\b[0-9]+\\.[0-9]+\\b");
+
+ _strings_re.setPattern("(\"[^\"]*)\"");
+
+ _comment_re.setPattern("//[^\n]*");
+
+ pattern.clear();
+ pattern.append("#(");
+ pattern.append(preprocs.split(" ").join("|"));
+ pattern.append(")[^\n]*");
+ _preprocs_re.setPattern(pattern);
+}