Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Commit

Permalink
highlighter: add support for hash declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
crackedmind committed Mar 3, 2021
1 parent 6b61d07 commit b28ca37
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions vcreatorhighlighter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ void VlangHighlighter::highlightBlock(const QString &text)
setFormat(token.offset, token.length, formatForCategory(TextEditor::C_NUMBER));
break;

case Token::Hash: {
static QSet<QString> hashDecls = {"#include", "#flag", "#pkgconfig", "#define"};
if (hashDecls.contains(text.mid(token.offset, token.length)))
setFormat(token.offset, token.length, formatForCategory(TextEditor::C_PREPROCESSOR));
else
setFormat(token.offset, token.length, formatForCategory(TextEditor::C_TEXT));
} break;

case Token::Comment:
if (m_inMultilineComment
&& Utils::midView(text, token.end() - 2, 2) == QLatin1String("*/")) {
Expand Down
7 changes: 7 additions & 0 deletions vcreatorlexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,13 @@ QList<Token> Scanner::operator()(const QString &text, int startState)
case ',':
tokens.append(Token(index++, 1, Token::Comma));
break;
case '#': {
const int start = index;
do {
++index;
} while (index < text.length() && isIdentifierChar(text.at(index)));
tokens.append(Token(start, index - start, Token::Hash));
} break;

default:
if (ch.isSpace()) {
Expand Down
1 change: 1 addition & 0 deletions vcreatorlexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Token
String,
Comment,
Number,
Hash,
Operator,
BuiltinType,
BuiltinFn,
Expand Down

0 comments on commit b28ca37

Please sign in to comment.