refactor Highlighters

This commit is contained in:
Roy Qu 2022-12-10 20:41:07 +08:00
parent 5d0c49a0bc
commit 51743799c8
20 changed files with 183 additions and 183 deletions

View File

@ -33,16 +33,16 @@ HighlighterManager::HighlighterManager()
} }
QSynedit::PHighlighter HighlighterManager::getHighlighter(QSynedit::HighlighterLanguage language) QSynedit::PHighlighter HighlighterManager::getHighlighter(QSynedit::ProgrammingLanguage language)
{ {
switch(language) { switch(language) {
case QSynedit::HighlighterLanguage::Cpp: case QSynedit::ProgrammingLanguage::Cpp:
return getCppHighlighter(); return getCppHighlighter();
case QSynedit::HighlighterLanguage::Asssembly: case QSynedit::ProgrammingLanguage::Asssembly:
return getAsmHighlighter(); return getAsmHighlighter();
case QSynedit::HighlighterLanguage::Makefile: case QSynedit::ProgrammingLanguage::Makefile:
return getMakefileHighlighter(); return getMakefileHighlighter();
case QSynedit::HighlighterLanguage::GLSL: case QSynedit::ProgrammingLanguage::GLSL:
return getGLSLHighlighter(); return getGLSLHighlighter();
default: default:
return QSynedit::PHighlighter(); return QSynedit::PHighlighter();

View File

@ -23,7 +23,7 @@ class HighlighterManager
public: public:
HighlighterManager(); HighlighterManager();
QSynedit::PHighlighter getHighlighter(QSynedit::HighlighterLanguage language); QSynedit::PHighlighter getHighlighter(QSynedit::ProgrammingLanguage language);
QSynedit::PHighlighter getHighlighter(const QString& filename); QSynedit::PHighlighter getHighlighter(const QString& filename);
QSynedit::PHighlighter copyHighlighter(QSynedit::PHighlighter highlighter); QSynedit::PHighlighter copyHighlighter(QSynedit::PHighlighter highlighter);
QSynedit::PHighlighter getCppHighlighter(); QSynedit::PHighlighter getCppHighlighter();

View File

@ -390,7 +390,7 @@ bool Editor::saveAs(const QString &name, bool fromProject){
setUseCodeFolding(false); setUseCodeFolding(false);
} }
setHighlighter(newHighlighter); setHighlighter(newHighlighter);
if (!newHighlighter || newHighlighter->language() != QSynedit::HighlighterLanguage::Cpp) { if (!newHighlighter || newHighlighter->language() != QSynedit::ProgrammingLanguage::Cpp) {
mSyntaxIssues.clear(); mSyntaxIssues.clear();
} }
applyColorScheme(pSettings->editor().colorScheme()); applyColorScheme(pSettings->editor().colorScheme());
@ -1037,7 +1037,7 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
if (CppTypeKeywords.contains(token) if (CppTypeKeywords.contains(token)
|| ||
( (
highlighter()->language()==QSynedit::HighlighterLanguage::Cpp highlighter()->language()==QSynedit::ProgrammingLanguage::Cpp
&& &&
((QSynedit::CppHighlighter*)highlighter().get())->customTypeKeywords().contains(token) ((QSynedit::CppHighlighter*)highlighter().get())->customTypeKeywords().contains(token)
) )
@ -2350,7 +2350,7 @@ bool Editor::handleParentheseSkip()
if (document()->count()==0) if (document()->count()==0)
return false; return false;
if (highlighter() && highlighter()->supportBraceLevel()) { if (highlighter() && highlighter()->supportBraceLevel()) {
QSynedit::HighlighterState lastLineState = document()->ranges(document()->count()-1); QSynedit::SyntaxerState lastLineState = document()->ranges(document()->count()-1);
if (lastLineState.parenthesisLevel==0) { if (lastLineState.parenthesisLevel==0) {
setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over
return true; return true;
@ -2401,7 +2401,7 @@ bool Editor::handleBracketSkip()
if (document()->count()==0) if (document()->count()==0)
return false; return false;
if (highlighter() && highlighter()->supportBraceLevel()) { if (highlighter() && highlighter()->supportBraceLevel()) {
QSynedit::HighlighterState lastLineState = document()->ranges(document()->count()-1); QSynedit::SyntaxerState lastLineState = document()->ranges(document()->count()-1);
if (lastLineState.bracketLevel==0) { if (lastLineState.bracketLevel==0) {
setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over
return true; return true;
@ -2488,7 +2488,7 @@ bool Editor::handleBraceSkip()
return false; return false;
if (highlighter() && highlighter()->supportBraceLevel()) { if (highlighter() && highlighter()->supportBraceLevel()) {
QSynedit::HighlighterState lastLineState = document()->ranges(document()->count()-1); QSynedit::SyntaxerState lastLineState = document()->ranges(document()->count()-1);
if (lastLineState.braceLevel==0) { if (lastLineState.braceLevel==0) {
bool oldInsertMode = insertMode(); bool oldInsertMode = insertMode();
setInsertMode(false); //set mode to overwrite setInsertMode(false); //set mode to overwrite
@ -2662,7 +2662,7 @@ void Editor::initParser()
{ {
if (pSettings->codeCompletion().shareParser()) { if (pSettings->codeCompletion().shareParser()) {
if (pSettings->codeCompletion().enabled() if (pSettings->codeCompletion().enabled()
&& (highlighter() && highlighter()->language() == QSynedit::HighlighterLanguage::Cpp) && (highlighter() && highlighter()->language() == QSynedit::ProgrammingLanguage::Cpp)
) { ) {
mParser = sharedParser(mUseCppSyntax?ParserLanguage::CPlusPlus:ParserLanguage::C); mParser = sharedParser(mUseCppSyntax?ParserLanguage::CPlusPlus:ParserLanguage::C);
} }
@ -2682,7 +2682,7 @@ void Editor::initParser()
resetCppParser(mParser); resetCppParser(mParser);
mParser->setEnabled( mParser->setEnabled(
pSettings->codeCompletion().enabled() && pSettings->codeCompletion().enabled() &&
(highlighter() && highlighter()->language() == QSynedit::HighlighterLanguage::Cpp)); (highlighter() && highlighter()->language() == QSynedit::ProgrammingLanguage::Cpp));
} }
Editor::QuoteStatus Editor::getQuoteStatus() Editor::QuoteStatus Editor::getQuoteStatus()
@ -2814,8 +2814,8 @@ void Editor::reparse(bool resetParser)
return; return;
if (!highlighter()) if (!highlighter())
return; return;
if (highlighter()->language() != QSynedit::HighlighterLanguage::Cpp if (highlighter()->language() != QSynedit::ProgrammingLanguage::Cpp
&& highlighter()->language() != QSynedit::HighlighterLanguage::GLSL) && highlighter()->language() != QSynedit::ProgrammingLanguage::GLSL)
return; return;
if (!mParser) if (!mParser)
return; return;
@ -3122,7 +3122,7 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete, CodeComple
QSet<QString> keywords; QSet<QString> keywords;
if (highlighter()) { if (highlighter()) {
if (highlighter()->language() != QSynedit::HighlighterLanguage::Cpp ) { if (highlighter()->language() != QSynedit::ProgrammingLanguage::Cpp ) {
keywords = highlighter()->keywords(); keywords = highlighter()->keywords();
} else { } else {
if (mUseCppSyntax) { if (mUseCppSyntax) {
@ -4582,7 +4582,7 @@ void Editor::checkSyntaxInBack()
return; return;
if (!highlighter()) if (!highlighter())
return; return;
if (highlighter()->language()!=QSynedit::HighlighterLanguage::Cpp) if (highlighter()->language()!=QSynedit::ProgrammingLanguage::Cpp)
return; return;
pMainWindow->checkSyntaxInBack(this); pMainWindow->checkSyntaxInBack(this);
} }
@ -4792,14 +4792,14 @@ void Editor::applySettings()
} }
if (pSettings->editor().enableCustomCTypeKeywords()) { if (pSettings->editor().enableCustomCTypeKeywords()) {
if (highlighter() && highlighter()->language() == QSynedit::HighlighterLanguage::Cpp) { if (highlighter() && highlighter()->language() == QSynedit::ProgrammingLanguage::Cpp) {
QSet<QString> set; QSet<QString> set;
foreach(const QString& s, pSettings->editor().customCTypeKeywords()) foreach(const QString& s, pSettings->editor().customCTypeKeywords())
set.insert(s); set.insert(s);
((QSynedit::CppHighlighter*)(highlighter().get()))->setCustomTypeKeywords(set); ((QSynedit::CppHighlighter*)(highlighter().get()))->setCustomTypeKeywords(set);
} }
} else { } else {
if (highlighter() && highlighter()->language() == QSynedit::HighlighterLanguage::Cpp) { if (highlighter() && highlighter()->language() == QSynedit::ProgrammingLanguage::Cpp) {
((QSynedit::CppHighlighter*)(highlighter().get()))->setCustomTypeKeywords(QSet<QString>()); ((QSynedit::CppHighlighter*)(highlighter().get()))->setCustomTypeKeywords(QSet<QString>());
} }
} }
@ -4815,7 +4815,7 @@ 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::TokenAttribute>(attrName,
QSynedit::TokenType::Default); QSynedit::TokenType::Default);
attr->setForeground(item->foreground()); attr->setForeground(item->foreground());
attr->setBackground(item->background()); attr->setBackground(item->background());

View File

@ -1236,7 +1236,7 @@ int SynEdit::findIndentsStartLine(int line, QVector<int> indents)
if (line<0 || line>=mDocument->count()) if (line<0 || line>=mDocument->count())
return -1; return -1;
while (line>=1) { while (line>=1) {
HighlighterState range = mDocument->ranges(line); SyntaxerState range = mDocument->ranges(line);
QVector<int> newIndents = range.indents.mid(range.firstIndentThisLine); QVector<int> newIndents = range.indents.mid(range.firstIndentThisLine);
int i = 0; int i = 0;
int len = indents.length(); int len = indents.length();
@ -1535,7 +1535,7 @@ void SynEdit::doShrinkSelection(const BufferCoord &/*pos*/)
int SynEdit::findCommentStartLine(int searchStartLine) int SynEdit::findCommentStartLine(int searchStartLine)
{ {
int commentStartLine = searchStartLine; int commentStartLine = searchStartLine;
HighlighterState range; SyntaxerState range;
while (commentStartLine>=1) { while (commentStartLine>=1) {
range = mDocument->ranges(commentStartLine-1); range = mDocument->ranges(commentStartLine-1);
if (!mHighlighter->isLastLineCommentNotFinished(range.state)){ if (!mHighlighter->isLastLineCommentNotFinished(range.state)){
@ -1573,7 +1573,7 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
if (startLine>=1) { if (startLine>=1) {
//calculate the indents of last statement; //calculate the indents of last statement;
indentSpaces = leftSpaces(startLineText); indentSpaces = leftSpaces(startLineText);
HighlighterState rangePreceeding = mDocument->ranges(startLine-1); SyntaxerState rangePreceeding = mDocument->ranges(startLine-1);
mHighlighter->setState(rangePreceeding); mHighlighter->setState(rangePreceeding);
if (addIndent) { if (addIndent) {
// QString trimmedS = s.trimmed(); // QString trimmedS = s.trimmed();
@ -1585,7 +1585,7 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
} else { } else {
statePrePre = 0; statePrePre = 0;
} }
HighlighterState rangeAfterFirstToken = mHighlighter->getState(); SyntaxerState rangeAfterFirstToken = mHighlighter->getState();
QString firstToken = mHighlighter->getToken(); QString firstToken = mHighlighter->getToken();
PHighlighterAttribute attr = mHighlighter->getTokenAttribute(); PHighlighterAttribute attr = mHighlighter->getTokenAttribute();
if (attr->tokenType() == TokenType::Keyword if (attr->tokenType() == TokenType::Keyword
@ -1614,18 +1614,18 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
l = startLine; l = startLine;
} else if (attr->tokenType() == TokenType::Operator } else if (attr->tokenType() == TokenType::Operator
&& (firstToken == '{') && (firstToken == '{')
&& (rangePreceeding.getLastIndent()==sitStatement)) { && (rangePreceeding.getLastIndent()==IndentForStatement)) {
// current line starts with '{' and last statement not finished, we should consider it to calc indents // current line starts with '{' and last statement not finished, we should consider it to calc indents
matchingIndents = rangeAfterFirstToken.matchingIndents; matchingIndents = rangeAfterFirstToken.matchingIndents;
indentAdded = true; indentAdded = true;
l = startLine; l = startLine;
} else if (mHighlighter->language() == HighlighterLanguage::Cpp } else if (mHighlighter->language() == ProgrammingLanguage::Cpp
&& trimmedLineText.startsWith('#') && trimmedLineText.startsWith('#')
&& attr == ((CppHighlighter *)mHighlighter.get())->preprocessorAttribute()) { && attr == ((CppHighlighter *)mHighlighter.get())->preprocessorAttribute()) {
indentAdded = true; indentAdded = true;
indentSpaces=0; indentSpaces=0;
l=0; l=0;
} else if (mHighlighter->language() == HighlighterLanguage::Cpp } else if (mHighlighter->language() == ProgrammingLanguage::Cpp
&& mHighlighter->isLastLineCommentNotFinished(rangePreceeding.state) && mHighlighter->isLastLineCommentNotFinished(rangePreceeding.state)
) { ) {
// last line is a not finished comment, // last line is a not finished comment,
@ -1635,7 +1635,7 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
// the line the comment beginning , and add 1 additional space // the line the comment beginning , and add 1 additional space
additionIndent = 1; additionIndent = 1;
int commentStartLine = findCommentStartLine(startLine-1); int commentStartLine = findCommentStartLine(startLine-1);
HighlighterState range; SyntaxerState range;
indentSpaces = leftSpaces(mDocument->getString(commentStartLine-1)); indentSpaces = leftSpaces(mDocument->getString(commentStartLine-1));
range = mDocument->ranges(commentStartLine-1); range = mDocument->ranges(commentStartLine-1);
matchingIndents = range.matchingIndents; matchingIndents = range.matchingIndents;
@ -1645,7 +1645,7 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
//indents according to the beginning of the comment and 2 additional space //indents according to the beginning of the comment and 2 additional space
additionIndent = 0; additionIndent = 0;
int commentStartLine = findCommentStartLine(startLine-1); int commentStartLine = findCommentStartLine(startLine-1);
HighlighterState range; SyntaxerState range;
indentSpaces = leftSpaces(mDocument->getString(commentStartLine-1))+2; indentSpaces = leftSpaces(mDocument->getString(commentStartLine-1))+2;
range = mDocument->ranges(commentStartLine-1); range = mDocument->ranges(commentStartLine-1);
matchingIndents = range.matchingIndents; matchingIndents = range.matchingIndents;
@ -1659,7 +1659,7 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
// the preceeding line is the end of comment // the preceeding line is the end of comment
// we should use the indents of the start line of the comment // we should use the indents of the start line of the comment
int commentStartLine = findCommentStartLine(startLine-2); int commentStartLine = findCommentStartLine(startLine-2);
HighlighterState range; SyntaxerState range;
indentSpaces = leftSpaces(mDocument->getString(commentStartLine-1)); indentSpaces = leftSpaces(mDocument->getString(commentStartLine-1));
range = mDocument->ranges(commentStartLine-1); range = mDocument->ranges(commentStartLine-1);
matchingIndents = range.matchingIndents; matchingIndents = range.matchingIndents;
@ -1675,7 +1675,7 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
) { ) {
// find the indent's start line, and use it's indent as the default indent; // find the indent's start line, and use it's indent as the default indent;
while (l>=1) { while (l>=1) {
HighlighterState range = mDocument->ranges(l-1); SyntaxerState range = mDocument->ranges(l-1);
QVector<int> newIndents = range.indents.mid(range.firstIndentThisLine); QVector<int> newIndents = range.indents.mid(range.firstIndentThisLine);
int i = 0; int i = 0;
int len = matchingIndents.length(); int len = matchingIndents.length();
@ -1693,8 +1693,8 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
// we found the where the indent started // we found the where the indent started
if (len>0 && !range.matchingIndents.isEmpty() if (len>0 && !range.matchingIndents.isEmpty()
&& &&
( matchingIndents.back()== sitBrace ( matchingIndents.back()== IndentForBrace
|| matchingIndents.back() == sitStatement || matchingIndents.back() == IndentForStatement
) ) { ) ) {
// but it's not a complete statement // but it's not a complete statement
matchingIndents = range.matchingIndents; matchingIndents = range.matchingIndents;
@ -2906,7 +2906,7 @@ void SynEdit::doAddChar(QChar AChar)
if (mActiveSelectionMode==SelectionMode::Normal if (mActiveSelectionMode==SelectionMode::Normal
&& mOptions.testFlag(eoAutoIndent) && mOptions.testFlag(eoAutoIndent)
&& mHighlighter && mHighlighter
&& mHighlighter->language() == HighlighterLanguage::Cpp && mHighlighter->language() == ProgrammingLanguage::Cpp
&& (oldCaretY<=mDocument->count()) ) { && (oldCaretY<=mDocument->count()) ) {
//unindent if ':' at end of the line //unindent if ':' at end of the line
@ -3408,7 +3408,7 @@ void SynEdit::updateModifiedStatus()
int SynEdit::scanFrom(int Index, int canStopIndex) int SynEdit::scanFrom(int Index, int canStopIndex)
{ {
HighlighterState iRange; SyntaxerState iRange;
int Result = std::max(0,Index); int Result = std::max(0,Index);
if (Result >= mDocument->count()) if (Result >= mDocument->count())
return Result; return Result;
@ -3462,7 +3462,7 @@ void SynEdit::rescanRange(int line)
} }
mHighlighter->setLine(mDocument->getString(line), line); mHighlighter->setLine(mDocument->getString(line), line);
mHighlighter->nextToEol(); mHighlighter->nextToEol();
HighlighterState iRange = mHighlighter->getState(); SyntaxerState iRange = mHighlighter->getState();
mDocument->setRange(line,iRange); mDocument->setRange(line,iRange);
} }
@ -4981,7 +4981,7 @@ void SynEdit::doGotoBlockStart(bool isSelection)
{ {
if (mCaretY<0 || mCaretY>document()->count()) if (mCaretY<0 || mCaretY>document()->count())
return; return;
HighlighterState state = document()->ranges(mCaretY-1); SyntaxerState state = document()->ranges(mCaretY-1);
//todo: handle block other than {} //todo: handle block other than {}
if (document()->braceLevels(mCaretY-1)==0) { if (document()->braceLevels(mCaretY-1)==0) {
doGotoEditorStart(isSelection); doGotoEditorStart(isSelection);
@ -5003,7 +5003,7 @@ void SynEdit::doGotoBlockEnd(bool isSelection)
{ {
if (mCaretY<0 || mCaretY>document()->count()) if (mCaretY<0 || mCaretY>document()->count())
return; return;
HighlighterState state = document()->ranges(mCaretY-1); SyntaxerState state = document()->ranges(mCaretY-1);
//todo: handle block other than {} //todo: handle block other than {}
if (document()->blockLevel(mCaretY-1)==0) { if (document()->blockLevel(mCaretY-1)==0) {
doGotoEditorEnd(isSelection); doGotoEditorEnd(isSelection);
@ -5479,7 +5479,7 @@ int SynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList&
int caretY=pos.line; int caretY=pos.line;
// step1: insert the first line of Value into current line // step1: insert the first line of Value into current line
if (text.length()>1) { if (text.length()>1) {
if (!mUndoing && mHighlighter && mHighlighter->language()==HighlighterLanguage::Cpp && mOptions.testFlag(eoAutoIndent)) { if (!mUndoing && mHighlighter && mHighlighter->language()==ProgrammingLanguage::Cpp && mOptions.testFlag(eoAutoIndent)) {
QString s = trimLeft(text[0]); QString s = trimLeft(text[0]);
if (sLeftSide.isEmpty()) { if (sLeftSide.isEmpty()) {
sLeftSide = GetLeftSpacing(calcIndentSpaces(caretY,s,true),true); sLeftSide = GetLeftSpacing(calcIndentSpaces(caretY,s,true),true);
@ -5509,7 +5509,7 @@ int SynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList&
if (i==text.length()-1) { if (i==text.length()-1) {
str = sRightSide; str = sRightSide;
} else { } else {
if (!mUndoing && mHighlighter && mHighlighter->language()==HighlighterLanguage::Cpp && mOptions.testFlag(eoAutoIndent) && notInComment) { if (!mUndoing && mHighlighter && mHighlighter->language()==ProgrammingLanguage::Cpp && mOptions.testFlag(eoAutoIndent) && notInComment) {
str = GetLeftSpacing(calcIndentSpaces(caretY,"",true),true); str = GetLeftSpacing(calcIndentSpaces(caretY,"",true),true);
} else { } else {
str = ""; str = "";
@ -5519,7 +5519,7 @@ int SynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList&
str = text[i]; str = text[i];
if (i==text.length()-1) if (i==text.length()-1)
str += sRightSide; str += sRightSide;
if (!mUndoing && mHighlighter && mHighlighter->language()==HighlighterLanguage::Cpp && mOptions.testFlag(eoAutoIndent) && notInComment) { if (!mUndoing && mHighlighter && mHighlighter->language()==ProgrammingLanguage::Cpp && mOptions.testFlag(eoAutoIndent) && notInComment) {
int indentSpaces = calcIndentSpaces(caretY,str,true); int indentSpaces = calcIndentSpaces(caretY,str,true);
str = GetLeftSpacing(indentSpaces,true)+trimLeft(str); str = GetLeftSpacing(indentSpaces,true)+trimLeft(str);
} }

View File

@ -158,7 +158,7 @@ QString Document::lineBreak() const
return "\n"; return "\n";
} }
HighlighterState Document::ranges(int index) SyntaxerState Document::ranges(int index)
{ {
QMutexLocker locker(&mMutex); QMutexLocker locker(&mMutex);
if (index>=0 && index < mLines.size()) { if (index>=0 && index < mLines.size()) {
@ -166,7 +166,7 @@ HighlighterState Document::ranges(int index)
} else { } else {
ListIndexOutOfBounds(index); ListIndexOutOfBounds(index);
} }
return HighlighterState(); return SyntaxerState();
} }
void Document::insertItem(int Index, const QString &s) void Document::insertItem(int Index, const QString &s)
@ -201,7 +201,7 @@ void Document::setAppendNewLineAtEOF(bool appendNewLineAtEOF)
mAppendNewLineAtEOF = appendNewLineAtEOF; mAppendNewLineAtEOF = appendNewLineAtEOF;
} }
void Document::setRange(int Index, const HighlighterState& range) void Document::setRange(int Index, const SyntaxerState& range)
{ {
QMutexLocker locker(&mMutex); QMutexLocker locker(&mMutex);
if (Index<0 || Index>=mLines.count()) { if (Index<0 || Index>=mLines.count()) {

View File

@ -32,7 +32,7 @@ namespace QSynedit {
struct DocumentLine { struct DocumentLine {
QString fString; QString fString;
HighlighterState fRange; SyntaxerState fRange;
int fColumns; // int fColumns; //
public: public:
@ -64,8 +64,8 @@ public:
int blockEnded(int index); int blockEnded(int index);
int lengthOfLongestLine(); int lengthOfLongestLine();
QString lineBreak() const; QString lineBreak() const;
HighlighterState ranges(int index); SyntaxerState ranges(int index);
void setRange(int index, const HighlighterState& range); void setRange(int index, const SyntaxerState& range);
QString getString(int index); QString getString(int index);
int count(); int count();
QString text(); QString text();

View File

@ -979,7 +979,7 @@ void SynEditTextPainter::paintLines()
|| sToken == "(" || sToken == "("
|| sToken == "{" || sToken == "{"
) { ) {
HighlighterState rangeState = edit->mHighlighter->getState(); SyntaxerState rangeState = edit->mHighlighter->getState();
getBraceColorAttr(rangeState.bracketLevel getBraceColorAttr(rangeState.bracketLevel
+rangeState.braceLevel +rangeState.braceLevel
+rangeState.parenthesisLevel +rangeState.parenthesisLevel
@ -988,7 +988,7 @@ void SynEditTextPainter::paintLines()
|| sToken == ")" || sToken == ")"
|| sToken == "}" || sToken == "}"
){ ){
HighlighterState rangeState = edit->mHighlighter->getState(); SyntaxerState rangeState = edit->mHighlighter->getState();
getBraceColorAttr(rangeState.bracketLevel getBraceColorAttr(rangeState.bracketLevel
+rangeState.braceLevel +rangeState.braceLevel
+rangeState.parenthesisLevel+1, +rangeState.parenthesisLevel+1,

View File

@ -98,13 +98,13 @@ const QSet<QString> ASMHighlighter::Keywords {
ASMHighlighter::ASMHighlighter() ASMHighlighter::ASMHighlighter()
{ {
mNumberAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrNumber, TokenType::Number); mNumberAttribute = std::make_shared<TokenAttribute>(SYNS_AttrNumber, TokenType::Number);
addAttribute(mNumberAttribute); addAttribute(mNumberAttribute);
mDirectiveAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrVariable, TokenType::Keyword); mDirectiveAttribute = std::make_shared<TokenAttribute>(SYNS_AttrVariable, TokenType::Keyword);
addAttribute(mDirectiveAttribute); addAttribute(mDirectiveAttribute);
mLabelAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrFunction, TokenType::Keyword); mLabelAttribute = std::make_shared<TokenAttribute>(SYNS_AttrFunction, TokenType::Keyword);
addAttribute(mLabelAttribute); addAttribute(mLabelAttribute);
mRegisterAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrClass, TokenType::Keyword); mRegisterAttribute = std::make_shared<TokenAttribute>(SYNS_AttrClass, TokenType::Keyword);
addAttribute(mRegisterAttribute); addAttribute(mRegisterAttribute);
} }
@ -298,9 +298,9 @@ QString ASMHighlighter::languageName()
return "asm"; return "asm";
} }
HighlighterLanguage ASMHighlighter::language() ProgrammingLanguage ASMHighlighter::language()
{ {
return HighlighterLanguage::Asssembly; return ProgrammingLanguage::Asssembly;
} }
QString ASMHighlighter::getToken() const QString ASMHighlighter::getToken() const
@ -439,12 +439,12 @@ bool ASMHighlighter::isLastLineStringNotFinished(int /*state*/) const
return true; return true;
} }
HighlighterState ASMHighlighter::getState() const SyntaxerState ASMHighlighter::getState() const
{ {
return HighlighterState(); return SyntaxerState();
} }
void ASMHighlighter::setState(const HighlighterState&) void ASMHighlighter::setState(const SyntaxerState&)
{ {
} }

View File

@ -88,7 +88,7 @@ public:
bool eol() const override; bool eol() const override;
QString languageName() override; QString languageName() override;
HighlighterLanguage language() override; ProgrammingLanguage language() override;
QString getToken() const override; QString getToken() const override;
const PHighlighterAttribute &getTokenAttribute() const override; const PHighlighterAttribute &getTokenAttribute() const override;
int getTokenPos() override; int getTokenPos() override;
@ -100,8 +100,8 @@ public:
bool getTokenFinished() const override; bool getTokenFinished() const override;
bool isLastLineCommentNotFinished(int state) const override; bool isLastLineCommentNotFinished(int state) const override;
bool isLastLineStringNotFinished(int state) const override; bool isLastLineStringNotFinished(int state) const override;
HighlighterState getState() const override; SyntaxerState getState() const override;
void setState(const HighlighterState& rangeState) override; void setState(const SyntaxerState& rangeState) override;
void resetState() override; void resetState() override;

View File

@ -22,22 +22,22 @@ Highlighter::Highlighter() :
mEnabled(true), mEnabled(true),
mWordBreakChars{ WordBreakChars } mWordBreakChars{ WordBreakChars }
{ {
mCommentAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrComment, mCommentAttribute = std::make_shared<TokenAttribute>(SYNS_AttrComment,
TokenType::Comment); TokenType::Comment);
addAttribute(mCommentAttribute); addAttribute(mCommentAttribute);
mIdentifierAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrIdentifier, mIdentifierAttribute = std::make_shared<TokenAttribute>(SYNS_AttrIdentifier,
TokenType::Identifier); TokenType::Identifier);
addAttribute(mIdentifierAttribute); addAttribute(mIdentifierAttribute);
mKeywordAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrReservedWord, mKeywordAttribute = std::make_shared<TokenAttribute>(SYNS_AttrReservedWord,
TokenType::Keyword); TokenType::Keyword);
addAttribute(mKeywordAttribute); addAttribute(mKeywordAttribute);
mStringAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrString, mStringAttribute = std::make_shared<TokenAttribute>(SYNS_AttrString,
TokenType::String); TokenType::String);
addAttribute(mStringAttribute); addAttribute(mStringAttribute);
mWhitespaceAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrSpace, mWhitespaceAttribute = std::make_shared<TokenAttribute>(SYNS_AttrSpace,
TokenType::Space); TokenType::Space);
addAttribute(mWhitespaceAttribute); addAttribute(mWhitespaceAttribute);
mSymbolAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrSymbol, mSymbolAttribute = std::make_shared<TokenAttribute>(SYNS_AttrSymbol,
TokenType::Operator); TokenType::Operator);
addAttribute(mSymbolAttribute); addAttribute(mSymbolAttribute);
} }
@ -196,49 +196,49 @@ void Highlighter::setEnabled(bool value)
} }
} }
FontStyles HighlighterAttribute::styles() const FontStyles TokenAttribute::styles() const
{ {
return mStyles; return mStyles;
} }
void HighlighterAttribute::setStyles(const FontStyles &styles) void TokenAttribute::setStyles(const FontStyles &styles)
{ {
if (mStyles!=styles) { if (mStyles!=styles) {
mStyles = styles; mStyles = styles;
} }
} }
const QColor& HighlighterAttribute::foreground() const const QColor& TokenAttribute::foreground() const
{ {
return mForeground; return mForeground;
} }
void HighlighterAttribute::setForeground(const QColor &color) void TokenAttribute::setForeground(const QColor &color)
{ {
mForeground = color; mForeground = color;
} }
const QColor &HighlighterAttribute::background() const const QColor &TokenAttribute::background() const
{ {
return mBackground; return mBackground;
} }
void HighlighterAttribute::setBackground(const QColor &background) void TokenAttribute::setBackground(const QColor &background)
{ {
mBackground = background; mBackground = background;
} }
TokenType HighlighterAttribute::tokenType() const TokenType TokenAttribute::tokenType() const
{ {
return mTokenType; return mTokenType;
} }
QString HighlighterAttribute::name() const QString TokenAttribute::name() const
{ {
return mName; return mName;
} }
HighlighterAttribute::HighlighterAttribute(const QString &name, TokenType tokenType): TokenAttribute::TokenAttribute(const QString &name, TokenType tokenType):
mForeground(QColor()), mForeground(QColor()),
mBackground(QColor()), mBackground(QColor()),
mName(name), mName(name),
@ -248,7 +248,7 @@ HighlighterAttribute::HighlighterAttribute(const QString &name, TokenType tokenT
} }
bool HighlighterState::operator==(const HighlighterState &s2) bool SyntaxerState::operator==(const SyntaxerState &s2)
{ {
// indents contains the information of brace/parenthesis/brackets embedded levels // indents contains the information of brace/parenthesis/brackets embedded levels
return (state == s2.state) return (state == s2.state)
@ -256,14 +256,14 @@ bool HighlighterState::operator==(const HighlighterState &s2)
; ;
} }
int HighlighterState::getLastIndent() int SyntaxerState::getLastIndent()
{ {
if (indents.isEmpty()) if (indents.isEmpty())
return -1; return -1;
return indents.back(); return indents.back();
} }
HighlighterState::HighlighterState(): SyntaxerState::SyntaxerState():
state(0), state(0),
blockLevel(0), blockLevel(0),
blockStarted(0), blockStarted(0),

View File

@ -27,14 +27,14 @@
#include "../Types.h" #include "../Types.h"
namespace QSynedit { namespace QSynedit {
enum SynIndentType { enum IndentType {
sitBrace = 0, IndentForBrace,
sitParenthesis = 1, IndentForParenthesis,
sitBracket = 2, IndentForBracket,
sitStatement = 3, IndentForStatement,
}; };
struct HighlighterState { struct SyntaxerState {
int state; // current syntax parsing state int state; // current syntax parsing state
int blockLevel; // needed by block folding int blockLevel; // needed by block folding
int blockStarted; // needed by block folding int blockStarted; // needed by block folding
@ -51,9 +51,9 @@ struct HighlighterState {
QVector<int> matchingIndents; /* the indent matched ( and removed ) QVector<int> matchingIndents; /* the indent matched ( and removed )
but not started at this line but not started at this line
(need by auto indent) */ (need by auto indent) */
bool operator==(const HighlighterState& s2); bool operator==(const SyntaxerState& s2);
int getLastIndent(); int getLastIndent();
HighlighterState(); SyntaxerState();
}; };
enum class TokenType { enum class TokenType {
@ -78,7 +78,7 @@ enum class TokenType {
Embeded //language embeded in others Embeded //language embeded in others
}; };
enum class HighlighterLanguage { enum class ProgrammingLanguage {
DecideBySuffix, DecideBySuffix,
Composition, Composition,
Asssembly, Asssembly,
@ -88,9 +88,9 @@ enum class HighlighterLanguage {
Custom Custom
}; };
class HighlighterAttribute { class TokenAttribute {
public: public:
explicit HighlighterAttribute(const QString& name, TokenType mTokenType); explicit TokenAttribute(const QString& name, TokenType mTokenType);
QString name() const; QString name() const;
@ -113,7 +113,7 @@ private:
TokenType mTokenType; TokenType mTokenType;
}; };
typedef std::shared_ptr<HighlighterAttribute> PHighlighterAttribute; typedef std::shared_ptr<TokenAttribute> PHighlighterAttribute;
using HighlighterAttributeList = QVector<PHighlighterAttribute>; using HighlighterAttributeList = QVector<PHighlighterAttribute>;
class Highlighter { class Highlighter {
@ -142,20 +142,20 @@ public:
virtual bool isLastLineCommentNotFinished(int state) const = 0; virtual bool isLastLineCommentNotFinished(int state) const = 0;
virtual bool isLastLineStringNotFinished(int state) const = 0; virtual bool isLastLineStringNotFinished(int state) const = 0;
virtual bool eol() const = 0; virtual bool eol() const = 0;
virtual HighlighterState getState() const = 0; virtual SyntaxerState getState() const = 0;
virtual QString getToken() const=0; virtual QString getToken() const=0;
virtual const PHighlighterAttribute &getTokenAttribute() const=0; virtual const PHighlighterAttribute &getTokenAttribute() const=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;
virtual void nextToEol(); virtual void nextToEol();
virtual void setState(const HighlighterState& rangeState) = 0; virtual void setState(const SyntaxerState& rangeState) = 0;
virtual void setLine(const QString& newLine, int lineNumber) = 0; virtual void setLine(const QString& newLine, int lineNumber) = 0;
virtual void resetState() = 0; virtual void resetState() = 0;
virtual QSet<QString> keywords() const; virtual QSet<QString> keywords() const;
virtual QString languageName() = 0; virtual QString languageName() = 0;
virtual HighlighterLanguage language() = 0; virtual ProgrammingLanguage language() = 0;
virtual QString foldString(); virtual QString foldString();

View File

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

View File

@ -143,48 +143,48 @@ const QSet<QString> CppHighlighter::Keywords {
}; };
CppHighlighter::CppHighlighter(): Highlighter() CppHighlighter::CppHighlighter(): Highlighter()
{ {
mAsmAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrAssembler, mAsmAttribute = std::make_shared<TokenAttribute>(SYNS_AttrAssembler,
TokenType::Embeded); TokenType::Embeded);
addAttribute(mAsmAttribute); addAttribute(mAsmAttribute);
mCharAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrCharacter, mCharAttribute = std::make_shared<TokenAttribute>(SYNS_AttrCharacter,
TokenType::Character); TokenType::Character);
addAttribute(mCharAttribute); addAttribute(mCharAttribute);
mClassAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrClass, mClassAttribute = std::make_shared<TokenAttribute>(SYNS_AttrClass,
TokenType::Identifier); TokenType::Identifier);
addAttribute(mClassAttribute); addAttribute(mClassAttribute);
mFloatAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrFloat, mFloatAttribute = std::make_shared<TokenAttribute>(SYNS_AttrFloat,
TokenType::Number); TokenType::Number);
addAttribute(mFloatAttribute); addAttribute(mFloatAttribute);
mFunctionAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrFunction, mFunctionAttribute = std::make_shared<TokenAttribute>(SYNS_AttrFunction,
TokenType::Identifier); TokenType::Identifier);
addAttribute(mFunctionAttribute); addAttribute(mFunctionAttribute);
mGlobalVarAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrGlobalVariable, mGlobalVarAttribute = std::make_shared<TokenAttribute>(SYNS_AttrGlobalVariable,
TokenType::Identifier); TokenType::Identifier);
addAttribute(mGlobalVarAttribute); addAttribute(mGlobalVarAttribute);
mHexAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrHexadecimal, mHexAttribute = std::make_shared<TokenAttribute>(SYNS_AttrHexadecimal,
TokenType::Number); TokenType::Number);
addAttribute(mHexAttribute); addAttribute(mHexAttribute);
mInvalidAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrIllegalChar, mInvalidAttribute = std::make_shared<TokenAttribute>(SYNS_AttrIllegalChar,
TokenType::Error); TokenType::Error);
addAttribute(mInvalidAttribute); addAttribute(mInvalidAttribute);
mLocalVarAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrLocalVariable, mLocalVarAttribute = std::make_shared<TokenAttribute>(SYNS_AttrLocalVariable,
TokenType::Identifier); TokenType::Identifier);
addAttribute(mLocalVarAttribute); addAttribute(mLocalVarAttribute);
mNumberAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrNumber, mNumberAttribute = std::make_shared<TokenAttribute>(SYNS_AttrNumber,
TokenType::Number); TokenType::Number);
addAttribute(mNumberAttribute); addAttribute(mNumberAttribute);
mOctAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrOctal, mOctAttribute = std::make_shared<TokenAttribute>(SYNS_AttrOctal,
TokenType::Number); TokenType::Number);
addAttribute(mOctAttribute); addAttribute(mOctAttribute);
mPreprocessorAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrPreprocessor, mPreprocessorAttribute = std::make_shared<TokenAttribute>(SYNS_AttrPreprocessor,
TokenType::Preprocessor); TokenType::Preprocessor);
addAttribute(mPreprocessorAttribute); addAttribute(mPreprocessorAttribute);
mStringEscapeSequenceAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrStringEscapeSequences, mStringEscapeSequenceAttribute = std::make_shared<TokenAttribute>(SYNS_AttrStringEscapeSequences,
TokenType::String); TokenType::String);
addAttribute(mStringEscapeSequenceAttribute); addAttribute(mStringEscapeSequenceAttribute);
mVariableAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrVariable, mVariableAttribute = std::make_shared<TokenAttribute>(SYNS_AttrVariable,
TokenType::Identifier); TokenType::Identifier);
addAttribute(mVariableAttribute); addAttribute(mVariableAttribute);
resetState(); resetState();
@ -382,7 +382,7 @@ void CppHighlighter::braceCloseProc()
} else { } else {
mRange.blockEnded++ ; mRange.blockEnded++ ;
} }
popIndents(sitBrace); popIndents(IndentForBrace);
} }
void CppHighlighter::braceOpenProc() void CppHighlighter::braceOpenProc()
@ -396,19 +396,19 @@ void CppHighlighter::braceOpenProc()
mRange.braceLevel += 1; mRange.braceLevel += 1;
mRange.blockLevel += 1; mRange.blockLevel += 1;
mRange.blockStarted++; mRange.blockStarted++;
if (mRange.getLastIndent() == sitStatement) { if (mRange.getLastIndent() == IndentForStatement) {
// if last indent is started by 'if' 'for' etc // if last indent is started by 'if' 'for' etc
// just replace it // just replace it
while (mRange.getLastIndent() == sitStatement) while (mRange.getLastIndent() == IndentForStatement)
popIndents(sitStatement); popIndents(IndentForStatement);
pushIndents(sitBrace); pushIndents(IndentForBrace);
// int idx = mRange.indents.length()-1; // int idx = mRange.indents.length()-1;
// if (idx < mRange.firstIndentThisLine) { // if (idx < mRange.firstIndentThisLine) {
// mRange.firstIndentThisLine = idx; // mRange.firstIndentThisLine = idx;
// } // }
// mRange.indents.replace(idx,1,BraceIndentType); // mRange.indents.replace(idx,1,BraceIndentType);
} else { } else {
pushIndents(sitBrace); pushIndents(IndentForBrace);
} }
} }
@ -570,7 +570,7 @@ void CppHighlighter::identProc()
if (isKeyword(word)) { if (isKeyword(word)) {
mTokenId = TokenId::Key; mTokenId = TokenId::Key;
if (CppStatementKeyWords.contains(word)) { if (CppStatementKeyWords.contains(word)) {
pushIndents(sitStatement); pushIndents(IndentForStatement);
} }
} else { } else {
mTokenId = TokenId::Identifier; mTokenId = TokenId::Identifier;
@ -912,7 +912,7 @@ void CppHighlighter::roundCloseProc()
mRange.parenthesisLevel--; mRange.parenthesisLevel--;
if (mRange.parenthesisLevel<0) if (mRange.parenthesisLevel<0)
mRange.parenthesisLevel=0; mRange.parenthesisLevel=0;
popIndents(sitParenthesis); popIndents(IndentForParenthesis);
} }
void CppHighlighter::roundOpenProc() void CppHighlighter::roundOpenProc()
@ -920,7 +920,7 @@ void CppHighlighter::roundOpenProc()
mRun += 1; mRun += 1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
mRange.parenthesisLevel++; mRange.parenthesisLevel++;
pushIndents(sitParenthesis); pushIndents(IndentForParenthesis);
} }
void CppHighlighter::semiColonProc() void CppHighlighter::semiColonProc()
@ -929,8 +929,8 @@ void CppHighlighter::semiColonProc()
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
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() == IndentForStatement) {
popIndents(sitStatement); popIndents(IndentForStatement);
} }
} }
@ -994,7 +994,7 @@ void CppHighlighter::squareCloseProc()
mRange.bracketLevel--; mRange.bracketLevel--;
if (mRange.bracketLevel<0) if (mRange.bracketLevel<0)
mRange.bracketLevel=0; mRange.bracketLevel=0;
popIndents(sitBracket); popIndents(IndentForBracket);
} }
void CppHighlighter::squareOpenProc() void CppHighlighter::squareOpenProc()
@ -1002,7 +1002,7 @@ void CppHighlighter::squareOpenProc()
mRun+=1; mRun+=1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
mRange.bracketLevel++; mRange.bracketLevel++;
pushIndents(sitBracket); pushIndents(IndentForBracket);
} }
void CppHighlighter::starProc() void CppHighlighter::starProc()
@ -1593,7 +1593,7 @@ bool CppHighlighter::isKeyword(const QString &word)
return Keywords.contains(word) || mCustomTypeKeywords.contains(word); return Keywords.contains(word) || mCustomTypeKeywords.contains(word);
} }
void CppHighlighter::setState(const HighlighterState& rangeState) void CppHighlighter::setState(const SyntaxerState& rangeState)
{ {
mRange = rangeState; mRange = rangeState;
// current line's left / right parenthesis count should be reset before parsing each line // current line's left / right parenthesis count should be reset before parsing each line
@ -1625,12 +1625,12 @@ QString CppHighlighter::languageName()
return "cpp"; return "cpp";
} }
HighlighterLanguage CppHighlighter::language() ProgrammingLanguage CppHighlighter::language()
{ {
return HighlighterLanguage::Cpp; return ProgrammingLanguage::Cpp;
} }
HighlighterState CppHighlighter::getState() const SyntaxerState CppHighlighter::getState() const
{ {
return mRange; return mRange;
} }

View File

@ -137,7 +137,7 @@ private:
private: private:
bool mAsmStart; bool mAsmStart;
HighlighterState mRange; SyntaxerState mRange;
// SynRangeState mSpaceRange; // SynRangeState mSpaceRange;
QString mLine; QString mLine;
int mLineSize; int mLineSize;
@ -179,15 +179,15 @@ public:
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;
void setState(const HighlighterState& rangeState) override; void setState(const SyntaxerState& rangeState) override;
void resetState() override; void resetState() override;
QString languageName() override; QString languageName() override;
HighlighterLanguage language() override; ProgrammingLanguage language() override;
// SynHighlighter interface // SynHighlighter interface
public: public:
HighlighterState getState() const override; SyntaxerState getState() const override;
// SynHighlighter interface // SynHighlighter interface
public: public:

View File

@ -22,8 +22,8 @@ QString CustomHighlighterV1::languageName()
return mLanguageName; return mLanguageName;
} }
HighlighterLanguage CustomHighlighterV1::language() ProgrammingLanguage CustomHighlighterV1::language()
{ {
return HighlighterLanguage::Custom; return ProgrammingLanguage::Custom;
} }
} }

View File

@ -27,7 +27,7 @@ public:
void resetState() override; void resetState() override;
QString languageName() override; QString languageName() override;
HighlighterLanguage language() override; ProgrammingLanguage language() override;
protected: protected:
bool mIgnoreCase; bool mIgnoreCase;
QString mCommentBlockStart; QString mCommentBlockStart;
@ -47,7 +47,7 @@ protected:
QString mLanguageName; QString mLanguageName;
QSet<QString> mSuffixes; QSet<QString> mSuffixes;
HighlighterState mRange; SyntaxerState mRange;
// SynRangeState mSpaceRange; // SynRangeState mSpaceRange;
QString mLine; QString mLine;
int mLineSize; int mLineSize;

View File

@ -83,48 +83,48 @@ const QSet<QString> GLSLHighlighter::Keywords {
GLSLHighlighter::GLSLHighlighter(): Highlighter() GLSLHighlighter::GLSLHighlighter(): Highlighter()
{ {
mAsmAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrAssembler, mAsmAttribute = std::make_shared<TokenAttribute>(SYNS_AttrAssembler,
TokenType::Embeded); TokenType::Embeded);
addAttribute(mAsmAttribute); addAttribute(mAsmAttribute);
mCharAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrCharacter, mCharAttribute = std::make_shared<TokenAttribute>(SYNS_AttrCharacter,
TokenType::Character); TokenType::Character);
addAttribute(mCharAttribute); addAttribute(mCharAttribute);
mClassAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrClass, mClassAttribute = std::make_shared<TokenAttribute>(SYNS_AttrClass,
TokenType::Identifier); TokenType::Identifier);
addAttribute(mClassAttribute); addAttribute(mClassAttribute);
mFloatAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrFloat, mFloatAttribute = std::make_shared<TokenAttribute>(SYNS_AttrFloat,
TokenType::Number); TokenType::Number);
addAttribute(mFloatAttribute); addAttribute(mFloatAttribute);
mFunctionAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrFunction, mFunctionAttribute = std::make_shared<TokenAttribute>(SYNS_AttrFunction,
TokenType::Identifier); TokenType::Identifier);
addAttribute(mFunctionAttribute); addAttribute(mFunctionAttribute);
mGlobalVarAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrGlobalVariable, mGlobalVarAttribute = std::make_shared<TokenAttribute>(SYNS_AttrGlobalVariable,
TokenType::Identifier); TokenType::Identifier);
addAttribute(mGlobalVarAttribute); addAttribute(mGlobalVarAttribute);
mHexAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrHexadecimal, mHexAttribute = std::make_shared<TokenAttribute>(SYNS_AttrHexadecimal,
TokenType::Number); TokenType::Number);
addAttribute(mHexAttribute); addAttribute(mHexAttribute);
mInvalidAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrIllegalChar, mInvalidAttribute = std::make_shared<TokenAttribute>(SYNS_AttrIllegalChar,
TokenType::Error); TokenType::Error);
addAttribute(mInvalidAttribute); addAttribute(mInvalidAttribute);
mLocalVarAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrLocalVariable, mLocalVarAttribute = std::make_shared<TokenAttribute>(SYNS_AttrLocalVariable,
TokenType::Identifier); TokenType::Identifier);
addAttribute(mLocalVarAttribute); addAttribute(mLocalVarAttribute);
mNumberAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrNumber, mNumberAttribute = std::make_shared<TokenAttribute>(SYNS_AttrNumber,
TokenType::Number); TokenType::Number);
addAttribute(mNumberAttribute); addAttribute(mNumberAttribute);
mOctAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrOctal, mOctAttribute = std::make_shared<TokenAttribute>(SYNS_AttrOctal,
TokenType::Number); TokenType::Number);
addAttribute(mOctAttribute); addAttribute(mOctAttribute);
mPreprocessorAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrPreprocessor, mPreprocessorAttribute = std::make_shared<TokenAttribute>(SYNS_AttrPreprocessor,
TokenType::Preprocessor); TokenType::Preprocessor);
addAttribute(mPreprocessorAttribute); addAttribute(mPreprocessorAttribute);
mStringEscapeSequenceAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrStringEscapeSequences, mStringEscapeSequenceAttribute = std::make_shared<TokenAttribute>(SYNS_AttrStringEscapeSequences,
TokenType::String); TokenType::String);
addAttribute(mStringEscapeSequenceAttribute); addAttribute(mStringEscapeSequenceAttribute);
mVariableAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrVariable, mVariableAttribute = std::make_shared<TokenAttribute>(SYNS_AttrVariable,
TokenType::Identifier); TokenType::Identifier);
addAttribute(mVariableAttribute); addAttribute(mVariableAttribute);
@ -322,7 +322,7 @@ void GLSLHighlighter::braceCloseProc()
} else { } else {
mRange.blockEnded++ ; mRange.blockEnded++ ;
} }
popIndents(sitBrace); popIndents(IndentForBrace);
} }
void GLSLHighlighter::braceOpenProc() void GLSLHighlighter::braceOpenProc()
@ -336,19 +336,19 @@ void GLSLHighlighter::braceOpenProc()
mRange.braceLevel += 1; mRange.braceLevel += 1;
mRange.blockLevel += 1; mRange.blockLevel += 1;
mRange.blockStarted += 1; mRange.blockStarted += 1;
if (mRange.getLastIndent() == sitStatement) { if (mRange.getLastIndent() == IndentForStatement) {
// if last indent is started by 'if' 'for' etc // if last indent is started by 'if' 'for' etc
// just replace it // just replace it
while (mRange.getLastIndent() == sitStatement) while (mRange.getLastIndent() == IndentForStatement)
popIndents(sitStatement); popIndents(IndentForStatement);
pushIndents(sitBrace); pushIndents(IndentForBrace);
// int idx = mRange.indents.length()-1; // int idx = mRange.indents.length()-1;
// if (idx < mRange.firstIndentThisLine) { // if (idx < mRange.firstIndentThisLine) {
// mRange.firstIndentThisLine = idx; // mRange.firstIndentThisLine = idx;
// } // }
// mRange.indents.replace(idx,1,BraceIndentType); // mRange.indents.replace(idx,1,BraceIndentType);
} else { } else {
pushIndents(sitBrace); pushIndents(IndentForBrace);
} }
} }
@ -483,7 +483,7 @@ void GLSLHighlighter::identProc()
if (isKeyword(word)) { if (isKeyword(word)) {
mTokenId = TokenId::Key; mTokenId = TokenId::Key;
if (GLSLStatementKeyWords.contains(word)) { if (GLSLStatementKeyWords.contains(word)) {
pushIndents(sitStatement); pushIndents(IndentForStatement);
} }
} else { } else {
mTokenId = TokenId::Identifier; mTokenId = TokenId::Identifier;
@ -821,7 +821,7 @@ void GLSLHighlighter::roundCloseProc()
mRange.parenthesisLevel--; mRange.parenthesisLevel--;
if (mRange.parenthesisLevel<0) if (mRange.parenthesisLevel<0)
mRange.parenthesisLevel=0; mRange.parenthesisLevel=0;
popIndents(sitParenthesis); popIndents(IndentForParenthesis);
} }
void GLSLHighlighter::roundOpenProc() void GLSLHighlighter::roundOpenProc()
@ -829,7 +829,7 @@ void GLSLHighlighter::roundOpenProc()
mRun += 1; mRun += 1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
mRange.parenthesisLevel++; mRange.parenthesisLevel++;
pushIndents(sitParenthesis); pushIndents(IndentForParenthesis);
} }
void GLSLHighlighter::semiColonProc() void GLSLHighlighter::semiColonProc()
@ -838,8 +838,8 @@ void GLSLHighlighter::semiColonProc()
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
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() == IndentForStatement) {
popIndents(sitStatement); popIndents(IndentForStatement);
} }
} }
@ -892,7 +892,7 @@ void GLSLHighlighter::squareCloseProc()
mRange.bracketLevel--; mRange.bracketLevel--;
if (mRange.bracketLevel<0) if (mRange.bracketLevel<0)
mRange.bracketLevel=0; mRange.bracketLevel=0;
popIndents(sitBracket); popIndents(IndentForBracket);
} }
void GLSLHighlighter::squareOpenProc() void GLSLHighlighter::squareOpenProc()
@ -900,7 +900,7 @@ void GLSLHighlighter::squareOpenProc()
mRun+=1; mRun+=1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
mRange.bracketLevel++; mRange.bracketLevel++;
pushIndents(sitBracket); pushIndents(IndentForBracket);
} }
void GLSLHighlighter::starProc() void GLSLHighlighter::starProc()
@ -1429,7 +1429,7 @@ bool GLSLHighlighter::isKeyword(const QString &word)
return Keywords.contains(word); return Keywords.contains(word);
} }
void GLSLHighlighter::setState(const HighlighterState& rangeState) void GLSLHighlighter::setState(const SyntaxerState& rangeState)
{ {
mRange = rangeState; mRange = rangeState;
// current line's left / right parenthesis count should be reset before parsing each line // current line's left / right parenthesis count should be reset before parsing each line
@ -1462,12 +1462,12 @@ QString GLSLHighlighter::languageName()
return "glsl"; return "glsl";
} }
HighlighterLanguage GLSLHighlighter::language() ProgrammingLanguage GLSLHighlighter::language()
{ {
return HighlighterLanguage::GLSL; return ProgrammingLanguage::GLSL;
} }
HighlighterState GLSLHighlighter::getState() const SyntaxerState GLSLHighlighter::getState() const
{ {
return mRange; return mRange;
} }

