refactor highlighters

This commit is contained in:
Roy Qu 2022-12-10 21:23:49 +08:00
parent d0732b9989
commit c4a41403bc
40 changed files with 436 additions and 458 deletions

View File

@ -1,38 +0,0 @@
/*
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef HIGHLIGHTERMANAGER_H
#define HIGHLIGHTERMANAGER_H
#include "qsynedit/highlighter/base.h"
class HighlighterManager
{
public:
HighlighterManager();
QSynedit::PHighlighter getHighlighter(QSynedit::ProgrammingLanguage language);
QSynedit::PHighlighter getHighlighter(const QString& filename);
QSynedit::PHighlighter copyHighlighter(QSynedit::PHighlighter highlighter);
QSynedit::PHighlighter getCppHighlighter();
QSynedit::PHighlighter getAsmHighlighter();
QSynedit::PHighlighter getGLSLHighlighter();
QSynedit::PHighlighter getMakefileHighlighter();
void applyColorScheme(QSynedit::PHighlighter highlighter, const QString& schemeName);
};
extern HighlighterManager highlighterManager;
#endif // HIGHLIGHTERMANAGER_H

View File

@ -75,7 +75,6 @@ LIBS += advapi32.lib user32.lib
}
SOURCES += \
HighlighterManager.cpp \
autolinkmanager.cpp \
caretlist.cpp \
codeformatter.cpp \
@ -129,6 +128,7 @@ SOURCES += \
settingsdialog/toolsgitwidget.cpp \
shortcutmanager.cpp \
symbolusagemanager.cpp \
syntaxermanager.cpp \
thememanager.cpp \
todoparser.cpp \
toolsmanager.cpp \
@ -209,7 +209,6 @@ SOURCES += \
widgets/signalmessagedialog.cpp
HEADERS += \
HighlighterManager.h \
SimpleIni.h \
autolinkmanager.h \
caretlist.h \
@ -264,6 +263,7 @@ HEADERS += \
settingsdialog/toolsgitwidget.h \
shortcutmanager.h \
symbolusagemanager.h \
syntaxermanager.h \
thememanager.h \
todoparser.h \
toolsmanager.h \

View File

@ -428,7 +428,7 @@ void ColorManager::loadSchemesInDir(const QString &dirName, bool isBundled, bool
void ColorManager::initItemDefines()
{
//Highlighter colors
//Token highlight colors
addDefine(SYNS_AttrAssembler,
QObject::tr("Assembler"),
QObject::tr("Syntax"),

View File

@ -18,7 +18,7 @@
#define COLORSCHEME_H
#include <QColor>
#include "qsynedit/highlighter/base.h"
#include "qsynedit/syntaxer/syntaxer.h"
#include "parser/statementmodel.h"
#define EXT_COLOR_SCHEME ".scheme"

View File

@ -22,7 +22,7 @@
#include <QFile>
#include <QMessageBox>
#include <QTextCodec>
#include "HighlighterManager.h"
#include "syntaxermanager.h"
#include "project.h"
CppRefacter::CppRefacter(QObject *parent) : QObject(parent)
@ -207,7 +207,7 @@ PSearchResultTreeItem CppRefacter::findOccurenceInFile(
QByteArray encoding;
editor.document()->loadFromFile(filename,ENCODING_AUTO_DETECT,encoding);
}
editor.setHighlighter(HighlighterManager().getCppHighlighter());
editor.setSyntaxer(syntaxerManager.getCppSyntaxer());
int posY = 0;
while (posY < editor.document()->count()) {
QString line = editor.document()->getString(posY);
@ -217,16 +217,16 @@ PSearchResultTreeItem CppRefacter::findOccurenceInFile(
}
if (posY == 0) {
editor.highlighter()->resetState();
editor.syntaxer()->resetState();
} else {
editor.highlighter()->setState(
editor.syntaxer()->setState(
editor.document()->ranges(posY-1));
}
editor.highlighter()->setLine(line,posY);
while (!editor.highlighter()->eol()) {
int start = editor.highlighter()->getTokenPos() + 1;
QString token = editor.highlighter()->getToken();
QSynedit::PTokenAttribute attr = editor.highlighter()->getTokenAttribute();
editor.syntaxer()->setLine(line,posY);
while (!editor.syntaxer()->eol()) {
int start = editor.syntaxer()->getTokenPos() + 1;
QString token = editor.syntaxer()->getToken();
QSynedit::PTokenAttribute attr = editor.syntaxer()->getTokenAttribute();
if (attr && attr->tokenType()==QSynedit::TokenType::Identifier) {
if (token == statement->command) {
//same name symbol , test if the same statement;
@ -253,7 +253,7 @@ PSearchResultTreeItem CppRefacter::findOccurenceInFile(
}
}
}
editor.highlighter()->next();
editor.syntaxer()->next();
}
posY++;
}
@ -272,22 +272,22 @@ void CppRefacter::renameSymbolInFile(const QString &filename, const PStatement &
editor.document()->loadFromFile(filename,ENCODING_AUTO_DETECT,encoding);
}
QStringList newContents;
editor.setHighlighter(HighlighterManager().getCppHighlighter());
editor.setSyntaxer(syntaxerManager.getCppSyntaxer());
int posY = 0;
while (posY < editor.document()->count()) {
QString line = editor.document()->getString(posY);
if (posY == 0) {
editor.highlighter()->resetState();
editor.syntaxer()->resetState();
} else {
editor.highlighter()->setState(
editor.syntaxer()->setState(
editor.document()->ranges(posY-1));
}
editor.highlighter()->setLine(line,posY);
editor.syntaxer()->setLine(line,posY);
QString newLine;
while (!editor.highlighter()->eol()) {
int start = editor.highlighter()->getTokenPos() + 1;
QString token = editor.highlighter()->getToken();
while (!editor.syntaxer()->eol()) {
int start = editor.syntaxer()->getTokenPos() + 1;
QString token = editor.syntaxer()->getToken();
if (token == statement->command) {
//same name symbol , test if the same statement;
QSynedit::BufferCoord p;
@ -305,7 +305,7 @@ void CppRefacter::renameSymbolInFile(const QString &filename, const PStatement &
}
}
newLine += token;
editor.highlighter()->next();
editor.syntaxer()->next();
}
newContents.append(newLine);
posY++;

View File

@ -29,8 +29,8 @@
#include <QMessageBox>
#include <QDebug>
#include <QMimeData>
#include "qsynedit/highlighter/cpp.h"
#include "HighlighterManager.h"
#include "qsynedit/syntaxer/cpp.h"
#include "syntaxermanager.h"
#include "qsynedit/exporter/synrtfexporter.h"
#include "qsynedit/exporter/synhtmlexporter.h"
#include "qsynedit/Constants.h"
@ -105,17 +105,17 @@ Editor::Editor(QWidget *parent, const QString& filename,
mFilename = QString("untitled%1").arg(getNewFileNumber());
}
QFileInfo fileInfo(mFilename);
QSynedit::PHighlighter highlighter;
QSynedit::PSyntaxer syntaxer;
if (!isNew) {
loadFile();
highlighter = highlighterManager.getHighlighter(mFilename);
syntaxer = syntaxerManager.getSyntaxer(mFilename);
} else {
mFileEncoding = ENCODING_ASCII;
highlighter=highlighterManager.getCppHighlighter();
syntaxer=syntaxerManager.getCppSyntaxer();
}
if (highlighter) {
setHighlighter(highlighter);
if (syntaxer) {
setSyntaxer(syntaxer);
setUseCodeFolding(true);
} else {
setUseCodeFolding(false);
@ -225,7 +225,7 @@ void Editor::loadFile(QString filename) {
default:
mUseCppSyntax = pSettings->editor().defaultFileCpp();
}
if (highlighter()) {
if (syntaxer()) {
reparse(true);
if (pSettings->editor().syntaxCheckWhenLineChanged()) {
checkSyntaxInBack();
@ -382,15 +382,15 @@ bool Editor::saveAs(const QString &name, bool fromProject){
mUseCppSyntax = pSettings->editor().defaultFileCpp();
}
//update (reassign highlighter)
QSynedit::PHighlighter newHighlighter = HighlighterManager().getHighlighter(mFilename);
if (newHighlighter) {
//update (reassign syntaxer)
QSynedit::PSyntaxer newSyntaxer = syntaxerManager.getSyntaxer(mFilename);
if (newSyntaxer) {
setUseCodeFolding(true);
} else {
setUseCodeFolding(false);
}
setHighlighter(newHighlighter);
if (!newHighlighter || newHighlighter->language() != QSynedit::ProgrammingLanguage::Cpp) {
setSyntaxer(newSyntaxer);
if (!newSyntaxer || newSyntaxer->language() != QSynedit::ProgrammingLanguage::Cpp) {
mSyntaxIssues.clear();
}
applyColorScheme(pSettings->editor().colorScheme());
@ -483,11 +483,11 @@ void Editor::undoSymbolCompletion(int pos)
QString token;
bool tokenFinished;
if (!highlighter())
if (!syntaxer())
return;
if (!pSettings->editor().removeSymbolPairs())
return;
if (!getHighlighterAttriAtRowCol(caretXY(), token, tokenFinished, attr))
if (!getTokenAttriAtRowCol(caretXY(), token, tokenFinished, attr))
return;
if ((attr->tokenType() == QSynedit::TokenType::Comment) && (!tokenFinished))
return ;
@ -635,9 +635,9 @@ void Editor::keyPressEvent(QKeyEvent *event)
insertString.append(" */");
}
insertCodeSnippet(linesToText(insertString));
} else if (highlighter()
} else if (syntaxer()
&& caretY()>=2
&& highlighter()->isLastLineCommentNotFinished(
&& syntaxer()->isLastLineCommentNotFinished(
document()->ranges(caretY()-2).state)) {
s=trimLeft(lineText());
if (s.startsWith("* ")) {
@ -917,7 +917,7 @@ void Editor::onGetEditingAreas(int Line, QSynedit::EditingAreaList &areaList)
// int spaceBefore = mLineBeforeTabStop.length()-TrimLeft(mLineBeforeTabStop).length();
p->beginX = mTabStopBegin;
p->endX = mTabStopEnd;
p->color = highlighter()->stringAttribute()->foreground();
p->color = syntaxer()->stringAttribute()->foreground();
areaList.append(p);
}
PSyntaxIssueList lst = getSyntaxIssuesAtLine(Line);
@ -966,7 +966,7 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
if (token.isEmpty())
return;
if (mParser && highlighter()) {
if (mParser && syntaxer()) {
QString lineText = document()->getString(line-1);
if (mParser->isIncludeLine(lineText)) {
if (cursor() == Qt::PointingHandCursor) {
@ -1018,7 +1018,7 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
style.setFlag(QSynedit::FontStyle::fsUnderline,item->underlined());
style.setFlag(QSynedit::FontStyle::fsStrikeOut,item->strikeout());
} else {
foreground = highlighter()->identifierAttribute()->foreground();
foreground = syntaxer()->identifierAttribute()->foreground();
}
if (cursor() == Qt::PointingHandCursor) {
QSynedit::BufferCoord p;
@ -1032,14 +1032,14 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
}
//selection
if (highlighter() && attr) {
if (syntaxer() && attr) {
if (attr->tokenType() == QSynedit::TokenType::Keyword) {
if (CppTypeKeywords.contains(token)
||
(
highlighter()->language()==QSynedit::ProgrammingLanguage::Cpp
syntaxer()->language()==QSynedit::ProgrammingLanguage::Cpp
&&
((QSynedit::CppHighlighter*)highlighter().get())->customTypeKeywords().contains(token)
((QSynedit::CppSyntaxer*)syntaxer().get())->customTypeKeywords().contains(token)
)
)
{
@ -1481,12 +1481,12 @@ void Editor::copyAsHTML()
exporter.setExportAsText(false);
exporter.setUseBackground(pSettings->editor().copyHTMLUseBackground());
exporter.setFont(font());
QSynedit::PHighlighter hl = highlighter();
QSynedit::PSyntaxer hl = syntaxer();
if (!pSettings->editor().copyHTMLUseEditorColor()) {
hl = highlighterManager.copyHighlighter(highlighter());
highlighterManager.applyColorScheme(hl,pSettings->editor().copyHTMLColorScheme());
hl = syntaxerManager.copy(syntaxer());
syntaxerManager.applyColorScheme(hl,pSettings->editor().copyHTMLColorScheme());
}
exporter.setHighlighter(hl);
exporter.setSyntaxer(hl);
exporter.setOnFormatToken(std::bind(&Editor::onExportedFormatToken,
this,
std::placeholders::_1,
@ -1541,7 +1541,7 @@ void Editor::addSyntaxIssues(int line, int startChar, int endChar, CompileIssueT
start = 1;
token = document()->getString(line-1);
} else if (endChar < 1) {
if (!getHighlighterAttriAtRowColEx(p,token,start,attr))
if (!getTokenAttriAtRowColEx(p,token,start,attr))
return;
} else {
start = startChar;
@ -1699,7 +1699,7 @@ void Editor::onStatusChanged(QSynedit::StatusChanges changes)
clearUserCodeInTabStops();
}
}
} else if (!selAvail() && highlighter() && pSettings->editor().highlightMathingBraces()){
} else if (!selAvail() && syntaxer() && pSettings->editor().highlightMathingBraces()){
invalidateLine(mHighlightCharPos1.line);
invalidateLine(mHighlightCharPos2.line);
mHighlightCharPos1 = QSynedit::BufferCoord{0,0};
@ -1720,7 +1720,7 @@ void Editor::onStatusChanged(QSynedit::StatusChanges changes)
}
QSynedit::PTokenAttribute attr;
QString token;
if (getHighlighterAttriAtRowCol(coord,token,attr)
if (getTokenAttriAtRowCol(coord,token,attr)
&& attr->tokenType() == QSynedit::TokenType::Operator) {
QSynedit::BufferCoord complementCharPos = getMatchingBracketEx(coord);
if (!foldHidesLine(coord.line)
@ -1938,38 +1938,38 @@ QStringList Editor::getExpressionAtPosition(
const QSynedit::BufferCoord &pos)
{
QStringList result;
if (!highlighter())
if (!syntaxer())
return result;
int line = pos.line-1;
int ch = pos.ch-1;
int symbolMatchingLevel = 0;
LastSymbolType lastSymbolType=LastSymbolType::None;
QSynedit::PHighlighter highlighter;
QSynedit::PSyntaxer syntaxer;
if (isNew())
highlighter = highlighterManager.getCppHighlighter();
syntaxer = syntaxerManager.getCppSyntaxer();
else
highlighter = highlighterManager.getHighlighter(mFilename);
if (!highlighter)
syntaxer = syntaxerManager.getSyntaxer(mFilename);
if (!syntaxer)
return result;
while (true) {
if (line>=document()->count() || line<0)
break;
QStringList tokens;
if (line==0) {
highlighter->resetState();
syntaxer->resetState();
} else {
highlighter->setState(document()->ranges(line-1));
syntaxer->setState(document()->ranges(line-1));
}
QString sLine = document()->getString(line);
highlighter->setLine(sLine,line-1);
while (!highlighter->eol()) {
int start = highlighter->getTokenPos();
QString token = highlighter->getToken();
syntaxer->setLine(sLine,line-1);
while (!syntaxer->eol()) {
int start = syntaxer->getTokenPos();
QString token = syntaxer->getToken();
int endPos = start + token.length()-1;
if (start>ch) {
break;
}
QSynedit::PTokenAttribute attr = highlighter->getTokenAttribute();
QSynedit::PTokenAttribute attr = syntaxer->getTokenAttribute();
if ( (line == pos.line-1)
&& (start<=ch) && (ch<=endPos)) {
if (attr->tokenType() == QSynedit::TokenType::Comment
@ -1981,7 +1981,7 @@ QStringList Editor::getExpressionAtPosition(
&& attr->tokenType() != QSynedit::TokenType::Space){
tokens.append(token);
}
highlighter->next();
syntaxer->next();
}
for (int i=tokens.count()-1;i>=0;i--) {
QString token = tokens[i];
@ -2199,12 +2199,12 @@ bool Editor::handleSymbolCompletion(QChar key)
return false;
//todo: better methods to detect current caret type
if (highlighter()) {
if (syntaxer()) {
if (caretX() <= 1) {
if (caretY()>1) {
if (highlighter()->isLastLineCommentNotFinished(document()->ranges(caretY() - 2).state))
if (syntaxer()->isLastLineCommentNotFinished(document()->ranges(caretY() - 2).state))
return false;
if (highlighter()->isLastLineStringNotFinished(document()->ranges(caretY() - 2).state)
if (syntaxer()->isLastLineStringNotFinished(document()->ranges(caretY() - 2).state)
&& (key!='\"') && (key!='\''))
return false;
}
@ -2214,7 +2214,7 @@ bool Editor::handleSymbolCompletion(QChar key)
QSynedit::PTokenAttribute attr;
QString token;
bool tokenFinished;
if (getHighlighterAttriAtRowCol(HighlightPos, token, tokenFinished, attr)) {
if (getTokenAttriAtRowCol(HighlightPos, token, tokenFinished, attr)) {
if ((attr->tokenType() == QSynedit::TokenType::Comment) && (!tokenFinished))
return false;
if ((attr->tokenType() == QSynedit::TokenType::String) && (!tokenFinished)
@ -2228,11 +2228,6 @@ bool Editor::handleSymbolCompletion(QChar key)
}
}
// Check if that line is highlighted as string or character or comment
// if (Attr = fText.Highlighter.StringAttribute) or (Attr = fText.Highlighter.CommentAttribute) or SameStr(Attr.Name,
// 'Character') then
// Exit;
QuoteStatus status;
switch(key.unicode()) {
case '(':
@ -2349,7 +2344,7 @@ bool Editor::handleParentheseSkip()
if (document()->count()==0)
return false;
if (highlighter() && highlighter()->supportBraceLevel()) {
if (syntaxer() && syntaxer()->supportBraceLevel()) {
QSynedit::SyntaxerState lastLineState = document()->ranges(document()->count()-1);
if (lastLineState.parenthesisLevel==0) {
setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over
@ -2400,7 +2395,7 @@ bool Editor::handleBracketSkip()
if (document()->count()==0)
return false;
if (highlighter() && highlighter()->supportBraceLevel()) {
if (syntaxer() && syntaxer()->supportBraceLevel()) {
QSynedit::SyntaxerState lastLineState = document()->ranges(document()->count()-1);
if (lastLineState.bracketLevel==0) {
setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over
@ -2487,7 +2482,7 @@ bool Editor::handleBraceSkip()
if (document()->count()==0)
return false;
if (highlighter() && highlighter()->supportBraceLevel()) {
if (syntaxer() && syntaxer()->supportBraceLevel()) {
QSynedit::SyntaxerState lastLineState = document()->ranges(document()->count()-1);
if (lastLineState.braceLevel==0) {
bool oldInsertMode = insertMode();
@ -2531,7 +2526,7 @@ bool Editor::handleSingleQuoteCompletion()
endUpdate();
return true;
}
if (ch == 0 || highlighter()->isWordBreakChar(ch) || highlighter()->isSpaceChar(ch)) {
if (ch == 0 || syntaxer()->isWordBreakChar(ch) || syntaxer()->isSpaceChar(ch)) {
// insert ''
beginUpdate();
beginUndoBlock();
@ -2571,7 +2566,7 @@ bool Editor::handleDoubleQuoteCompletion()
endUpdate();
return true;
}
if ((ch == 0) || highlighter()->isWordBreakChar(ch) || highlighter()->isSpaceChar(ch)) {
if ((ch == 0) || syntaxer()->isWordBreakChar(ch) || syntaxer()->isSpaceChar(ch)) {
// insert ""
beginUpdate();
beginUndoBlock();
@ -2662,7 +2657,7 @@ void Editor::initParser()
{
if (pSettings->codeCompletion().shareParser()) {
if (pSettings->codeCompletion().enabled()
&& (highlighter() && highlighter()->language() == QSynedit::ProgrammingLanguage::Cpp)
&& (syntaxer() && syntaxer()->language() == QSynedit::ProgrammingLanguage::Cpp)
) {
mParser = sharedParser(mUseCppSyntax?ParserLanguage::CPlusPlus:ParserLanguage::C);
}
@ -2682,15 +2677,15 @@ void Editor::initParser()
resetCppParser(mParser);
mParser->setEnabled(
pSettings->codeCompletion().enabled() &&
(highlighter() && highlighter()->language() == QSynedit::ProgrammingLanguage::Cpp));
(syntaxer() && syntaxer()->language() == QSynedit::ProgrammingLanguage::Cpp));
}
Editor::QuoteStatus Editor::getQuoteStatus()
{
QuoteStatus Result = QuoteStatus::NotQuote;
if (!highlighter())
if (!syntaxer())
return Result;
if ((caretY()>1) && highlighter()->isLastLineStringNotFinished(document()->ranges(caretY() - 2).state))
if ((caretY()>1) && syntaxer()->isLastLineStringNotFinished(document()->ranges(caretY() - 2).state))
Result = QuoteStatus::DoubleQuote;
QString Line = document()->getString(caretY()-1);
@ -2812,10 +2807,10 @@ void Editor::reparse(bool resetParser)
return;
if (!pSettings->codeCompletion().enabled())
return;
if (!highlighter())
if (!syntaxer())
return;
if (highlighter()->language() != QSynedit::ProgrammingLanguage::Cpp
&& highlighter()->language() != QSynedit::ProgrammingLanguage::GLSL)
if (syntaxer()->language() != QSynedit::ProgrammingLanguage::Cpp
&& syntaxer()->language() != QSynedit::ProgrammingLanguage::GLSL)
return;
if (!mParser)
return;
@ -2845,7 +2840,7 @@ void Editor::reparseTodo()
{
if (!mParentPageControl)
return;
if (!highlighter())
if (!syntaxer())
return;
if (pSettings->editor().parseTodos())
pMainWindow->todoParser()->parseFile(mFilename, inProject());
@ -2996,12 +2991,12 @@ void Editor::exportAsRTF(const QString &rtfFilename)
exporter.setExportAsText(true);
exporter.setUseBackground(pSettings->editor().copyRTFUseBackground());
exporter.setFont(font());
QSynedit::PHighlighter hl = highlighter();
QSynedit::PSyntaxer hl = syntaxer();
if (!pSettings->editor().copyRTFUseEditorColor()) {
hl = highlighterManager.copyHighlighter(highlighter());
highlighterManager.applyColorScheme(hl,pSettings->editor().copyRTFColorScheme());
hl = syntaxerManager.copy(syntaxer());
syntaxerManager.applyColorScheme(hl,pSettings->editor().copyRTFColorScheme());
}
exporter.setHighlighter(hl);
exporter.setSyntaxer(hl);
exporter.setOnFormatToken(std::bind(&Editor::onExportedFormatToken,
this,
std::placeholders::_1,
@ -3021,12 +3016,12 @@ void Editor::exportAsHTML(const QString &htmlFilename)
exporter.setExportAsText(false);
exporter.setUseBackground(pSettings->editor().copyHTMLUseBackground());
exporter.setFont(font());
QSynedit::PHighlighter hl = highlighter();
QSynedit::PSyntaxer hl = syntaxer();
if (!pSettings->editor().copyHTMLUseEditorColor()) {
hl = highlighterManager.copyHighlighter(highlighter());
highlighterManager.applyColorScheme(hl,pSettings->editor().copyHTMLColorScheme());
hl = syntaxerManager.copy(syntaxer());
syntaxerManager.applyColorScheme(hl,pSettings->editor().copyHTMLColorScheme());
}
exporter.setHighlighter(hl);
exporter.setSyntaxer(hl);
exporter.setOnFormatToken(std::bind(&Editor::onExportedFormatToken,
this,
std::placeholders::_1,
@ -3049,7 +3044,7 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete, CodeComple
if (!mParser || !mParser->enabled())
return;
if (!highlighter())
if (!syntaxer())
return;
if (mCompletionPopup->isVisible()) // already in search, don't do it again
@ -3061,7 +3056,7 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete, CodeComple
QSynedit::PTokenAttribute attr;
bool tokenFinished;
QSynedit::BufferCoord pBeginPos, pEndPos;
if (getHighlighterAttriAtRowCol(
if (getTokenAttriAtRowCol(
QSynedit::BufferCoord{caretX() - 1,
caretY()}, s, tokenFinished, attr)) {
if (attr->tokenType() == QSynedit::TokenType::Preprocessor) {//Preprocessor
@ -3121,9 +3116,9 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete, CodeComple
);
QSet<QString> keywords;
if (highlighter()) {
if (highlighter()->language() != QSynedit::ProgrammingLanguage::Cpp ) {
keywords = highlighter()->keywords();
if (syntaxer()) {
if (syntaxer()->language() != QSynedit::ProgrammingLanguage::Cpp ) {
keywords = syntaxer()->keywords();
} else {
if (mUseCppSyntax) {
foreach (const QString& keyword, CppKeywords.keys()) {
@ -3341,14 +3336,6 @@ void Editor::completionInsert(bool appendFunc)
&& (statement->args != "(void)")) {
setCaretX(caretX() - funcAddOn.length()+1);
//todo: function hint
// immediately activate function hint
// if devEditor.ShowFunctionTip and Assigned(fText.Highlighter) then begin
// fText.SetFocus;
// fFunctionTip.Parser := fParser;
// fFunctionTip.FileName := fFileName;
// fFunctionTip.Show;
// end;
} else {
setCaretX(caretX());
}
@ -3542,7 +3529,7 @@ bool Editor::onCompletionInputMethod(QInputMethodEvent *event)
Editor::TipType Editor::getTipType(QPoint point, QSynedit::BufferCoord& pos)
{
// Only allow in the text area...
if (pointToCharLine(point, pos) && highlighter()) {
if (pointToCharLine(point, pos) && syntaxer()) {
if (!pMainWindow->debugger()->executing()
&& getSyntaxIssueAtPosition(pos)) {
return TipType::Error;
@ -3552,7 +3539,7 @@ Editor::TipType Editor::getTipType(QPoint point, QSynedit::BufferCoord& pos)
QString s;
// Only allow hand tips in highlighted areas
if (getHighlighterAttriAtRowCol(pos,s,attr)) {
if (getTokenAttriAtRowCol(pos,s,attr)) {
// Only allow Identifiers, Preprocessor directives, and selection
if (attr) {
if (selAvail()) {
@ -3561,7 +3548,7 @@ Editor::TipType Editor::getTipType(QPoint point, QSynedit::BufferCoord& pos)
return TipType::Selection;
} else if (mParser && mParser->isIncludeLine(document()->getString(pos.line-1))) {
return TipType::Preprocessor;
}else if (attr == highlighter()->identifierAttribute())
}else if (attr == syntaxer()->identifierAttribute())
return TipType::Identifier;
}
}
@ -3710,7 +3697,7 @@ void Editor::updateFunctionTip(bool showTip)
pMainWindow->functionTip()->hide();
return;
}
if (!highlighter())
if (!syntaxer())
return;
if (!mParser || !mParser->enabled())
@ -3745,22 +3732,22 @@ void Editor::updateFunctionTip(bool showTip)
QStringList tokens;
QList<int> positions;
if (currentLine==0)
highlighter()->resetState();
syntaxer()->resetState();
else
highlighter()->setState(
syntaxer()->setState(
document()->ranges(currentLine-1));
highlighter()->setLine(line,currentLine);
while(!highlighter()->eol()) {
int start = highlighter()->getTokenPos();
QString token = highlighter()->getToken();
QSynedit::PTokenAttribute attr = highlighter()->getTokenAttribute();
syntaxer()->setLine(line,currentLine);
while(!syntaxer()->eol()) {
int start = syntaxer()->getTokenPos();
QString token = syntaxer()->getToken();
QSynedit::PTokenAttribute attr = syntaxer()->getTokenAttribute();
if (start>=currentChar)
break;
if (attr->tokenType() != QSynedit::TokenType::Comment
&& attr->tokenType() != QSynedit::TokenType::Space) {
if (foundFunctionStart) {
if (attr!=highlighter()->identifierAttribute())
if (attr!=syntaxer()->identifierAttribute())
return; // not a function
functionNamePos.line = currentLine+1;
functionNamePos.ch = start+1;
@ -3773,7 +3760,7 @@ void Editor::updateFunctionTip(bool showTip)
&& start+token.length()>=caretPos.ch) {
return; // in comment, do nothing
}
highlighter()->next();
syntaxer()->next();
}
if (!foundFunctionStart) {
for (int i=tokens.length()-1;i>=0;i--) {
@ -3962,9 +3949,9 @@ void Editor::popUserCodeInTabStops()
}
}
void Editor::onExportedFormatToken(QSynedit::PHighlighter syntaxHighlighter, int Line, int column, const QString &token, QSynedit::PTokenAttribute& attr)
void Editor::onExportedFormatToken(QSynedit::PSyntaxer syntaxer, int Line, int column, const QString &token, QSynedit::PTokenAttribute& attr)
{
if (!syntaxHighlighter)
if (!syntaxer)
return;
if (token.isEmpty())
return;
@ -3972,7 +3959,7 @@ void Editor::onExportedFormatToken(QSynedit::PHighlighter syntaxHighlighter, int
if (mCompletionPopup->isVisible() || mHeaderCompletionPopup->isVisible())
return;
if (mParser && (attr == syntaxHighlighter->identifierAttribute())) {
if (mParser && (attr == syntaxer->identifierAttribute())) {
QSynedit::BufferCoord p{column,Line};
QSynedit::BufferCoord pBeginPos,pEndPos;
QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation);
@ -3990,41 +3977,41 @@ void Editor::onExportedFormatToken(QSynedit::PHighlighter syntaxHighlighter, int
kind = StatementKind::skVariable;
}
}
QSynedit::CppHighlighter* cppHighlighter = dynamic_cast<QSynedit::CppHighlighter*>(syntaxHighlighter.get());
QSynedit::CppSyntaxer* cppSyntaxer = dynamic_cast<QSynedit::CppSyntaxer*>(syntaxer.get());
switch(kind) {
case StatementKind::skFunction:
case StatementKind::skConstructor:
case StatementKind::skDestructor:
attr = cppHighlighter->functionAttribute();
attr = cppSyntaxer->functionAttribute();
break;
case StatementKind::skClass:
case StatementKind::skTypedef:
case StatementKind::skAlias:
attr = cppHighlighter->classAttribute();
attr = cppSyntaxer->classAttribute();
break;
case StatementKind::skEnumClassType:
case StatementKind::skEnumType:
break;
case StatementKind::skLocalVariable:
case StatementKind::skParameter:
attr = cppHighlighter->localVarAttribute();
attr = cppSyntaxer->localVarAttribute();
break;
case StatementKind::skVariable:
attr = cppHighlighter->variableAttribute();
attr = cppSyntaxer->variableAttribute();
break;
case StatementKind::skGlobalVariable:
attr = cppHighlighter->globalVarAttribute();
attr = cppSyntaxer->globalVarAttribute();
break;
case StatementKind::skEnum:
case StatementKind::skPreprocessor:
attr = cppHighlighter->preprocessorAttribute();
attr = cppSyntaxer->preprocessorAttribute();
break;
case StatementKind::skKeyword:
attr = cppHighlighter->keywordAttribute();
attr = cppSyntaxer->keywordAttribute();
break;
case StatementKind::skNamespace:
case StatementKind::skNamespaceAlias:
attr = cppHighlighter->stringAttribute();
attr = cppSyntaxer->stringAttribute();
break;
default:
break;
@ -4580,9 +4567,9 @@ void Editor::checkSyntaxInBack()
return;
if (readOnly())
return;
if (!highlighter())
if (!syntaxer())
return;
if (highlighter()->language()!=QSynedit::ProgrammingLanguage::Cpp)
if (syntaxer()->language()!=QSynedit::ProgrammingLanguage::Cpp)
return;
pMainWindow->checkSyntaxInBack(this);
}
@ -4737,7 +4724,7 @@ void Editor::applySettings()
options.setFlag(QSynedit::eoHalfPageScroll,pSettings->editor().halfPageScroll());
options.setFlag(QSynedit::eoShowRainbowColor,
pSettings->editor().rainbowParenthesis()
&& highlighter() && highlighter()->supportBraceLevel());
&& syntaxer() && syntaxer()->supportBraceLevel());
setOptions(options);
setTabWidth(pSettings->editor().tabWidth());
@ -4792,15 +4779,15 @@ void Editor::applySettings()
}
if (pSettings->editor().enableCustomCTypeKeywords()) {
if (highlighter() && highlighter()->language() == QSynedit::ProgrammingLanguage::Cpp) {
if (syntaxer() && syntaxer()->language() == QSynedit::ProgrammingLanguage::Cpp) {
QSet<QString> set;
foreach(const QString& s, pSettings->editor().customCTypeKeywords())
set.insert(s);
((QSynedit::CppHighlighter*)(highlighter().get()))->setCustomTypeKeywords(set);
((QSynedit::CppSyntaxer*)(syntaxer().get()))->setCustomTypeKeywords(set);
}
} else {
if (highlighter() && highlighter()->language() == QSynedit::ProgrammingLanguage::Cpp) {
((QSynedit::CppHighlighter*)(highlighter().get()))->setCustomTypeKeywords(QSet<QString>());
if (syntaxer() && syntaxer()->language() == QSynedit::ProgrammingLanguage::Cpp) {
((QSynedit::CppSyntaxer*)(syntaxer().get()))->setCustomTypeKeywords(QSet<QString>());
}
}
@ -4828,9 +4815,9 @@ void Editor::applyColorScheme(const QString& schemeName)
QSynedit::EditorOptions options = getOptions();
options.setFlag(QSynedit::EditorOption::eoShowRainbowColor,
pSettings->editor().rainbowParenthesis()
&& highlighter() && highlighter()->supportBraceLevel());
&& syntaxer() && syntaxer()->supportBraceLevel());
setOptions(options);
highlighterManager.applyColorScheme(highlighter(),schemeName);
syntaxerManager.applyColorScheme(syntaxer(),schemeName);
if (pSettings->editor().rainbowParenthesis()) {
QSynedit::PTokenAttribute attr0 =createRainbowAttribute(SYNS_AttrSymbol,
schemeName,COLOR_SCHEME_BRACE_1);

View File

@ -290,7 +290,7 @@ private:
void updateFunctionTip(bool showTip);
void clearUserCodeInTabStops();
void popUserCodeInTabStops();
void onExportedFormatToken(QSynedit::PHighlighter syntaxHighlighter, int Line, int column, const QString& token,
void onExportedFormatToken(QSynedit::PSyntaxer syntaxer, int Line, int column, const QString& token,
QSynedit::PTokenAttribute &attr);
void onScrollBarValueChanged();
static PCppParser sharedParser(ParserLanguage language);

View File

@ -17,7 +17,7 @@
#include "cppparser.h"
#include "parserutils.h"
#include "../utils.h"
#include "qsynedit/highlighter/cpp.h"
#include "qsynedit/syntaxer/cpp.h"
#include <QApplication>
#include <QDate>
@ -4772,19 +4772,19 @@ PStatement CppParser::doParseEvalTypeInfo(
QString s = type;
// qDebug()<<"eval type info"<<type;
int position = s.length()-1;
QSynedit::CppHighlighter highlighter;
highlighter.resetState();
highlighter.setLine(type,0);
QSynedit::CppSyntaxer syntaxer;
syntaxer.resetState();
syntaxer.setLine(type,0);
int bracketLevel = 0;
int templateLevel = 0;
while(!highlighter.eol()) {
QString token = highlighter.getToken();
while(!syntaxer.eol()) {
QString token = syntaxer.getToken();
if (bracketLevel == 0 && templateLevel ==0) {
if (token == "*")
pointerLevel++;
else if (token == "&")
pointerLevel--;
else if (highlighter.getTokenAttribute()->tokenType() == QSynedit::TokenType::Identifier) {
else if (syntaxer.getTokenAttribute()->tokenType() == QSynedit::TokenType::Identifier) {
baseType += token;
} else if (token == "[") {
pointerLevel++;
@ -4809,7 +4809,7 @@ PStatement CppParser::doParseEvalTypeInfo(
}
templateParams += token;
}
highlighter.next();
syntaxer.next();
}
while ((position >= 0) && (s[position] == '*'
|| s[position] == ' '

View File

@ -14,42 +14,42 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "HighlighterManager.h"
#include "syntaxermanager.h"
#include <QFileInfo>
#include <QObject>
#include "qsynedit/Constants.h"
#include "qsynedit/highlighter/cpp.h"
#include "qsynedit/highlighter/asm.h"
#include "qsynedit/highlighter/glsl.h"
#include "qsynedit/highlighter/makefilehighlighter.h"
#include "qsynedit/syntaxer/cpp.h"
#include "qsynedit/syntaxer/asm.h"
#include "qsynedit/syntaxer/glsl.h"
#include "qsynedit/syntaxer/makefile.h"
#include "qsynedit/Constants.h"
#include "colorscheme.h"
HighlighterManager highlighterManager;
SyntaxerManager syntaxerManager;
HighlighterManager::HighlighterManager()
SyntaxerManager::SyntaxerManager()
{
}
QSynedit::PHighlighter HighlighterManager::getHighlighter(QSynedit::ProgrammingLanguage language)
QSynedit::PSyntaxer SyntaxerManager::getSyntaxer(QSynedit::ProgrammingLanguage language)
{
switch(language) {
case QSynedit::ProgrammingLanguage::Cpp:
return getCppHighlighter();
return getCppSyntaxer();
case QSynedit::ProgrammingLanguage::Asssembly:
return getAsmHighlighter();
return getAsmSyntaxer();
case QSynedit::ProgrammingLanguage::Makefile:
return getMakefileHighlighter();
return getMakefileSyntaxer();
case QSynedit::ProgrammingLanguage::GLSL:
return getGLSLHighlighter();
return getGLSLSyntaxer();
default:
return QSynedit::PHighlighter();
return QSynedit::PSyntaxer();
}
}
QSynedit::PHighlighter HighlighterManager::getHighlighter(const QString &filename)
QSynedit::PSyntaxer SyntaxerManager::getSyntaxer(const QString &filename)
{
QFileInfo info(filename);
QString suffix = info.suffix();
@ -59,59 +59,55 @@ QSynedit::PHighlighter HighlighterManager::getHighlighter(const QString &filenam
|| suffix == "hxx" || suffix == "hh" || suffix == "C"
|| suffix == "CPP" || suffix =="H" || suffix == "c++"
|| suffix == "h++") {
return getCppHighlighter();
return getCppSyntaxer();
} else if (suffix == "vs" || suffix == "fs" || suffix == "frag") {
return getGLSLHighlighter();
return getGLSLSyntaxer();
} else if (suffix == "s" || suffix == "asm") {
return getAsmHighlighter();
return getAsmSyntaxer();
} else if (basename.compare("makefile", Qt::CaseInsensitive)==0) {
return getMakefileHighlighter();
return getMakefileSyntaxer();
} else if (suffix.isEmpty()) {
return getCppHighlighter();
return getCppSyntaxer();
}
return QSynedit::PHighlighter();
return QSynedit::PSyntaxer();
}
QSynedit::PHighlighter HighlighterManager::copyHighlighter(QSynedit::PHighlighter highlighter)
QSynedit::PSyntaxer SyntaxerManager::copy(QSynedit::PSyntaxer syntaxer)
{
if (!highlighter)
return QSynedit::PHighlighter();
return getHighlighter(highlighter->language());
if (!syntaxer)
return QSynedit::PSyntaxer();
return getSyntaxer(syntaxer->language());
}
QSynedit::PHighlighter HighlighterManager::getCppHighlighter()
QSynedit::PSyntaxer SyntaxerManager::getCppSyntaxer()
{
std::shared_ptr<QSynedit::CppHighlighter> highlighter = std::make_shared<QSynedit::CppHighlighter>();
return highlighter;
return std::make_shared<QSynedit::CppSyntaxer>();
}
QSynedit::PHighlighter HighlighterManager::getAsmHighlighter()
QSynedit::PSyntaxer SyntaxerManager::getAsmSyntaxer()
{
std::shared_ptr<QSynedit::ASMHighlighter> highlighter=std::make_shared<QSynedit::ASMHighlighter>();
return highlighter;
return std::make_shared<QSynedit::ASMSyntaxer>();
}
QSynedit::PHighlighter HighlighterManager::getGLSLHighlighter()
QSynedit::PSyntaxer SyntaxerManager::getGLSLSyntaxer()
{
std::shared_ptr<QSynedit::GLSLHighlighter> highlighter=std::make_shared<QSynedit::GLSLHighlighter>();
return highlighter;
return std::make_shared<QSynedit::GLSLSyntaxer>();
}
QSynedit::PHighlighter HighlighterManager::getMakefileHighlighter()
QSynedit::PSyntaxer SyntaxerManager::getMakefileSyntaxer()
{
std::shared_ptr<QSynedit::MakefileHighlighter> highlighter=std::make_shared<QSynedit::MakefileHighlighter>();
return highlighter;
return std::make_shared<QSynedit::MakefileSyntaxer>();
}
void HighlighterManager::applyColorScheme(QSynedit::PHighlighter highlighter, const QString &schemeName)
void SyntaxerManager::applyColorScheme(QSynedit::PSyntaxer syntaxer, const QString &schemeName)
{
if (!highlighter)
if (!syntaxer)
return;
for (QString name: highlighter->attributes().keys()) {
for (QString name: syntaxer->attributes().keys()) {
PColorSchemeItem item = pColorManager->getItem(schemeName,name);
if (item) {
QSynedit::PTokenAttribute attr = highlighter->attributes()[name];
QSynedit::PTokenAttribute attr = syntaxer->attributes()[name];
attr->setBackground(item->background());
attr->setForeground(item->foreground());
QSynedit::FontStyles styles = QSynedit::FontStyle::fsNone;

View File

@ -0,0 +1,38 @@
/*
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef SYNTAXERMANAGER_H
#define SYNTAXERMANAGER_H
#include "qsynedit/syntaxer/syntaxer.h"
class SyntaxerManager
{
public:
SyntaxerManager();
QSynedit::PSyntaxer getSyntaxer(QSynedit::ProgrammingLanguage language);
QSynedit::PSyntaxer getSyntaxer(const QString& filename);
QSynedit::PSyntaxer copy(QSynedit::PSyntaxer syntaxer);
QSynedit::PSyntaxer getCppSyntaxer();
QSynedit::PSyntaxer getAsmSyntaxer();
QSynedit::PSyntaxer getGLSLSyntaxer();
QSynedit::PSyntaxer getMakefileSyntaxer();
void applyColorScheme(QSynedit::PSyntaxer syntaxer, const QString& schemeName);
};
extern SyntaxerManager syntaxerManager;
#endif // SYNTAXERMANAGER_H

View File

@ -106,15 +106,15 @@ TodoThread::TodoThread(const QStringList &files, QObject *parent): QThread(paren
void TodoThread::parseFile()
{
QSynedit::PHighlighter highlighter = highlighterManager.getCppHighlighter();
QSynedit::PSyntaxer syntaxer = syntaxerManager.getCppSyntaxer();
emit parseStarted();
doParseFile(mFilename,highlighter);
doParseFile(mFilename,syntaxer);
emit parseFinished();
}
void TodoThread::parseFiles()
{
QSynedit::PHighlighter highlighter = highlighterManager.getCppHighlighter();
QSynedit::PSyntaxer highlighter = syntaxerManager.getCppSyntaxer();
emit parseStarted();
foreach(const QString& filename,mFiles) {
doParseFile(filename,highlighter);
@ -122,33 +122,33 @@ void TodoThread::parseFiles()
emit parseFinished();
}
void TodoThread::doParseFile(const QString &filename, QSynedit::PHighlighter highlighter)
void TodoThread::doParseFile(const QString &filename, QSynedit::PSyntaxer syntaxer)
{
emit parsingFile(filename);
QStringList lines;
if (!pMainWindow->editorList()->getContentFromOpenedEditor(filename,lines)) {
lines = readFileToLines(filename);
}
highlighter->resetState();
syntaxer->resetState();
for (int i =0;i<lines.count();i++) {
highlighter->setLine(lines[i],i);
while (!highlighter->eol()) {
syntaxer->setLine(lines[i],i);
while (!syntaxer->eol()) {
QSynedit::PTokenAttribute attr;
attr = highlighter->getTokenAttribute();
attr = syntaxer->getTokenAttribute();
if (attr && attr->tokenType() == QSynedit::TokenType::Comment) {
QString token = highlighter->getToken();
QString token = syntaxer->getToken();
int pos = token.indexOf(todoReg);
if (pos>=0) {
emit todoFound(
filename,
i+1,
pos+highlighter->getTokenPos(),
pos+syntaxer->getTokenPos(),
lines[i].trimmed()
);
break;
}
}
highlighter->next();
syntaxer->next();
}
}

View File

@ -21,7 +21,7 @@
#include <QThread>
#include <QMutex>
#include <QAbstractListModel>
#include "HighlighterManager.h"
#include "syntaxermanager.h"
#include "qsynedit/Constants.h"
struct TodoItem {
@ -76,7 +76,7 @@ signals:
private:
void parseFile();
void parseFiles();
void doParseFile(const QString& filename, QSynedit::PHighlighter highlighter);
void doParseFile(const QString& filename, QSynedit::PSyntaxer syntaxer);
private:
QString mFilename;
QStringList mFiles;

View File

@ -17,7 +17,7 @@
#include <QDesktopWidget>
#include "cpudialog.h"
#include "ui_cpudialog.h"
#include "../HighlighterManager.h"
#include "../syntaxermanager.h"
#include "../mainwindow.h"
#include "../debugger.h"
#include "../settings.h"
@ -32,7 +32,7 @@ CPUDialog::CPUDialog(QWidget *parent) :
setWindowFlags(windowFlags() | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint);
setWindowFlag(Qt::WindowContextHelpButtonHint,false);
ui->setupUi(this);
ui->txtCode->setHighlighter(highlighterManager.getAsmHighlighter());
ui->txtCode->setSyntaxer(syntaxerManager.getAsmSyntaxer());
ui->txtCode->setReadOnly(true);
ui->txtCode->gutter().setShowLineNumbers(false);
ui->txtCode->setCaretUseTextColor(true);
@ -42,7 +42,7 @@ CPUDialog::CPUDialog(QWidget *parent) :
ui->txtCode->setGutterWidth(0);
ui->txtCode->setUseCodeFolding(false);
ui->txtCode->setRightEdge(0);
highlighterManager.applyColorScheme(ui->txtCode->highlighter(),
syntaxerManager.applyColorScheme(ui->txtCode->syntaxer(),
pSettings->editor().colorScheme());
PColorSchemeItem item = pColorManager->getItem(pSettings->editor().colorScheme(),COLOR_SCHEME_ACTIVE_LINE);
if (item) {

View File

@ -57,7 +57,7 @@ void FilePropertiesDialog::calcFile(Editor *editor,
j++;
QString token;
QSynedit::PTokenAttribute attr;
if (editor->getHighlighterAttriAtRowCol(QSynedit::BufferCoord{j+1,i+1},
if (editor->getTokenAttriAtRowCol(QSynedit::BufferCoord{j+1,i+1},
token,attr)) {
// if it is preprocessor...
if (attr->name() == SYNS_AttrPreprocessor) {

View File

@ -30,17 +30,16 @@ SOURCES += qsynedit/CodeFolding.cpp \
qsynedit/exporter/synexporter.cpp \
qsynedit/exporter/synhtmlexporter.cpp \
qsynedit/exporter/synrtfexporter.cpp \
qsynedit/highlighter/asm.cpp \
qsynedit/highlighter/base.cpp \
qsynedit/highlighter/composition.cpp \
qsynedit/highlighter/cpp.cpp \
qsynedit/highlighter/customhighlighterv1.cpp \
qsynedit/highlighter/glsl.cpp \
qsynedit/syntaxer/asm.cpp \
qsynedit/syntaxer/cpp.cpp \
qsynedit/syntaxer/customhighlighterv1.cpp \
qsynedit/syntaxer/glsl.cpp \
qsynedit/Search.cpp \
qsynedit/SearchBase.cpp \
qsynedit/SearchRegex.cpp \
qsynedit/Types.cpp \
qsynedit/highlighter/makefilehighlighter.cpp
qsynedit/syntaxer/makefile.cpp \
qsynedit/syntaxer/syntaxer.cpp
HEADERS += qsynedit/Search.h \
qsynedit/SearchBase.h \
@ -57,12 +56,11 @@ HEADERS += qsynedit/Search.h \
qsynedit/exporter/synexporter.h \
qsynedit/exporter/synhtmlexporter.h \
qsynedit/exporter/synrtfexporter.h \
qsynedit/highlighter/asm.h \
qsynedit/highlighter/base.h \
qsynedit/highlighter/composition.h \
qsynedit/highlighter/cpp.h \
qsynedit/highlighter/customhighlighterv1.h \
qsynedit/highlighter/glsl.h \
qsynedit/highlighter/makefilehighlighter.h
qsynedit/syntaxer/asm.h \
qsynedit/syntaxer/cpp.h \
qsynedit/syntaxer/customhighlighterv1.h \
qsynedit/syntaxer/glsl.h \
qsynedit/syntaxer/makefile.h \
qsynedit/syntaxer/syntaxer.h
INCLUDEPATH += ../redpanda_qt_utils

View File

@ -30,7 +30,7 @@ extern const QChar SoftBreakGlyph;
#define MAX_SCROLL 65535
// names for highlighter attributes
// names for token attributes
#define SYNS_AttrAssembler "Assembler"
#define SYNS_AttrCharacter "Character"
#define SYNS_AttrClass "Class"

View File

@ -42,24 +42,24 @@ int getEOL(const QString &Line, int start)
return Line.size();
}
static bool internalEnumHighlighterAttris(PSyntaxer syntaxer,
static bool internalEnumTokenAttributes(PSyntaxer syntaxer,
bool skipDuplicates,
TokenAttributeProc highlighterAttriProc,
TokenAttributeProc tokenAttriProc,
std::initializer_list<void *>& params,
SyntaxerList& highlighterList) {
SyntaxerList& syntaxerList) {
bool Result = true;
if (highlighterList.indexOf(syntaxer)>0) {
if (syntaxerList.indexOf(syntaxer)>0) {
if (skipDuplicates)
return Result;
} else {
highlighterList.append(syntaxer);
syntaxerList.append(syntaxer);
}
if (syntaxer) {
for (PTokenAttribute pAttr: syntaxer->attributes()){
QString UniqueAttriName = syntaxer->languageName()
+ QString("%1").arg(highlighterList.indexOf(syntaxer)) + '.'
+ QString("%1").arg(syntaxerList.indexOf(syntaxer)) + '.'
+ pAttr->name();
Result = highlighterAttriProc(syntaxer, pAttr,
Result = tokenAttriProc(syntaxer, pAttr,
UniqueAttriName, params);
if (!Result)
break;
@ -69,16 +69,16 @@ static bool internalEnumHighlighterAttris(PSyntaxer syntaxer,
}
bool enumTokenAttributes(PSyntaxer syntaxer, bool skipDuplicates,
TokenAttributeProc highlighterAttriProc,
TokenAttributeProc tokenAttriProc,
std::initializer_list<void *> params)
{
if (!syntaxer || !highlighterAttriProc) {
if (!syntaxer || !tokenAttriProc) {
return false;
}
SyntaxerList syntaxerList;
return internalEnumHighlighterAttris(syntaxer, skipDuplicates,
highlighterAttriProc, params, syntaxerList);
return internalEnumTokenAttributes(syntaxer, skipDuplicates,
tokenAttriProc, params, syntaxerList);
}
int mulDiv(int a, int b, int c)

View File

@ -21,7 +21,7 @@
#include <memory>
#include <QString>
#include <QSet>
#include "highlighter/syntaxer.h"
#include "syntaxer/syntaxer.h"
#include <QPaintDevice>
#include <QTextStream>
#include <QVector>
@ -50,7 +50,7 @@ using TokenAttributeProc = std::function<bool(PSyntaxer syntaxer,
PTokenAttribute attri, const QString& uniqueAttriName,
QList<void *> params)>;
// Enums all child highlighters and their attributes of a TSynMultiSyn through a
// Enums all child syntaxers and their attributes of a TSynMultiSyn through a
// callback function.
// This function also handles nested TSynMultiSyns including their MarkerAttri.
bool enumTokenAttributes(PSyntaxer syntaxer,

View File

@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "SynEdit.h"
#include "highlighter/cpp.h"
#include "syntaxer/cpp.h"
#include <QApplication>
#include <QFontMetrics>
#include <algorithm>
@ -24,7 +24,7 @@
#include <QPaintEvent>
#include <QPainter>
#include <QTimerEvent>
#include "highlighter/syntaxer.h"
#include "syntaxer/syntaxer.h"
#include "Constants.h"
#include "TextPainter.h"
#include <QClipboard>
@ -349,48 +349,48 @@ bool SynEdit::canRedo() const
int SynEdit::maxScrollWidth() const
{
int maxLen = mDocument->lengthOfLongestLine();
if (highlighter())
maxLen = maxLen+stringColumns(highlighter()->foldString(),maxLen);
if (syntaxer())
maxLen = maxLen+stringColumns(syntaxer()->foldString(),maxLen);
if (mOptions.testFlag(eoScrollPastEol))
return std::max(maxLen ,1);
else
return std::max(maxLen-mCharsInWindow+1, 1);
}
bool SynEdit::getHighlighterAttriAtRowCol(const BufferCoord &pos, QString &token, PTokenAttribute &attri)
bool SynEdit::getTokenAttriAtRowCol(const BufferCoord &pos, QString &token, PTokenAttribute &attri)
{
int tmpStart;
return getHighlighterAttriAtRowColEx(pos, token, tmpStart, attri);
return getTokenAttriAtRowColEx(pos, token, tmpStart, attri);
}
bool SynEdit::getHighlighterAttriAtRowCol(const BufferCoord &pos, QString &token, bool &tokenFinished, PTokenAttribute &attri)
bool SynEdit::getTokenAttriAtRowCol(const BufferCoord &pos, QString &token, bool &tokenFinished, PTokenAttribute &attri)
{
int posX, posY, endPos, start;
QString line;
posY = pos.line - 1;
if (mHighlighter && (posY >= 0) && (posY < mDocument->count())) {
if (mSyntaxer && (posY >= 0) && (posY < mDocument->count())) {
line = mDocument->getString(posY);
if (posY == 0) {
mHighlighter->resetState();
mSyntaxer->resetState();
} else {
mHighlighter->setState(mDocument->ranges(posY-1));
mSyntaxer->setState(mDocument->ranges(posY-1));
}
mHighlighter->setLine(line, posY);
mSyntaxer->setLine(line, posY);
posX = pos.ch;
if ((posX > 0) && (posX <= line.length())) {
while (!mHighlighter->eol()) {
start = mHighlighter->getTokenPos() + 1;
token = mHighlighter->getToken();
while (!mSyntaxer->eol()) {
start = mSyntaxer->getTokenPos() + 1;
token = mSyntaxer->getToken();
endPos = start + token.length()-1;
if ((posX >= start) && (posX <= endPos)) {
attri = mHighlighter->getTokenAttribute();
attri = mSyntaxer->getTokenAttribute();
if (posX == endPos)
tokenFinished = mHighlighter->getTokenFinished();
tokenFinished = mSyntaxer->getTokenFinished();
else
tokenFinished = false;
return true;
}
mHighlighter->next();
mSyntaxer->next();
}
}
}
@ -400,30 +400,30 @@ bool SynEdit::getHighlighterAttriAtRowCol(const BufferCoord &pos, QString &token
return false;
}
bool SynEdit::getHighlighterAttriAtRowColEx(const BufferCoord &pos, QString &token, int &start, PTokenAttribute &attri)
bool SynEdit::getTokenAttriAtRowColEx(const BufferCoord &pos, QString &token, int &start, PTokenAttribute &attri)
{
int posX, posY, endPos;
QString line;
posY = pos.line - 1;
if (mHighlighter && (posY >= 0) && (posY < mDocument->count())) {
if (mSyntaxer && (posY >= 0) && (posY < mDocument->count())) {
line = mDocument->getString(posY);
if (posY == 0) {
mHighlighter->resetState();
mSyntaxer->resetState();
} else {
mHighlighter->setState(mDocument->ranges(posY-1));
mSyntaxer->setState(mDocument->ranges(posY-1));
}
mHighlighter->setLine(line, posY);
mSyntaxer->setLine(line, posY);
posX = pos.ch;
if ((posX > 0) && (posX <= line.length())) {
while (!mHighlighter->eol()) {
start = mHighlighter->getTokenPos() + 1;
token = mHighlighter->getToken();
while (!mSyntaxer->eol()) {
start = mSyntaxer->getTokenPos() + 1;
token = mSyntaxer->getToken();
endPos = start + token.length()-1;
if ((posX >= start) && (posX <= endPos)) {
attri = mHighlighter->getTokenAttribute();
attri = mSyntaxer->getTokenAttribute();
return true;
}
mHighlighter->next();
mSyntaxer->next();
}
}
}
@ -516,7 +516,7 @@ BufferCoord SynEdit::getMatchingBracketEx(BufferCoord APoint)
p.line = PosY;
if ((Test == BracketInc) || (Test == BracketDec)) {
isCommentOrStringOrChar = false;
if (getHighlighterAttriAtRowCol(p, vDummy, attr))
if (getTokenAttriAtRowCol(p, vDummy, attr))
isCommentOrStringOrChar =
(attr->tokenType() == TokenType::String) ||
(attr->tokenType() == TokenType::Comment) ||
@ -550,7 +550,7 @@ BufferCoord SynEdit::getMatchingBracketEx(BufferCoord APoint)
p.line = PosY;
if ((Test == BracketInc) || (Test == BracketDec)) {
isCommentOrStringOrChar = false;
if (getHighlighterAttriAtRowCol(p, vDummy, attr))
if (getTokenAttriAtRowCol(p, vDummy, attr))
isCommentOrStringOrChar =
(attr->tokenType() == TokenType::String) ||
(attr->tokenType() == TokenType::Comment) ||
@ -1292,7 +1292,7 @@ BufferCoord SynEdit::getPreviousLeftBrace(int x, int y)
p.ch = PosX;
p.line = PosY;
if (Test=='{' || Test == '}') {
if (getHighlighterAttriAtRowCol(p, vDummy, attr)) {
if (getTokenAttriAtRowCol(p, vDummy, attr)) {
isCommentOrStringOrChar =
(attr->tokenType() == TokenType::String) ||
(attr->tokenType() == TokenType::Comment) ||
@ -1538,7 +1538,7 @@ int SynEdit::findCommentStartLine(int searchStartLine)
SyntaxerState range;
while (commentStartLine>=1) {
range = mDocument->ranges(commentStartLine-1);
if (!mHighlighter->isLastLineCommentNotFinished(range.state)){
if (!mSyntaxer->isLastLineCommentNotFinished(range.state)){
commentStartLine++;
break;
}
@ -1554,7 +1554,7 @@ int SynEdit::findCommentStartLine(int searchStartLine)
int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
{
if (!mHighlighter)
if (!mSyntaxer)
return 0;
line = std::min(line, mDocument->count()+1);
if (line<=1)
@ -1574,20 +1574,20 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
//calculate the indents of last statement;
indentSpaces = leftSpaces(startLineText);
SyntaxerState rangePreceeding = mDocument->ranges(startLine-1);
mHighlighter->setState(rangePreceeding);
mSyntaxer->setState(rangePreceeding);
if (addIndent) {
// QString trimmedS = s.trimmed();
QString trimmedLineText = lineText.trimmed();
mHighlighter->setLine(trimmedLineText,line-1);
mSyntaxer->setLine(trimmedLineText,line-1);
int statePrePre;
if (startLine>1) {
statePrePre = mDocument->ranges(startLine-2).state;
} else {
statePrePre = 0;
}
SyntaxerState rangeAfterFirstToken = mHighlighter->getState();
QString firstToken = mHighlighter->getToken();
PTokenAttribute attr = mHighlighter->getTokenAttribute();
SyntaxerState rangeAfterFirstToken = mSyntaxer->getState();
QString firstToken = mSyntaxer->getToken();
PTokenAttribute attr = mSyntaxer->getTokenAttribute();
if (attr->tokenType() == TokenType::Keyword
&& lineText.endsWith(':')
&& (
@ -1596,11 +1596,11 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
|| firstToken == "default"
)) {
// public: private: protecte: case: should indents like it's parent statement
mHighlighter->setState(rangePreceeding);
mHighlighter->setLine("}",line-1);
rangeAfterFirstToken = mHighlighter->getState();
firstToken = mHighlighter->getToken();
attr = mHighlighter->getTokenAttribute();
mSyntaxer->setState(rangePreceeding);
mSyntaxer->setLine("}",line-1);
rangeAfterFirstToken = mSyntaxer->getState();
firstToken = mSyntaxer->getToken();
attr = mSyntaxer->getTokenAttribute();
}
bool indentAdded = false;
int additionIndent = 0;
@ -1619,14 +1619,14 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
matchingIndents = rangeAfterFirstToken.matchingIndents;
indentAdded = true;
l = startLine;
} else if (mHighlighter->language() == ProgrammingLanguage::Cpp
} else if (mSyntaxer->language() == ProgrammingLanguage::Cpp
&& trimmedLineText.startsWith('#')
&& attr == ((CppSyntaxer *)mHighlighter.get())->preprocessorAttribute()) {
&& attr == ((CppSyntaxer *)mSyntaxer.get())->preprocessorAttribute()) {
indentAdded = true;
indentSpaces=0;
l=0;
} else if (mHighlighter->language() == ProgrammingLanguage::Cpp
&& mHighlighter->isLastLineCommentNotFinished(rangePreceeding.state)
} else if (mSyntaxer->language() == ProgrammingLanguage::Cpp
&& mSyntaxer->isLastLineCommentNotFinished(rangePreceeding.state)
) {
// last line is a not finished comment,
if (trimmedLineText.startsWith("*")) {
@ -1652,10 +1652,10 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
indentAdded = true;
l = startLine;
}
} else if ( mHighlighter->isLastLineCommentNotFinished(statePrePre)
} else if ( mSyntaxer->isLastLineCommentNotFinished(statePrePre)
&& rangePreceeding.matchingIndents.isEmpty()
&& rangePreceeding.firstIndentThisLine>=rangePreceeding.indents.length()
&& !mHighlighter->isLastLineCommentNotFinished(rangePreceeding.state)) {
&& !mSyntaxer->isLastLineCommentNotFinished(rangePreceeding.state)) {
// 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);
@ -1723,7 +1723,7 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
PTokenAttribute attr;
coord.line = startLine;
coord.ch = document()->getString(startLine-1).length();
if (getHighlighterAttriAtRowCol(coord,token,attr)
if (getTokenAttriAtRowCol(coord,token,attr)
&& attr->tokenType() == QSynedit::TokenType::Operator
&& token == ":") {
indentSpaces += tabWidth();
@ -1982,7 +1982,7 @@ QString SynEdit::getDisplayStringAtLine(int line) const
QString s = mDocument->getString(line-1);
PCodeFoldingRange foldRange = foldStartAtLine(line);
if ((foldRange) && foldRange->collapsed) {
return s+highlighter()->foldString();
return s+syntaxer()->foldString();
}
return s;
}
@ -2395,7 +2395,7 @@ void SynEdit::insertLine(bool moveCaret)
if (mCaretX>lineText().length()+1) {
PCodeFoldingRange foldRange = foldStartAtLine(mCaretY);
if ((foldRange) && foldRange->collapsed) {
QString s = Temp+highlighter()->foldString();
QString s = Temp+syntaxer()->foldString();
if (mCaretX > s.length()) {
if (!mUndoing) {
addCaretToUndo();
@ -2426,19 +2426,19 @@ void SynEdit::insertLine(bool moveCaret)
bool notInComment=true;
properSetLine(mCaretY-1,leftLineText);
//update range stated for line mCaretY
if (mHighlighter) {
if (mSyntaxer) {
if (mCaretY==1) {
mHighlighter->resetState();
mSyntaxer->resetState();
} else {
mHighlighter->setState(mDocument->ranges(mCaretY-2));
mSyntaxer->setState(mDocument->ranges(mCaretY-2));
}
mHighlighter->setLine(leftLineText, mCaretY-1);
mHighlighter->nextToEol();
mDocument->setRange(mCaretY-1,mHighlighter->getState());
notInComment = !mHighlighter->isLastLineCommentNotFinished(
mHighlighter->getState().state)
&& !mHighlighter->isLastLineStringNotFinished(
mHighlighter->getState().state);
mSyntaxer->setLine(leftLineText, mCaretY-1);
mSyntaxer->nextToEol();
mDocument->setRange(mCaretY-1,mSyntaxer->getState());
notInComment = !mSyntaxer->isLastLineCommentNotFinished(
mSyntaxer->getState().state)
&& !mSyntaxer->isLastLineStringNotFinished(
mSyntaxer->getState().state);
}
int indentSpaces = 0;
if (mOptions.testFlag(eoAutoIndent)) {
@ -2905,8 +2905,8 @@ void SynEdit::doAddChar(QChar AChar)
// auto
if (mActiveSelectionMode==SelectionMode::Normal
&& mOptions.testFlag(eoAutoIndent)
&& mHighlighter
&& mHighlighter->language() == ProgrammingLanguage::Cpp
&& mSyntaxer
&& mSyntaxer->language() == ProgrammingLanguage::Cpp
&& (oldCaretY<=mDocument->count()) ) {
//unindent if ':' at end of the line
@ -3295,8 +3295,8 @@ void SynEdit::recalcCharExtent()
FontStyle styles[] = {FontStyle::fsBold, FontStyle::fsItalic, FontStyle::fsStrikeOut, FontStyle::fsUnderline};
bool hasStyles[] = {false,false,false,false};
int size = 4;
if (mHighlighter && mHighlighter->attributes().count()>0) {
for (const PTokenAttribute& attribute: mHighlighter->attributes()) {
if (mSyntaxer && mSyntaxer->attributes().count()>0) {
for (const PTokenAttribute& attribute: mSyntaxer->attributes()) {
for (int i=0;i<size;i++) {
if (attribute->styles().testFlag(styles[i]))
hasStyles[i] = true;
@ -3414,14 +3414,14 @@ int SynEdit::scanFrom(int Index, int canStopIndex)
return Result;
if (Result == 0) {
mHighlighter->resetState();
mSyntaxer->resetState();
} else {
mHighlighter->setState(mDocument->ranges(Result-1));
mSyntaxer->setState(mDocument->ranges(Result-1));
}
do {
mHighlighter->setLine(mDocument->getString(Result), Result);
mHighlighter->nextToEol();
iRange = mHighlighter->getState();
mSyntaxer->setLine(mDocument->getString(Result), Result);
mSyntaxer->nextToEol();
iRange = mSyntaxer->getState();
if (Result > canStopIndex){
if (mDocument->ranges(Result).state == iRange.state
&& mDocument->ranges(Result).blockLevel == iRange.blockLevel
@ -3448,7 +3448,7 @@ int SynEdit::scanFrom(int Index, int canStopIndex)
void SynEdit::rescanRange(int line)
{
if (!mHighlighter)
if (!mSyntaxer)
return;
line--;
line = std::max(0,line);
@ -3456,24 +3456,24 @@ void SynEdit::rescanRange(int line)
return;
if (line == 0) {
mHighlighter->resetState();
mSyntaxer->resetState();
} else {
mHighlighter->setState(mDocument->ranges(line-1));
mSyntaxer->setState(mDocument->ranges(line-1));
}
mHighlighter->setLine(mDocument->getString(line), line);
mHighlighter->nextToEol();
SyntaxerState iRange = mHighlighter->getState();
mSyntaxer->setLine(mDocument->getString(line), line);
mSyntaxer->nextToEol();
SyntaxerState iRange = mSyntaxer->getState();
mDocument->setRange(line,iRange);
}
void SynEdit::rescanRanges()
{
if (mHighlighter && !mDocument->empty()) {
mHighlighter->resetState();
if (mSyntaxer && !mDocument->empty()) {
mSyntaxer->resetState();
for (int i =0;i<mDocument->count();i++) {
mHighlighter->setLine(mDocument->getString(i), i);
mHighlighter->nextToEol();
mDocument->setRange(i, mHighlighter->getState());
mSyntaxer->setLine(mDocument->getString(i), i);
mSyntaxer->nextToEol();
mDocument->setRange(i, mSyntaxer->getState());
}
}
if (mUseCodeFolding)
@ -3611,9 +3611,9 @@ void SynEdit::scanForFoldRanges(PCodeFoldingRanges topFoldRanges)
}
//this func should only be used in findSubFoldRange
int SynEdit::lineHasChar(int Line, int startChar, QChar character, const QString& highlighterAttrName) {
int SynEdit::lineHasChar(int Line, int startChar, QChar character, const QString& tokenAttrName) {
QString CurLine = mDocument->getString(Line);
if (!mHighlighter){
if (!mSyntaxer){
for (int i=startChar; i<CurLine.length();i++) {
if (CurLine[i]==character) {
return i;
@ -3629,12 +3629,12 @@ int SynEdit::lineHasChar(int Line, int startChar, QChar character, const QString
mHighlighter->setLine(CurLine,Line);
*/
QString token;
while (!mHighlighter->eol()) {
token = mHighlighter->getToken();
PTokenAttribute attr = mHighlighter->getTokenAttribute();
if (token == character && attr->name()==highlighterAttrName)
return mHighlighter->getTokenPos();
mHighlighter->next();
while (!mSyntaxer->eol()) {
token = mSyntaxer->getToken();
PTokenAttribute attr = mSyntaxer->getTokenAttribute();
if (token == character && attr->name()==tokenAttrName)
return mSyntaxer->getTokenPos();
mSyntaxer->next();
}
}
return -1;
@ -3645,7 +3645,7 @@ void SynEdit::findSubFoldRange(PCodeFoldingRanges topFoldRanges, PCodeFoldingRan
PCodeFoldingRange collapsedFold;
int line = 0;
QString curLine;
if (!mHighlighter)
if (!mSyntaxer)
return;
while (line < mDocument->count()) { // index is valid for LinesToScan and fLines
@ -4597,7 +4597,7 @@ QString SynEdit::selText() const
PCodeFoldingRange foldRange = foldStartAtLine(blockEnd().line);
QString s = mDocument->getString(Last);
if ((foldRange) && foldRange->collapsed && ColTo>s.length()) {
s=s+highlighter()->foldString();
s=s+syntaxer()->foldString();
if (ColTo>s.length()) {
Last = foldRange->toLine-1;
ColTo = mDocument->getString(Last).length()+1;
@ -4676,7 +4676,7 @@ QStringList SynEdit::getContent(BufferCoord startPos, BufferCoord endPos, Select
PCodeFoldingRange foldRange = foldStartAtLine(endPos.line);
QString s = mDocument->getString(Last);
if ((foldRange) && foldRange->collapsed && ColTo>s.length()) {
s=s+highlighter()->foldString();
s=s+syntaxer()->foldString();
if (ColTo>s.length()) {
Last = foldRange->toLine-1;
ColTo = mDocument->getString(Last).length()+1;
@ -4751,7 +4751,7 @@ QString SynEdit::displayLineText()
QString s= mDocument->getString(mCaretY - 1);
PCodeFoldingRange foldRange = foldStartAtLine(mCaretY);
if ((foldRange) && foldRange->collapsed) {
return s+highlighter()->foldString();
return s+syntaxer()->foldString();
}
return s;
}
@ -4772,17 +4772,17 @@ void SynEdit::setLineText(const QString s)
mDocument->putString(mCaretY-1,s);
}
PSyntaxer SynEdit::highlighter() const
PSyntaxer SynEdit::syntaxer() const
{
return mHighlighter;
return mSyntaxer;
}
void SynEdit::setHighlighter(const PSyntaxer &highlighter)
void SynEdit::setSyntaxer(const PSyntaxer &syntaxer)
{
PSyntaxer oldHighlighter= mHighlighter;
mHighlighter = highlighter;
if (oldHighlighter && mHighlighter &&
oldHighlighter->language() == highlighter->language()) {
PSyntaxer oldSyntaxer = mSyntaxer;
mSyntaxer = syntaxer;
if (oldSyntaxer && mSyntaxer &&
oldSyntaxer ->language() == syntaxer->language()) {
} else {
recalcCharExtent();
mDocument->beginUpdate();
@ -5335,7 +5335,7 @@ void SynEdit::doDeleteText(BufferCoord startPos, BufferCoord endPos, SelectionMo
PCodeFoldingRange foldRange = foldStartAtLine(endPos.line);
QString s = mDocument->getString(endPos.line-1);
if ((foldRange) && foldRange->collapsed && endPos.ch>s.length()) {
QString newS=s+highlighter()->foldString();
QString newS=s+syntaxer()->foldString();
if ((startPos.ch<=s.length() || startPos.line<endPos.line)
&& endPos.ch>newS.length() ) {
//selection has whole block
@ -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()==ProgrammingLanguage::Cpp && mOptions.testFlag(eoAutoIndent)) {
if (!mUndoing && mSyntaxer && mSyntaxer->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()==ProgrammingLanguage::Cpp && mOptions.testFlag(eoAutoIndent) && notInComment) {
if (!mUndoing && mSyntaxer && mSyntaxer->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()==ProgrammingLanguage::Cpp && mOptions.testFlag(eoAutoIndent) && notInComment) {
if (!mUndoing && mSyntaxer && mSyntaxer->language()==ProgrammingLanguage::Cpp && mOptions.testFlag(eoAutoIndent) && notInComment) {
int indentSpaces = calcIndentSpaces(caretY,str,true);
str = GetLeftSpacing(indentSpaces,true)+trimLeft(str);
}
@ -5983,8 +5983,8 @@ void SynEdit::onBeginFirstPaintLock()
bool SynEdit::isIdentChar(const QChar &ch)
{
if (mHighlighter) {
return mHighlighter->isIdentChar(ch);
if (mSyntaxer) {
return mSyntaxer->isIdentChar(ch);
} else {
if (ch == '_') {
return true;
@ -6639,7 +6639,7 @@ void SynEdit::onLinesDeleted(int index, int count)
{
if (mUseCodeFolding)
foldOnListDeleted(index + 1, count);
if (mHighlighter && mDocument->count() > 0)
if (mSyntaxer && mDocument->count() > 0)
scanFrom(index, index+1);
invalidateLines(index + 1, INT_MAX);
invalidateGutterLines(index + 1, INT_MAX);
@ -6649,7 +6649,7 @@ void SynEdit::onLinesInserted(int index, int count)
{
if (mUseCodeFolding)
foldOnListInserted(index + 1, count);
if (mHighlighter && mDocument->count() > 0) {
if (mSyntaxer && mDocument->count() > 0) {
// int vLastScan = index;
// do {
scanFrom(index, index+count);
@ -6663,7 +6663,7 @@ void SynEdit::onLinesInserted(int index, int count)
void SynEdit::onLinesPutted(int index, int count)
{
int vEndLine = index + 1;
if (mHighlighter) {
if (mSyntaxer) {
vEndLine = std::max(vEndLine, scanFrom(index, index+count) + 1);
}
invalidateLines(index + 1, vEndLine);
@ -6721,8 +6721,8 @@ void SynEdit::setBlockEnd(BufferCoord Value)
Value.ch = 1;
} else {
int maxLen = mDocument->lengthOfLongestLine();
if (highlighter())
maxLen = maxLen+stringColumns(highlighter()->foldString(),maxLen);
if (syntaxer())
maxLen = maxLen+stringColumns(syntaxer()->foldString(),maxLen);
Value.ch = minMax(Value.ch, 1, maxLen+1);
}
if (Value.ch != mBlockEnd.ch || Value.line != mBlockEnd.line) {
@ -6820,8 +6820,8 @@ void SynEdit::setBlockBegin(BufferCoord value)
value.ch = 1;
} else {
int maxLen = mDocument->lengthOfLongestLine();
if (highlighter())
maxLen = maxLen+stringColumns(highlighter()->foldString(),maxLen);
if (syntaxer())
maxLen = maxLen+stringColumns(syntaxer()->foldString(),maxLen);
value.ch = minMax(value.ch, 1, maxLen+1);
}
if (selAvail()) {

View File

@ -131,9 +131,6 @@ using SynPaintTransientProc = std::function<void(const QPaintDevice& paintDevice
using ProcessCommandProc = std::function<void(EditCommand& command, QChar& AChar, void* data)>;
using MouseCursorProc = std::function<void(const BufferCoord& aLineCharPos, QCursor & aCursor)>;
using PaintProc = std::function<void(const QPaintDevice& paintDevice )>;
//using SynPreparePaintHighlightTokenProc = std::function<void(int row,
// int column, const QString& token, PSynHighlighterAttribute attr,
// FontStyles& style, QColor& foreground, QColor& background)>;
using SearchMathedProc = std::function<SearchAction(const QString& sSearch,
const QString& sReplace, int Line, int ch, int wordLen)>;
using SearchConfirmAroundProc = std::function<bool ()>;
@ -247,11 +244,11 @@ public:
int maxScrollWidth() const;
int maxScrollHeight() const;
bool getHighlighterAttriAtRowCol(const BufferCoord& pos, QString& token,
bool getTokenAttriAtRowCol(const BufferCoord& pos, QString& token,
PTokenAttribute& attri);
bool getHighlighterAttriAtRowCol(const BufferCoord& pos, QString& token,
bool getTokenAttriAtRowCol(const BufferCoord& pos, QString& token,
bool& tokenFinished, PTokenAttribute& attri);
bool getHighlighterAttriAtRowColEx(const BufferCoord& pos, QString& token,
bool getTokenAttriAtRowColEx(const BufferCoord& pos, QString& token,
int &start, PTokenAttribute& attri);
void beginUndoBlock();
@ -341,8 +338,8 @@ public:
bool modified() const;
void setModified(bool Value);
PSyntaxer highlighter() const;
void setHighlighter(const PSyntaxer &highlighter);
PSyntaxer syntaxer() const;
void setSyntaxer(const PSyntaxer &syntaxer);
bool useCodeFolding() const;
void setUseCodeFolding(bool value);
@ -514,7 +511,7 @@ private:
void rescanFolds(); // rescan for folds
void rescanForFoldRanges();
void scanForFoldRanges(PCodeFoldingRanges topFoldRanges);
int lineHasChar(int Line, int startChar, QChar character, const QString& highlighterAttrName);
int lineHasChar(int Line, int startChar, QChar character, const QString& tokenAttrName);
void findSubFoldRange(PCodeFoldingRanges topFoldRanges,PCodeFoldingRanges& parentFoldRanges, PCodeFoldingRange Parent);
PCodeFoldingRange collapsedFoldStartAtLine(int Line);
void initializeCaret();
@ -667,7 +664,7 @@ private:
ScrollStyle mScrollBars;
int mTextHeight;
int mTopLine;
PSyntaxer mHighlighter;
PSyntaxer mSyntaxer;
QColor mSelectedForeground;
QColor mSelectedBackground;
QColor mForegroundColor;

View File

@ -18,7 +18,7 @@
#define SYNEDITSTRINGLIST_H
#include <QStringList>
#include "highlighter/syntaxer.h"
#include "syntaxer/syntaxer.h"
#include <QFontMetrics>
#include <QMutex>
#include <QVector>

View File

@ -619,7 +619,7 @@ void SynEditTextPainter::addHighlightToken(const QString &Token, int columnsBefo
foreground = edit->mForegroundColor;
}
edit->onPreparePaintHighlightToken(cLine,edit->mHighlighter->getTokenPos()+1,
edit->onPreparePaintHighlightToken(cLine,edit->mSyntaxer->getTokenPos()+1,
Token,p_Attri,style,foreground,background);
// Do we have to paint the old chars first, or can we just append?
@ -702,17 +702,17 @@ void SynEditTextPainter::paintFoldAttributes()
X = TabSteps * edit->mCharWidth + edit->textOffset() - 2;
TabSteps+=edit->tabWidth();
indentLevel++ ;
if (edit->mHighlighter) {
if (edit->mSyntaxer) {
if (edit->mCodeFolding.indentGuides) {
PTokenAttribute attr = edit->mHighlighter->symbolAttribute();
PTokenAttribute attr = edit->mSyntaxer->symbolAttribute();
getBraceColorAttr(indentLevel,attr);
paintColor = attr->foreground();
}
if (edit->mCodeFolding.fillIndents) {
PTokenAttribute attr = edit->mHighlighter->symbolAttribute();
PTokenAttribute attr = edit->mSyntaxer->symbolAttribute();
getBraceColorAttr(indentLevel,attr);
gradientStart=attr->foreground();
attr = edit->mHighlighter->symbolAttribute();
attr = edit->mSyntaxer->symbolAttribute();
getBraceColorAttr(indentLevel+1,attr);
gradientStart=attr->foreground();
}
@ -792,7 +792,7 @@ void SynEditTextPainter::paintLines()
int cRow; // row index for the loop
int vLine;
QString sLine; // the current line
QString sToken; // highlighter token info
QString sToken; // token info
int nTokenColumnsBefore, nTokenColumnLen;
PTokenAttribute attr;
int vFirstChar;
@ -894,7 +894,7 @@ void SynEditTextPainter::paintLines()
bLineSelected = (!bComplexLine) && (nLineSelStart > 0);
rcToken = rcLine;
if (!edit->mHighlighter || !edit->mHighlighter->enabled()) {
if (!edit->mSyntaxer || !edit->mSyntaxer->enabled()) {
sToken = sLine;
if (bCurrentLine) {
nTokenColumnLen = edit->stringColumns(sLine,0);
@ -938,12 +938,12 @@ void SynEditTextPainter::paintLines()
// necessary because we probably did not scan to the end of the last
// line - the internal highlighter range might be wrong.
if (vLine == 1) {
edit->mHighlighter->resetState();
edit->mSyntaxer->resetState();
} else {
edit->mHighlighter->setState(
edit->mSyntaxer->setState(
edit->mDocument->ranges(vLine-2));
}
edit->mHighlighter->setLine(sLine, vLine - 1);
edit->mSyntaxer->setLine(sLine, vLine - 1);
// Try to concatenate as many tokens as possible to minimize the count
// of ExtTextOut calls necessary. This depends on the selection state
// or the line having special colors. For spaces the foreground color
@ -951,14 +951,14 @@ void SynEditTextPainter::paintLines()
TokenAccu.Columns = 0;
nTokenColumnsBefore = 0;
// Test first whether anything of this token is visible.
while (!edit->mHighlighter->eol()) {
sToken = edit->mHighlighter->getToken();
while (!edit->mSyntaxer->eol()) {
sToken = edit->mSyntaxer->getToken();
// Work-around buggy highlighters which return empty tokens.
if (sToken.isEmpty()) {
edit->mHighlighter->next();
if (edit->mHighlighter->eol())
edit->mSyntaxer->next();
if (edit->mSyntaxer->eol())
break;
sToken = edit->mHighlighter->getToken();
sToken = edit->mSyntaxer->getToken();
// Maybe should also test whether GetTokenPos changed...
if (sToken.isEmpty()) {
qDebug()<<SynEdit::tr("The highlighter seems to be in an infinite loop");
@ -974,12 +974,12 @@ void SynEditTextPainter::paintLines()
nTokenColumnLen = vLastChar - nTokenColumnsBefore;
}
// It's at least partially visible. Get the token attributes now.
attr = edit->mHighlighter->getTokenAttribute();
attr = edit->mSyntaxer->getTokenAttribute();
if (sToken == "["
|| sToken == "("
|| sToken == "{"
) {
SyntaxerState rangeState = edit->mHighlighter->getState();
SyntaxerState rangeState = edit->mSyntaxer->getState();
getBraceColorAttr(rangeState.bracketLevel
+rangeState.braceLevel
+rangeState.parenthesisLevel
@ -988,15 +988,15 @@ void SynEditTextPainter::paintLines()
|| sToken == ")"
|| sToken == "}"
){
SyntaxerState rangeState = edit->mHighlighter->getState();
SyntaxerState rangeState = edit->mSyntaxer->getState();
getBraceColorAttr(rangeState.bracketLevel
+rangeState.braceLevel
+rangeState.parenthesisLevel+1,
attr);
}
if (bCurrentLine && edit->mInputPreeditString.length()>0) {
int startPos = edit->mHighlighter->getTokenPos()+1;
int endPos = edit->mHighlighter->getTokenPos() + sToken.length();
int startPos = edit->mSyntaxer->getTokenPos()+1;
int endPos = edit->mSyntaxer->getTokenPos() + sToken.length();
//qDebug()<<startPos<<":"<<endPos<<" - "+sToken+" - "<<edit->mCaretX<<":"<<edit->mCaretX+edit->mInputPreeditString.length();
if (!(endPos < edit->mCaretX
|| startPos >= edit->mCaretX+edit->mInputPreeditString.length())) {
@ -1012,11 +1012,11 @@ void SynEditTextPainter::paintLines()
}
nTokenColumnsBefore+=nTokenColumnLen;
// Let the highlighter scan the next token.
edit->mHighlighter->next();
edit->mSyntaxer->next();
}
// Don't assume HL.GetTokenPos is valid after HL.GetEOL == True.
//nTokenColumnsBefore += edit->stringColumns(sToken,nTokenColumnsBefore);
if (edit->mHighlighter->eol() && (nTokenColumnsBefore < vLastChar)) {
if (edit->mSyntaxer->eol() && (nTokenColumnsBefore < vLastChar)) {
int lineColumns = edit->mDocument->lineColumns(vLine-1);
// Draw text that couldn't be parsed by the highlighter, if any.
if (nTokenColumnsBefore < lineColumns) {
@ -1034,17 +1034,17 @@ void SynEditTextPainter::paintLines()
(!bSpecialLine) && (edit->mDocument->lineColumns(vLine-1) < vLastChar)) {
addHighlightToken(LineBreakGlyph,
edit->mDocument->lineColumns(vLine-1) - (vFirstChar - FirstCol),
edit->charColumns(LineBreakGlyph),vLine, edit->mHighlighter->whitespaceAttribute());
edit->charColumns(LineBreakGlyph),vLine, edit->mSyntaxer->whitespaceAttribute());
}
}
// Paint folding
foldRange = edit->foldStartAtLine(vLine);
if ((foldRange) && foldRange->collapsed) {
sFold = edit->highlighter()->foldString();
sFold = edit->syntaxer()->foldString();
nFold = edit->stringColumns(sFold,edit->mDocument->lineColumns(vLine-1));
attr = edit->mHighlighter->symbolAttribute();
getBraceColorAttr(edit->mHighlighter->getState().braceLevel,attr);
attr = edit->mSyntaxer->symbolAttribute();
getBraceColorAttr(edit->mSyntaxer->getState().braceLevel,attr);
addHighlightToken(sFold,edit->mDocument->lineColumns(vLine-1) - (vFirstChar - FirstCol)
, nFold, vLine, attr);
}

View File

@ -21,7 +21,7 @@
#include <QPainter>
#include <QString>
#include "Types.h"
#include "highlighter/syntaxer.h"
#include "syntaxer/syntaxer.h"
#include "MiscClasses.h"
namespace QSynedit {

View File

@ -61,7 +61,7 @@ void SynExporter::ExportAll(PDocument ALines)
void SynExporter::ExportRange(PDocument ALines, BufferCoord Start, BufferCoord Stop)
{
// abort if not all necessary conditions are met
if (!ALines || !mHighlighter || (ALines->count() == 0))
if (!ALines || !mSyntaxer || (ALines->count() == 0))
return;
Stop.line = std::max(1, std::min(Stop.line, ALines->count()));
Stop.ch = std::max(1, std::min(Stop.ch, ALines->getString(Stop.line - 1).length() + 1));
@ -77,9 +77,9 @@ void SynExporter::ExportRange(PDocument ALines, BufferCoord Start, BufferCoord S
mFirstAttribute = true;
if (Start.line == 1)
mHighlighter->resetState();
mSyntaxer->resetState();
else
mHighlighter->setState(ALines->ranges(Start.line-2));
mSyntaxer->setState(ALines->ranges(Start.line-2));
for (int i = Start.line; i<=Stop.line; i++) {
QString Line = ALines->getString(i-1);
// order is important, since Start.Y might be equal to Stop.Y
@ -88,17 +88,17 @@ void SynExporter::ExportRange(PDocument ALines, BufferCoord Start, BufferCoord S
// if ( (i = Start.Line) && (Start.Char > 1))
// Line.remove(0, Start.Char - 1);
// export the line
mHighlighter->setLine(Line, i);
while (!mHighlighter->eol()) {
PTokenAttribute attri = mHighlighter->getTokenAttribute();
int startPos = mHighlighter->getTokenPos();
QString token = mHighlighter->getToken();
mSyntaxer->setLine(Line, i);
while (!mSyntaxer->eol()) {
PTokenAttribute attri = mSyntaxer->getTokenAttribute();
int startPos = mSyntaxer->getTokenPos();
QString token = mSyntaxer->getToken();
if (i==Start.line && (startPos+token.length() < Start.ch)) {
mHighlighter->next();
mSyntaxer->next();
continue;
}
if (i==Stop.line && (startPos >= Stop.ch-1)) {
mHighlighter->next();
mSyntaxer->next();
continue;
}
if (i==Stop.line && (startPos+token.length() > Stop.ch)) {
@ -110,10 +110,10 @@ void SynExporter::ExportRange(PDocument ALines, BufferCoord Start, BufferCoord S
QString Token = ReplaceReservedChars(token);
if (mOnFormatToken)
mOnFormatToken(mHighlighter, i, mHighlighter->getTokenPos()+1, mHighlighter->getToken(),attri);
mOnFormatToken(mSyntaxer, i, mSyntaxer->getTokenPos()+1, mSyntaxer->getToken(),attri);
SetTokenAttribute(attri);
FormatToken(Token);
mHighlighter->next();
mSyntaxer->next();
}
if (i!=Stop.line)
FormatNewLine();
@ -166,18 +166,18 @@ void SynExporter::setFont(const QFont &font)
mFont = font;
}
PSyntaxer SynExporter::highlighter() const
PSyntaxer SynExporter::syntaxer() const
{
return mHighlighter;
return mSyntaxer;
}
void SynExporter::setHighlighter(PSyntaxer Value)
void SynExporter::setSyntaxer(PSyntaxer value)
{
if (mHighlighter != Value) {
mHighlighter = Value;
if (mSyntaxer != value) {
mSyntaxer = value;
clear();
if ((mHighlighter) && (mHighlighter->whitespaceAttribute()) && mUseBackground)
mBackgroundColor = mHighlighter->whitespaceAttribute()->background();
if ((mSyntaxer) && (mSyntaxer->whitespaceAttribute()) && mUseBackground)
mBackgroundColor = mSyntaxer->whitespaceAttribute()->background();
}
}
@ -206,8 +206,8 @@ void SynExporter::setUseBackground(bool Value)
if (mUseBackground != Value) {
mUseBackground = Value;
clear();
if ((mHighlighter) && (mHighlighter->whitespaceAttribute()) && mUseBackground)
mBackgroundColor = mHighlighter->whitespaceAttribute()->background();
if ((mSyntaxer) && (mSyntaxer->whitespaceAttribute()) && mUseBackground)
mBackgroundColor = mSyntaxer->whitespaceAttribute()->background();
}
}

View File

@ -69,8 +69,8 @@ public:
QFont font() const;
void setFont(const QFont &font);
PSyntaxer highlighter() const;
void setHighlighter(PSyntaxer Value);
PSyntaxer syntaxer() const;
void setSyntaxer(PSyntaxer value);
QString title() const;
void setTitle(const QString &Value);
@ -112,7 +112,7 @@ protected:
QString mDefaultFilter;
bool mExportAsText;
QFont mFont;
PSyntaxer mHighlighter;
PSyntaxer mSyntaxer;
QColor mLastBG;
QColor mLastFG;
FontStyles mLastStyle;

View File

@ -124,7 +124,7 @@ void SynHTMLExporter::FormatAttributeDone(bool , bool , FontStyles )
void SynHTMLExporter::FormatAttributeInit(bool , bool , FontStyles )
{
QString StyleName = GetStyleName(mHighlighter, mLastAttri);
QString StyleName = GetStyleName(mSyntaxer, mLastAttri);
AddData(QString("<span class=\"%1\">").arg(StyleName));
}
@ -135,7 +135,7 @@ void SynHTMLExporter::FormatAfterLastAttribute()
void SynHTMLExporter::FormatBeforeFirstAttribute(bool, bool, FontStyles)
{
QString StyleName = GetStyleName(mHighlighter, mLastAttri);
QString StyleName = GetStyleName(mSyntaxer, mLastAttri);
AddData(QString("<span class=\"%1\">").arg(StyleName));
}
@ -164,7 +164,7 @@ QString SynHTMLExporter::GetHeader()
{
using namespace std::placeholders;
QString Styles;
enumTokenAttributes(mHighlighter, true,
enumTokenAttributes(mSyntaxer, true,
std::bind(&SynHTMLExporter::AttriToCSSCallback,
this, _1, _2, _3, _4),
{&Styles});

View File

@ -14,8 +14,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef SYNEDITCPPHIGHLIGHTER_H
#define SYNEDITCPPHIGHLIGHTER_H
#ifndef QSYNEDIT_CPP_SYNTAXER_H
#define QSYNEDIT_CPP_SYNTAXER_H
#include "syntaxer.h"
#include <QSet>

View File

@ -14,8 +14,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef SYNEDITGLSLHIGHLIGHTER_H
#define SYNEDITGLSLHIGHLIGHTER_H
#ifndef QSYNEDIT_GLSL_SYNTAXER_H
#define QSYNEDIT_GLSL_SYNTAXER_H
#include "syntaxer.h"
#include <QSet>

View File

@ -14,8 +14,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef MAKEFILE_H
#define MAKEFILE_H
#ifndef QSYNEDIT_MAKEFILE_SYNTAXER_H
#define QSYNEDIT_MAKEFILE_SYNTAXER_H
#include "syntaxer.h"