[Qt-creator] [patch] C++ syntax highlighting and the (unused) 'style' format.

roberto.raggi at nokia.com roberto.raggi at nokia.com
Tue Apr 6 11:20:13 CEST 2010


Hi,

You don't need to use a binary search to recognize keywords. The C++ keywords
are classified while tokenizing so instead of

+    MATCH_TABLE_LATIN(DeclSpec,
+        /* len: 3 */ "int", 0,
+        /* len: 4 */ "void", "bool", "char", "long", "auto", 0,
+        /* len: 5 */ "const", "float", "short", 0,
+        /* len: 6 */ "signed", "static", "extern", "double", 0,
+        /* len: 7 */ "wchar_t", "static", "mutable", 0,
+        /* len: 8 */ "unsigned", "volatile", "register", 0 );

you should write something like

switch (token.kind()) {
  case T_VOID: case T_iNT: ...:
     return true;
  ...
}

Of course, that doesn't apply to the preprocessor directives because they are not classified.

I'm not against highlighting primitive types but i don't think that hardcoding the matching of size_t & co in the lexer is a good idea.
Yeah, I know about the hack we use in the lexer to match Qt-like classes (e.g. QObject, QPushButton and so on...) but I think it's wrong and we should definitely try to get rid of that ugly hack.

ciao robe

On Apr 2, 2010, at 3:23 PM, ext tbp wrote:

> Hello,
> this patch tries to address the fact the 'type' syntax highlighting
> format isn't used in any version of QtCreator i've tried but for Qt
> specific stuff.
> It demotes some keywords (most of 7.1 [dcl.dcl])  and identifiers
> ending with '_t' as types.
> 
> Given this is my first tentative to contribute to this project, being
> not quite sure about which set of features of C++ were allowed, i've
> tried to restrain myself (ie i haven't added __m128 & co) yet i
> couldn't resist removing some of the string matching spaghetti. Sorry.
> If more aggressive preprocessor tricks are allowed, i'd like to
> tighten it some more (but i feared even basic variadic macros would
> already be too much).
> 
> This patch is against v1.2.1 mostly because i haven't found out how to
> statically build Qt 4.7 and trunk.
> 
> PS: I've seen signs of semantic highlighting in v2.0, which i'm
> interested in, but couldn't quite figure how/what it was supposed to
> effect.
> <cpphighlighter.diff><ATT00001..txt>





More information about the Qt-creator-old mailing list