Commit 7ccc6fc7 authored by Rhys Weatherley's avatar Rhys Weatherley
Browse files

Highlight reserved GLSL keywords

parent e151381a
......@@ -207,6 +207,7 @@
%token PREPROC "preprocessor directive"
%token COMMENT "comment"
%token ERROR "error"
%token RESERVED "reserved word"
%start translation_unit
......
......@@ -393,10 +393,11 @@ int Lexer::findKeyword(const char *word, int length) const
if (!(t & Variant_Mask))
return t;
if ((_variant & t & Variant_Mask) == 0) {
// TODO: issue a proper error for the unsupported keyword
QByteArray keyword(word, length);
fprintf(stderr, "unsupported keyword `%s' at line %d\n",
keyword.constData(), _lineno);
// Return a "reserved word" token if this keyword is not permitted
// in the current language variant so that the syntax highlighter
// can warn the user about the word.
if (!_scanKeywords)
return Parser::T_RESERVED;
}
return t & ~Variant_Mask;
}
......
This diff is collapsed.
#line 213 "./glsl.g"
#line 214 "./glsl.g"
/**************************************************************************
**
......
This diff is collapsed.
......@@ -172,6 +172,7 @@ public:
T_PRECISION = 104,
T_PREPROC = 169,
T_QUESTION = 105,
T_RESERVED = 172,
T_RETURN = 106,
T_RIGHT_ANGLE = 107,
T_RIGHT_ASSIGN = 108,
......@@ -238,12 +239,12 @@ public:
ACCEPT_STATE = 440,
RULE_COUNT = 314,
STATE_COUNT = 459,
TERMINAL_COUNT = 172,
TERMINAL_COUNT = 173,
NON_TERMINAL_COUNT = 84,
GOTO_INDEX_OFFSET = 459,
GOTO_INFO_OFFSET = 4728,
GOTO_CHECK_OFFSET = 4728
GOTO_INFO_OFFSET = 4757,
GOTO_CHECK_OFFSET = 4757
};
static const char *const spell [];
......
......@@ -176,9 +176,14 @@ void GLSLTextEditor::setFontSettings(const TextEditor::FontSettings &fs)
<< QLatin1String(TextEditor::Constants::C_STRING)
<< QLatin1String(TextEditor::Constants::C_TYPE)
<< QLatin1String(TextEditor::Constants::C_KEYWORD)
<< QLatin1String(TextEditor::Constants::C_FIELD)
<< QLatin1String(TextEditor::Constants::C_OPERATOR)
<< QLatin1String(TextEditor::Constants::C_PREPROCESSOR)
<< QLatin1String(TextEditor::Constants::C_LABEL)
<< QLatin1String(TextEditor::Constants::C_COMMENT)
<< QLatin1String(TextEditor::Constants::C_VISUAL_WHITESPACE);
<< QLatin1String(TextEditor::Constants::C_DOXYGEN_COMMENT)
<< QLatin1String(TextEditor::Constants::C_DOXYGEN_TAG)
<< QLatin1String(TextEditor::Constants::C_VISUAL_WHITESPACE)
<< QLatin1String(TextEditor::Constants::C_REMOVED_LINE);
}
highlighter->setFormats(fs.toTextCharFormats(categories));
......@@ -252,7 +257,6 @@ void GLSLTextEditor::updateDocumentNow()
m_updateDocumentTimer->stop();
const int variant = Lexer::Variant_GLSL_Qt | // ### hardcoded
Lexer::Variant_GLSL_ES_100 |
Lexer::Variant_VertexShader |
Lexer::Variant_FragmentShader;
const QString contents = toPlainText(); // get the code from the editor
......
......@@ -57,6 +57,10 @@ void Highlighter::highlightBlock(const QString &text)
lex.setState(qMax(0, previousBlockState()));
lex.setScanKeywords(false);
lex.setScanComments(true);
const int variant = GLSL::Lexer::Variant_GLSL_Qt | // ### FIXME: hardcoded
GLSL::Lexer::Variant_VertexShader |
GLSL::Lexer::Variant_FragmentShader;
lex.setVariant(variant);
GLSL::Token tk;
do {
lex.yylex(&tk);
......@@ -66,7 +70,10 @@ void Highlighter::highlightBlock(const QString &text)
else if (tk.is(GLSL::Parser::T_COMMENT))
setFormat(tk.position, tk.length, Qt::darkGreen); // ### FIXME: m_formats[GLSLCommentFormat]);
else if (tk.is(GLSL::Parser::T_IDENTIFIER)) {
if (lex.findKeyword(data.constData() + tk.position, tk.length) != 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]);
else if (kind != GLSL::Parser::T_IDENTIFIER)
setFormat(tk.position, tk.length, m_formats[GLSLKeywordFormat]);
}
} while (tk.isNot(GLSL::Parser::EOF_SYMBOL));
......
......@@ -51,6 +51,7 @@ public:
GLSLDoxygenCommentFormat,
GLSLDoxygenTagFormat,
GLSLVisualWhitespace,
GLSLReservedKeyword,
NumGLSLFormats
};
......
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