diff --git a/jsedit.cpp b/jsedit.cpp index aff5f81..05978ad 100644 --- a/jsedit.cpp +++ b/jsedit.cpp @@ -54,6 +54,7 @@ protected: private: QSet m_keywords; QSet m_knownIds; + QSet m_customIds; QHash m_colors; QString m_markString; Qt::CaseSensitivity m_markCaseSensitivity; @@ -73,6 +74,7 @@ JSHighlighter::JSHighlighter(QTextDocument *parent) m_colors[JSEdit::Keyword] = QColor("#000080"); m_colors[JSEdit::BuiltIn] = QColor("#008080"); m_colors[JSEdit::Marker] = QColor("#ffff00"); + m_colors[JSEdit::Custom] = QColor("#ff00ff"); // https://developer.mozilla.org/en/JavaScript/Reference/Reserved_Words m_keywords << "break"; @@ -248,6 +250,27 @@ JSHighlighter::JSHighlighter(QTextDocument *parent) m_knownIds << "window"; m_knownIds << "navigator"; m_knownIds << "userAgent"; + + //Custom objects + m_customIds << "host"; + m_customIds << "can"; + m_customIds << "isotp"; + m_customIds << "uds"; + //Custom callback functions + m_customIds << "setup"; + m_customIds << "tick"; + m_customIds << "gotCANFrame"; + m_customIds << "gotISOTPMessage"; + m_customIds << "gotUDSMessage"; + //Custom functions + m_customIds << "setTickInterval"; + m_customIds << "log"; //Duplicate + m_customIds << "addParameter"; + m_customIds << "setFilter"; + m_customIds << "clearFilters"; + m_customIds << "sendFrame"; + m_customIds << "sendISOTP"; + m_customIds << "sendUDS"; } void JSHighlighter::setColor(JSEdit::ColorComponent component, const QColor &color) @@ -269,6 +292,7 @@ void JSHighlighter::highlightBlock(const QString &text) }; QList bracketPositions; + QString previousToken; int blockState = previousBlockState(); int bracketLevel = blockState >> 4; @@ -336,10 +360,17 @@ void JSHighlighter::highlightBlock(const QString &text) case Identifier: if (ch.isSpace() || !(ch.isDigit() || ch.isLetter() || ch == '_')) { QString token = text.mid(start, i - start).trimmed(); - if (m_keywords.contains(token)) + if (m_customIds.contains(token) && m_customIds.contains(previousToken)) { + setFormat(start, i - start, m_colors[JSEdit::Custom]); + } else if (m_keywords.contains(token)) { setFormat(start, i - start, m_colors[JSEdit::Keyword]); - else if (m_knownIds.contains(token)) + } else if (m_knownIds.contains(token)) { setFormat(start, i - start, m_colors[JSEdit::BuiltIn]); + if (ch == '.') previousToken = token; + } else if (m_customIds.contains(token)) { + setFormat(start, i - start, m_colors[JSEdit::Custom]); + if (ch == '.') previousToken = token; + } state = Start; } else { ++i;