Introduced a simple incremental lexer for GLSL.

This commit is contained in:
Roberto Raggi
2010-11-10 15:44:59 +01:00
parent f6eeed0372
commit 959edbe10b
23 changed files with 1733 additions and 944 deletions

View File

@@ -1,4 +1,4 @@
HEADERS += $$PWD/glsllexer.h $$PWD/glslparser.h glslparsertable_p.h $$PWD/glslast.h
HEADERS += $$PWD/glsl.h $$PWD/glsllexer.h $$PWD/glslparser.h glslparsertable_p.h $$PWD/glslast.h
SOURCES += $$PWD/glslkeywords.cpp $$PWD/glslparser.cpp $$PWD/glslparsertable.cpp \
$$PWD/glsllexer.cpp $$PWD/glslast.cpp $$PWD/glsldump.cpp $$PWD/glsldelete.cpp

View File

@@ -1,3 +1,32 @@
---------------------------------------------------------------------------
--
-- This file is part of Qt Creator
--
-- Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
--
-- Contact: Nokia Corporation (qt-info@nokia.com)
--
-- Commercial Usage
--
-- Licensees holding valid Qt Commercial licenses may use this file in
-- accordance with the Qt Commercial License Agreement provided with the
-- Software or, alternatively, in accordance with the terms contained in
-- a written agreement between you and Nokia.
--
-- GNU Lesser General Public License Usage
--
-- Alternatively, this file may be used under the terms of the GNU Lesser
-- General Public License version 2.1 as published by the Free Software
-- Foundation and appearing in the file LICENSE.LGPL included in the
-- packaging of this file. Please review the following information to
-- ensure the GNU Lesser General Public License version 2.1 requirements
-- will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
--
-- If you are unsure which license is appropriate for your use, please
-- contact the sales department at http://qt.nokia.com/contact.
---------------------------------------------------------------------------
--
-- todo:
-- spelling of XOR_OP and CARET
@@ -174,11 +203,42 @@
%token XOR_OP "^"
%token TRUE "true"
%token FALSE "false"
%token PREPROC "preprocessor directive"
%token COMMENT "comment"
%token ERROR "error"
%start translation_unit
/:
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "$header"
#include "glsllexer.h"
#include "glslast.h"
@@ -214,6 +274,35 @@ private:
:/
/.
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "glslparser.h"
#include <iostream>

45
src/libs/glsl/glsl.h Normal file
View File

@@ -0,0 +1,45 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef GLSL_H
#define GLSL_H
#include <QtCore/qglobal.h>
#include <cstdlib>
#include <cstddef>
#if defined(GLSL_BUILD_LIB)
# define GLSL_EXPORT Q_DECL_EXPORT
#elif defined(GLSL_BUILD_STATIC_LIB)
# define GLSL_EXPORT
#else
# define GLSL_EXPORT Q_DECL_IMPORT
#endif
#endif // GLSL_H

View File

@@ -1,9 +1,8 @@
TEMPLATE = lib
CONFIG += dll
TARGET = GLSL
DEFINES += GLSL_BUILD_DIR QT_CREATOR
DEFINES += GLSL_BUILD_LIB QT_CREATOR
include(../../qtcreatorlibrary.pri)
include(glsl-lib.pri)
include(../utils/utils.pri)

View File

@@ -1,3 +1,31 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "glslast.h"
using namespace GLSL;

View File

@@ -1,3 +1,31 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef GLSLAST_H
#define GLSLAST_H

View File

@@ -1,3 +1,31 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "glslast.h"

View File

@@ -1,3 +1,31 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "glslast.h"

View File

@@ -1,3 +1,32 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "glsllexer.h"
#include "glslparser.h"

View File

@@ -1,3 +1,31 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "glsllexer.h"
#include "glslparser.h"
@@ -13,7 +41,10 @@ Lexer::Lexer(const char *source, unsigned size)
_size(size),
_yychar('\n'),
_lineno(0),
_variant(Variant_Mask & ~Variant_Reserved) // everything except reserved
_state(0),
_variant(Variant_Mask & ~Variant_Reserved), // everything except reserved
_scanKeywords(true),
_scanComments(false)
{
}
@@ -23,12 +54,9 @@ Lexer::~Lexer()
void Lexer::yyinp()
{
if (_it != _end) {
_yychar = *_it++;
_yychar = (unsigned char) *_it++;
if (_yychar == '\n')
++_lineno;
} else
_yychar = 0;
}
int Lexer::yylex(Token *tk)
@@ -44,6 +72,11 @@ int Lexer::yylex(Token *tk)
return kind;
}
enum {
State_normal,
State_comment
};
int Lexer::yylex_helper(const char **position, int *line)
{
again:
@@ -56,6 +89,22 @@ again:
if (_yychar == 0)
return Parser::EOF_SYMBOL;
if (_state == State_comment) {
while (_yychar) {
if (_yychar == '*') {
yyinp();
if (_yychar == '/') {
yyinp();
_state = State_normal;
break;
}
} else {
yyinp();
}
}
return Parser::T_COMMENT;
}
const int ch = _yychar;
yyinp();
@@ -171,6 +220,8 @@ again:
if (_yychar == '\n')
break;
}
if (_scanComments)
return Parser::T_COMMENT;
goto again;
} else if (_yychar == '*') {
yyinp();
@@ -179,12 +230,18 @@ again:
yyinp();
if (_yychar == '/') {
yyinp();
if (_scanComments)
return Parser::T_COMMENT;
goto again;
}
} else {
yyinp();
}
}
if (_scanComments) {
_state = State_comment;
return Parser::T_COMMENT;
}
goto again;
} else if (_yychar == '=') {
yyinp();
@@ -302,16 +359,9 @@ again:
while (std::isalnum(_yychar) || _yychar == '_') {
yyinp();
}
int t = classify(word, _it - word -1);
if (!(t & Variant_Mask))
return t;
if ((_variant & t & Variant_Mask) == 0) {
// TODO: issue a proper error for the unsupported keyword
std::string keyword(word, _it - word -1);
fprintf(stderr, "unsupported keyword `%s' at line %d\n",
keyword.c_str(), _lineno);
}
return t & ~Variant_Mask;
if (_scanKeywords)
return findKeyword(word, _it - word - 1);
return Parser::T_IDENTIFIER;
} else if (std::isdigit(ch)) {
while (std::isalnum(_yychar) || _yychar == '.') {
yyinp();
@@ -323,3 +373,17 @@ again:
return Parser::T_ERROR;
}
int Lexer::findKeyword(const char *word, int length) const
{
int t = classify(word, length);
if (!(t & Variant_Mask))
return t;
if ((_variant & t & Variant_Mask) == 0) {
// TODO: issue a proper error for the unsupported keyword
std::string keyword(word, length);
fprintf(stderr, "unsupported keyword `%s' at line %d\n",
keyword.c_str(), _lineno);
}
return t & ~Variant_Mask;
}

View File

@@ -1,9 +1,40 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef GLSLLEXER_H
#define GLSLLEXER_H
#include "glsl.h"
namespace GLSL {
class Token
class GLSL_EXPORT Token
{
public:
int kind;
@@ -23,7 +54,7 @@ public:
bool isNot(int k) const { return k != kind; }
};
class Lexer
class GLSL_EXPORT Lexer
{
public:
Lexer(const char *source, unsigned size);
@@ -44,10 +75,20 @@ public:
Variant_Mask = 0xFFFF0000
};
int state() const { return _state; }
void setState(int state) { _state = state; }
int variant() const { return _variant; }
void setVariant(int flags) { _variant = flags; }
bool scanKeywords() const { return _scanKeywords; }
void setScanKeywords(bool scanKeywords) { _scanKeywords = scanKeywords; }
bool scanComments() const { return _scanComments; }
void setScanComments(bool scanComments) { _scanComments = scanComments; }
int yylex(Token *tk);
int findKeyword(const char *word, int length) const;
private:
static int classify(const char *s, int len);
@@ -62,7 +103,10 @@ private:
int _size;
int _yychar;
int _lineno;
int _state;
int _variant;
unsigned _scanKeywords: 1;
unsigned _scanComments: 1;
};
} // end of namespace GLSL

View File

@@ -1,4 +1,33 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "glslparser.h"
#include <iostream>

View File

