forked from qt-creator/qt-creator
Highlight QML context types.
This commit is contained in:
@@ -90,6 +90,14 @@ void QScriptHighlighter::highlightBlock(const QString &text)
|
||||
setFormat(token.offset, token.length, m_formats[KeywordFormat]);
|
||||
break;
|
||||
|
||||
case Token::String:
|
||||
setFormat(token.offset, token.length, m_formats[StringFormat]);
|
||||
break;
|
||||
|
||||
case Token::Comment:
|
||||
setFormat(token.offset, token.length, m_formats[CommentFormat]);
|
||||
break;
|
||||
|
||||
case Token::LeftParenthesis:
|
||||
onOpeningParenthesis('(', token.offset);
|
||||
break;
|
||||
@@ -115,7 +123,9 @@ void QScriptHighlighter::highlightBlock(const QString &text)
|
||||
break;
|
||||
|
||||
case Token::Identifier: {
|
||||
if (m_duiEnabled && maybeQmlKeyword(text.midRef(token.offset, token.length))) {
|
||||
const QStringRef spell = text.midRef(token.offset, token.length);
|
||||
|
||||
if (m_duiEnabled && maybeQmlKeyword(spell)) {
|
||||
// check the previous token
|
||||
if (index == 0 || tokens.at(index - 1).isNot(Token::Dot)) {
|
||||
if (index + 1 == tokens.size() || tokens.at(index + 1).isNot(Token::Colon)) {
|
||||
@@ -123,6 +133,13 @@ void QScriptHighlighter::highlightBlock(const QString &text)
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (m_duiEnabled && index > 0 && maybeQmlBuiltinType(spell)) {
|
||||
const Token &previousToken = tokens.at(index - 1);
|
||||
if (previousToken.is(Token::Identifier) && text.at(previousToken.offset) == QLatin1Char('p')
|
||||
&& text.midRef(previousToken.offset, previousToken.length) == QLatin1String("property")) {
|
||||
setFormat(token.offset, token.length, m_formats[KeywordFormat]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (index + 1 < tokens.size()) {
|
||||
@@ -247,3 +264,35 @@ bool QScriptHighlighter::maybeQmlKeyword(const QStringRef &text) const
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool QScriptHighlighter::maybeQmlBuiltinType(const QStringRef &text) const
|
||||
{
|
||||
if (text.isEmpty())
|
||||
return false;
|
||||
|
||||
const QChar ch = text.at(0);
|
||||
|
||||
if (ch == QLatin1Char('i') && text == QLatin1String("int")) {
|
||||
return true;
|
||||
} else if (ch == QLatin1Char('b') && text == QLatin1String("bool")) {
|
||||
return true;
|
||||
} else if (ch == QLatin1Char('d') && text == QLatin1String("double")) {
|
||||
return true;
|
||||
} else if (ch == QLatin1Char('r') && text == QLatin1String("real")) {
|
||||
return true;
|
||||
} else if (ch == QLatin1Char('s') && text == QLatin1String("string")) {
|
||||
return true;
|
||||
} else if (ch == QLatin1Char('u') && text == QLatin1String("url")) {
|
||||
return true;
|
||||
} else if (ch == QLatin1Char('c') && text == QLatin1String("color")) {
|
||||
return true;
|
||||
} else if (ch == QLatin1Char('d') && text == QLatin1String("date")) {
|
||||
return true;
|
||||
} else if (ch == QLatin1Char('v') && text == QLatin1String("var")) {
|
||||
return true;
|
||||
} else if (ch == QLatin1Char('v') && text == QLatin1String("variant")) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ protected:
|
||||
virtual void onClosingParenthesis(QChar parenthesis, int pos);
|
||||
|
||||
bool maybeQmlKeyword(const QStringRef &text) const;
|
||||
bool maybeQmlBuiltinType(const QStringRef &text) const;
|
||||
|
||||
protected:
|
||||
QmlJSScanner m_scanner;
|
||||
|
||||
Reference in New Issue
Block a user