- change: Default value of option "Editors share one code analyzer" is ON if available physical memory <= 32G

- change: Default value of option "Auto clear symbols in hidden editors" is ON if number of CPU cores > 8 and "Editors share one code analyzer" is on
  - refactor qsynedit's highlighter, work save
This commit is contained in:
Roy Qu 2022-11-23 11:41:16 +08:00
parent d86e93dc35
commit e352ef345c
17 changed files with 244 additions and 492 deletions

View File

@ -6,6 +6,8 @@ Red Panda C++ Version 2.5
- enhancement: project's custom compile include/lib/bin directory is under folder of the app, save them using the path relative to the app
- enhancement: slightly reduce memory usage
- enhancement: Options -> editor -> custom C/C++ type keywords page
- change: Default value of option "Editors share one code analyzer" is ON if available physical memory <= 32G
- change: Default value of option "Auto clear symbols in hidden editors" is ON if number of CPU cores > 8 and "Editors share one code analyzer" is on
Red Panda C++ Version 2.4

View File

@ -479,18 +479,17 @@ void Editor::setPageControl(QTabWidget *newPageControl)
void Editor::undoSymbolCompletion(int pos)
{
QSynedit::PHighlighterAttribute Attr;
QString Token;
QSynedit::PHighlighterAttribute attr;
QString token;
bool tokenFinished;
QSynedit::TokenType tokenType;
if (!highlighter())
return;
if (!pSettings->editor().removeSymbolPairs())
return;
if (!getHighlighterAttriAtRowCol(caretXY(), Token, tokenFinished, tokenType, Attr))
if (!getHighlighterAttriAtRowCol(caretXY(), token, tokenFinished, attr))
return;
if ((tokenType == QSynedit::TokenType::Comment) && (!tokenFinished))
if ((attr->tokenType() == QSynedit::TokenType::Comment) && (!tokenFinished))
return ;
//convert caret x to string index;
pos--;
@ -499,19 +498,19 @@ void Editor::undoSymbolCompletion(int pos)
return;
QChar DeletedChar = lineText().at(pos);
QChar NextChar = lineText().at(pos+1);
if ((tokenType == QSynedit::TokenType::Character) && (DeletedChar != '\''))
if ((attr->tokenType() == QSynedit::TokenType::Character) && (DeletedChar != '\''))
return;
if (tokenType == QSynedit::TokenType::StringEscapeSequence)
return;
if (tokenType == QSynedit::TokenType::String) {
// if (attr->tokenType() == QSynedit::TokenType::StringEscapeSequence)
// return;
if (attr->tokenType() == QSynedit::TokenType::String) {
if ((DeletedChar!='"') && (DeletedChar!='('))
return;
if ((DeletedChar=='"') && (Token!="\"\""))
if ((DeletedChar=='"') && (token!="\"\""))
return;
if ((DeletedChar=='(') && (!Token.startsWith("R\"")))
if ((DeletedChar=='(') && (!token.startsWith("R\"")))
return;
}
if ((DeletedChar == '\'') && (tokenType == QSynedit::TokenType::Number))
if ((DeletedChar == '\'') && (attr->tokenType() == QSynedit::TokenType::Number))
return;
if ((DeletedChar == '<') &&
!(mParser && mParser->isIncludeLine(lineText())))
@ -1393,11 +1392,10 @@ void Editor::showEvent(QShowEvent */*event*/)
void Editor::hideEvent(QHideEvent */*event*/)
{
if (pSettings->codeCompletion().clearWhenEditorHidden()
&& !pSettings->codeCompletion().shareParser()
&& !inProject() && mParser
&& !pMainWindow->isMinimized()) {
//recreate a parser, to totally clean memories the parse uses;
initParser();
//recreate a parser, to totally clean memories the parser uses;
resetCppParser(mParser);
}
if (mParser) {
disconnect(mParser.get(),
@ -1520,8 +1518,7 @@ void Editor::addSyntaxIssues(int line, int startChar, int endChar, CompileIssueT
PSyntaxIssue pError;
QSynedit::BufferCoord p;
QString token;
QSynedit::TokenType tokenType;
int tokenKind,start;
int start;
QSynedit::PHighlighterAttribute attr;
PSyntaxIssueList lst;
if ((line<1) || (line>document()->count()))
@ -1533,7 +1530,7 @@ void Editor::addSyntaxIssues(int line, int startChar, int endChar, CompileIssueT
start = 1;
token = document()->getString(line-1);
} else if (endChar < 1) {
if (!getHighlighterAttriAtRowColEx(p,token,tokenType,tokenKind,start,attr))
if (!getHighlighterAttriAtRowColEx(p,token,start,attr))
return;
} else {
start = startChar;
@ -2201,19 +2198,18 @@ bool Editor::handleSymbolCompletion(QChar key)
} else {
QSynedit::BufferCoord HighlightPos = QSynedit::BufferCoord{caretX()-1, caretY()};
// Check if that line is highlighted as comment
QSynedit::PHighlighterAttribute Attr;
QString Token;
QSynedit::PHighlighterAttribute attr;
QString token;
bool tokenFinished;
QSynedit::TokenType tokenType;
if (getHighlighterAttriAtRowCol(HighlightPos, Token, tokenFinished, tokenType,Attr)) {
if ((tokenType == QSynedit::TokenType::Comment) && (!tokenFinished))
if (getHighlighterAttriAtRowCol(HighlightPos, token, tokenFinished, attr)) {
if ((attr->tokenType() == QSynedit::TokenType::Comment) && (!tokenFinished))
return false;
if ((tokenType == QSynedit::TokenType::String) && (!tokenFinished)
if ((attr->tokenType() == QSynedit::TokenType::String) && (!tokenFinished)
&& (key!='\'') && (key!='\"') && (key!='(') && (key!=')'))
return false;
if (( key=='<' || key =='>') && (mParser && !mParser->isIncludeLine(lineText())))
return false;
if ((key == '\'') && (Attr->name() == "SYNS_AttrNumber"))
if ((key == '\'') && (attr->name() == "SYNS_AttrNumber"))
return false;
}
}
@ -2650,7 +2646,6 @@ bool Editor::handleCodeCompletion(QChar key)
void Editor::initParser()
{
// mParser=nullptr;
if (pSettings->codeCompletion().shareParser()) {
if (pSettings->codeCompletion().enabled()
&& (highlighter() && highlighter()->getClass() == QSynedit::HighlighterClass::CppHighlighter)
@ -3051,26 +3046,25 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete, CodeComple
QString s;
QSynedit::PHighlighterAttribute attr;
bool tokenFinished;
QSynedit::TokenType tokenType;
QSynedit::BufferCoord pBeginPos, pEndPos;
if (getHighlighterAttriAtRowCol(
QSynedit::BufferCoord{caretX() - 1,
caretY()}, s, tokenFinished,tokenType, attr)) {
if (tokenType == QSynedit::TokenType::PreprocessDirective) {//Preprocessor
caretY()}, s, tokenFinished, attr)) {
if (attr->tokenType() == QSynedit::TokenType::Preprocessor) {//Preprocessor
word = getWordAtPosition(this,caretXY(),pBeginPos,pEndPos, WordPurpose::wpDirective);
if (!word.startsWith('#')) {
word = "";
}
} else if (tokenType == QSynedit::TokenType::Comment) { //Comment, javadoc tag
} else if (attr->tokenType() == QSynedit::TokenType::Comment) { //Comment, javadoc tag
word = getWordAtPosition(this,caretXY(),pBeginPos,pEndPos, WordPurpose::wpJavadoc);
if (!word.startsWith('@')) {
return;
}
} else if (
(tokenType != QSynedit::TokenType::Symbol) &&
(tokenType != QSynedit::TokenType::Space) &&
(tokenType != QSynedit::TokenType::Keyword) &&
(tokenType != QSynedit::TokenType::Identifier)
(attr->tokenType() != QSynedit::TokenType::Operator) &&
(attr->tokenType() != QSynedit::TokenType::Space) &&
(attr->tokenType() != QSynedit::TokenType::Keyword) &&
(attr->tokenType() != QSynedit::TokenType::Identifier)
) {
return;
}
@ -4800,7 +4794,8 @@ void Editor::applySettings()
static QSynedit::PHighlighterAttribute createRainbowAttribute(const QString& attrName, const QString& schemeName, const QString& schemeItemName) {
PColorSchemeItem item = pColorManager->getItem(schemeName,schemeItemName);
if (item) {
QSynedit::PHighlighterAttribute attr = std::make_shared<QSynedit::HighlighterAttribute>(attrName);
QSynedit::PHighlighterAttribute attr = std::make_shared<QSynedit::HighlighterAttribute>(attrName,
QSynedit::TokenType::Default);
attr->setForeground(item->foreground());
attr->setBackground(item->background());
return attr;

View File

@ -198,15 +198,12 @@ bool EditorList::closeEditor(Editor* editor, bool transferFocus, bool force) {
if (editor) {
editor->activate();
pMainWindow->updateClassBrowserForEditor(editor);
} else {
pMainWindow->updateClassBrowserForEditor(nullptr);
}
} else {
editor = getEditor();
if (!editor) {
pMainWindow->updateClassBrowserForEditor(nullptr);
}
}
editor = getEditor();
if (!editor) {
pMainWindow->updateClassBrowserForEditor(nullptr);
}
emit editorClosed();
endUpdate();
return true;

View File

@ -27,6 +27,9 @@
#include <QScreen>
#include <QDesktopWidget>
#include <QHash>
#ifdef Q_OS_LINUX
#include <sys/sysinfo.h>
#endif
const char ValueToChar[28] = {'0', '1', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
@ -3774,19 +3777,23 @@ void Settings::CodeCompletion::setShowCodeIns(bool newShowCodeIns)
bool Settings::CodeCompletion::clearWhenEditorHidden()
{
if (!mShareParser) {
#ifdef Q_OS_WIN
MEMORYSTATUSEX statex;
statex.dwLength = sizeof (statex);
MEMORYSTATUSEX statex;
statex.dwLength = sizeof (statex);
GlobalMemoryStatusEx (&statex);
GlobalMemoryStatusEx (&statex);
if (statex.ullTotalPhys < (long long int)2*1024*1024*1024) {
mClearWhenEditorHidden = true;
}
if (statex.ullAvailPhys < (long long int)2*1024*1024*1024) {
return true;
}
if (statex.ullAvailPhys < (long long int)2*1024*1024*1024) {
return true;
}
#elif defined(Q_OS_LINUX)
struct sysinfo si;
sysinfo(&si);
if (si.freeram < (long long int)2*1024*1024*1024) {
return true;
}
#endif
}
return mClearWhenEditorHidden;
}
@ -3817,21 +3824,6 @@ void Settings::CodeCompletion::setHideSymbolsStartsWithTwoUnderLine(bool newHide
bool Settings::CodeCompletion::shareParser()
{
#ifdef Q_OS_WIN
MEMORYSTATUSEX statex;
statex.dwLength = sizeof (statex);
GlobalMemoryStatusEx (&statex);
if (statex.ullTotalPhys < (long long int)1024*1024*1024) {
mShareParser = true;
}
if (statex.ullAvailPhys < (long long int)1*1024*1024*1024) {
return true;
}
#endif
return mShareParser;
}
@ -4001,8 +3993,8 @@ void Settings::CodeCompletion::doLoad()
mHideSymbolsStartsWithTwoUnderLine = boolValue("hide_symbols_start_with_two_underline", true);
mHideSymbolsStartsWithUnderLine = boolValue("hide_symbols_start_with_underline", false);
bool doClear = true;
bool shouldShare=true;
bool shouldShare= true;
bool doClear = false;
#ifdef Q_OS_WIN
MEMORYSTATUSEX statex;
@ -4010,14 +4002,25 @@ void Settings::CodeCompletion::doLoad()
statex.dwLength = sizeof (statex);
GlobalMemoryStatusEx (&statex);
if (statex.ullAvailPhys > (long long int)16*1024*1024*1024) {
doClear = false;
if (statex.ullAvailPhys > (long long int)24*1024*1024*1024) {
shouldShare = false;
}
if (statex.ullAvailPhys > (long long int)10*1024*1024*1024) {
if (shouldShare) {
SYSTEM_INFO info;
GetSystemInfo(&info);
if (info.dwNumberOfProcessors>8 && info.dwProcessorType) {
doClear = true;
}
}
#elif defined(Q_OS_LINUX)
struct sysinfo si;
sysinfo(&si);
if (si.freeram > (long long int)24*1024*1024*1024) {
shouldShare = false;
}
#endif
mClearWhenEditorHidden = boolValue("clear_when_editor_hidden",doClear);
mShareParser = boolValue("share_parser",shouldShare);
}

View File

@ -129,15 +129,13 @@ void TodoThread::doParseFile(const QString &filename, QSynedit::PHighlighter hig
if (!pMainWindow->editorList()->getContentFromOpenedEditor(filename,lines)) {
lines = readFileToLines(filename);
}
QSynedit::PHighlighterAttribute commentAttr = highlighter->getAttribute(SYNS_AttrComment);
highlighter->resetState();
for (int i =0;i<lines.count();i++) {
highlighter->setLine(lines[i],i);
while (!highlighter->eol()) {
QSynedit::PHighlighterAttribute attr;
attr = highlighter->getTokenAttribute();
if (attr == commentAttr) {
if (attr && attr->tokenType() == QSynedit::TokenType::Comment) {
QString token = highlighter->getToken();
int pos = token.indexOf(todoReg);
if (pos>=0) {

View File

@ -359,12 +359,11 @@ int SynEdit::maxScrollWidth() const
bool SynEdit::getHighlighterAttriAtRowCol(const BufferCoord &pos, QString &token, PHighlighterAttribute &attri)
{
TokenType tmpType;
int tmpKind, tmpStart;
return getHighlighterAttriAtRowColEx(pos, token, tmpType, tmpKind,tmpStart, attri);
int tmpStart;
return getHighlighterAttriAtRowColEx(pos, token, tmpStart, attri);
}
bool SynEdit::getHighlighterAttriAtRowCol(const BufferCoord &pos, QString &token, bool &tokenFinished, TokenType &tokenType, PHighlighterAttribute &attri)
bool SynEdit::getHighlighterAttriAtRowCol(const BufferCoord &pos, QString &token, bool &tokenFinished, PHighlighterAttribute &attri)
{
int posX, posY, endPos, start;
QString line;
@ -389,7 +388,6 @@ bool SynEdit::getHighlighterAttriAtRowCol(const BufferCoord &pos, QString &token
tokenFinished = mHighlighter->getTokenFinished();
else
tokenFinished = false;
tokenType = mHighlighter->getTokenType();
return true;
}
mHighlighter->next();
@ -402,7 +400,7 @@ bool SynEdit::getHighlighterAttriAtRowCol(const BufferCoord &pos, QString &token
return false;
}
bool SynEdit::getHighlighterAttriAtRowColEx(const BufferCoord &pos, QString &token, TokenType &tokenType, TokenKind &tokenKind, int &start, PHighlighterAttribute &attri)
bool SynEdit::getHighlighterAttriAtRowColEx(const BufferCoord &pos, QString &token, int &start, PHighlighterAttribute &attri)
{
int posX, posY, endPos;
QString line;
@ -423,8 +421,6 @@ bool SynEdit::getHighlighterAttriAtRowColEx(const BufferCoord &pos, QString &tok
endPos = start + token.length()-1;
if ((posX >= start) && (posX <= endPos)) {
attri = mHighlighter->getTokenAttribute();
tokenKind = mHighlighter->getTokenKind();
tokenType = mHighlighter->getTokenType();
return true;
}
mHighlighter->next();
@ -433,8 +429,6 @@ bool SynEdit::getHighlighterAttriAtRowColEx(const BufferCoord &pos, QString &tok
}
token = "";
attri = PHighlighterAttribute();
tokenKind = 0;
tokenType = TokenType::Default;
return false;
}

View File

@ -250,11 +250,9 @@ public:
bool getHighlighterAttriAtRowCol(const BufferCoord& pos, QString& token,
PHighlighterAttribute& attri);
bool getHighlighterAttriAtRowCol(const BufferCoord& pos, QString& token,
bool& tokenFinished, TokenType& tokenType,
PHighlighterAttribute& attri);
bool& tokenFinished, PHighlighterAttribute& attri);
bool getHighlighterAttriAtRowColEx(const BufferCoord& pos, QString& token,
TokenType& tokenType, TokenKind &tokenKind, int &start,
PHighlighterAttribute& attri);
int &start, PHighlighterAttribute& attri);
void beginUndoBlock();
void endUndoBlock();

View File

@ -57,21 +57,21 @@ const QSet<QString> ASMHighlighter::Keywords {
ASMHighlighter::ASMHighlighter()
{
mCommentAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrComment);
mCommentAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrComment, TokenType::Comment);
mCommentAttribute->setStyles(FontStyle::fsItalic);
addAttribute(mCommentAttribute);
mIdentifierAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrIdentifier);
mIdentifierAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrIdentifier, TokenType::Identifier);
addAttribute(mIdentifierAttribute);
mKeywordAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrReservedWord);
mKeywordAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrReservedWord, TokenType::Keyword);
mKeywordAttribute->setStyles(FontStyle::fsBold);
addAttribute(mKeywordAttribute);
mNumberAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrNumber);
mNumberAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrNumber, TokenType::Number);
addAttribute(mNumberAttribute);
mWhitespaceAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrSpace);
mWhitespaceAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrSpace, TokenType::Space);
addAttribute(mWhitespaceAttribute);
mStringAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrString);
mStringAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrString, TokenType::String);
addAttribute(mStringAttribute);
mSymbolAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrSymbol);
mSymbolAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrSymbol, TokenType::Operator);
addAttribute(mSymbolAttribute);
}
@ -257,38 +257,12 @@ PHighlighterAttribute ASMHighlighter::getTokenAttribute() const
return mSymbolAttribute;
case TokenId::Unknown:
return mIdentifierAttribute;
default:
break;
}
return PHighlighterAttribute();
}
TokenKind ASMHighlighter::getTokenKind()
{
return mTokenID;
}
TokenType ASMHighlighter::getTokenType()
{
switch(mTokenID) {
case TokenId::Comment:
return TokenType::Comment;
case TokenId::Identifier:
return TokenType::Identifier;
case TokenId::Key:
return TokenType::Keyword;
case TokenId::Number:
return TokenType::Number;
case TokenId::Space:
return TokenType::Space;
case TokenId::String:
return TokenType::String;
case TokenId::Symbol:
return TokenType::Symbol;
case TokenId::Unknown:
return TokenType::Default;
}
return TokenType::Default;
}
int ASMHighlighter::getTokenPos()
{
return mTokenPos;

View File

@ -23,7 +23,7 @@ namespace QSynedit {
class ASMHighlighter : public Highlighter
{
enum TokenId {
enum class TokenId {
Comment,
Identifier,
Key,
@ -47,7 +47,7 @@ private:
int mStringLen;
QChar mToIdent;
int mTokenPos;
TokenKind mTokenID;
TokenId mTokenID;
PHighlighterAttribute mNumberAttribute;
private:
@ -75,8 +75,6 @@ public:
HighlighterLanguage language() override;
QString getToken() const override;
PHighlighterAttribute getTokenAttribute() const override;
TokenKind getTokenKind() override;
TokenType getTokenType() override;
int getTokenPos() override;
void next() override;
void setLine(const QString &newLine, int lineNumber) override;

View File

@ -65,11 +65,6 @@ PHighlighterAttribute Highlighter::symbolAttribute() const
return mSymbolAttribute;
}
TokenType Highlighter::getTokenType()
{
return TokenType::Default;
}
bool Highlighter::isKeyword(const QString &)
{
return false;
@ -162,13 +157,9 @@ int Highlighter::attributesCount() const
return mAttributes.size();
}
PHighlighterAttribute Highlighter::getAttribute(const QString &name) const
PHighlighterAttribute Highlighter::getAttribute(const QString& name) const
{
auto search = mAttributes.find(name);
if (search!=mAttributes.end()) {
return search.value();
}
return PHighlighterAttribute();
return mAttributes.value(name,PHighlighterAttribute());
}
bool Highlighter::enabled() const
@ -215,23 +206,22 @@ void HighlighterAttribute::setBackground(const QColor &background)
mBackground = background;
}
TokenType HighlighterAttribute::tokenType() const
{
return mTokenType;
}
QString HighlighterAttribute::name() const
{
return mName;
}
void HighlighterAttribute::setName(const QString &name)
{
if (mName!=name) {
mName = name;
}
}
HighlighterAttribute::HighlighterAttribute(const QString &name):
HighlighterAttribute::HighlighterAttribute(const QString &name, TokenType tokenType):
mForeground(QColor()),
mBackground(QColor()),
mName(name),
mStyles(FontStyle::fsNone)
mStyles(FontStyle::fsNone),
mTokenType(tokenType)
{
}

View File

@ -52,13 +52,27 @@ struct HighlighterState {
HighlighterState();
};
typedef int TokenKind;
enum class TokenType {
Default, Space, Comment,
PreprocessDirective, String, StringEscapeSequence,
Identifier, Symbol,
Character, Keyword, Number};
Default,
Comment, // any comment
Space,
String, // a string constant: "this is a string"
Character, // a character constant: 'c', '\n'
Number, // a number constant: 234, 0xff
Identifier, // any variable name
Keyword, // any keyword
Operator, // "sizeof", "+", "*", etc.
Preprocessor, //generic Preprocessor
Error,
Embeded //language embeded in others
};
enum class HighlighterClass {
Composition,
@ -76,10 +90,9 @@ enum class HighlighterLanguage {
class HighlighterAttribute {
public:
explicit HighlighterAttribute(const QString& name);
explicit HighlighterAttribute(const QString& name, TokenType mTokenType);
QString name() const;
void setName(const QString &name);
FontStyles styles() const;
void setStyles(const FontStyles &styles);
@ -90,11 +103,14 @@ public:
QColor background() const;
void setBackground(const QColor &background);
TokenType tokenType() const;
private:
QColor mForeground;
QColor mBackground;
QString mName;
FontStyles mStyles;
TokenType mTokenType;
};
typedef std::shared_ptr<HighlighterAttribute> PHighlighterAttribute;
@ -133,8 +149,6 @@ public:
virtual HighlighterState getState() const = 0;
virtual QString getToken() const=0;
virtual PHighlighterAttribute getTokenAttribute() const=0;
virtual TokenType getTokenType();
virtual TokenKind getTokenKind() = 0;
virtual int getTokenPos() = 0;
virtual bool isKeyword(const QString& word);
virtual void next() = 0;

View File

@ -38,7 +38,8 @@ HighlighterSchema::HighlighterSchema(QObject *parent):
QObject(parent),
mCaseSensitive(true)
{
mMarkerAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrMarker);
mMarkerAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrMarker,
QSynedit::TokenType::Default);
mMarkerAttribute->setForeground(Qt::yellow);
mMarkerAttribute->setStyles(FontStyle::fsBold);
}

View File

@ -143,47 +143,57 @@ const QSet<QString> CppHighlighter::Keywords {
};
CppHighlighter::CppHighlighter(): Highlighter()
{
mAsmAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrAssembler);
mAsmAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrAssembler,
TokenType::Embeded);
addAttribute(mAsmAttribute);
mCharAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrCharacter);
mCharAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrCharacter,
TokenType::Character);
addAttribute(mCharAttribute);
mCommentAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrComment);
addAttribute(mCommentAttribute);
mClassAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrClass);
addAttribute(mClassAttribute);
mFloatAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrFloat);
addAttribute(mFloatAttribute);
mFunctionAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrFunction);
addAttribute(mFunctionAttribute);
mGlobalVarAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrGlobalVariable);
addAttribute(mGlobalVarAttribute);
mHexAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrHexadecimal);
addAttribute(mHexAttribute);
mIdentifierAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrIdentifier);
addAttribute(mIdentifierAttribute);
mInvalidAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrIllegalChar);
addAttribute(mInvalidAttribute);
mLocalVarAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrLocalVariable);
addAttribute(mLocalVarAttribute);
mNumberAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrNumber);
addAttribute(mNumberAttribute);
mOctAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrOctal);
addAttribute(mOctAttribute);
mPreprocessorAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrPreprocessor);
addAttribute(mPreprocessorAttribute);
mKeywordAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrReservedWord);
addAttribute(mKeywordAttribute);
mWhitespaceAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrSpace);
addAttribute(mWhitespaceAttribute);
mStringAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrString);
addAttribute(mStringAttribute);
mStringEscapeSequenceAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrStringEscapeSequences);
addAttribute(mStringEscapeSequenceAttribute);
mSymbolAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrSymbol);
addAttribute(mSymbolAttribute);
mVariableAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrVariable);
addAttribute(mVariableAttribute);
mClassAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrClass,
TokenType::Identifier);
addAttribute(mClassAttribute);
mFloatAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrFloat,
TokenType::Number);
addAttribute(mFloatAttribute);
mFunctionAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrFunction,
TokenType::Identifier);
addAttribute(mFunctionAttribute);
mGlobalVarAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrGlobalVariable,
TokenType::Identifier);
addAttribute(mGlobalVarAttribute);
mHexAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrHexadecimal,
TokenType::Number);
addAttribute(mHexAttribute);
mIdentifierAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrIdentifier,
TokenType::Identifier);
addAttribute(mIdentifierAttribute);
mInvalidAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrIllegalChar,
TokenType::Error);
addAttribute(mInvalidAttribute);
mLocalVarAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrLocalVariable,
TokenType::Identifier);
addAttribute(mLocalVarAttribute);
mNumberAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrNumber,
TokenType::Number);
addAttribute(mNumberAttribute);
mOctAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrOctal,
TokenType::Number);
addAttribute(mOctAttribute);
mPreprocessorAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrPreprocessor,
TokenType::Preprocessor);
addAttribute(mPreprocessorAttribute);
mKeywordAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrReservedWord,
TokenType::Keyword);
addAttribute(mKeywordAttribute);
mStringEscapeSequenceAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrStringEscapeSequences,
TokenType::String);
addAttribute(mStringEscapeSequenceAttribute);
mVariableAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrVariable,
TokenType::Identifier);
addAttribute(mVariableAttribute);
resetState();
}
@ -257,12 +267,7 @@ PHighlighterAttribute CppHighlighter::localVarAttribute() const
return mLocalVarAttribute;
}
CppHighlighter::ExtTokenId CppHighlighter::getExtTokenId()
{
return mExtTokenId;
}
TokenKind CppHighlighter::getTokenId()
CppHighlighter::TokenId CppHighlighter::getTokenId()
{
if ((mRange.state == RangeState::rsAsm || mRange.state == RangeState::rsAsmBlock)
&& !mAsmStart && !(mTokenId == TokenId::Comment || mTokenId == TokenId::Space
@ -280,16 +285,13 @@ void CppHighlighter::andSymbolProc()
switch (mLine[mRun+1].unicode()) {
case '=':
mRun+=2;
mExtTokenId = ExtTokenId::AndAssign;
return;
case '&':
mRun+=2;
mExtTokenId = ExtTokenId::LogAnd;
return;
}
}
mRun+=1;
mExtTokenId = ExtTokenId::And;
}
void CppHighlighter::ansiCppProc()
@ -372,7 +374,6 @@ void CppHighlighter::braceCloseProc()
{
mRun += 1;
mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::BraceClose;
if (mRange.state == RangeState::rsAsmBlock) {
mRange.state = rsUnknown;
}
@ -392,7 +393,6 @@ void CppHighlighter::braceOpenProc()
{
mRun += 1;
mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::BraceOpen;
if (mRange.state == RangeState::rsAsm) {
mRange.state = RangeState::rsAsmBlock;
mAsmStart = true;
@ -420,10 +420,8 @@ void CppHighlighter::colonProc()
mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize && mLine[mRun+1]==':') {
mRun+=2;
mExtTokenId = ExtTokenId::ScopeResolution;
} else {
mRun+=1;
mExtTokenId = ExtTokenId::Colon;
}
}
@ -431,7 +429,6 @@ void CppHighlighter::commaProc()
{
mRun+=1;
mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::Comma;
}
void CppHighlighter::directiveProc()
@ -540,10 +537,8 @@ void CppHighlighter::equalProc()
mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize && mLine[mRun+1] == '=') {
mRun += 2;
mExtTokenId = ExtTokenId::LogEqual;
} else {
mRun += 1;
mExtTokenId = ExtTokenId::Assign;
}
}
@ -554,21 +549,17 @@ void CppHighlighter::greaterProc()
switch (mLine[mRun+1].unicode()) {
case '=':
mRun += 2;
mExtTokenId = ExtTokenId::GreaterThanEqual;
return;
case '>':
if (mRun+2<mLineSize && mLine[mRun+2] == '=') {
mRun+=3;
mExtTokenId = ExtTokenId::ShiftRightAssign;
} else {
mRun += 2;
mExtTokenId = ExtTokenId::ShiftRight;
}
return;
}
}
mRun+=1;
mExtTokenId = ExtTokenId::GreaterThan;
}
void CppHighlighter::identProc()
@ -596,21 +587,17 @@ void CppHighlighter::lowerProc()
switch(mLine[mRun+1].unicode()) {
case '=':
mRun+=2;
mExtTokenId = ExtTokenId::LessThanEqual;
return;
case '<':
if (mRun+2<mLineSize && mLine[mRun+2] == '=') {
mRun+=3;
mExtTokenId = ExtTokenId::ShiftLeftAssign;
} else {
mRun+=2;
mExtTokenId = ExtTokenId::ShiftLeft;
}
return;
}
}
mRun+=1;
mExtTokenId = ExtTokenId::LessThan;
}
void CppHighlighter::minusProc()
@ -620,25 +607,20 @@ void CppHighlighter::minusProc()
switch(mLine[mRun+1].unicode()) {
case '=':
mRun += 2;
mExtTokenId = ExtTokenId::SubtractAssign;
return;
case '-':
mRun += 2;
mExtTokenId = ExtTokenId::Decrement;
return;
case '>':
if (mRun+2<mLineSize && mLine[mRun+2]=='*') {
mRun += 3;
mExtTokenId = ExtTokenId::PointerToMemberOfPointer;
} else {
mRun += 2;
mExtTokenId = ExtTokenId::Arrow;
}
return;
}
}
mRun += 1;
mExtTokenId = ExtTokenId::Subtract;
}
void CppHighlighter::modSymbolProc()
@ -646,10 +628,8 @@ void CppHighlighter::modSymbolProc()
mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize && mLine[mRun+1]=='=') {
mRun += 2;
mExtTokenId = ExtTokenId::ModAssign;
} else {
mRun += 1;
mExtTokenId = ExtTokenId::Mod;
}
}
@ -658,10 +638,8 @@ void CppHighlighter::notSymbolProc()
mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize && mLine[mRun+1]=='=') {
mRun+=2;
mExtTokenId = ExtTokenId::NotEqual;
} else {
mRun+=1;
mExtTokenId = ExtTokenId::LogComplement;
}
}
@ -859,16 +837,13 @@ void CppHighlighter::orSymbolProc()
switch ( mLine[mRun+1].unicode()) {
case '=':
mRun+=2;
mExtTokenId = ExtTokenId::IncOrAssign;
return;
case '|':
mRun+=2;
mExtTokenId = ExtTokenId::LogOr;
return;
}
}
mRun+=1;
mExtTokenId = ExtTokenId::IncOr;
}
void CppHighlighter::plusProc()
@ -878,16 +853,13 @@ void CppHighlighter::plusProc()
switch(mLine[mRun+1].unicode()){
case '=':
mRun+=2;
mExtTokenId = ExtTokenId::AddAssign;
return;
case '+':
mRun+=2;
mExtTokenId = ExtTokenId::Increment;
return;
}
}
mRun+=1;
mExtTokenId = ExtTokenId::Add;
}
void CppHighlighter::pointProc()
@ -895,22 +867,18 @@ void CppHighlighter::pointProc()
mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize && mLine[mRun+1] == '*' ) {
mRun+=2;
mExtTokenId = ExtTokenId::PointerToMemberOfObject;
} else if (mRun+2<mLineSize && mLine[mRun+1] == '.' && mLine[mRun+2] == '.') {
mRun+=3;
mExtTokenId = ExtTokenId::Ellipse;
} else if (mRun+1<mLineSize && mLine[mRun+1]>='0' && mLine[mRun+1]<='9') {
numberProc();
} else {
mRun+=1;
mExtTokenId = ExtTokenId::Point;
}
}
void CppHighlighter::questionProc()
{
mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::Question;
mRun+=1;
}
@ -944,7 +912,6 @@ void CppHighlighter::roundCloseProc()
{
mRun += 1;
mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::RoundClose;
mRange.parenthesisLevel--;
if (mRange.parenthesisLevel<0)
mRange.parenthesisLevel=0;
@ -955,7 +922,6 @@ void CppHighlighter::roundOpenProc()
{
mRun += 1;
mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::RoundOpen;
mRange.parenthesisLevel++;
pushIndents(sitParenthesis);
}
@ -964,7 +930,6 @@ void CppHighlighter::semiColonProc()
{
mRun += 1;
mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::SemiColon;
if (mRange.state == RangeState::rsAsm)
mRange.state = RangeState::rsUnknown;
while (mRange.getLastIndent() == sitStatement) {
@ -999,20 +964,17 @@ void CppHighlighter::slashProc()
case '=':
mRun+=2;
mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::DivideAssign;
return;
}
}
mRun += 1;
mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::Divide;
}
void CppHighlighter::backSlashProc()
{
if (mRun+1==mLineSize-1) {
mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::BackSlash;
} else {
mTokenId = TokenId::Unknown;
}
@ -1032,7 +994,6 @@ void CppHighlighter::squareCloseProc()
{
mRun+=1;
mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::SquareClose;
mRange.bracketLevel--;
if (mRange.bracketLevel<0)
mRange.bracketLevel=0;
@ -1043,7 +1004,6 @@ void CppHighlighter::squareOpenProc()
{
mRun+=1;
mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::SquareOpen;
mRange.bracketLevel++;
pushIndents(sitBracket);
}
@ -1053,10 +1013,8 @@ void CppHighlighter::starProc()
mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize && mLine[mRun+1] == '=') {
mRun += 2;
mExtTokenId = ExtTokenId::MultiplyAssign;
} else {
mRun += 1;
mExtTokenId = ExtTokenId::Star;
}
}
@ -1277,7 +1235,6 @@ void CppHighlighter::tildeProc()
{
mRun+=1;
mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::BitComplement;
}
void CppHighlighter::unknownProc()
@ -1291,10 +1248,8 @@ void CppHighlighter::xorSymbolProc()
mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize && mLine[mRun+1]=='=') {
mRun+=2;
mExtTokenId = ExtTokenId::XorAssign;
} else {
mRun+=1;
mExtTokenId = ExtTokenId::Xor;
}
}
@ -1526,11 +1481,6 @@ PHighlighterAttribute CppHighlighter::getTokenAttribute() const
}
}
TokenKind CppHighlighter::getTokenKind()
{
return mTokenId;
}
int CppHighlighter::getTokenPos()
{
return mTokenPos;
@ -1640,58 +1590,6 @@ bool CppHighlighter::isKeyword(const QString &word)
return Keywords.contains(word) || mCustomTypeKeywords.contains(word);
}
TokenType CppHighlighter::getTokenType()
{
switch(mTokenId) {
case TokenId::Comment:
return TokenType::Comment;
case TokenId::Directive:
return TokenType::PreprocessDirective;
case TokenId::Identifier:
return TokenType::Identifier;
case TokenId::Key:
return TokenType::Keyword;
case TokenId::Space:
switch (mRange.state) {
case RangeState::rsAnsiC:
case RangeState::rsAnsiCAsm:
case RangeState::rsAnsiCAsmBlock:
case RangeState::rsAsm:
case RangeState::rsAsmBlock:
case RangeState::rsDirectiveComment:
case RangeState::rsCppComment:
return TokenType::Comment;
case RangeState::rsDirective:
case RangeState::rsMultiLineDirective:
return TokenType::PreprocessDirective;
case RangeState::rsString:
case RangeState::rsMultiLineString:
case RangeState::rsStringEscapeSeq:
case RangeState::rsMultiLineStringEscapeSeq:
case RangeState::rsRawString:
return TokenType::String;
case RangeState::rsChar :
return TokenType::Character;
default:
return TokenType::Space;
}
case TokenId::String:
return TokenType::String;
case TokenId::StringEscapeSeq:
return TokenType::StringEscapeSequence;
case TokenId::RawString:
return TokenType::String;
case TokenId::Char:
return TokenType::Character;
case TokenId::Symbol:
return TokenType::Symbol;
case TokenId::Number:
return TokenType::Number;
default:
return TokenType::Default;
}
}
void CppHighlighter::setState(const HighlighterState& rangeState)
{
mRange = rangeState;

View File

@ -23,8 +23,8 @@ namespace QSynedit {
class CppHighlighter: public Highlighter
{
enum TokenId {
Asm = 1,
enum class TokenId {
Asm,
Comment,
Directive,
Identifier,
@ -44,20 +44,6 @@ class CppHighlighter: public Highlighter
RawString
};
enum class ExtTokenId {
Add, AddAssign, And, AndAssign, Arrow, Assign,
BitComplement, BraceClose, BraceOpen, Colon, Comma,
Decrement, Divide, DivideAssign, Ellipse, GreaterThan,
GreaterThanEqual, IncOr, IncOrAssign, Increment, LessThan,
LessThanEqual, LogAnd, LogComplement, LogEqual, LogOr,
Mod, ModAssign, MultiplyAssign, NotEqual, Point, PointerToMemberOfObject,
PointerToMemberOfPointer,Question,
RoundClose, RoundOpen, ScopeResolution, SemiColon, ShiftLeft,
ShiftLeftAssign, ShiftRight, ShiftRightAssign, SquareClose,
SquareOpen, Star, Subtract, SubtractAssign, Xor,
XorAssign, BackSlash
};
enum RangeState {
rsUnknown, rsAnsiC, rsAnsiCAsm, rsAnsiCAsmBlock, rsAsm,
rsAsmBlock, rsDirective, rsDirectiveComment, rsString,
@ -100,8 +86,7 @@ public:
static const QSet<QString> Keywords;
ExtTokenId getExtTokenId();
TokenKind getTokenId();
TokenId getTokenId();
private:
void andSymbolProc();
void ansiCppProc();
@ -160,8 +145,7 @@ private:
int mStringLen;
int mToIdent;
int mTokenPos;
int mTokenId;
ExtTokenId mExtTokenId;
TokenId mTokenId;
int mLineNumber;
int mLeftBraces;
int mRightBraces;
@ -191,12 +175,10 @@ public:
bool eol() const override;
QString getToken() const override;
PHighlighterAttribute getTokenAttribute() const override;
TokenKind getTokenKind() override;
int getTokenPos() override;
void next() override;
void setLine(const QString &newLine, int lineNumber) override;
bool isKeyword(const QString &word) override;
TokenType getTokenType() override;
void setState(const HighlighterState& rangeState) override;
void resetState() override;
HighlighterClass getClass() const override;

View File

@ -7,13 +7,39 @@ class CustomHighlighterV1:public Highlighter
{
public:
CustomHighlighterV1();
protected:
bool mIgnoreCase;
QSet<QString> mKeywords;
QSet<QString> mTypeKeywords;
QSet<QString> mCallableKeywords;
QSet<QString> mKeywords1;
QSet<QString> mKeywords2;
QSet<QString> mKeywords3;
QSet<QString> mKeywords4;
QSet<QString> mKeywords5;
QSet<QString> mKeywords6;
QSet<QString> mOperators;
QString mLanguageName;
QSet<QString> mSuffixes;
HighlighterState mRange;
// SynRangeState mSpaceRange;
QString mLine;
int mLineSize;
int mRun;
int mStringLen;
int mTokenPos;
int mTokenId;
int mLineNumber;
int mLeftBraces;
int mRightBraces;
QSet<QString> mCustomTypeKeywords;
PHighlighterAttribute mInvalidAttribute;
PHighlighterAttribute mTypeKeywordAttribute;
PHighlighterAttribute mCallableAttribute;
};
}

View File

@ -83,45 +83,56 @@ const QSet<QString> GLSLHighlighter::Keywords {
GLSLHighlighter::GLSLHighlighter(): Highlighter()
{
mAsmAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrAssembler);
mAsmAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrAssembler,
TokenType::Embeded);
addAttribute(mAsmAttribute);
mCharAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrCharacter);
mCharAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrCharacter,
TokenType::Character);
addAttribute(mCharAttribute);
mCommentAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrComment);
addAttribute(mCommentAttribute);
mClassAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrClass);
mClassAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrClass,
TokenType::Identifier);
addAttribute(mClassAttribute);
mFloatAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrFloat);
mFloatAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrFloat,
TokenType::Number);
addAttribute(mFloatAttribute);
mFunctionAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrFunction);
mFunctionAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrFunction,
TokenType::Identifier);
addAttribute(mFunctionAttribute);
mGlobalVarAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrGlobalVariable);
mGlobalVarAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrGlobalVariable,
TokenType::Identifier);
addAttribute(mGlobalVarAttribute);
mHexAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrHexadecimal);
mHexAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrHexadecimal,
TokenType::Number);
addAttribute(mHexAttribute);
mIdentifierAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrIdentifier);
mIdentifierAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrIdentifier,
TokenType::Identifier);
addAttribute(mIdentifierAttribute);
mInvalidAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrIllegalChar);
mInvalidAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrIllegalChar,
TokenType::Error);
addAttribute(mInvalidAttribute);
mLocalVarAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrLocalVariable);
mLocalVarAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrLocalVariable,
TokenType::Identifier);
addAttribute(mLocalVarAttribute);
mNumberAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrNumber);
mNumberAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrNumber,
TokenType::Number);
addAttribute(mNumberAttribute);
mOctAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrOctal);
mOctAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrOctal,
TokenType::Number);
addAttribute(mOctAttribute);
mPreprocessorAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrPreprocessor);
mPreprocessorAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrPreprocessor,
TokenType::Preprocessor);
addAttribute(mPreprocessorAttribute);
mKeywordAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrReservedWord);
mKeywordAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrReservedWord,
TokenType::Keyword);
addAttribute(mKeywordAttribute);
mWhitespaceAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrSpace);
addAttribute(mWhitespaceAttribute);
mStringAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrString);
addAttribute(mStringAttribute);
mStringEscapeSequenceAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrStringEscapeSequences);
mStringEscapeSequenceAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrStringEscapeSequences,
TokenType::String);
addAttribute(mStringEscapeSequenceAttribute);
mSymbolAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrSymbol);
addAttribute(mSymbolAttribute);
mVariableAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrVariable);
mVariableAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrVariable,
TokenType::Identifier);
addAttribute(mVariableAttribute);
resetState();
@ -197,12 +208,7 @@ PHighlighterAttribute GLSLHighlighter::localVarAttribute() const
return mLocalVarAttribute;
}
GLSLHighlighter::ExtTokenId GLSLHighlighter::getExtTokenId()
{
return mExtTokenId;
}
TokenKind GLSLHighlighter::getTokenId()
GLSLHighlighter::TokenId GLSLHighlighter::getTokenId()
{
if ((mRange.state == RangeState::rsAsm || mRange.state == RangeState::rsAsmBlock)
&& !mAsmStart && !(mTokenId == TokenId::Comment || mTokenId == TokenId::Space
@ -219,15 +225,12 @@ void GLSLHighlighter::andSymbolProc()
switch (mLine[mRun+1].unicode()) {
case '=':
mRun+=2;
mExtTokenId = ExtTokenId::AndAssign;
break;
case '&':
mRun+=2;
mExtTokenId = ExtTokenId::LogAnd;
break;
default:
mRun+=1;
mExtTokenId = ExtTokenId::And;
}
}
@ -311,7 +314,6 @@ void GLSLHighlighter::braceCloseProc()
{
mRun += 1;
mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::BraceClose;
if (mRange.state == RangeState::rsAsmBlock) {
mRange.state = rsUnknown;
}
@ -331,7 +333,6 @@ void GLSLHighlighter::braceOpenProc()
{
mRun += 1;
mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::BraceOpen;
if (mRange.state == RangeState::rsAsm) {
mRange.state = RangeState::rsAsmBlock;
mAsmStart = true;
@ -359,10 +360,8 @@ void GLSLHighlighter::colonProc()
mTokenId = TokenId::Symbol;
if (mLine[mRun+1]==':') {
mRun+=2;
mExtTokenId = ExtTokenId::ScopeResolution;
} else {
mRun+=1;
mExtTokenId = ExtTokenId::Colon;
}
}
@ -370,7 +369,6 @@ void GLSLHighlighter::commaProc()
{
mRun+=1;
mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::Comma;
}
void GLSLHighlighter::directiveProc()
@ -453,10 +451,8 @@ void GLSLHighlighter::equalProc()
mTokenId = TokenId::Symbol;
if (mLine[mRun+1] == '=') {
mRun += 2;
mExtTokenId = ExtTokenId::LogEqual;
} else {
mRun += 1;
mExtTokenId = ExtTokenId::Assign;
}
}
@ -466,20 +462,16 @@ void GLSLHighlighter::greaterProc()
switch (mLine[mRun + 1].unicode()) {
case '=':
mRun += 2;
mExtTokenId = ExtTokenId::GreaterThanEqual;
break;
case '>':
if (mLine[mRun+2] == '=') {
mRun+=3;
mExtTokenId = ExtTokenId::ShiftRightAssign;
} else {
mRun += 2;
mExtTokenId = ExtTokenId::ShiftRight;
}
break;
default:
mRun+=1;
mExtTokenId = ExtTokenId::GreaterThan;
}
}
@ -507,20 +499,16 @@ void GLSLHighlighter::lowerProc()
switch(mLine[mRun+1].unicode()) {
case '=':
mRun+=2;
mExtTokenId = ExtTokenId::LessThanEqual;
break;
case '<':
if (mLine[mRun+2] == '=') {
mRun+=3;
mExtTokenId = ExtTokenId::ShiftLeftAssign;
} else {
mRun+=2;
mExtTokenId = ExtTokenId::ShiftLeft;
}
break;
default:
mRun+=1;
mExtTokenId = ExtTokenId::LessThan;
}
}
@ -530,24 +518,19 @@ void GLSLHighlighter::minusProc()
switch(mLine[mRun+1].unicode()) {
case '=':
mRun += 2;
mExtTokenId = ExtTokenId::SubtractAssign;
break;
case '-':
mRun += 2;
mExtTokenId = ExtTokenId::Decrement;
break;
case '>':
if (mLine[mRun+2]=='*') {
mRun += 3;
mExtTokenId = ExtTokenId::PointerToMemberOfPointer;
} else {
mRun += 2;
mExtTokenId = ExtTokenId::Arrow;
}
break;
default:
mRun += 1;
mExtTokenId = ExtTokenId::Subtract;
}
}
@ -557,11 +540,9 @@ void GLSLHighlighter::modSymbolProc()
switch(mLine[mRun + 1].unicode()) {
case '=':
mRun += 2;
mExtTokenId = ExtTokenId::ModAssign;
break;
default:
mRun += 1;
mExtTokenId = ExtTokenId::Mod;
}
}
@ -571,11 +552,9 @@ void GLSLHighlighter::notSymbolProc()
switch(mLine[mRun + 1].unicode()) {
case '=':
mRun+=2;
mExtTokenId = ExtTokenId::NotEqual;
break;
default:
mRun+=1;
mExtTokenId = ExtTokenId::LogComplement;
}
}
@ -768,15 +747,12 @@ void GLSLHighlighter::orSymbolProc()
switch ( mLine[mRun+1].unicode()) {
case '=':
mRun+=2;
mExtTokenId = ExtTokenId::IncOrAssign;
break;
case '|':
mRun+=2;
mExtTokenId = ExtTokenId::LogOr;
break;
default:
mRun+=1;
mExtTokenId = ExtTokenId::IncOr;
}
}
@ -786,15 +762,12 @@ void GLSLHighlighter::plusProc()
switch(mLine[mRun+1].unicode()){
case '=':
mRun+=2;
mExtTokenId = ExtTokenId::AddAssign;
break;
case '+':
mRun+=2;
mExtTokenId = ExtTokenId::Increment;
break;
default:
mRun+=1;
mExtTokenId = ExtTokenId::Add;
}
}
@ -803,22 +776,18 @@ void GLSLHighlighter::pointProc()
mTokenId = TokenId::Symbol;
if (mLine[mRun+1] == '*' ) {
mRun+=2;
mExtTokenId = ExtTokenId::PointerToMemberOfObject;
} else if (mLine[mRun+1] == '.' && mLine[mRun+2] == '.') {
mRun+=3;
mExtTokenId = ExtTokenId::Ellipse;
} else if (mLine[mRun+1]>='0' && mLine[mRun+1]<='9') {
numberProc();
} else {
mRun+=1;
mExtTokenId = ExtTokenId::Point;
}
}
void GLSLHighlighter::questionProc()
{
mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::Question;
mRun+=1;
}
@ -852,7 +821,6 @@ void GLSLHighlighter::roundCloseProc()
{
mRun += 1;
mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::RoundClose;
mRange.parenthesisLevel--;
if (mRange.parenthesisLevel<0)
mRange.parenthesisLevel=0;
@ -863,7 +831,6 @@ void GLSLHighlighter::roundOpenProc()
{
mRun += 1;
mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::RoundOpen;
mRange.parenthesisLevel++;
pushIndents(sitParenthesis);
}
@ -872,7 +839,6 @@ void GLSLHighlighter::semiColonProc()
{
mRun += 1;
mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::SemiColon;
if (mRange.state == RangeState::rsAsm)
mRange.state = RangeState::rsUnknown;
while (mRange.getLastIndent() == sitStatement) {
@ -906,12 +872,10 @@ void GLSLHighlighter::slashProc()
case '=':
mRun+=2;
mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::DivideAssign;
break;
default:
mRun += 1;
mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::Divide;
}
}
@ -928,7 +892,6 @@ void GLSLHighlighter::squareCloseProc()
{
mRun+=1;
mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::SquareClose;
mRange.bracketLevel--;
if (mRange.bracketLevel<0)
mRange.bracketLevel=0;
@ -939,7 +902,6 @@ void GLSLHighlighter::squareOpenProc()
{
mRun+=1;
mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::SquareOpen;
mRange.bracketLevel++;
pushIndents(sitBracket);
}
@ -949,10 +911,8 @@ void GLSLHighlighter::starProc()
mTokenId = TokenId::Symbol;
if (mLine[mRun+1] == '=') {
mRun += 2;
mExtTokenId = ExtTokenId::MultiplyAssign;
} else {
mRun += 1;
mExtTokenId = ExtTokenId::Star;
}
}
@ -1157,7 +1117,6 @@ void GLSLHighlighter::tildeProc()
{
mRun+=1;
mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::BitComplement;
}
void GLSLHighlighter::unknownProc()
@ -1171,10 +1130,8 @@ void GLSLHighlighter::xorSymbolProc()
mTokenId = TokenId::Symbol;
if (mLine[mRun+1]=='=') {
mRun+=2;
mExtTokenId = ExtTokenId::XorAssign;
} else {
mRun+=1;
mExtTokenId = ExtTokenId::Xor;
}
}
@ -1392,11 +1349,6 @@ PHighlighterAttribute GLSLHighlighter::getTokenAttribute() const
}
}
TokenKind GLSLHighlighter::getTokenKind()
{
return mTokenId;
}
int GLSLHighlighter::getTokenPos()
{
return mTokenPos;
@ -1478,58 +1430,6 @@ bool GLSLHighlighter::isKeyword(const QString &word)
return Keywords.contains(word);
}
TokenType GLSLHighlighter::getTokenType()
{
switch(mTokenId) {
case TokenId::Comment:
return TokenType::Comment;
case TokenId::Directive:
return TokenType::PreprocessDirective;
case TokenId::Identifier:
return TokenType::Identifier;
case TokenId::Key:
return TokenType::Keyword;
case TokenId::Space:
switch (mRange.state) {
case RangeState::rsAnsiC:
case RangeState::rsAnsiCAsm:
case RangeState::rsAnsiCAsmBlock:
case RangeState::rsAsm:
case RangeState::rsAsmBlock:
case RangeState::rsDirectiveComment:
case RangeState::rsCppComment:
return TokenType::Comment;
case RangeState::rsDirective:
case RangeState::rsMultiLineDirective:
return TokenType::PreprocessDirective;
case RangeState::rsString:
case RangeState::rsMultiLineString:
case RangeState::rsStringEscapeSeq:
case RangeState::rsMultiLineStringEscapeSeq:
case RangeState::rsRawString:
return TokenType::String;
case RangeState::rsChar :
return TokenType::Character;
default:
return TokenType::Space;
}
case TokenId::String:
return TokenType::String;
case TokenId::StringEscapeSeq:
return TokenType::StringEscapeSequence;
case TokenId::RawString:
return TokenType::String;
case TokenId::Char:
return TokenType::Character;
case TokenId::Symbol:
return TokenType::Symbol;
case TokenId::Number:
return TokenType::Number;
default:
return TokenType::Default;
}
}
void GLSLHighlighter::setState(const HighlighterState& rangeState)
{
mRange = rangeState;

View File

@ -23,8 +23,8 @@ namespace QSynedit {
class GLSLHighlighter: public Highlighter
{
enum TokenId {
Asm = 1,
enum class TokenId {
Asm,
Comment,
Directive,
Identifier,
@ -44,20 +44,6 @@ class GLSLHighlighter: public Highlighter
RawString
};
enum class ExtTokenId {
Add, AddAssign, And, AndAssign, Arrow, Assign,
BitComplement, BraceClose, BraceOpen, Colon, Comma,
Decrement, Divide, DivideAssign, Ellipse, GreaterThan,
GreaterThanEqual, IncOr, IncOrAssign, Increment, LessThan,
LessThanEqual, LogAnd, LogComplement, LogEqual, LogOr,
Mod, ModAssign, MultiplyAssign, NotEqual, Point, PointerToMemberOfObject,
PointerToMemberOfPointer,Question,
RoundClose, RoundOpen, ScopeResolution, SemiColon, ShiftLeft,
ShiftLeftAssign, ShiftRight, ShiftRightAssign, SquareClose,
SquareOpen, Star, Subtract, SubtractAssign, Xor,
XorAssign
};
enum RangeState {
rsUnknown, rsAnsiC, rsAnsiCAsm, rsAnsiCAsmBlock, rsAsm,
rsAsmBlock, rsDirective, rsDirectiveComment, rsString,
@ -100,8 +86,7 @@ public:
static const QSet<QString> Keywords;
ExtTokenId getExtTokenId();
TokenKind getTokenId();
TokenId getTokenId();
private:
void andSymbolProc();
void ansiCppProc();
@ -158,8 +143,7 @@ private:
int mStringLen;
int mToIdent;
int mTokenPos;
int mTokenId;
ExtTokenId mExtTokenId;
TokenId mTokenId;
int mLineNumber;
int mLeftBraces;
int mRightBraces;
@ -187,12 +171,10 @@ public:
bool eol() const override;
QString getToken() const override;
PHighlighterAttribute getTokenAttribute() const override;
TokenKind getTokenKind() override;
int getTokenPos() override;
void next() override;
void setLine(const QString &newLine, int lineNumber) override;
bool isKeyword(const QString &word) override;
TokenType getTokenType() override;
void setState(const HighlighterState& rangeState) override;
void resetState() override;
HighlighterClass getClass() const override;