@@ -1,4 +1,33 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "glslparsertable_p.h"
#include "glsllexer.h"
#include "glslast.h"

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,63 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtCore module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
// of other Qt classes. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
// This file was generated by qlalr - DO NOT EDIT!
#ifndef GLSLPARSERTABLE_P_H
#define GLSLPARSERTABLE_P_H
#include <QtCore/qglobal.h>
QT_BEGIN_NAMESPACE
class GLSLParserTable
{
public:
@@ -23,6 +79,7 @@ public:
T_CENTROID = 14,
T_COLON = 15,
T_COMMA = 16,
T_COMMENT = 170,
T_CONST = 17,
T_CONTINUE = 18,
T_DASH = 19,
@@ -51,7 +108,7 @@ public:
T_ELSE = 42,
T_EQUAL = 43,
T_EQ_OP = 44,
T_ERROR = 169,
T_ERROR = 171,
T_FALSE = 168,
T_FLAT = 45,
T_FLOAT = 46,
@@ -113,6 +170,7 @@ public:
T_PERCENT = 102,
T_PLUS = 103,
T_PRECISION = 104,
T_PREPROC = 169,
T_QUESTION = 105,
T_RETURN = 106,
T_RIGHT_ANGLE = 107,
@@ -180,12 +238,12 @@ public:
ACCEPT_STATE = 435,
RULE_COUNT = 312,
STATE_COUNT = 455,
TERMINAL_COUNT = 170,
TERMINAL_COUNT = 172,
NON_TERMINAL_COUNT = 82,
GOTO_INDEX_OFFSET = 455,
GOTO_INFO_OFFSET = 4753,
GOTO_CHECK_OFFSET = 4753
GOTO_INFO_OFFSET = 4796,
GOTO_CHECK_OFFSET = 4796
};
static const char *const spell [];
@@ -218,5 +276,6 @@ public:
};
QT_END_NAMESPACE
#endif // GLSLPARSERTABLE_P_H

View File

@@ -2,5 +2,5 @@
me=$(dirname $0)
cat $me/specs/glsl.g.in $me/specs/grammar.txt > $me/glsl.g
qlalr --no-lines --no-debug $me/glsl.g
qlalr --qt --no-lines --no-debug $me/glsl.g

View File

@@ -1,3 +1,32 @@
---------------------------------------------------------------------------
--
-- This file is part of Qt Creator
--
-- Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
--
-- Contact: Nokia Corporation (qt-info@nokia.com)
--
-- Commercial Usage
--
-- Licensees holding valid Qt Commercial licenses may use this file in
-- accordance with the Qt Commercial License Agreement provided with the
-- Software or, alternatively, in accordance with the terms contained in
-- a written agreement between you and Nokia.
--
-- GNU Lesser General Public License Usage
--
-- Alternatively, this file may be used under the terms of the GNU Lesser
-- General Public License version 2.1 as published by the Free Software
-- Foundation and appearing in the file LICENSE.LGPL included in the
-- packaging of this file. Please review the following information to
-- ensure the GNU Lesser General Public License version 2.1 requirements
-- will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
--
-- If you are unsure which license is appropriate for your use, please
-- contact the sales department at http://qt.nokia.com/contact.
---------------------------------------------------------------------------
--
-- todo:
-- spelling of XOR_OP and CARET
@@ -174,11 +203,42 @@
%token XOR_OP "^"
%token TRUE "true"
%token FALSE "false"
%token PREPROC "preprocessor directive"
%token COMMENT "comment"
%token ERROR "error"
%start translation_unit
/:
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "$header"
#include "glsllexer.h"
#include "glslast.h"
@@ -214,6 +274,35 @@ private:
:/
/.
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "glslparser.h"
#include <iostream>

View File

@@ -5,5 +5,8 @@
<sub-class-of type="text/plain"/>
<comment>GLSL file</comment>
<glob pattern="*.glsl"/>
<glob pattern="*.frag"/>
<glob pattern="*.fsh"/>
<glob pattern="*.vsh"/>
</mime-type>
</mime-info>

View File

@@ -1,4 +1,4 @@
<plugin name=\"GLSLditor\" version=\"$$QTCREATOR_VERSION\" compatVersion=\"$$QTCREATOR_VERSION\">
<plugin name=\"GLSLEditor\" version=\"$$QTCREATOR_VERSION\" compatVersion=\"$$QTCREATOR_VERSION\">
<vendor>Nokia Corporation</vendor>
<copyright>(C) 2010 Nokia Corporation</copyright>
<license>

View File

