Commit 496cfdd2 authored by Anton Kalmykov's avatar Anton Kalmykov Committed by Nikolai Kosjar

Add syntax highlight for primitive data types

Syntax highlight rules for keywords are changed to highlight control
keywords and primitive data types separately.

Change-Id: Ifb25be7a97b92589030aa190641320c233dc7f2d
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 2982a763
......@@ -16,6 +16,7 @@
<style name="Field"/>
<style name="Function"/>
<style name="Keyword" foreground="#ffff55"/>
<style name="PrimitiveType" foreground="#ffff55"/>
<style name="Label" foreground="#ffff55"/>
<style name="LineNumber" foreground="#888888" background="#232323"/>
<style name="Link" foreground="#0055ff"/>
......
......@@ -16,6 +16,7 @@
<style name="Field"/>
<style name="Function"/>
<style name="Keyword" bold="true"/>
<style name="PrimitiveType" bold="true"/>
<style name="Label"/>
<style name="LineNumber" foreground="#c7c4c1" background="#efebe7"/>
<style name="Link" foreground="#0000ff"/>
......
......@@ -21,6 +21,7 @@
<style name="Field" bold="true"/>
<style name="Function"/>
<style name="Keyword" foreground="#808bed"/>
<style name="PrimitiveType" foreground="#808bed"/>
<style name="Label" foreground="#e76000"/>
<style name="LineNumber" foreground="#8b8bcd" background="#2e2e2e"/>
<style name="Link" foreground="#409090"/>
......
......@@ -10,6 +10,7 @@
<style name="Field" foreground="#660e7a" bold="true"/>
<style name="Function" foreground="#000000"/>
<style name="Keyword" foreground="#000080" bold="true"/>
<style name="PrimitiveType" foreground="#000080" bold="true"/>
<style name="Label" foreground="#800000" bold="true"/>
<style name="Local" foreground="#000000"/>
<style name="Number" foreground="#0000ff"/>
......
......@@ -46,21 +46,20 @@ const char *token_names[] = {
("|="), ("||"), ("+"), ("+="), ("++"), ("#"), ("##"), ("?"), ("}"),
("]"), (")"), (";"), ("*"), ("*="), ("~"), ("~="),
("alignas"), ("alignof"), ("asm"), ("auto"), ("bool"), ("break"), ("case"), ("catch"),
("char"), ("char16_t"), ("char32_t"),
("alignas"), ("alignof"), ("asm"), ("auto"), ("break"), ("case"), ("catch"),
("class"), ("const"), ("const_cast"), ("constexpr"), ("continue"),
("decltype"), ("default"),
("delete"), ("do"), ("double"), ("dynamic_cast"), ("else"), ("enum"),
("explicit"), ("export"), ("extern"), ("false"), ("float"), ("for"),
("friend"), ("goto"), ("if"), ("inline"), ("int"), ("long"),
("delete"), ("do"), ("dynamic_cast"), ("else"), ("enum"),
("explicit"), ("export"), ("extern"), ("false"), ("for"),
("friend"), ("goto"), ("if"), ("inline"),
("mutable"), ("namespace"), ("new"), ("noexcept"),
("nullptr"), ("operator"), ("private"),
("protected"), ("public"), ("register"), ("reinterpret_cast"),
("return"), ("short"), ("signed"), ("sizeof"), ("static"),("static_assert"),
("return"), ("sizeof"), ("static"), ("static_assert"),
("static_cast"), ("struct"), ("switch"), ("template"), ("this"), ("thread_local"),
("throw"), ("true"), ("try"), ("typedef"), ("typeid"), ("typename"),
("union"), ("unsigned"), ("using"), ("virtual"), ("void"),
("volatile"), ("wchar_t"), ("while"),
("union"), ("using"), ("virtual"),
("volatile"), ("while"),
// gnu
("__attribute__"), ("__thread"), ("__typeof__"),
......@@ -72,6 +71,10 @@ const char *token_names[] = {
("@protected"), ("@protocol"), ("@public"), ("@required"), ("@selector"),
("@synchronized"), ("@synthesize"), ("@throw"), ("@try"),
// Primitive types
("bool"), ("char"), ("char16_t"), ("char32_t"), ("double"), ("float"), ("int"),
("long"), ("short"), ("signed"), ("unsigned"), ("void"), ("wchar_t"),
// Qt keywords
("emit"), ("SIGNAL"), ("SLOT"), ("Q_SIGNAL"), ("Q_SLOT"), ("signals"), ("slots"),
("Q_FOREACH"), ("Q_D"), ("Q_Q"),
......
......@@ -119,13 +119,9 @@ enum Kind {
T_ALIGNOF,
T_ASM,
T_AUTO,
T_BOOL,
T_BREAK,
T_CASE,
T_CATCH,
T_CHAR,
T_CHAR16_T,
T_CHAR32_T,
T_CLASS,
T_CONST,
T_CONST_CAST,
......@@ -135,7 +131,6 @@ enum Kind {
T_DEFAULT,
T_DELETE,
T_DO,
T_DOUBLE,
T_DYNAMIC_CAST,
T_ELSE,
T_ENUM,
......@@ -143,14 +138,11 @@ enum Kind {
T_EXPORT,
T_EXTERN,
T_FALSE,
T_FLOAT,
T_FOR,
T_FRIEND,
T_GOTO,
T_IF,
T_INLINE,
T_INT,
T_LONG,
T_MUTABLE,
T_NAMESPACE,
T_NEW,
......@@ -163,8 +155,6 @@ enum Kind {
T_REGISTER,
T_REINTERPRET_CAST,
T_RETURN,
T_SHORT,
T_SIGNED,
T_SIZEOF,
T_STATIC,
T_STATIC_ASSERT,
......@@ -181,12 +171,9 @@ enum Kind {
T_TYPEID,
T_TYPENAME,
T_UNION,
T_UNSIGNED,
T_USING,
T_VIRTUAL,
T_VOID,
T_VOLATILE,
T_WCHAR_T,
T_WHILE,
T___ATTRIBUTE__,
......@@ -223,6 +210,23 @@ enum Kind {
T_LAST_OBJC_AT_KEYWORD = T_AT_TRY,
// Primitive types
T_FIRST_PRIMITIVE,
T_BOOL = T_FIRST_PRIMITIVE,
T_CHAR,
T_CHAR16_T,
T_CHAR32_T,
T_DOUBLE,
T_FLOAT,
T_INT,
T_LONG,
T_SHORT,
T_SIGNED,
T_UNSIGNED,
T_VOID,
T_WCHAR_T,
T_LAST_PRIMITIVE = T_WCHAR_T,
T_FIRST_QT_KEYWORD,
// Qt keywords
......@@ -247,6 +251,7 @@ enum Kind {
T_Q_DECLARE_INTERFACE,
T_Q_OBJECT,
T_Q_GADGET,
T_LAST_KEYWORD = T_Q_GADGET,
// aliases
......@@ -320,7 +325,10 @@ public:
{ return f.kind >= T_FIRST_OPERATOR && f.kind <= T_LAST_OPERATOR; }
inline bool isKeyword() const
{ return f.kind >= T_FIRST_KEYWORD && f.kind < T_FIRST_QT_KEYWORD; }
{ return f.kind >= T_FIRST_KEYWORD && f.kind < T_FIRST_PRIMITIVE; }
inline bool isPrimitiveType() const
{ return f.kind >= T_FIRST_PRIMITIVE && f.kind <= T_LAST_PRIMITIVE; }
inline bool isComment() const
{ return f.kind == T_COMMENT || f.kind == T_DOXY_COMMENT ||
......
......@@ -43,6 +43,7 @@ enum CppFormats {
CppStringFormat,
CppTypeFormat,
CppKeywordFormat,
CppPrimitiveTypeFormat,
CppOperatorFormat,
CppPreprocessorFormat,
CppLabelFormat,
......
......@@ -52,6 +52,7 @@ CppHighlighter::CppHighlighter(QTextDocument *document) :
<< TextEditor::C_STRING
<< TextEditor::C_TYPE
<< TextEditor::C_KEYWORD
<< TextEditor::C_PRIMITIVE_TYPE
<< TextEditor::C_OPERATOR
<< TextEditor::C_PREPROCESSOR
<< TextEditor::C_LABEL
......@@ -220,6 +221,9 @@ void CppHighlighter::highlightBlock(const QString &text)
|| CppTools::isQtKeyword(text.midRef(tk.utf16charsBegin(), tk.utf16chars()))
|| tk.isObjCAtKeyword()) {
setFormat(tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(CppKeywordFormat));
} else if (tk.isPrimitiveType()) {
setFormat(tk.utf16charsBegin(), tk.utf16chars(),
formatForCategory(CppPrimitiveTypeFormat));
} else if (tk.isOperator()) {
setFormat(tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(CppOperatorFormat));
} else if (i == 0 && tokens.size() > 1 && tk.is(T_IDENTIFIER) && tokens.at(1).is(T_COLON)) {
......
......@@ -1727,6 +1727,10 @@ void CppCompletionAssistProcessor::addKeywords()
// keyword completion items.
for (int i = T_FIRST_KEYWORD; i < keywordLimit; ++i)
addCompletionItem(QLatin1String(Token::name(i)), m_icons.keywordIcon(), KeywordsOrder);
// primitive type completion items.
for (int i = T_FIRST_PRIMITIVE; i <= T_LAST_PRIMITIVE; ++i)
addCompletionItem(QLatin1String(Token::name(i)), m_icons.keywordIcon(), KeywordsOrder);
}
void CppCompletionAssistProcessor::addMacros(const QString &fileName, const CPlusPlus::Snapshot &snapshot)
......
......@@ -62,6 +62,7 @@ const char *nameForStyle(TextStyle style)
case C_VIRTUAL_METHOD: return "VirtualMethod";
case C_FUNCTION: return "Function";
case C_KEYWORD: return "Keyword";
case C_PRIMITIVE_TYPE: return "PrimitiveType";
case C_OPERATOR: return "Operator";
case C_PREPROCESSOR: return "Preprocessor";
case C_LABEL: return "Label";
......
......@@ -59,6 +59,7 @@ enum TextStyle {
C_VIRTUAL_METHOD,
C_FUNCTION,
C_KEYWORD,
C_PRIMITIVE_TYPE,
C_OPERATOR,
C_PREPROCESSOR,
C_LABEL,
......
......@@ -139,6 +139,8 @@ TextEditorSettings::TextEditorSettings(QObject *parent)
Qt::darkBlue));
formatDescr.append(FormatDescription(C_STRING, tr("String"),
tr("Character and string literals."), Qt::darkGreen));
formatDescr.append(FormatDescription(C_PRIMITIVE_TYPE, tr("Primitive Type"),
tr("Primitive data types"), Qt::darkYellow));
formatDescr.append(FormatDescription(C_TYPE, tr("Type"), tr("Name of a type."),
Qt::darkMagenta));
formatDescr.append(FormatDescription(C_LOCAL, tr("Local"), tr("Local variables.")));
......@@ -204,8 +206,8 @@ TextEditorSettings::TextEditorSettings(QObject *parent)
jsGlobalFormat));
formatDescr.append(FormatDescription(C_KEYWORD, tr("Keyword"),
tr("Reserved keywords of the programming language."),
Qt::darkYellow));
tr("Reserved keywords of the programming language except "
"keywords denoting primitive types."), Qt::darkYellow));
formatDescr.append(FormatDescription(C_OPERATOR, tr("Operator"),
tr("Operators (for example operator++ or operator-=).")));
formatDescr.append(FormatDescription(C_PREPROCESSOR, tr("Preprocessor"),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment