refactor Highlighters
This commit is contained in:
parent
5d0c49a0bc
commit
51743799c8
|
@ -33,16 +33,16 @@ HighlighterManager::HighlighterManager()
|
|||
|
||||
}
|
||||
|
||||
QSynedit::PHighlighter HighlighterManager::getHighlighter(QSynedit::HighlighterLanguage language)
|
||||
QSynedit::PHighlighter HighlighterManager::getHighlighter(QSynedit::ProgrammingLanguage language)
|
||||
{
|
||||
switch(language) {
|
||||
case QSynedit::HighlighterLanguage::Cpp:
|
||||
case QSynedit::ProgrammingLanguage::Cpp:
|
||||
return getCppHighlighter();
|
||||
case QSynedit::HighlighterLanguage::Asssembly:
|
||||
case QSynedit::ProgrammingLanguage::Asssembly:
|
||||
return getAsmHighlighter();
|
||||
case QSynedit::HighlighterLanguage::Makefile:
|
||||
case QSynedit::ProgrammingLanguage::Makefile:
|
||||
return getMakefileHighlighter();
|
||||
case QSynedit::HighlighterLanguage::GLSL:
|
||||
case QSynedit::ProgrammingLanguage::GLSL:
|
||||
return getGLSLHighlighter();
|
||||
default:
|
||||
return QSynedit::PHighlighter();
|
||||
|
|
|
@ -23,7 +23,7 @@ class HighlighterManager
|
|||
public:
|
||||
HighlighterManager();
|
||||
|
||||
QSynedit::PHighlighter getHighlighter(QSynedit::HighlighterLanguage language);
|
||||
QSynedit::PHighlighter getHighlighter(QSynedit::ProgrammingLanguage language);
|
||||
QSynedit::PHighlighter getHighlighter(const QString& filename);
|
||||
QSynedit::PHighlighter copyHighlighter(QSynedit::PHighlighter highlighter);
|
||||
QSynedit::PHighlighter getCppHighlighter();
|
||||
|
|
|
@ -390,7 +390,7 @@ bool Editor::saveAs(const QString &name, bool fromProject){
|
|||
setUseCodeFolding(false);
|
||||
}
|
||||
setHighlighter(newHighlighter);
|
||||
if (!newHighlighter || newHighlighter->language() != QSynedit::HighlighterLanguage::Cpp) {
|
||||
if (!newHighlighter || newHighlighter->language() != QSynedit::ProgrammingLanguage::Cpp) {
|
||||
mSyntaxIssues.clear();
|
||||
}
|
||||
applyColorScheme(pSettings->editor().colorScheme());
|
||||
|
@ -1037,7 +1037,7 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
|
|||
if (CppTypeKeywords.contains(token)
|
||||
||
|
||||
(
|
||||
highlighter()->language()==QSynedit::HighlighterLanguage::Cpp
|
||||
highlighter()->language()==QSynedit::ProgrammingLanguage::Cpp
|
||||
&&
|
||||
((QSynedit::CppHighlighter*)highlighter().get())->customTypeKeywords().contains(token)
|
||||
)
|
||||
|
@ -2350,7 +2350,7 @@ bool Editor::handleParentheseSkip()
|
|||
if (document()->count()==0)
|
||||
return false;
|
||||
if (highlighter() && highlighter()->supportBraceLevel()) {
|
||||
QSynedit::HighlighterState lastLineState = document()->ranges(document()->count()-1);
|
||||
QSynedit::SyntaxerState lastLineState = document()->ranges(document()->count()-1);
|
||||
if (lastLineState.parenthesisLevel==0) {
|
||||
setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over
|
||||
return true;
|
||||
|
@ -2401,7 +2401,7 @@ bool Editor::handleBracketSkip()
|
|||
if (document()->count()==0)
|
||||
return false;
|
||||
if (highlighter() && highlighter()->supportBraceLevel()) {
|
||||
QSynedit::HighlighterState lastLineState = document()->ranges(document()->count()-1);
|
||||
QSynedit::SyntaxerState lastLineState = document()->ranges(document()->count()-1);
|
||||
if (lastLineState.bracketLevel==0) {
|
||||
setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over
|
||||
return true;
|
||||
|
@ -2488,7 +2488,7 @@ bool Editor::handleBraceSkip()
|
|||
return false;
|
||||
|
||||
if (highlighter() && highlighter()->supportBraceLevel()) {
|
||||
QSynedit::HighlighterState lastLineState = document()->ranges(document()->count()-1);
|
||||
QSynedit::SyntaxerState lastLineState = document()->ranges(document()->count()-1);
|
||||
if (lastLineState.braceLevel==0) {
|
||||
bool oldInsertMode = insertMode();
|
||||
setInsertMode(false); //set mode to overwrite
|
||||
|
@ -2662,7 +2662,7 @@ void Editor::initParser()
|
|||
{
|
||||
if (pSettings->codeCompletion().shareParser()) {
|
||||
if (pSettings->codeCompletion().enabled()
|
||||
&& (highlighter() && highlighter()->language() == QSynedit::HighlighterLanguage::Cpp)
|
||||
&& (highlighter() && highlighter()->language() == QSynedit::ProgrammingLanguage::Cpp)
|
||||
) {
|
||||
mParser = sharedParser(mUseCppSyntax?ParserLanguage::CPlusPlus:ParserLanguage::C);
|
||||
}
|
||||
|
@ -2682,7 +2682,7 @@ void Editor::initParser()
|
|||
resetCppParser(mParser);
|
||||
mParser->setEnabled(
|
||||
pSettings->codeCompletion().enabled() &&
|
||||
(highlighter() && highlighter()->language() == QSynedit::HighlighterLanguage::Cpp));
|
||||
(highlighter() && highlighter()->language() == QSynedit::ProgrammingLanguage::Cpp));
|
||||
}
|
||||
|
||||
Editor::QuoteStatus Editor::getQuoteStatus()
|
||||
|
@ -2814,8 +2814,8 @@ void Editor::reparse(bool resetParser)
|
|||
return;
|
||||
if (!highlighter())
|
||||
return;
|
||||
if (highlighter()->language() != QSynedit::HighlighterLanguage::Cpp
|
||||
&& highlighter()->language() != QSynedit::HighlighterLanguage::GLSL)
|
||||
if (highlighter()->language() != QSynedit::ProgrammingLanguage::Cpp
|
||||
&& highlighter()->language() != QSynedit::ProgrammingLanguage::GLSL)
|
||||
return;
|
||||
if (!mParser)
|
||||
return;
|
||||
|
@ -3122,7 +3122,7 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete, CodeComple
|
|||
|
||||
QSet<QString> keywords;
|
||||
if (highlighter()) {
|
||||
if (highlighter()->language() != QSynedit::HighlighterLanguage::Cpp ) {
|
||||
if (highlighter()->language() != QSynedit::ProgrammingLanguage::Cpp ) {
|
||||
keywords = highlighter()->keywords();
|
||||
} else {
|
||||
if (mUseCppSyntax) {
|
||||
|
@ -4582,7 +4582,7 @@ void Editor::checkSyntaxInBack()
|
|||
return;
|
||||
if (!highlighter())
|
||||
return;
|
||||
if (highlighter()->language()!=QSynedit::HighlighterLanguage::Cpp)
|
||||
if (highlighter()->language()!=QSynedit::ProgrammingLanguage::Cpp)
|
||||
return;
|
||||
pMainWindow->checkSyntaxInBack(this);
|
||||
}
|
||||
|
@ -4792,14 +4792,14 @@ void Editor::applySettings()
|
|||
}
|
||||
|
||||
if (pSettings->editor().enableCustomCTypeKeywords()) {
|
||||
if (highlighter() && highlighter()->language() == QSynedit::HighlighterLanguage::Cpp) {
|
||||
if (highlighter() && highlighter()->language() == QSynedit::ProgrammingLanguage::Cpp) {
|
||||
QSet<QString> set;
|
||||
foreach(const QString& s, pSettings->editor().customCTypeKeywords())
|
||||
set.insert(s);
|
||||
((QSynedit::CppHighlighter*)(highlighter().get()))->setCustomTypeKeywords(set);
|
||||
}
|
||||
} else {
|
||||
if (highlighter() && highlighter()->language() == QSynedit::HighlighterLanguage::Cpp) {
|
||||
if (highlighter() && highlighter()->language() == QSynedit::ProgrammingLanguage::Cpp) {
|
||||
((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) {
|
||||
PColorSchemeItem item = pColorManager->getItem(schemeName,schemeItemName);
|
||||
if (item) {
|
||||
QSynedit::PHighlighterAttribute attr = std::make_shared<QSynedit::HighlighterAttribute>(attrName,
|
||||
QSynedit::PHighlighterAttribute attr = std::make_shared<QSynedit::TokenAttribute>(attrName,
|
||||
QSynedit::TokenType::Default);
|
||||
attr->setForeground(item->foreground());
|
||||
attr->setBackground(item->background());
|
||||
|
|
|
@ -1236,7 +1236,7 @@ int SynEdit::findIndentsStartLine(int line, QVector<int> indents)
|
|||
if (line<0 || line>=mDocument->count())
|
||||
return -1;
|
||||
while (line>=1) {
|
||||
HighlighterState range = mDocument->ranges(line);
|
||||
SyntaxerState range = mDocument->ranges(line);
|
||||
QVector<int> newIndents = range.indents.mid(range.firstIndentThisLine);
|
||||
int i = 0;
|
||||
int len = indents.length();
|
||||
|
@ -1535,7 +1535,7 @@ void SynEdit::doShrinkSelection(const BufferCoord &/*pos*/)
|
|||
int SynEdit::findCommentStartLine(int searchStartLine)
|
||||
{
|
||||
int commentStartLine = searchStartLine;
|
||||
HighlighterState range;
|
||||
SyntaxerState range;
|
||||
while (commentStartLine>=1) {
|
||||
range = mDocument->ranges(commentStartLine-1);
|
||||
if (!mHighlighter->isLastLineCommentNotFinished(range.state)){
|
||||
|
@ -1573,7 +1573,7 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
|
|||
if (startLine>=1) {
|
||||
//calculate the indents of last statement;
|
||||
indentSpaces = leftSpaces(startLineText);
|
||||
HighlighterState rangePreceeding = mDocument->ranges(startLine-1);
|
||||
SyntaxerState rangePreceeding = mDocument->ranges(startLine-1);
|
||||
mHighlighter->setState(rangePreceeding);
|
||||
if (addIndent) {
|
||||
// QString trimmedS = s.trimmed();
|
||||
|
@ -1585,7 +1585,7 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
|
|||
} else {
|
||||
statePrePre = 0;
|
||||
}
|
||||
HighlighterState rangeAfterFirstToken = mHighlighter->getState();
|
||||
SyntaxerState rangeAfterFirstToken = mHighlighter->getState();
|
||||
QString firstToken = mHighlighter->getToken();
|
||||
PHighlighterAttribute attr = mHighlighter->getTokenAttribute();
|
||||
if (attr->tokenType() == TokenType::Keyword
|
||||
|
@ -1614,18 +1614,18 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
|
|||
l = startLine;
|
||||
} else if (attr->tokenType() == TokenType::Operator
|
||||
&& (firstToken == '{')
|
||||
&& (rangePreceeding.getLastIndent()==sitStatement)) {
|
||||
&& (rangePreceeding.getLastIndent()==IndentForStatement)) {
|
||||
// current line starts with '{' and last statement not finished, we should consider it to calc indents
|
||||
matchingIndents = rangeAfterFirstToken.matchingIndents;
|
||||
indentAdded = true;
|
||||
l = startLine;
|
||||
} else if (mHighlighter->language() == HighlighterLanguage::Cpp
|
||||
} else if (mHighlighter->language() == ProgrammingLanguage::Cpp
|
||||
&& trimmedLineText.startsWith('#')
|
||||
&& attr == ((CppHighlighter *)mHighlighter.get())->preprocessorAttribute()) {
|
||||
indentAdded = true;
|
||||
indentSpaces=0;
|
||||
l=0;
|
||||
} else if (mHighlighter->language() == HighlighterLanguage::Cpp
|
||||
} else if (mHighlighter->language() == ProgrammingLanguage::Cpp
|
||||
&& mHighlighter->isLastLineCommentNotFinished(rangePreceeding.state)
|
||||
) {
|
||||
// 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
|
||||
additionIndent = 1;
|
||||
int commentStartLine = findCommentStartLine(startLine-1);
|
||||
HighlighterState range;
|
||||
SyntaxerState range;
|
||||
indentSpaces = leftSpaces(mDocument->getString(commentStartLine-1));
|
||||
range = mDocument->ranges(commentStartLine-1);
|
||||
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
|
||||
additionIndent = 0;
|
||||
int commentStartLine = findCommentStartLine(startLine-1);
|
||||
HighlighterState range;
|
||||
SyntaxerState range;
|
||||
indentSpaces = leftSpaces(mDocument->getString(commentStartLine-1))+2;
|
||||
range = mDocument->ranges(commentStartLine-1);
|
||||
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
|
||||
// we should use the indents of the start line of the comment
|
||||
int commentStartLine = findCommentStartLine(startLine-2);
|
||||
HighlighterState range;
|
||||
SyntaxerState range;
|
||||
indentSpaces = leftSpaces(mDocument->getString(commentStartLine-1));
|
||||
range = mDocument->ranges(commentStartLine-1);
|
||||
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;
|
||||
while (l>=1) {
|
||||
HighlighterState range = mDocument->ranges(l-1);
|
||||
SyntaxerState range = mDocument->ranges(l-1);
|
||||
QVector<int> newIndents = range.indents.mid(range.firstIndentThisLine);
|
||||
int i = 0;
|
||||
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
|
||||
if (len>0 && !range.matchingIndents.isEmpty()
|
||||
&&
|
||||
( matchingIndents.back()== sitBrace
|
||||
|| matchingIndents.back() == sitStatement
|
||||
( matchingIndents.back()== IndentForBrace
|
||||
|| matchingIndents.back() == IndentForStatement
|
||||
) ) {
|
||||
// but it's not a complete statement
|
||||
matchingIndents = range.matchingIndents;
|
||||
|
@ -2906,7 +2906,7 @@ void SynEdit::doAddChar(QChar AChar)
|
|||
if (mActiveSelectionMode==SelectionMode::Normal
|
||||
&& mOptions.testFlag(eoAutoIndent)
|
||||
&& mHighlighter
|
||||
&& mHighlighter->language() == HighlighterLanguage::Cpp
|
||||
&& mHighlighter->language() == ProgrammingLanguage::Cpp
|
||||
&& (oldCaretY<=mDocument->count()) ) {
|
||||
|
||||
//unindent if ':' at end of the line
|
||||
|
@ -3408,7 +3408,7 @@ void SynEdit::updateModifiedStatus()
|
|||
|
||||
int SynEdit::scanFrom(int Index, int canStopIndex)
|
||||
{
|
||||
HighlighterState iRange;
|
||||
SyntaxerState iRange;
|
||||
int Result = std::max(0,Index);
|
||||
if (Result >= mDocument->count())
|
||||
return Result;
|
||||
|
@ -3462,7 +3462,7 @@ void SynEdit::rescanRange(int line)
|
|||
}
|
||||
mHighlighter->setLine(mDocument->getString(line), line);
|
||||
mHighlighter->nextToEol();
|
||||
HighlighterState iRange = mHighlighter->getState();
|
||||
SyntaxerState iRange = mHighlighter->getState();
|
||||
mDocument->setRange(line,iRange);
|
||||
}
|
||||
|
||||
|
@ -4981,7 +4981,7 @@ void SynEdit::doGotoBlockStart(bool isSelection)
|
|||
{
|
||||
if (mCaretY<0 || mCaretY>document()->count())
|
||||
return;
|
||||
HighlighterState state = document()->ranges(mCaretY-1);
|
||||
SyntaxerState state = document()->ranges(mCaretY-1);
|
||||
//todo: handle block other than {}
|
||||
if (document()->braceLevels(mCaretY-1)==0) {
|
||||
doGotoEditorStart(isSelection);
|
||||
|
@ -5003,7 +5003,7 @@ void SynEdit::doGotoBlockEnd(bool isSelection)
|
|||
{
|
||||
if (mCaretY<0 || mCaretY>document()->count())
|
||||
return;
|
||||
HighlighterState state = document()->ranges(mCaretY-1);
|
||||
SyntaxerState state = document()->ranges(mCaretY-1);
|
||||
//todo: handle block other than {}
|
||||
if (document()->blockLevel(mCaretY-1)==0) {
|
||||
doGotoEditorEnd(isSelection);
|
||||
|
@ -5479,7 +5479,7 @@ int SynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList&
|
|||
int caretY=pos.line;
|
||||
// step1: insert the first line of Value into current line
|
||||
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]);
|
||||
if (sLeftSide.isEmpty()) {
|
||||
sLeftSide = GetLeftSpacing(calcIndentSpaces(caretY,s,true),true);
|
||||
|
@ -5509,7 +5509,7 @@ int SynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList&
|
|||
if (i==text.length()-1) {
|
||||
str = sRightSide;
|
||||
} 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);
|
||||
} else {
|
||||
str = "";
|
||||
|
@ -5519,7 +5519,7 @@ int SynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList&
|
|||
str = text[i];
|
||||
if (i==text.length()-1)
|
||||
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);
|
||||
str = GetLeftSpacing(indentSpaces,true)+trimLeft(str);
|
||||
}
|
||||
|
|
|
@ -158,7 +158,7 @@ QString Document::lineBreak() const
|
|||
return "\n";
|
||||
}
|
||||
|
||||
HighlighterState Document::ranges(int index)
|
||||
SyntaxerState Document::ranges(int index)
|
||||
{
|
||||
QMutexLocker locker(&mMutex);
|
||||
if (index>=0 && index < mLines.size()) {
|
||||
|
@ -166,7 +166,7 @@ HighlighterState Document::ranges(int index)
|
|||
} else {
|
||||
ListIndexOutOfBounds(index);
|
||||
}
|
||||
return HighlighterState();
|
||||
return SyntaxerState();
|
||||
}
|
||||
|
||||
void Document::insertItem(int Index, const QString &s)
|
||||
|
@ -201,7 +201,7 @@ void Document::setAppendNewLineAtEOF(bool appendNewLineAtEOF)
|
|||
mAppendNewLineAtEOF = appendNewLineAtEOF;
|
||||
}
|
||||
|
||||
void Document::setRange(int Index, const HighlighterState& range)
|
||||
void Document::setRange(int Index, const SyntaxerState& range)
|
||||
{
|
||||
QMutexLocker locker(&mMutex);
|
||||
if (Index<0 || Index>=mLines.count()) {
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace QSynedit {
|
|||
|
||||
struct DocumentLine {
|
||||
QString fString;
|
||||
HighlighterState fRange;
|
||||
SyntaxerState fRange;
|
||||
int fColumns; //
|
||||
|
||||
public:
|
||||
|
@ -64,8 +64,8 @@ public:
|
|||
int blockEnded(int index);
|
||||
int lengthOfLongestLine();
|
||||
QString lineBreak() const;
|
||||
HighlighterState ranges(int index);
|
||||
void setRange(int index, const HighlighterState& range);
|
||||
SyntaxerState ranges(int index);
|
||||
void setRange(int index, const SyntaxerState& range);
|
||||
QString getString(int index);
|
||||
int count();
|
||||
QString text();
|
||||
|
|
|
@ -979,7 +979,7 @@ void SynEditTextPainter::paintLines()
|
|||
|| sToken == "("
|
||||
|| sToken == "{"
|
||||
) {
|
||||
HighlighterState rangeState = edit->mHighlighter->getState();
|
||||
SyntaxerState rangeState = edit->mHighlighter->getState();
|
||||
getBraceColorAttr(rangeState.bracketLevel
|
||||
+rangeState.braceLevel
|
||||
+rangeState.parenthesisLevel
|
||||
|
@ -988,7 +988,7 @@ void SynEditTextPainter::paintLines()
|
|||
|| sToken == ")"
|
||||
|| sToken == "}"
|
||||
){
|
||||
HighlighterState rangeState = edit->mHighlighter->getState();
|
||||
SyntaxerState rangeState = edit->mHighlighter->getState();
|
||||
getBraceColorAttr(rangeState.bracketLevel
|
||||
+rangeState.braceLevel
|
||||
+rangeState.parenthesisLevel+1,
|
||||
|
|
|
@ -98,13 +98,13 @@ const QSet<QString> ASMHighlighter::Keywords {
|
|||
|
||||
ASMHighlighter::ASMHighlighter()
|
||||
{
|
||||
mNumberAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrNumber, TokenType::Number);
|
||||
mNumberAttribute = std::make_shared<TokenAttribute>(SYNS_AttrNumber, TokenType::Number);
|
||||
addAttribute(mNumberAttribute);
|
||||
mDirectiveAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrVariable, TokenType::Keyword);
|
||||
mDirectiveAttribute = std::make_shared<TokenAttribute>(SYNS_AttrVariable, TokenType::Keyword);
|
||||
addAttribute(mDirectiveAttribute);
|
||||
mLabelAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrFunction, TokenType::Keyword);
|
||||
mLabelAttribute = std::make_shared<TokenAttribute>(SYNS_AttrFunction, TokenType::Keyword);
|
||||
addAttribute(mLabelAttribute);
|
||||
mRegisterAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrClass, TokenType::Keyword);
|
||||
mRegisterAttribute = std::make_shared<TokenAttribute>(SYNS_AttrClass, TokenType::Keyword);
|
||||
addAttribute(mRegisterAttribute);
|
||||
}
|
||||
|
||||
|
@ -298,9 +298,9 @@ QString ASMHighlighter::languageName()
|
|||
return "asm";
|
||||
}
|
||||
|
||||
HighlighterLanguage ASMHighlighter::language()
|
||||
ProgrammingLanguage ASMHighlighter::language()
|
||||
{
|
||||
return HighlighterLanguage::Asssembly;
|
||||
return ProgrammingLanguage::Asssembly;
|
||||
}
|
||||
|
||||
QString ASMHighlighter::getToken() const
|
||||
|
@ -439,12 +439,12 @@ bool ASMHighlighter::isLastLineStringNotFinished(int /*state*/) const
|
|||
return true;
|
||||
}
|
||||
|
||||
HighlighterState ASMHighlighter::getState() const
|
||||
SyntaxerState ASMHighlighter::getState() const
|
||||
{
|
||||
return HighlighterState();
|
||||
return SyntaxerState();
|
||||
}
|
||||
|
||||
void ASMHighlighter::setState(const HighlighterState&)
|
||||
void ASMHighlighter::setState(const SyntaxerState&)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ public:
|
|||
bool eol() const override;
|
||||
|
||||
QString languageName() override;
|
||||
HighlighterLanguage language() override;
|
||||
ProgrammingLanguage language() override;
|
||||
QString getToken() const override;
|
||||
const PHighlighterAttribute &getTokenAttribute() const override;
|
||||
int getTokenPos() override;
|
||||
|
@ -100,8 +100,8 @@ public:
|
|||
bool getTokenFinished() const override;
|
||||
bool isLastLineCommentNotFinished(int state) const override;
|
||||
bool isLastLineStringNotFinished(int state) const override;
|
||||
HighlighterState getState() const override;
|
||||
void setState(const HighlighterState& rangeState) override;
|
||||
SyntaxerState getState() const override;
|
||||
void setState(const SyntaxerState& rangeState) override;
|
||||
void resetState() override;
|
||||
|
||||
|
||||
|
|
|
@ -22,22 +22,22 @@ Highlighter::Highlighter() :
|
|||
mEnabled(true),
|
||||
mWordBreakChars{ WordBreakChars }
|
||||
{
|
||||
mCommentAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrComment,
|
||||
mCommentAttribute = std::make_shared<TokenAttribute>(SYNS_AttrComment,
|
||||
TokenType::Comment);
|
||||
addAttribute(mCommentAttribute);
|
||||
mIdentifierAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrIdentifier,
|
||||
mIdentifierAttribute = std::make_shared<TokenAttribute>(SYNS_AttrIdentifier,
|
||||
TokenType::Identifier);
|
||||
addAttribute(mIdentifierAttribute);
|
||||
mKeywordAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrReservedWord,
|
||||
mKeywordAttribute = std::make_shared<TokenAttribute>(SYNS_AttrReservedWord,
|
||||
TokenType::Keyword);
|
||||
addAttribute(mKeywordAttribute);
|
||||
mStringAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrString,
|
||||
mStringAttribute = std::make_shared<TokenAttribute>(SYNS_AttrString,
|
||||
TokenType::String);
|
||||
addAttribute(mStringAttribute);
|
||||
mWhitespaceAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrSpace,
|
||||
mWhitespaceAttribute = std::make_shared<TokenAttribute>(SYNS_AttrSpace,
|
||||
TokenType::Space);
|
||||
addAttribute(mWhitespaceAttribute);
|
||||
mSymbolAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrSymbol,
|
||||
mSymbolAttribute = std::make_shared<TokenAttribute>(SYNS_AttrSymbol,
|
||||
TokenType::Operator);
|
||||
addAttribute(mSymbolAttribute);
|
||||
}
|
||||
|
@ -196,49 +196,49 @@ void Highlighter::setEnabled(bool value)
|
|||
}
|
||||
}
|
||||
|
||||
FontStyles HighlighterAttribute::styles() const
|
||||
FontStyles TokenAttribute::styles() const
|
||||
{
|
||||
return mStyles;
|
||||
}
|
||||
|
||||
void HighlighterAttribute::setStyles(const FontStyles &styles)
|
||||
void TokenAttribute::setStyles(const FontStyles &styles)
|
||||
{
|
||||
if (mStyles!=styles) {
|
||||
mStyles = styles;
|
||||
}
|
||||
}
|
||||
|
||||
const QColor& HighlighterAttribute::foreground() const
|
||||
const QColor& TokenAttribute::foreground() const
|
||||
{
|
||||
return mForeground;
|
||||
}
|
||||
|
||||
void HighlighterAttribute::setForeground(const QColor &color)
|
||||
void TokenAttribute::setForeground(const QColor &color)
|
||||
{
|
||||
mForeground = color;
|
||||
}
|
||||
|
||||
const QColor &HighlighterAttribute::background() const
|
||||
const QColor &TokenAttribute::background() const
|
||||
{
|
||||
return mBackground;
|
||||
}
|
||||
|
||||
void HighlighterAttribute::setBackground(const QColor &background)
|
||||
void TokenAttribute::setBackground(const QColor &background)
|
||||
{
|
||||
mBackground = background;
|
||||
}
|
||||
|
||||
TokenType HighlighterAttribute::tokenType() const
|
||||
TokenType TokenAttribute::tokenType() const
|
||||
{
|
||||
return mTokenType;
|
||||
}
|
||||
|
||||
QString HighlighterAttribute::name() const
|
||||
QString TokenAttribute::name() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
HighlighterAttribute::HighlighterAttribute(const QString &name, TokenType tokenType):
|
||||
TokenAttribute::TokenAttribute(const QString &name, TokenType tokenType):
|
||||
mForeground(QColor()),
|
||||
mBackground(QColor()),
|
||||
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
|
||||
return (state == s2.state)
|
||||
|
@ -256,14 +256,14 @@ bool HighlighterState::operator==(const HighlighterState &s2)
|
|||
;
|
||||
}
|
||||
|
||||
int HighlighterState::getLastIndent()
|
||||
int SyntaxerState::getLastIndent()
|
||||
{
|
||||
if (indents.isEmpty())
|
||||
return -1;
|
||||
return indents.back();
|
||||
}
|
||||
|
||||
HighlighterState::HighlighterState():
|
||||
SyntaxerState::SyntaxerState():
|
||||
state(0),
|
||||
blockLevel(0),
|
||||
blockStarted(0),
|
||||
|
|
|
@ -27,14 +27,14 @@
|
|||
#include "../Types.h"
|
||||
|
||||
namespace QSynedit {
|
||||
enum SynIndentType {
|
||||
sitBrace = 0,
|
||||
sitParenthesis = 1,
|
||||
sitBracket = 2,
|
||||
sitStatement = 3,
|
||||
enum IndentType {
|
||||
IndentForBrace,
|
||||
IndentForParenthesis,
|
||||
IndentForBracket,
|
||||
IndentForStatement,
|
||||
};
|
||||
|
||||
struct HighlighterState {
|
||||
struct SyntaxerState {
|
||||
int state; // current syntax parsing state
|
||||
int blockLevel; // needed by block folding
|
||||
int blockStarted; // needed by block folding
|
||||
|
@ -51,9 +51,9 @@ struct HighlighterState {
|
|||
QVector<int> matchingIndents; /* the indent matched ( and removed )
|
||||
but not started at this line
|
||||
(need by auto indent) */
|
||||
bool operator==(const HighlighterState& s2);
|
||||
bool operator==(const SyntaxerState& s2);
|
||||
int getLastIndent();
|
||||
HighlighterState();
|
||||
SyntaxerState();
|
||||
};
|
||||
|
||||
enum class TokenType {
|
||||
|
@ -78,7 +78,7 @@ enum class TokenType {
|
|||
Embeded //language embeded in others
|
||||
};
|
||||
|
||||
enum class HighlighterLanguage {
|
||||
enum class ProgrammingLanguage {
|
||||
DecideBySuffix,
|
||||
Composition,
|
||||
Asssembly,
|
||||
|
@ -88,9 +88,9 @@ enum class HighlighterLanguage {
|
|||
Custom
|
||||
};
|
||||
|
||||
class HighlighterAttribute {
|
||||
class TokenAttribute {
|
||||
public:
|
||||
explicit HighlighterAttribute(const QString& name, TokenType mTokenType);
|
||||
explicit TokenAttribute(const QString& name, TokenType mTokenType);
|
||||
|
||||
QString name() const;
|
||||
|
||||
|
@ -113,7 +113,7 @@ private:
|
|||
TokenType mTokenType;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<HighlighterAttribute> PHighlighterAttribute;
|
||||
typedef std::shared_ptr<TokenAttribute> PHighlighterAttribute;
|
||||
using HighlighterAttributeList = QVector<PHighlighterAttribute>;
|
||||
|
||||
class Highlighter {
|
||||
|
@ -142,20 +142,20 @@ public:
|
|||
virtual bool isLastLineCommentNotFinished(int state) const = 0;
|
||||
virtual bool isLastLineStringNotFinished(int state) const = 0;
|
||||
virtual bool eol() const = 0;
|
||||
virtual HighlighterState getState() const = 0;
|
||||
virtual SyntaxerState getState() const = 0;
|
||||
virtual QString getToken() const=0;
|
||||
virtual const PHighlighterAttribute &getTokenAttribute() const=0;
|
||||
virtual int getTokenPos() = 0;
|
||||
virtual bool isKeyword(const QString& word);
|
||||
virtual void next() = 0;
|
||||
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 resetState() = 0;
|
||||
virtual QSet<QString> keywords() const;
|
||||
|
||||
virtual QString languageName() = 0;
|
||||
virtual HighlighterLanguage language() = 0;
|
||||
virtual ProgrammingLanguage language() = 0;
|
||||
|
||||
virtual QString foldString();
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ HighlighterSchema::HighlighterSchema(QObject *parent):
|
|||
QObject(parent),
|
||||
mCaseSensitive(true)
|
||||
{
|
||||
mMarkerAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrMarker,
|
||||
mMarkerAttribute = std::make_shared<TokenAttribute>(SYNS_AttrMarker,
|
||||
QSynedit::TokenType::Default);
|
||||
mMarkerAttribute->setForeground(Qt::yellow);
|
||||
mMarkerAttribute->setStyles(FontStyle::fsBold);
|
||||
|
|
|
@ -143,48 +143,48 @@ const QSet<QString> CppHighlighter::Keywords {
|
|||
};
|
||||
CppHighlighter::CppHighlighter(): Highlighter()
|
||||
{
|
||||
mAsmAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrAssembler,
|
||||
mAsmAttribute = std::make_shared<TokenAttribute>(SYNS_AttrAssembler,
|
||||
TokenType::Embeded);
|
||||
addAttribute(mAsmAttribute);
|
||||
mCharAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrCharacter,
|
||||
mCharAttribute = std::make_shared<TokenAttribute>(SYNS_AttrCharacter,
|
||||
TokenType::Character);
|
||||
addAttribute(mCharAttribute);
|
||||
|
||||
mClassAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrClass,
|
||||
mClassAttribute = std::make_shared<TokenAttribute>(SYNS_AttrClass,
|
||||
TokenType::Identifier);
|
||||
addAttribute(mClassAttribute);
|
||||
mFloatAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrFloat,
|
||||
mFloatAttribute = std::make_shared<TokenAttribute>(SYNS_AttrFloat,
|
||||
TokenType::Number);
|
||||
addAttribute(mFloatAttribute);
|
||||
mFunctionAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrFunction,
|
||||
mFunctionAttribute = std::make_shared<TokenAttribute>(SYNS_AttrFunction,
|
||||
TokenType::Identifier);
|
||||
addAttribute(mFunctionAttribute);
|
||||
mGlobalVarAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrGlobalVariable,
|
||||
mGlobalVarAttribute = std::make_shared<TokenAttribute>(SYNS_AttrGlobalVariable,
|
||||
TokenType::Identifier);
|
||||
addAttribute(mGlobalVarAttribute);
|
||||
mHexAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrHexadecimal,
|
||||
mHexAttribute = std::make_shared<TokenAttribute>(SYNS_AttrHexadecimal,
|
||||
TokenType::Number);
|
||||
addAttribute(mHexAttribute);
|
||||
mInvalidAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrIllegalChar,
|
||||
mInvalidAttribute = std::make_shared<TokenAttribute>(SYNS_AttrIllegalChar,
|
||||
TokenType::Error);
|
||||
addAttribute(mInvalidAttribute);
|
||||
mLocalVarAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrLocalVariable,
|
||||
mLocalVarAttribute = std::make_shared<TokenAttribute>(SYNS_AttrLocalVariable,
|
||||
TokenType::Identifier);
|
||||
addAttribute(mLocalVarAttribute);
|
||||
mNumberAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrNumber,
|
||||
mNumberAttribute = std::make_shared<TokenAttribute>(SYNS_AttrNumber,
|
||||
TokenType::Number);
|
||||
addAttribute(mNumberAttribute);
|
||||
mOctAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrOctal,
|
||||
mOctAttribute = std::make_shared<TokenAttribute>(SYNS_AttrOctal,
|
||||
TokenType::Number);
|
||||
addAttribute(mOctAttribute);
|
||||
mPreprocessorAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrPreprocessor,
|
||||
mPreprocessorAttribute = std::make_shared<TokenAttribute>(SYNS_AttrPreprocessor,
|
||||
TokenType::Preprocessor);
|
||||
addAttribute(mPreprocessorAttribute);
|
||||
|
||||
mStringEscapeSequenceAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrStringEscapeSequences,
|
||||
mStringEscapeSequenceAttribute = std::make_shared<TokenAttribute>(SYNS_AttrStringEscapeSequences,
|
||||
TokenType::String);
|
||||
addAttribute(mStringEscapeSequenceAttribute);
|
||||
mVariableAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrVariable,
|
||||
mVariableAttribute = std::make_shared<TokenAttribute>(SYNS_AttrVariable,
|
||||
TokenType::Identifier);
|
||||
addAttribute(mVariableAttribute);
|
||||
resetState();
|
||||
|
@ -382,7 +382,7 @@ void CppHighlighter::braceCloseProc()
|
|||
} else {
|
||||
mRange.blockEnded++ ;
|
||||
}
|
||||
popIndents(sitBrace);
|
||||
popIndents(IndentForBrace);
|
||||
}
|
||||
|
||||
void CppHighlighter::braceOpenProc()
|
||||
|
@ -396,19 +396,19 @@ void CppHighlighter::braceOpenProc()
|
|||
mRange.braceLevel += 1;
|
||||
mRange.blockLevel += 1;
|
||||
mRange.blockStarted++;
|
||||
if (mRange.getLastIndent() == sitStatement) {
|
||||
if (mRange.getLastIndent() == IndentForStatement) {
|
||||
// if last indent is started by 'if' 'for' etc
|
||||
// just replace it
|
||||
while (mRange.getLastIndent() == sitStatement)
|
||||
popIndents(sitStatement);
|
||||
pushIndents(sitBrace);
|
||||
while (mRange.getLastIndent() == IndentForStatement)
|
||||
popIndents(IndentForStatement);
|
||||
pushIndents(IndentForBrace);
|
||||
// int idx = mRange.indents.length()-1;
|
||||
// if (idx < mRange.firstIndentThisLine) {
|
||||
// mRange.firstIndentThisLine = idx;
|
||||
// }
|
||||
// mRange.indents.replace(idx,1,BraceIndentType);
|
||||
} else {
|
||||
pushIndents(sitBrace);
|
||||
pushIndents(IndentForBrace);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -570,7 +570,7 @@ void CppHighlighter::identProc()
|
|||
if (isKeyword(word)) {
|
||||
mTokenId = TokenId::Key;
|
||||
if (CppStatementKeyWords.contains(word)) {
|
||||
pushIndents(sitStatement);
|
||||
pushIndents(IndentForStatement);
|
||||
}
|
||||
} else {
|
||||
mTokenId = TokenId::Identifier;
|
||||
|
@ -912,7 +912,7 @@ void CppHighlighter::roundCloseProc()
|
|||
mRange.parenthesisLevel--;
|
||||
if (mRange.parenthesisLevel<0)
|
||||
mRange.parenthesisLevel=0;
|
||||
popIndents(sitParenthesis);
|
||||
popIndents(IndentForParenthesis);
|
||||
}
|
||||
|
||||
void CppHighlighter::roundOpenProc()
|
||||
|
@ -920,7 +920,7 @@ void CppHighlighter::roundOpenProc()
|
|||
mRun += 1;
|
||||
mTokenId = TokenId::Symbol;
|
||||
mRange.parenthesisLevel++;
|
||||
pushIndents(sitParenthesis);
|
||||
pushIndents(IndentForParenthesis);
|
||||
}
|
||||
|
||||
void CppHighlighter::semiColonProc()
|
||||
|
@ -929,8 +929,8 @@ void CppHighlighter::semiColonProc()
|
|||
mTokenId = TokenId::Symbol;
|
||||
if (mRange.state == RangeState::rsAsm)
|
||||
mRange.state = RangeState::rsUnknown;
|
||||
while (mRange.getLastIndent() == sitStatement) {
|
||||
popIndents(sitStatement);
|
||||
while (mRange.getLastIndent() == IndentForStatement) {
|
||||
popIndents(IndentForStatement);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -994,7 +994,7 @@ void CppHighlighter::squareCloseProc()
|
|||
mRange.bracketLevel--;
|
||||
if (mRange.bracketLevel<0)
|
||||
mRange.bracketLevel=0;
|
||||
popIndents(sitBracket);
|
||||
popIndents(IndentForBracket);
|
||||
}
|
||||
|
||||
void CppHighlighter::squareOpenProc()
|
||||
|
@ -1002,7 +1002,7 @@ void CppHighlighter::squareOpenProc()
|
|||
mRun+=1;
|
||||
mTokenId = TokenId::Symbol;
|
||||
mRange.bracketLevel++;
|
||||
pushIndents(sitBracket);
|
||||
pushIndents(IndentForBracket);
|
||||
}
|
||||
|
||||
void CppHighlighter::starProc()
|
||||
|
@ -1593,7 +1593,7 @@ bool CppHighlighter::isKeyword(const QString &word)
|
|||
return Keywords.contains(word) || mCustomTypeKeywords.contains(word);
|
||||
}
|
||||
|
||||
void CppHighlighter::setState(const HighlighterState& rangeState)
|
||||
void CppHighlighter::setState(const SyntaxerState& rangeState)
|
||||
{
|
||||
mRange = rangeState;
|
||||
// current line's left / right parenthesis count should be reset before parsing each line
|
||||
|
@ -1625,12 +1625,12 @@ QString CppHighlighter::languageName()
|
|||
return "cpp";
|
||||
}
|
||||
|
||||
HighlighterLanguage CppHighlighter::language()
|
||||
ProgrammingLanguage CppHighlighter::language()
|
||||
{
|
||||
return HighlighterLanguage::Cpp;
|
||||
return ProgrammingLanguage::Cpp;
|
||||
}
|
||||
|
||||
HighlighterState CppHighlighter::getState() const
|
||||
SyntaxerState CppHighlighter::getState() const
|
||||
{
|
||||
return mRange;
|
||||
}
|
||||
|
|
|
@ -137,7 +137,7 @@ private:
|
|||
|
||||
private:
|
||||
bool mAsmStart;
|
||||
HighlighterState mRange;
|
||||
SyntaxerState mRange;
|
||||
// SynRangeState mSpaceRange;
|
||||
QString mLine;
|
||||
int mLineSize;
|
||||
|
@ -179,15 +179,15 @@ public:
|
|||
void next() override;
|
||||
void setLine(const QString &newLine, int lineNumber) override;
|
||||
bool isKeyword(const QString &word) override;
|
||||
void setState(const HighlighterState& rangeState) override;
|
||||
void setState(const SyntaxerState& rangeState) override;
|
||||
void resetState() override;
|
||||
|
||||
QString languageName() override;
|
||||
HighlighterLanguage language() override;
|
||||
ProgrammingLanguage language() override;
|
||||
|
||||
// SynHighlighter interface
|
||||
public:
|
||||
HighlighterState getState() const override;
|
||||
SyntaxerState getState() const override;
|
||||
|
||||
// SynHighlighter interface
|
||||
public:
|
||||
|
|
|
@ -22,8 +22,8 @@ QString CustomHighlighterV1::languageName()
|
|||
return mLanguageName;
|
||||
}
|
||||
|
||||
HighlighterLanguage CustomHighlighterV1::language()
|
||||
ProgrammingLanguage CustomHighlighterV1::language()
|
||||
{
|
||||
return HighlighterLanguage::Custom;
|
||||
return ProgrammingLanguage::Custom;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public:
|
|||
void resetState() override;
|
||||
|
||||
QString languageName() override;
|
||||
HighlighterLanguage language() override;
|
||||
ProgrammingLanguage language() override;
|
||||
protected:
|
||||
bool mIgnoreCase;
|
||||
QString mCommentBlockStart;
|
||||
|
@ -47,7 +47,7 @@ protected:
|
|||
QString mLanguageName;
|
||||
QSet<QString> mSuffixes;
|
||||
|
||||
HighlighterState mRange;
|
||||
SyntaxerState mRange;
|
||||
// SynRangeState mSpaceRange;
|
||||
QString mLine;
|
||||
int mLineSize;
|
||||
|
|
|
@ -83,48 +83,48 @@ const QSet<QString> GLSLHighlighter::Keywords {
|
|||
|
||||
GLSLHighlighter::GLSLHighlighter(): Highlighter()
|
||||
{
|
||||
mAsmAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrAssembler,
|
||||
mAsmAttribute = std::make_shared<TokenAttribute>(SYNS_AttrAssembler,
|
||||
TokenType::Embeded);
|
||||
addAttribute(mAsmAttribute);
|
||||
mCharAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrCharacter,
|
||||
mCharAttribute = std::make_shared<TokenAttribute>(SYNS_AttrCharacter,
|
||||
TokenType::Character);
|
||||
addAttribute(mCharAttribute);
|
||||
|
||||
mClassAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrClass,
|
||||
mClassAttribute = std::make_shared<TokenAttribute>(SYNS_AttrClass,
|
||||
TokenType::Identifier);
|
||||
addAttribute(mClassAttribute);
|
||||
mFloatAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrFloat,
|
||||
mFloatAttribute = std::make_shared<TokenAttribute>(SYNS_AttrFloat,
|
||||
TokenType::Number);
|
||||
addAttribute(mFloatAttribute);
|
||||
mFunctionAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrFunction,
|
||||
mFunctionAttribute = std::make_shared<TokenAttribute>(SYNS_AttrFunction,
|
||||
TokenType::Identifier);
|
||||
addAttribute(mFunctionAttribute);
|
||||
mGlobalVarAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrGlobalVariable,
|
||||
mGlobalVarAttribute = std::make_shared<TokenAttribute>(SYNS_AttrGlobalVariable,
|
||||
TokenType::Identifier);
|
||||
addAttribute(mGlobalVarAttribute);
|
||||
mHexAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrHexadecimal,
|
||||
mHexAttribute = std::make_shared<TokenAttribute>(SYNS_AttrHexadecimal,
|
||||
TokenType::Number);
|
||||
addAttribute(mHexAttribute);
|
||||
mInvalidAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrIllegalChar,
|
||||
mInvalidAttribute = std::make_shared<TokenAttribute>(SYNS_AttrIllegalChar,
|
||||
TokenType::Error);
|
||||
addAttribute(mInvalidAttribute);
|
||||
mLocalVarAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrLocalVariable,
|
||||
mLocalVarAttribute = std::make_shared<TokenAttribute>(SYNS_AttrLocalVariable,
|
||||
TokenType::Identifier);
|
||||
addAttribute(mLocalVarAttribute);
|
||||
mNumberAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrNumber,
|
||||
mNumberAttribute = std::make_shared<TokenAttribute>(SYNS_AttrNumber,
|
||||
TokenType::Number);
|
||||
addAttribute(mNumberAttribute);
|
||||
mOctAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrOctal,
|
||||
mOctAttribute = std::make_shared<TokenAttribute>(SYNS_AttrOctal,
|
||||
TokenType::Number);
|
||||
addAttribute(mOctAttribute);
|
||||
mPreprocessorAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrPreprocessor,
|
||||
mPreprocessorAttribute = std::make_shared<TokenAttribute>(SYNS_AttrPreprocessor,
|
||||
TokenType::Preprocessor);
|
||||
addAttribute(mPreprocessorAttribute);
|
||||
|
||||
mStringEscapeSequenceAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrStringEscapeSequences,
|
||||
mStringEscapeSequenceAttribute = std::make_shared<TokenAttribute>(SYNS_AttrStringEscapeSequences,
|
||||
TokenType::String);
|
||||
addAttribute(mStringEscapeSequenceAttribute);
|
||||
mVariableAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrVariable,
|
||||
mVariableAttribute = std::make_shared<TokenAttribute>(SYNS_AttrVariable,
|
||||
TokenType::Identifier);
|
||||
addAttribute(mVariableAttribute);
|
||||
|
||||
|
@ -322,7 +322,7 @@ void GLSLHighlighter::braceCloseProc()
|
|||
} else {
|
||||
mRange.blockEnded++ ;
|
||||
}
|
||||
popIndents(sitBrace);
|
||||
popIndents(IndentForBrace);
|
||||
}
|
||||
|
||||
void GLSLHighlighter::braceOpenProc()
|
||||
|
@ -336,19 +336,19 @@ void GLSLHighlighter::braceOpenProc()
|
|||
mRange.braceLevel += 1;
|
||||
mRange.blockLevel += 1;
|
||||
mRange.blockStarted += 1;
|
||||
if (mRange.getLastIndent() == sitStatement) {
|
||||
if (mRange.getLastIndent() == IndentForStatement) {
|
||||
// if last indent is started by 'if' 'for' etc
|
||||
// just replace it
|
||||
while (mRange.getLastIndent() == sitStatement)
|
||||
popIndents(sitStatement);
|
||||
pushIndents(sitBrace);
|
||||
while (mRange.getLastIndent() == IndentForStatement)
|
||||
popIndents(IndentForStatement);
|
||||
pushIndents(IndentForBrace);
|
||||
// int idx = mRange.indents.length()-1;
|
||||
// if (idx < mRange.firstIndentThisLine) {
|
||||
// mRange.firstIndentThisLine = idx;
|
||||
// }
|
||||
// mRange.indents.replace(idx,1,BraceIndentType);
|
||||
} else {
|
||||
pushIndents(sitBrace);
|
||||
pushIndents(IndentForBrace);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -483,7 +483,7 @@ void GLSLHighlighter::identProc()
|
|||
if (isKeyword(word)) {
|
||||
mTokenId = TokenId::Key;
|
||||
if (GLSLStatementKeyWords.contains(word)) {
|
||||
pushIndents(sitStatement);
|
||||
pushIndents(IndentForStatement);
|
||||
}
|
||||
} else {
|
||||
mTokenId = TokenId::Identifier;
|
||||
|
@ -821,7 +821,7 @@ void GLSLHighlighter::roundCloseProc()
|
|||
mRange.parenthesisLevel--;
|
||||
if (mRange.parenthesisLevel<0)
|
||||
mRange.parenthesisLevel=0;
|
||||
popIndents(sitParenthesis);
|
||||
popIndents(IndentForParenthesis);
|
||||
}
|
||||
|
||||
void GLSLHighlighter::roundOpenProc()
|
||||
|
@ -829,7 +829,7 @@ void GLSLHighlighter::roundOpenProc()
|
|||
mRun += 1;
|
||||
mTokenId = TokenId::Symbol;
|
||||
mRange.parenthesisLevel++;
|
||||
pushIndents(sitParenthesis);
|
||||
pushIndents(IndentForParenthesis);
|
||||
}
|
||||
|
||||
void GLSLHighlighter::semiColonProc()
|
||||
|
@ -838,8 +838,8 @@ void GLSLHighlighter::semiColonProc()
|
|||
mTokenId = TokenId::Symbol;
|
||||
if (mRange.state == RangeState::rsAsm)
|
||||
mRange.state = RangeState::rsUnknown;
|
||||
while (mRange.getLastIndent() == sitStatement) {
|
||||
popIndents(sitStatement);
|
||||
while (mRange.getLastIndent() == IndentForStatement) {
|
||||
popIndents(IndentForStatement);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -892,7 +892,7 @@ void GLSLHighlighter::squareCloseProc()
|
|||
mRange.bracketLevel--;
|
||||
if (mRange.bracketLevel<0)
|
||||
mRange.bracketLevel=0;
|
||||
popIndents(sitBracket);
|
||||
popIndents(IndentForBracket);
|
||||
}
|
||||
|
||||
void GLSLHighlighter::squareOpenProc()
|
||||
|
@ -900,7 +900,7 @@ void GLSLHighlighter::squareOpenProc()
|
|||
mRun+=1;
|
||||
mTokenId = TokenId::Symbol;
|
||||
mRange.bracketLevel++;
|
||||
pushIndents(sitBracket);
|
||||
pushIndents(IndentForBracket);
|
||||
}
|
||||
|
||||
void GLSLHighlighter::starProc()
|
||||
|
@ -1429,7 +1429,7 @@ bool GLSLHighlighter::isKeyword(const QString &word)
|
|||
return Keywords.contains(word);
|
||||
}
|
||||
|
||||
void GLSLHighlighter::setState(const HighlighterState& rangeState)
|
||||
void GLSLHighlighter::setState(const SyntaxerState& rangeState)
|
||||
{
|
||||
mRange = rangeState;
|
||||
// current line's left / right parenthesis count should be reset before parsing each line
|
||||
|
@ -1462,12 +1462,12 @@ QString GLSLHighlighter::languageName()
|
|||
return "glsl";
|
||||
}
|
||||
|
||||
HighlighterLanguage GLSLHighlighter::language()
|
||||
ProgrammingLanguage GLSLHighlighter::language()
|
||||
{
|
||||
return HighlighterLanguage::GLSL;
|
||||
return ProgrammingLanguage::GLSL;
|
||||
}
|
||||
|
||||
HighlighterState GLSLHighlighter::getState() const
|
||||
SyntaxerState GLSLHighlighter::getState() const
|
||||
{
|
||||
return mRange;
|
||||
}
|
||||
|
|
|
@ -134,7 +134,7 @@ private:
|
|||
|
||||
private:
|
||||
bool mAsmStart;
|
||||
HighlighterState mRange;
|
||||
SyntaxerState mRange;
|
||||
// SynRangeState mSpaceRange;
|
||||
QString mLineString;
|
||||
QChar* mLine;
|
||||
|
@ -175,15 +175,15 @@ public:
|
|||
void next() override;
|
||||
void setLine(const QString &newLine, int lineNumber) override;
|
||||
bool isKeyword(const QString &word) override;
|
||||
void setState(const HighlighterState& rangeState) override;
|
||||
void setState(const SyntaxerState& rangeState) override;
|
||||
void resetState() override;
|
||||
|
||||
QString languageName() override;
|
||||
HighlighterLanguage language() override;
|
||||
ProgrammingLanguage language() override;
|
||||
|
||||
// SynHighlighter interface
|
||||
public:
|
||||
HighlighterState getState() const override;
|
||||
SyntaxerState getState() const override;
|
||||
|
||||
// SynHighlighter interface
|
||||
public:
|
||||
|
|
|
@ -182,17 +182,17 @@ const QSet<QString> MakefileHighlighter::Directives {
|
|||
|
||||
MakefileHighlighter::MakefileHighlighter()
|
||||
{
|
||||
mTargetAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrClass, TokenType::Identifier);
|
||||
mTargetAttribute = std::make_shared<TokenAttribute>(SYNS_AttrClass, TokenType::Identifier);
|
||||
addAttribute(mTargetAttribute);
|
||||
mCommandAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrGlobalVariable, TokenType::Identifier);
|
||||
mCommandAttribute = std::make_shared<TokenAttribute>(SYNS_AttrGlobalVariable, TokenType::Identifier);
|
||||
addAttribute(mCommandAttribute);
|
||||
mCommandParamAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrPreprocessor, TokenType::Identifier);
|
||||
mCommandParamAttribute = std::make_shared<TokenAttribute>(SYNS_AttrPreprocessor, TokenType::Identifier);
|
||||
addAttribute(mCommandParamAttribute);
|
||||
mNumberAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrNumber, TokenType::Number);
|
||||
mNumberAttribute = std::make_shared<TokenAttribute>(SYNS_AttrNumber, TokenType::Number);
|
||||
addAttribute(mNumberAttribute);
|
||||
mVariableAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrLocalVariable, TokenType::Identifier);
|
||||
mVariableAttribute = std::make_shared<TokenAttribute>(SYNS_AttrLocalVariable, TokenType::Identifier);
|
||||
addAttribute(mVariableAttribute);
|
||||
mExpressionAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrFunction, TokenType::Identifier);
|
||||
mExpressionAttribute = std::make_shared<TokenAttribute>(SYNS_AttrFunction, TokenType::Identifier);
|
||||
addAttribute(mExpressionAttribute);
|
||||
}
|
||||
|
||||
|
@ -421,9 +421,9 @@ QString MakefileHighlighter::languageName()
|
|||
return "makefile";
|
||||
}
|
||||
|
||||
HighlighterLanguage MakefileHighlighter::language()
|
||||
ProgrammingLanguage MakefileHighlighter::language()
|
||||
{
|
||||
return HighlighterLanguage::Makefile;
|
||||
return ProgrammingLanguage::Makefile;
|
||||
}
|
||||
|
||||
QString MakefileHighlighter::getToken() const
|
||||
|
@ -662,14 +662,14 @@ bool MakefileHighlighter::isLastLineStringNotFinished(int /*state*/) const
|
|||
return false;
|
||||
}
|
||||
|
||||
HighlighterState MakefileHighlighter::getState() const
|
||||
SyntaxerState MakefileHighlighter::getState() const
|
||||
{
|
||||
HighlighterState state;
|
||||
SyntaxerState state;
|
||||
state.state = (int)mState;
|
||||
return state;
|
||||
}
|
||||
|
||||
void MakefileHighlighter::setState(const HighlighterState & rangeState)
|
||||
void MakefileHighlighter::setState(const SyntaxerState & rangeState)
|
||||
{
|
||||
mState = (RangeState)rangeState.state;
|
||||
mStates.clear();
|
||||
|
|
|
@ -133,7 +133,7 @@ public:
|
|||
bool eol() const override;
|
||||
|
||||
QString languageName() override;
|
||||
HighlighterLanguage language() override;
|
||||
ProgrammingLanguage language() override;
|
||||
QString getToken() const override;
|
||||
const PHighlighterAttribute &getTokenAttribute() const override;
|
||||
int getTokenPos() override;
|
||||
|
@ -145,8 +145,8 @@ public:
|
|||
bool getTokenFinished() const override;
|
||||
bool isLastLineCommentNotFinished(int state) const override;
|
||||
bool isLastLineStringNotFinished(int state) const override;
|
||||
HighlighterState getState() const override;
|
||||
void setState(const HighlighterState& rangeState) override;
|
||||
SyntaxerState getState() const override;
|
||||
void setState(const SyntaxerState& rangeState) override;
|
||||
void resetState() override;
|
||||
|
||||
bool isIdentChar(const QChar& ch) const override;
|
||||
|
|
Loading…
Reference in New Issue