- 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: 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: slightly reduce memory usage
- enhancement: Options -> editor -> custom C/C++ type keywords page - 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 Red Panda C++ Version 2.4

View File

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

View File

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

View File

@ -27,6 +27,9 @@
#include <QScreen> #include <QScreen>
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QHash> #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', const char ValueToChar[28] = {'0', '1', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
@ -3774,19 +3777,23 @@ void Settings::CodeCompletion::setShowCodeIns(bool newShowCodeIns)
bool Settings::CodeCompletion::clearWhenEditorHidden() bool Settings::CodeCompletion::clearWhenEditorHidden()
{ {
if (!mShareParser) {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
MEMORYSTATUSEX statex; MEMORYSTATUSEX statex;
statex.dwLength = sizeof (statex); statex.dwLength = sizeof (statex);
GlobalMemoryStatusEx (&statex);
GlobalMemoryStatusEx (&statex); if (statex.ullAvailPhys < (long long int)2*1024*1024*1024) {
if (statex.ullTotalPhys < (long long int)2*1024*1024*1024) { return true;
mClearWhenEditorHidden = true; }
} #elif defined(Q_OS_LINUX)
struct sysinfo si;
if (statex.ullAvailPhys < (long long int)2*1024*1024*1024) { sysinfo(&si);
return true; if (si.freeram < (long long int)2*1024*1024*1024) {
} return true;
}
#endif #endif
}
return mClearWhenEditorHidden; return mClearWhenEditorHidden;
} }
@ -3817,21 +3824,6 @@ void Settings::CodeCompletion::setHideSymbolsStartsWithTwoUnderLine(bool newHide
bool Settings::CodeCompletion::shareParser() 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; return mShareParser;
} }
@ -4001,8 +3993,8 @@ void Settings::CodeCompletion::doLoad()
mHideSymbolsStartsWithTwoUnderLine = boolValue("hide_symbols_start_with_two_underline", true); mHideSymbolsStartsWithTwoUnderLine = boolValue("hide_symbols_start_with_two_underline", true);
mHideSymbolsStartsWithUnderLine = boolValue("hide_symbols_start_with_underline", false); mHideSymbolsStartsWithUnderLine = boolValue("hide_symbols_start_with_underline", false);
bool doClear = true; bool shouldShare= true;
bool shouldShare=true; bool doClear = false;
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
MEMORYSTATUSEX statex; MEMORYSTATUSEX statex;
@ -4010,14 +4002,25 @@ void Settings::CodeCompletion::doLoad()
statex.dwLength = sizeof (statex); statex.dwLength = sizeof (statex);
GlobalMemoryStatusEx (&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; shouldShare = false;
} }
#endif #endif
mClearWhenEditorHidden = boolValue("clear_when_editor_hidden",doClear); mClearWhenEditorHidden = boolValue("clear_when_editor_hidden",doClear);
mShareParser = boolValue("share_parser",shouldShare); 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)) { if (!pMainWindow->editorList()->getContentFromOpenedEditor(filename,lines)) {
lines = readFileToLines(filename); lines = readFileToLines(filename);
} }
QSynedit::PHighlighterAttribute commentAttr = highlighter->getAttribute(SYNS_AttrComment);
highlighter->resetState(); highlighter->resetState();
for (int i =0;i<lines.count();i++) { for (int i =0;i<lines.count();i++) {
highlighter->setLine(lines[i],i); highlighter->setLine(lines[i],i);
while (!highlighter->eol()) { while (!highlighter->eol()) {
QSynedit::PHighlighterAttribute attr; QSynedit::PHighlighterAttribute attr;
attr = highlighter->getTokenAttribute(); attr = highlighter->getTokenAttribute();
if (attr == commentAttr) { if (attr && attr->tokenType() == QSynedit::TokenType::Comment) {
QString token = highlighter->getToken(); QString token = highlighter->getToken();
int pos = token.indexOf(todoReg); int pos = token.indexOf(todoReg);
if (pos>=0) { if (pos>=0) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -52,13 +52,27 @@ struct HighlighterState {
HighlighterState(); HighlighterState();
}; };
typedef int TokenKind;
enum class TokenType { enum class TokenType {
Default, Space, Comment, Default,
PreprocessDirective, String, StringEscapeSequence, Comment, // any comment
Identifier, Symbol, Space,
Character, Keyword, Number};
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 { enum class HighlighterClass {
Composition, Composition,
@ -76,10 +90,9 @@ enum class HighlighterLanguage {
class HighlighterAttribute { class HighlighterAttribute {
public: public:
explicit HighlighterAttribute(const QString& name); explicit HighlighterAttribute(const QString& name, TokenType mTokenType);
QString name() const; QString name() const;
void setName(const QString &name);
FontStyles styles() const; FontStyles styles() const;
void setStyles(const FontStyles &styles); void setStyles(const FontStyles &styles);
@ -90,11 +103,14 @@ public:
QColor background() const; QColor background() const;
void setBackground(const QColor &background); void setBackground(const QColor &background);
TokenType tokenType() const;
private: private:
QColor mForeground; QColor mForeground;
QColor mBackground; QColor mBackground;
QString mName; QString mName;
FontStyles mStyles; FontStyles mStyles;
TokenType mTokenType;
}; };
typedef std::shared_ptr<HighlighterAttribute> PHighlighterAttribute; typedef std::shared_ptr<HighlighterAttribute> PHighlighterAttribute;
@ -133,8 +149,6 @@ public:
virtual HighlighterState getState() const = 0; virtual HighlighterState getState() const = 0;
virtual QString getToken() const=0; virtual QString getToken() const=0;
virtual PHighlighterAttribute getTokenAttribute() const=0; virtual PHighlighterAttribute getTokenAttribute() const=0;
virtual TokenType getTokenType();
virtual TokenKind getTokenKind() = 0;
virtual int getTokenPos() = 0; virtual int getTokenPos() = 0;
virtual bool isKeyword(const QString& word); virtual bool isKeyword(const QString& word);
virtual void next() = 0; virtual void next() = 0;

View File

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

View File

@ -143,47 +143,57 @@ const QSet<QString> CppHighlighter::Keywords {
}; };
CppHighlighter::CppHighlighter(): Highlighter() CppHighlighter::CppHighlighter(): Highlighter()
{ {
mAsmAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrAssembler); mAsmAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrAssembler,
TokenType::Embeded);
addAttribute(mAsmAttribute); addAttribute(mAsmAttribute);
mCharAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrCharacter); mCharAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrCharacter,
TokenType::Character);
addAttribute(mCharAttribute); 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(); resetState();
} }
@ -257,12 +267,7 @@ PHighlighterAttribute CppHighlighter::localVarAttribute() const
return mLocalVarAttribute; return mLocalVarAttribute;
} }
CppHighlighter::ExtTokenId CppHighlighter::getExtTokenId() CppHighlighter::TokenId CppHighlighter::getTokenId()
{
return mExtTokenId;
}
TokenKind CppHighlighter::getTokenId()
{ {
if ((mRange.state == RangeState::rsAsm || mRange.state == RangeState::rsAsmBlock) if ((mRange.state == RangeState::rsAsm || mRange.state == RangeState::rsAsmBlock)
&& !mAsmStart && !(mTokenId == TokenId::Comment || mTokenId == TokenId::Space && !mAsmStart && !(mTokenId == TokenId::Comment || mTokenId == TokenId::Space
@ -280,16 +285,13 @@ void CppHighlighter::andSymbolProc()
switch (mLine[mRun+1].unicode()) { switch (mLine[mRun+1].unicode()) {
case '=': case '=':
mRun+=2; mRun+=2;
mExtTokenId = ExtTokenId::AndAssign;
return; return;
case '&': case '&':
mRun+=2; mRun+=2;
mExtTokenId = ExtTokenId::LogAnd;
return; return;
} }
} }
mRun+=1; mRun+=1;
mExtTokenId = ExtTokenId::And;
} }
void CppHighlighter::ansiCppProc() void CppHighlighter::ansiCppProc()
@ -372,7 +374,6 @@ void CppHighlighter::braceCloseProc()
{ {
mRun += 1; mRun += 1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::BraceClose;
if (mRange.state == RangeState::rsAsmBlock) { if (mRange.state == RangeState::rsAsmBlock) {
mRange.state = rsUnknown; mRange.state = rsUnknown;
} }
@ -392,7 +393,6 @@ void CppHighlighter::braceOpenProc()
{ {
mRun += 1; mRun += 1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::BraceOpen;
if (mRange.state == RangeState::rsAsm) { if (mRange.state == RangeState::rsAsm) {
mRange.state = RangeState::rsAsmBlock; mRange.state = RangeState::rsAsmBlock;
mAsmStart = true; mAsmStart = true;
@ -420,10 +420,8 @@ void CppHighlighter::colonProc()
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize && mLine[mRun+1]==':') { if (mRun+1<mLineSize && mLine[mRun+1]==':') {
mRun+=2; mRun+=2;
mExtTokenId = ExtTokenId::ScopeResolution;
} else { } else {
mRun+=1; mRun+=1;
mExtTokenId = ExtTokenId::Colon;
} }
} }
@ -431,7 +429,6 @@ void CppHighlighter::commaProc()
{ {
mRun+=1; mRun+=1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::Comma;
} }
void CppHighlighter::directiveProc() void CppHighlighter::directiveProc()
@ -540,10 +537,8 @@ void CppHighlighter::equalProc()
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize && mLine[mRun+1] == '=') { if (mRun+1<mLineSize && mLine[mRun+1] == '=') {
mRun += 2; mRun += 2;
mExtTokenId = ExtTokenId::LogEqual;
} else { } else {
mRun += 1; mRun += 1;
mExtTokenId = ExtTokenId::Assign;
} }
} }
@ -554,21 +549,17 @@ void CppHighlighter::greaterProc()
switch (mLine[mRun+1].unicode()) { switch (mLine[mRun+1].unicode()) {
case '=': case '=':
mRun += 2; mRun += 2;
mExtTokenId = ExtTokenId::GreaterThanEqual;
return; return;
case '>': case '>':
if (mRun+2<mLineSize && mLine[mRun+2] == '=') { if (mRun+2<mLineSize && mLine[mRun+2] == '=') {
mRun+=3; mRun+=3;
mExtTokenId = ExtTokenId::ShiftRightAssign;
} else { } else {
mRun += 2; mRun += 2;
mExtTokenId = ExtTokenId::ShiftRight;
} }
return; return;
} }
} }
mRun+=1; mRun+=1;
mExtTokenId = ExtTokenId::GreaterThan;
} }
void CppHighlighter::identProc() void CppHighlighter::identProc()
@ -596,21 +587,17 @@ void CppHighlighter::lowerProc()
switch(mLine[mRun+1].unicode()) { switch(mLine[mRun+1].unicode()) {
case '=': case '=':
mRun+=2; mRun+=2;
mExtTokenId = ExtTokenId::LessThanEqual;
return; return;
case '<': case '<':
if (mRun+2<mLineSize && mLine[mRun+2] == '=') { if (mRun+2<mLineSize && mLine[mRun+2] == '=') {
mRun+=3; mRun+=3;
mExtTokenId = ExtTokenId::ShiftLeftAssign;
} else { } else {
mRun+=2; mRun+=2;
mExtTokenId = ExtTokenId::ShiftLeft;
} }
return; return;
} }
} }
mRun+=1; mRun+=1;
mExtTokenId = ExtTokenId::LessThan;
} }
void CppHighlighter::minusProc() void CppHighlighter::minusProc()
@ -620,25 +607,20 @@ void CppHighlighter::minusProc()
switch(mLine[mRun+1].unicode()) { switch(mLine[mRun+1].unicode()) {
case '=': case '=':
mRun += 2; mRun += 2;
mExtTokenId = ExtTokenId::SubtractAssign;
return; return;
case '-': case '-':
mRun += 2; mRun += 2;
mExtTokenId = ExtTokenId::Decrement;
return; return;
case '>': case '>':
if (mRun+2<mLineSize && mLine[mRun+2]=='*') { if (mRun+2<mLineSize && mLine[mRun+2]=='*') {
mRun += 3; mRun += 3;
mExtTokenId = ExtTokenId::PointerToMemberOfPointer;
} else { } else {
mRun += 2; mRun += 2;
mExtTokenId = ExtTokenId::Arrow;
} }
return; return;
} }
} }
mRun += 1; mRun += 1;
mExtTokenId = ExtTokenId::Subtract;
} }
void CppHighlighter::modSymbolProc() void CppHighlighter::modSymbolProc()
@ -646,10 +628,8 @@ void CppHighlighter::modSymbolProc()
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize && mLine[mRun+1]=='=') { if (mRun+1<mLineSize && mLine[mRun+1]=='=') {
mRun += 2; mRun += 2;
mExtTokenId = ExtTokenId::ModAssign;
} else { } else {
mRun += 1; mRun += 1;
mExtTokenId = ExtTokenId::Mod;
} }
} }
@ -658,10 +638,8 @@ void CppHighlighter::notSymbolProc()
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize && mLine[mRun+1]=='=') { if (mRun+1<mLineSize && mLine[mRun+1]=='=') {
mRun+=2; mRun+=2;
mExtTokenId = ExtTokenId::NotEqual;
} else { } else {
mRun+=1; mRun+=1;
mExtTokenId = ExtTokenId::LogComplement;
} }
} }
@ -859,16 +837,13 @@ void CppHighlighter::orSymbolProc()
switch ( mLine[mRun+1].unicode()) { switch ( mLine[mRun+1].unicode()) {
case '=': case '=':
mRun+=2; mRun+=2;
mExtTokenId = ExtTokenId::IncOrAssign;
return; return;
case '|': case '|':
mRun+=2; mRun+=2;
mExtTokenId = ExtTokenId::LogOr;
return; return;
} }
} }
mRun+=1; mRun+=1;
mExtTokenId = ExtTokenId::IncOr;
} }
void CppHighlighter::plusProc() void CppHighlighter::plusProc()
@ -878,16 +853,13 @@ void CppHighlighter::plusProc()
switch(mLine[mRun+1].unicode()){ switch(mLine[mRun+1].unicode()){
case '=': case '=':
mRun+=2; mRun+=2;
mExtTokenId = ExtTokenId::AddAssign;
return; return;
case '+': case '+':
mRun+=2; mRun+=2;
mExtTokenId = ExtTokenId::Increment;
return; return;
} }
} }
mRun+=1; mRun+=1;
mExtTokenId = ExtTokenId::Add;
} }
void CppHighlighter::pointProc() void CppHighlighter::pointProc()
@ -895,22 +867,18 @@ void CppHighlighter::pointProc()
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize && mLine[mRun+1] == '*' ) { if (mRun+1<mLineSize && mLine[mRun+1] == '*' ) {
mRun+=2; mRun+=2;
mExtTokenId = ExtTokenId::PointerToMemberOfObject;
} else if (mRun+2<mLineSize && mLine[mRun+1] == '.' && mLine[mRun+2] == '.') { } else if (mRun+2<mLineSize && mLine[mRun+1] == '.' && mLine[mRun+2] == '.') {
mRun+=3; mRun+=3;
mExtTokenId = ExtTokenId::Ellipse;
} else if (mRun+1<mLineSize && mLine[mRun+1]>='0' && mLine[mRun+1]<='9') { } else if (mRun+1<mLineSize && mLine[mRun+1]>='0' && mLine[mRun+1]<='9') {
numberProc(); numberProc();
} else { } else {
mRun+=1; mRun+=1;
mExtTokenId = ExtTokenId::Point;
} }
} }
void CppHighlighter::questionProc() void CppHighlighter::questionProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::Question;
mRun+=1; mRun+=1;
} }
@ -944,7 +912,6 @@ void CppHighlighter::roundCloseProc()
{ {
mRun += 1; mRun += 1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::RoundClose;
mRange.parenthesisLevel--; mRange.parenthesisLevel--;
if (mRange.parenthesisLevel<0) if (mRange.parenthesisLevel<0)
mRange.parenthesisLevel=0; mRange.parenthesisLevel=0;
@ -955,7 +922,6 @@ void CppHighlighter::roundOpenProc()
{ {
mRun += 1; mRun += 1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::RoundOpen;
mRange.parenthesisLevel++; mRange.parenthesisLevel++;
pushIndents(sitParenthesis); pushIndents(sitParenthesis);
} }
@ -964,7 +930,6 @@ void CppHighlighter::semiColonProc()
{ {
mRun += 1; mRun += 1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::SemiColon;
if (mRange.state == RangeState::rsAsm) if (mRange.state == RangeState::rsAsm)
mRange.state = RangeState::rsUnknown; mRange.state = RangeState::rsUnknown;
while (mRange.getLastIndent() == sitStatement) { while (mRange.getLastIndent() == sitStatement) {
@ -999,20 +964,17 @@ void CppHighlighter::slashProc()
case '=': case '=':
mRun+=2; mRun+=2;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::DivideAssign;
return; return;
} }
} }
mRun += 1; mRun += 1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::Divide;
} }
void CppHighlighter::backSlashProc() void CppHighlighter::backSlashProc()
{ {
if (mRun+1==mLineSize-1) { if (mRun+1==mLineSize-1) {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::BackSlash;
} else { } else {
mTokenId = TokenId::Unknown; mTokenId = TokenId::Unknown;
} }
@ -1032,7 +994,6 @@ void CppHighlighter::squareCloseProc()
{ {
mRun+=1; mRun+=1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::SquareClose;
mRange.bracketLevel--; mRange.bracketLevel--;
if (mRange.bracketLevel<0) if (mRange.bracketLevel<0)
mRange.bracketLevel=0; mRange.bracketLevel=0;
@ -1043,7 +1004,6 @@ void CppHighlighter::squareOpenProc()
{ {
mRun+=1; mRun+=1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::SquareOpen;
mRange.bracketLevel++; mRange.bracketLevel++;
pushIndents(sitBracket); pushIndents(sitBracket);
} }
@ -1053,10 +1013,8 @@ void CppHighlighter::starProc()
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize && mLine[mRun+1] == '=') { if (mRun+1<mLineSize && mLine[mRun+1] == '=') {
mRun += 2; mRun += 2;
mExtTokenId = ExtTokenId::MultiplyAssign;
} else { } else {
mRun += 1; mRun += 1;
mExtTokenId = ExtTokenId::Star;
} }
} }
@ -1277,7 +1235,6 @@ void CppHighlighter::tildeProc()
{ {
mRun+=1; mRun+=1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
mExtTokenId = ExtTokenId::BitComplement;
} }
void CppHighlighter::unknownProc() void CppHighlighter::unknownProc()
@ -1291,10 +1248,8 @@ void CppHighlighter::xorSymbolProc()
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize && mLine[mRun+1]=='=') { if (mRun+1<mLineSize && mLine[mRun+1]=='=') {
mRun+=2; mRun+=2;
mExtTokenId = ExtTokenId::XorAssign;
} else { } else {
mRun+=1; mRun+=1;
mExtTokenId = ExtTokenId::Xor;
} }
} }
@ -1526,11 +1481,6 @@ PHighlighterAttribute CppHighlighter::getTokenAttribute() const
} }
} }
TokenKind CppHighlighter::getTokenKind()
{
return mTokenId;
}
int CppHighlighter::getTokenPos() int CppHighlighter::getTokenPos()
{ {
return mTokenPos; return mTokenPos;
@ -1640,58 +1590,6 @@ bool CppHighlighter::isKeyword(const QString &word)
return Keywords.contains(word) || mCustomTypeKeywords.contains(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) void CppHighlighter::setState(const HighlighterState& rangeState)
{ {
mRange = rangeState; mRange = rangeState;

View File

@ -23,8 +23,8 @@ namespace QSynedit {
class CppHighlighter: public Highlighter class CppHighlighter: public Highlighter
{ {
enum TokenId { enum class TokenId {
Asm = 1, Asm,
Comment, Comment,
Directive, Directive,
Identifier, Identifier,
@ -44,20 +44,6 @@ class CppHighlighter: public Highlighter
RawString 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 { enum RangeState {
rsUnknown, rsAnsiC, rsAnsiCAsm, rsAnsiCAsmBlock, rsAsm, rsUnknown, rsAnsiC, rsAnsiCAsm, rsAnsiCAsmBlock, rsAsm,
rsAsmBlock, rsDirective, rsDirectiveComment, rsString, rsAsmBlock, rsDirective, rsDirectiveComment, rsString,
@ -100,8 +86,7 @@ public:
static const QSet<QString> Keywords; static const QSet<QString> Keywords;
ExtTokenId getExtTokenId(); TokenId getTokenId();
TokenKind getTokenId();
private: private:
void andSymbolProc(); void andSymbolProc();
void ansiCppProc(); void ansiCppProc();
@ -160,8 +145,7 @@ private:
int mStringLen; int mStringLen;
int mToIdent; int mToIdent;
int mTokenPos; int mTokenPos;
int mTokenId; TokenId mTokenId;
ExtTokenId mExtTokenId;
int mLineNumber; int mLineNumber;
int mLeftBraces; int mLeftBraces;
int mRightBraces; int mRightBraces;
@ -191,12 +175,10 @@ public:
bool eol() const override; bool eol() const override;
QString getToken() const override; QString getToken() const override;
PHighlighterAttribute getTokenAttribute() const override; PHighlighterAttribute getTokenAttribute() const override;
TokenKind getTokenKind() override;
int getTokenPos() override; int getTokenPos() override;
void next() override; void next() override;
void setLine(const QString &newLine, int lineNumber) override; void setLine(const QString &newLine, int lineNumber) override;
bool isKeyword(const QString &word) override; bool isKeyword(const QString &word) override;
TokenType getTokenType() override;
void setState(const HighlighterState& rangeState) override; void setState(const HighlighterState& rangeState) override;
void resetState() override; void resetState() override;
HighlighterClass getClass() const override; HighlighterClass getClass() const override;

View File

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

View File

@ -23,8 +23,8 @@ namespace QSynedit {
class GLSLHighlighter: public Highlighter class GLSLHighlighter: public Highlighter
{ {
enum TokenId { enum class TokenId {
Asm = 1, Asm,
Comment, Comment,
Directive, Directive,
Identifier, Identifier,
@ -44,20 +44,6 @@ class GLSLHighlighter: public Highlighter
RawString 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 { enum RangeState {
rsUnknown, rsAnsiC, rsAnsiCAsm, rsAnsiCAsmBlock, rsAsm, rsUnknown, rsAnsiC, rsAnsiCAsm, rsAnsiCAsmBlock, rsAsm,
rsAsmBlock, rsDirective, rsDirectiveComment, rsString, rsAsmBlock, rsDirective, rsDirectiveComment, rsString,
@ -100,8 +86,7 @@ public:
static const QSet<QString> Keywords; static const QSet<QString> Keywords;
ExtTokenId getExtTokenId(); TokenId getTokenId();
TokenKind getTokenId();
private: private:
void andSymbolProc(); void andSymbolProc();
void ansiCppProc(); void ansiCppProc();
@ -158,8 +143,7 @@ private:
int mStringLen; int mStringLen;
int mToIdent; int mToIdent;
int mTokenPos; int mTokenPos;
int mTokenId; TokenId mTokenId;
ExtTokenId mExtTokenId;
int mLineNumber; int mLineNumber;
int mLeftBraces; int mLeftBraces;
int mRightBraces; int mRightBraces;
@ -187,12 +171,10 @@ public:
bool eol() const override; bool eol() const override;
QString getToken() const override; QString getToken() const override;
PHighlighterAttribute getTokenAttribute() const override; PHighlighterAttribute getTokenAttribute() const override;
TokenKind getTokenKind() override;
int getTokenPos() override; int getTokenPos() override;
void next() override; void next() override;
void setLine(const QString &newLine, int lineNumber) override; void setLine(const QString &newLine, int lineNumber) override;
bool isKeyword(const QString &word) override; bool isKeyword(const QString &word) override;
TokenType getTokenType() override;
void setState(const HighlighterState& rangeState) override; void setState(const HighlighterState& rangeState) override;
void resetState() override; void resetState() override;
HighlighterClass getClass() const override; HighlighterClass getClass() const override;