View File

@ -134,7 +134,7 @@ private:
private: private:
bool mAsmStart; bool mAsmStart;
HighlighterState mRange; SyntaxerState mRange;
// SynRangeState mSpaceRange; // SynRangeState mSpaceRange;
QString mLineString; QString mLineString;
QChar* mLine; QChar* mLine;
@ -175,15 +175,15 @@ public:
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;
void setState(const HighlighterState& rangeState) override; void setState(const SyntaxerState& rangeState) override;
void resetState() override; void resetState() override;
QString languageName() override; QString languageName() override;
HighlighterLanguage language() override; ProgrammingLanguage language() override;
// SynHighlighter interface // SynHighlighter interface
public: public:
HighlighterState getState() const override; SyntaxerState getState() const override;
// SynHighlighter interface // SynHighlighter interface
public: public:

View File

@ -182,17 +182,17 @@ const QSet<QString> MakefileHighlighter::Directives {
MakefileHighlighter::MakefileHighlighter() MakefileHighlighter::MakefileHighlighter()
{ {
mTargetAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrClass, TokenType::Identifier); mTargetAttribute = std::make_shared<TokenAttribute>(SYNS_AttrClass, TokenType::Identifier);
addAttribute(mTargetAttribute); addAttribute(mTargetAttribute);
mCommandAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrGlobalVariable, TokenType::Identifier); mCommandAttribute = std::make_shared<TokenAttribute>(SYNS_AttrGlobalVariable, TokenType::Identifier);
addAttribute(mCommandAttribute); addAttribute(mCommandAttribute);
mCommandParamAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrPreprocessor, TokenType::Identifier); mCommandParamAttribute = std::make_shared<TokenAttribute>(SYNS_AttrPreprocessor, TokenType::Identifier);
addAttribute(mCommandParamAttribute); addAttribute(mCommandParamAttribute);
mNumberAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrNumber, TokenType::Number); mNumberAttribute = std::make_shared<TokenAttribute>(SYNS_AttrNumber, TokenType::Number);
addAttribute(mNumberAttribute); addAttribute(mNumberAttribute);
mVariableAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrLocalVariable, TokenType::Identifier); mVariableAttribute = std::make_shared<TokenAttribute>(SYNS_AttrLocalVariable, TokenType::Identifier);
addAttribute(mVariableAttribute); addAttribute(mVariableAttribute);
mExpressionAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrFunction, TokenType::Identifier); mExpressionAttribute = std::make_shared<TokenAttribute>(SYNS_AttrFunction, TokenType::Identifier);
addAttribute(mExpressionAttribute); addAttribute(mExpressionAttribute);
} }
@ -421,9 +421,9 @@ QString MakefileHighlighter::languageName()
return "makefile"; return "makefile";
} }
HighlighterLanguage MakefileHighlighter::language() ProgrammingLanguage MakefileHighlighter::language()
{ {
return HighlighterLanguage::Makefile; return ProgrammingLanguage::Makefile;
} }
QString MakefileHighlighter::getToken() const QString MakefileHighlighter::getToken() const
@ -662,14 +662,14 @@ bool MakefileHighlighter::isLastLineStringNotFinished(int /*state*/) const
return false; return false;
} }
HighlighterState MakefileHighlighter::getState() const SyntaxerState MakefileHighlighter::getState() const
{ {
HighlighterState state; SyntaxerState state;
state.state = (int)mState; state.state = (int)mState;
return state; return state;
} }
void MakefileHighlighter::setState(const HighlighterState & rangeState) void MakefileHighlighter::setState(const SyntaxerState & rangeState)
{ {
mState = (RangeState)rangeState.state; mState = (RangeState)rangeState.state;
mStates.clear(); mStates.clear();

View File

@ -133,7 +133,7 @@ public:
bool eol() const override; bool eol() const override;
QString languageName() override; QString languageName() override;
HighlighterLanguage language() override; ProgrammingLanguage language() override;
QString getToken() const override; QString getToken() const override;
const PHighlighterAttribute &getTokenAttribute() const override; const PHighlighterAttribute &getTokenAttribute() const override;
int getTokenPos() override; int getTokenPos() override;
@ -145,8 +145,8 @@ public:
bool getTokenFinished() const override; bool getTokenFinished() const override;
bool isLastLineCommentNotFinished(int state) const override; bool isLastLineCommentNotFinished(int state) const override;
bool isLastLineStringNotFinished(int state) const override; bool isLastLineStringNotFinished(int state) const override;
HighlighterState getState() const override; SyntaxerState getState() const override;
void setState(const HighlighterState& rangeState) override; void setState(const SyntaxerState& rangeState) override;
void resetState() override; void resetState() override;
bool isIdentChar(const QChar& ch) const override; bool isIdentChar(const QChar& ch) const override;