Commit d61eb9c8 authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Syntax highlighting for Objective-C identifiers (super, self, nil, Nil, _cmd,...

Syntax highlighting for Objective-C identifiers (super, self, nil, Nil, _cmd, SEL, IMP, BOOL, YES, NO, id).
parent 4b44fa5f
......@@ -27,6 +27,7 @@
**
**************************************************************************/
#include "ObjectiveCTypeQualifiers.h"
#include "SimpleLexer.h"
#include <Lexer.h>
......@@ -83,7 +84,6 @@ SimpleLexer::SimpleLexer()
_qtMocRunEnabled(true),
_objCEnabled(false)
{
setObjCEnabled(true);
}
SimpleLexer::~SimpleLexer()
......@@ -156,6 +156,9 @@ QList<SimpleToken> SimpleLexer::operator()(const QString &text, int state)
simpleTk.text() == QLatin1String("include"))
lex.setScanAngleStringLiteralTokens(true);
if (_objCEnabled && tk.is(T_IDENTIFIER))
simpleTk.f._objcTypeQualifier = (classifyObjectiveCTypeQualifiers(firstChar + tk.offset, tk.f.length) != Token_identifier);
tokens.append(simpleTk);
}
......
......@@ -83,6 +83,7 @@ public:
bool isKeyword() const;
bool isComment() const;
bool isObjCAtKeyword() const;
bool isObjCTypeQualifier() const { return f._objcTypeQualifier; }
const char *name() const;
......@@ -102,6 +103,7 @@ public:
struct {
short _newline: 1;
short _whitespace: 1;
short _objcTypeQualifier: 1;
} f;
};
......
......@@ -61,6 +61,7 @@ void CppHighlighter::highlightBlock(const QString &text)
SimpleLexer tokenize;
tokenize.setQtMocRunEnabled(false);
tokenize.setObjCEnabled(true);
int initialState = state;
const QList<SimpleToken> tokens = tokenize(text, initialState);
......@@ -157,7 +158,7 @@ void CppHighlighter::highlightBlock(const QString &text)
initialState = 0;
}
} else if (tk.isKeyword() || isQtKeyword(tk.text()) || tk.isObjCAtKeyword())
} else if (tk.isKeyword() || isQtKeyword(tk.text()) || tk.isObjCAtKeyword() || tk.isObjCTypeQualifier())
setFormat(tk.position(), tk.length(), m_formats[CppKeywordFormat]);
else if (tk.isOperator())
......
......@@ -32,27 +32,88 @@
CPLUSPLUS_BEGIN_NAMESPACE
static inline int classify2(const char *s) {
if (s[0] == 'i') {
if (s[1] == 'n') {
return Token_in;
if (s[0] == 'N') {
if (s[1] == 'O') {
return Token_NO;
}
}
}
return Token_identifier;
else if (s[0] == 'i') {
if (s[1] == 'd') {
return Token_id;
}
else if (s[1] == 'n') {
return Token_in;
}
}
return Token_identifier;
}
static inline int classify3(const char *s) {
if (s[0] == 'o') {
if (s[1] == 'u') {
if (s[2] == 't') {
return Token_out;
}
if (s[0] == 'I') {
if (s[1] == 'M') {
if (s[2] == 'P') {
return Token_IMP;
}
}
}
}
return Token_identifier;
else if (s[0] == 'N') {
if (s[1] == 'i') {
if (s[2] == 'l') {
return Token_Nil;
}
}
}
else if (s[0] == 'S') {
if (s[1] == 'E') {
if (s[2] == 'L') {
return Token_SEL;
}
}
}
else if (s[0] == 'Y') {
if (s[1] == 'E') {
if (s[2] == 'S') {
return Token_YES;
}
}
}
else if (s[0] == 'n') {
if (s[1] == 'i') {
if (s[2] == 'l') {
return Token_nil;
}
}
}
else if (s[0] == 'o') {
if (s[1] == 'u') {
if (s[2] == 't') {
return Token_out;
}
}
}
return Token_identifier;
}
static inline int classify4(const char *s) {
if (s[0] == 'c') {
if (s[0] == '_') {
if (s[1] == 'c') {
if (s[2] == 'm') {
if (s[3] == 'd') {
return Token__cmd;
}
}
}
}
else if (s[0] == 'B') {
if (s[1] == 'O') {
if (s[2] == 'O') {
if (s[3] == 'L') {
return Token_BOOL;
}
}
}
}
else if (s[0] == 'c') {
if (s[1] == 'o') {
if (s[2] == 'p') {
if (s[3] == 'y') {
......@@ -61,6 +122,15 @@ static inline int classify4(const char *s) {
}
}
}
else if (s[0] == 's') {
if (s[1] == 'e') {
if (s[2] == 'l') {
if (s[3] == 'f') {
return Token_self;
}
}
}
}
return Token_identifier;
}
......@@ -87,6 +157,17 @@ static inline int classify5(const char *s) {
}
}
}
else if (s[0] == 's') {
if (s[1] == 'u') {
if (s[2] == 'p') {
if (s[3] == 'e') {
if (s[4] == 'r') {
return Token_super;
}
}
}
}
}
return Token_identifier;
}
......
......@@ -35,11 +35,22 @@ CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
enum {
Token_NO,
Token_id,
Token_in,
Token_YES,
Token_IMP,
Token_Nil,
Token_SEL,
Token_nil,
Token_out,
Token__cmd,
Token_BOOL,
Token_copy,
Token_self,
Token_byref,
Token_inout,
Token_super,
Token_assign,
Token_bycopy,
Token_getter,
......
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