summaryrefslogtreecommitdiff
path: root/src/plugins/glsleditor/glslhighlighter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/glsleditor/glslhighlighter.cpp')
-rw-r--r--src/plugins/glsleditor/glslhighlighter.cpp47
1 files changed, 29 insertions, 18 deletions
diff --git a/src/plugins/glsleditor/glslhighlighter.cpp b/src/plugins/glsleditor/glslhighlighter.cpp
index abe873b501..709023ea9f 100644
--- a/src/plugins/glsleditor/glslhighlighter.cpp
+++ b/src/plugins/glsleditor/glslhighlighter.cpp
@@ -42,6 +42,22 @@ using namespace TextEditor;
Highlighter::Highlighter(BaseTextDocument *parent)
: TextEditor::SyntaxHighlighter(parent)
{
+ static QVector<TextEditor::TextStyle> categories;
+ if (categories.isEmpty()) {
+ categories << TextEditor::C_NUMBER
+ << TextEditor::C_STRING
+ << TextEditor::C_TYPE
+ << TextEditor::C_KEYWORD
+ << TextEditor::C_OPERATOR
+ << TextEditor::C_PREPROCESSOR
+ << TextEditor::C_LABEL
+ << TextEditor::C_COMMENT
+ << TextEditor::C_DOXYGEN_COMMENT
+ << TextEditor::C_DOXYGEN_TAG
+ << TextEditor::C_VISUAL_WHITESPACE
+ << TextEditor::C_REMOVED_LINE;
+ }
+ setTextFormatCategories(categories);
}
Highlighter::~Highlighter()
@@ -49,11 +65,6 @@ Highlighter::~Highlighter()
}
-void Highlighter::setFormats(const QVector<QTextCharFormat> &formats)
-{
- qCopy(formats.begin(), formats.end(), m_formats);
-}
-
void Highlighter::highlightBlock(const QString &text)
{
const int previousState = previousBlockState();
@@ -96,7 +107,7 @@ void Highlighter::highlightBlock(const QString &text)
setCurrentBlockState(previousState);
BaseTextDocumentLayout::clearParentheses(currentBlock());
if (text.length()) // the empty line can still contain whitespace
- setFormat(0, text.length(), m_formats[GLSLVisualWhitespace]);
+ setFormat(0, text.length(), formatForCategory(GLSLVisualWhitespace));
BaseTextDocumentLayout::setFoldingIndent(currentBlock(), foldingIndent);
return;
}
@@ -120,7 +131,7 @@ void Highlighter::highlightBlock(const QString &text)
if (previousTokenEnd != tk.begin()) {
setFormat(previousTokenEnd, tk.begin() - previousTokenEnd,
- m_formats[GLSLVisualWhitespace]);
+ formatForCategory(GLSLVisualWhitespace));
}
if (tk.is(GLSL::Parser::T_LEFT_PAREN) || tk.is(GLSL::Parser::T_LEFT_BRACE) || tk.is(GLSL::Parser::T_LEFT_BRACKET)) {
@@ -157,17 +168,17 @@ void Highlighter::highlightBlock(const QString &text)
highlightAsPreprocessor = false;
if (false /* && i == 0 && tk.is(GLSL::Parser::T_POUND)*/) {
- highlightLine(text, tk.begin(), tk.length, m_formats[GLSLPreprocessorFormat]);
+ highlightLine(text, tk.begin(), tk.length, formatForCategory(GLSLPreprocessorFormat));
highlightAsPreprocessor = true;
} else if (highlightCurrentWordAsPreprocessor && isPPKeyword(text.midRef(tk.begin(), tk.length))) {
- setFormat(tk.begin(), tk.length, m_formats[GLSLPreprocessorFormat]);
+ setFormat(tk.begin(), tk.length, formatForCategory(GLSLPreprocessorFormat));
} else if (tk.is(GLSL::Parser::T_NUMBER)) {
- setFormat(tk.begin(), tk.length, m_formats[GLSLNumberFormat]);
+ setFormat(tk.begin(), tk.length, formatForCategory(GLSLNumberFormat));
} else if (tk.is(GLSL::Parser::T_COMMENT)) {
- highlightLine(text, tk.begin(), tk.length, m_formats[GLSLCommentFormat]);
+ highlightLine(text, tk.begin(), tk.length, formatForCategory(GLSLCommentFormat));
// we need to insert a close comment parenthesis, if
// - the line starts in a C Comment (initalState != 0)
@@ -190,9 +201,9 @@ void Highlighter::highlightBlock(const QString &text)
} else if (tk.is(GLSL::Parser::T_IDENTIFIER)) {
int kind = lex.findKeyword(data.constData() + tk.position, tk.length);
if (kind == GLSL::Parser::T_RESERVED)
- setFormat(tk.position, tk.length, m_formats[GLSLReservedKeyword]);
+ setFormat(tk.position, tk.length, formatForCategory(GLSLReservedKeyword));
else if (kind != GLSL::Parser::T_IDENTIFIER)
- setFormat(tk.position, tk.length, m_formats[GLSLKeywordFormat]);
+ setFormat(tk.position, tk.length, formatForCategory(GLSLKeywordFormat));
}
}
@@ -245,7 +256,7 @@ void Highlighter::highlightBlock(const QString &text)
void Highlighter::highlightLine(const QString &text, int position, int length,
const QTextCharFormat &format)
{
- const QTextCharFormat visualSpaceFormat = m_formats[GLSLVisualWhitespace];
+ const QTextCharFormat visualSpaceFormat = formatForCategory(GLSLVisualWhitespace);
const int end = position + length;
int index = position;
@@ -363,15 +374,15 @@ void Highlighter::highlightBlock(const QString &text)
const GLSL::Token &tk = tokens.at(i);
if (tk.is(GLSL::Parser::T_NUMBER)) {
- setFormat(tk.position, tk.length, m_formats[GLSLNumberFormat]);
+ setFormat(tk.position, tk.length, formatForCategory(GLSLNumberFormat);
} else if (tk.is(GLSL::Parser::T_COMMENT)) {
- setFormat(tk.position, tk.length, Qt::darkGreen); // ### FIXME: m_formats[GLSLCommentFormat]);
+ setFormat(tk.position, tk.length, Qt::darkGreen); // ### FIXME: formatForCategory(GLSLCommentFormat);
} else if (tk.is(GLSL::Parser::T_IDENTIFIER)) {
int kind = lex.findKeyword(data.constData() + tk.position, tk.length);
if (kind == GLSL::Parser::T_RESERVED)
- setFormat(tk.position, tk.length, m_formats[GLSLReservedKeyword]);
+ setFormat(tk.position, tk.length, formatForCategory(GLSLReservedKeyword);
else if (kind != GLSL::Parser::T_IDENTIFIER)
- setFormat(tk.position, tk.length, m_formats[GLSLKeywordFormat]);
+ setFormat(tk.position, tk.length, formatForCategory(GLSLKeywordFormat);
} else if (tk.is(GLSL::Parser::T_LEFT_PAREN) || tk.is(GLSL::Parser::T_LEFT_BRACE) || tk.is(GLSL::Parser::T_LEFT_BRACKET)) {
const QChar c = text.at(tk.begin());
parentheses.append(Parenthesis(Parenthesis::Opened, c, tk.begin()));