@@ -31,6 +31,7 @@
#include "glsleditoreditable.h"
#include "glsleditorconstants.h"
#include "glsleditorplugin.h"
#include "glslhighlighter.h"
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
@@ -89,7 +90,7 @@ GLSLTextEditor::GLSLTextEditor(QWidget *parent) :
connect(this, SIGNAL(textChanged()), this, SLOT(updateDocument()));
// baseTextDocument()->setSyntaxHighlighter(new Highlighter(document()));
baseTextDocument()->setSyntaxHighlighter(new Highlighter(document()));
// if (m_modelManager) {
// m_semanticHighlighter->setModelManager(m_modelManager);
@@ -147,8 +148,6 @@ Core::Context GLSLEditorEditable::context() const
void GLSLTextEditor::setFontSettings(const TextEditor::FontSettings &fs)
{
TextEditor::BaseTextEditor::setFontSettings(fs);
#warning set up the GLSL highlighter
#if 0
Highlighter *highlighter = qobject_cast<Highlighter*>(baseTextDocument()->syntaxHighlighter());
if (!highlighter)
return;
@@ -175,7 +174,6 @@ void GLSLTextEditor::setFontSettings(const TextEditor::FontSettings &fs)
highlighter->setFormats(fs.toTextCharFormats(categories));
highlighter->rehighlight();
#endif
}
QString GLSLTextEditor::wordUnderCursor() const
@@ -202,7 +200,9 @@ void GLSLTextEditor::createToolBar(GLSLEditorEditable *editable)
{
m_outlineCombo = new QComboBox;
m_outlineCombo->setMinimumContentsLength(22);
#ifdef __GNUC__
#warning set up the outline model
#endif
// m_outlineCombo->setModel(m_outlineModel);
QTreeView *treeView = new QTreeView;
@@ -219,10 +219,6 @@ void GLSLTextEditor::createToolBar(GLSLEditorEditable *editable)
policy.setHorizontalPolicy(QSizePolicy::Expanding);
m_outlineCombo->setSizePolicy(policy);
connect(m_outlineCombo, SIGNAL(activated(int)), this, SLOT(jumpToOutlineElement(int)));
connect(file(), SIGNAL(changed()), this, SLOT(updateFileName()));
QToolBar *toolBar = static_cast<QToolBar*>(editable->toolBar());
QList<QAction*> actions = toolBar->actions();

View File

@@ -14,13 +14,16 @@ glsleditoractionhandler.h \
glsleditorconstants.h \
glsleditoreditable.h \
glsleditorfactory.h \
glsleditorplugin.h
glsleditorplugin.h \
glslhighlighter.h
SOURCES += \
glsleditor.cpp \
glsleditoractionhandler.cpp \
glsleditoreditable.cpp \
glsleditorfactory.cpp \
glsleditorplugin.cpp
glsleditorplugin.cpp \
glslhighlighter.cpp
OTHER_FILES += GLSLEditor.mimetypes.xml
RESOURCES += glsleditor.qrc

View File

@@ -0,0 +1,74 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "glslhighlighter.h"
#include <glsl/glsllexer.h>
#include <glsl/glslparser.h>
#include <QtCore/QDebug>
using namespace GLSLEditor;
using namespace GLSLEditor::Internal;
Highlighter::Highlighter(QTextDocument *parent)
: TextEditor::SyntaxHighlighter(parent)
{
}
Highlighter::~Highlighter()
{
}
void Highlighter::setFormats(const QVector<QTextCharFormat> &formats)
{
qCopy(formats.begin(), formats.end(), m_formats);
}
void Highlighter::highlightBlock(const QString &text)
{
const QByteArray data = text.toLatin1();
GLSL::Lexer lex(data.constData(), data.size());
lex.setState(qMax(0, previousBlockState()));
lex.setScanKeywords(false);
lex.setScanComments(true);
GLSL::Token tk;
do {
lex.yylex(&tk);
if (tk.is(GLSL::Parser::T_NUMBER))
setFormat(tk.position, tk.length, m_formats[GLSLNumberFormat]);
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)
setFormat(tk.position, tk.length, m_formats[GLSLKeywordFormat]);
}
} while (tk.isNot(GLSL::Parser::EOF_SYMBOL));
setCurrentBlockState(lex.state());
}

View File

@@ -0,0 +1,72 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef GLSLHIGHLIGHTER_H
#define GLSLHIGHLIGHTER_H
#include <texteditor/syntaxhighlighter.h>
namespace GLSLEditor {
namespace Internal {
class Highlighter : public TextEditor::SyntaxHighlighter
{
Q_OBJECT
public:
enum Formats {
GLSLNumberFormat,
GLSLStringFormat,
GLSLTypeFormat,
GLSLKeywordFormat,
GLSLOperatorFormat,
GLSLPreprocessorFormat,
GLSLLabelFormat,
GLSLCommentFormat,
GLSLDoxygenCommentFormat,
GLSLDoxygenTagFormat,
GLSLVisualWhitespace,
NumGLSLFormats
};
explicit Highlighter(QTextDocument *parent);
virtual ~Highlighter();
void setFormats(const QVector<QTextCharFormat> &formats);
protected:
void highlightBlock(const QString &text);
private:
QTextCharFormat m_formats[NumGLSLFormats];
};
} // namespace Internal
} // namespace GLSLEditor
#endif // GLSLHIGHLIGHTER_H