refactor highlighters

This commit is contained in:
Roy Qu 2022-12-10 20:58:04 +08:00
parent 81d88fb5bd
commit d0732b9989
23 changed files with 336 additions and 337 deletions

View File

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

View File

@ -21,7 +21,7 @@
#include <memory> #include <memory>
#include <QString> #include <QString>
#include <QSet> #include <QSet>
#include "highlighter/base.h" #include "highlighter/syntaxer.h"
#include <QPaintDevice> #include <QPaintDevice>
#include <QTextStream> #include <QTextStream>
#include <QVector> #include <QVector>
@ -46,15 +46,15 @@ QStringList splitStrings(const QString& text);
int calSpanLines(const BufferCoord& startPos, const BufferCoord& endPos); int calSpanLines(const BufferCoord& startPos, const BufferCoord& endPos);
using TokenAttributeProc = std::function<bool(PHighlighter Highlighter, using TokenAttributeProc = std::function<bool(PSyntaxer syntaxer,
PTokenAttribute Attri, const QString& UniqueAttriName, PTokenAttribute attri, const QString& uniqueAttriName,
QList<void *> Params)>; QList<void *> params)>;
// Enums all child highlighters and their attributes of a TSynMultiSyn through a // Enums all child highlighters and their attributes of a TSynMultiSyn through a
// callback function. // callback function.
// This function also handles nested TSynMultiSyns including their MarkerAttri. // This function also handles nested TSynMultiSyns including their MarkerAttri.
bool enumTokenAttributes(PHighlighter Highlighter, bool enumTokenAttributes(PSyntaxer syntaxer,
bool SkipDuplicates, TokenAttributeProc highlighterAttriProc, bool skipDuplicates, TokenAttributeProc tokenAttriProc,
std::initializer_list<void *> Params); std::initializer_list<void *> Params);
FontStyles getFontStyles(const QFont& font); FontStyles getFontStyles(const QFont& font);

View File

@ -24,7 +24,7 @@
#include <QPaintEvent> #include <QPaintEvent>
#include <QPainter> #include <QPainter>
#include <QTimerEvent> #include <QTimerEvent>
#include "highlighter/base.h" #include "highlighter/syntaxer.h"
#include "Constants.h" #include "Constants.h"
#include "TextPainter.h" #include "TextPainter.h"
#include <QClipboard> #include <QClipboard>
@ -1621,7 +1621,7 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
l = startLine; l = startLine;
} else if (mHighlighter->language() == ProgrammingLanguage::Cpp } else if (mHighlighter->language() == ProgrammingLanguage::Cpp
&& trimmedLineText.startsWith('#') && trimmedLineText.startsWith('#')
&& attr == ((CppHighlighter *)mHighlighter.get())->preprocessorAttribute()) { && attr == ((CppSyntaxer *)mHighlighter.get())->preprocessorAttribute()) {
indentAdded = true; indentAdded = true;
indentSpaces=0; indentSpaces=0;
l=0; l=0;
@ -4772,14 +4772,14 @@ void SynEdit::setLineText(const QString s)
mDocument->putString(mCaretY-1,s); mDocument->putString(mCaretY-1,s);
} }
PHighlighter SynEdit::highlighter() const PSyntaxer SynEdit::highlighter() const
{ {
return mHighlighter; return mHighlighter;
} }
void SynEdit::setHighlighter(const PHighlighter &highlighter) void SynEdit::setHighlighter(const PSyntaxer &highlighter)
{ {
PHighlighter oldHighlighter= mHighlighter; PSyntaxer oldHighlighter= mHighlighter;
mHighlighter = highlighter; mHighlighter = highlighter;
if (oldHighlighter && mHighlighter && if (oldHighlighter && mHighlighter &&
oldHighlighter->language() == highlighter->language()) { oldHighlighter->language() == highlighter->language()) {

View File

@ -341,8 +341,8 @@ public:
bool modified() const; bool modified() const;
void setModified(bool Value); void setModified(bool Value);
PHighlighter highlighter() const; PSyntaxer highlighter() const;
void setHighlighter(const PHighlighter &highlighter); void setHighlighter(const PSyntaxer &highlighter);
bool useCodeFolding() const; bool useCodeFolding() const;
void setUseCodeFolding(bool value); void setUseCodeFolding(bool value);
@ -667,7 +667,7 @@ private:
ScrollStyle mScrollBars; ScrollStyle mScrollBars;
int mTextHeight; int mTextHeight;
int mTopLine; int mTopLine;
PHighlighter mHighlighter; PSyntaxer mHighlighter;
QColor mSelectedForeground; QColor mSelectedForeground;
QColor mSelectedBackground; QColor mSelectedBackground;
QColor mForegroundColor; QColor mForegroundColor;

View File

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

View File

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

View File

@ -166,12 +166,12 @@ void SynExporter::setFont(const QFont &font)
mFont = font; mFont = font;
} }
PHighlighter SynExporter::highlighter() const PSyntaxer SynExporter::highlighter() const
{ {
return mHighlighter; return mHighlighter;
} }
void SynExporter::setHighlighter(PHighlighter Value) void SynExporter::setHighlighter(PSyntaxer Value)
{ {
if (mHighlighter != Value) { if (mHighlighter != Value) {
mHighlighter = Value; mHighlighter = Value;

View File

@ -21,7 +21,7 @@
#include "../SynEdit.h" #include "../SynEdit.h"
namespace QSynedit { namespace QSynedit {
using FormatTokenHandler = std::function<void(PHighlighter syntaxHighlighter, int Line, int column, const QString& token, using FormatTokenHandler = std::function<void(PSyntaxer syntaxHighlighter, int line, int column, const QString& token,
PTokenAttribute& attr)>; PTokenAttribute& attr)>;
class SynExporter class SynExporter
{ {
@ -69,8 +69,8 @@ public:
QFont font() const; QFont font() const;
void setFont(const QFont &font); void setFont(const QFont &font);
PHighlighter highlighter() const; PSyntaxer highlighter() const;
void setHighlighter(PHighlighter Value); void setHighlighter(PSyntaxer Value);
QString title() const; QString title() const;
void setTitle(const QString &Value); void setTitle(const QString &Value);
@ -112,7 +112,7 @@ protected:
QString mDefaultFilter; QString mDefaultFilter;
bool mExportAsText; bool mExportAsText;
QFont mFont; QFont mFont;
PHighlighter mHighlighter; PSyntaxer mHighlighter;
QColor mLastBG; QColor mLastBG;
QColor mLastFG; QColor mLastFG;
FontStyles mLastStyle; FontStyles mLastStyle;

View File

@ -67,7 +67,7 @@ QString SynHTMLExporter::AttriToCSS(PTokenAttribute Attri, const QString &Unique
return Result; return Result;
} }
bool SynHTMLExporter::AttriToCSSCallback(PHighlighter , PTokenAttribute Attri, const QString& UniqueAttriName, QList<void *> params) bool SynHTMLExporter::AttriToCSSCallback(PSyntaxer , PTokenAttribute Attri, const QString& UniqueAttriName, QList<void *> params)
{ {
QString& styles = *static_cast<QString *>(params[0]); QString& styles = *static_cast<QString *>(params[0]);
styles.append(AttriToCSS(Attri,UniqueAttriName) + lineBreak()); styles.append(AttriToCSS(Attri,UniqueAttriName) + lineBreak());
@ -79,7 +79,7 @@ QString SynHTMLExporter::ColorToHTML(const QColor &AColor)
return AColor.name(); return AColor.name();
} }
QString SynHTMLExporter::GetStyleName(PHighlighter Highlighter, PTokenAttribute Attri) QString SynHTMLExporter::GetStyleName(PSyntaxer Highlighter, PTokenAttribute Attri)
{ {
QString result; QString result;
enumTokenAttributes(Highlighter,false, enumTokenAttributes(Highlighter,false,
@ -104,7 +104,7 @@ QString SynHTMLExporter::MakeValidName(const QString &Name)
return Result; return Result;
} }
bool SynHTMLExporter::StyleNameCallback(PHighlighter /*Highlighter*/, PTokenAttribute Attri, const QString& UniqueAttriName, QList<void *> params) bool SynHTMLExporter::StyleNameCallback(PSyntaxer /*Highlighter*/, PTokenAttribute Attri, const QString& UniqueAttriName, QList<void *> params)
{ {
PTokenAttribute& AttriToFind = *static_cast<PTokenAttribute*>(params[0]); PTokenAttribute& AttriToFind = *static_cast<PTokenAttribute*>(params[0]);
QString& StyleName = *static_cast<QString *>(params[1]); QString& StyleName = *static_cast<QString *>(params[1]);

View File

@ -32,13 +32,13 @@ protected:
private: private:
PTokenAttribute mLastAttri; PTokenAttribute mLastAttri;
QString AttriToCSS(PTokenAttribute Attri, const QString& UniqueAttriName); QString AttriToCSS(PTokenAttribute Attri, const QString& UniqueAttriName);
bool AttriToCSSCallback(PHighlighter Highlighter, PTokenAttribute Attri, bool AttriToCSSCallback(PSyntaxer Highlighter, PTokenAttribute Attri,
const QString& UniqueAttriName, QList<void *> params); const QString& UniqueAttriName, QList<void *> params);
QString ColorToHTML(const QColor &AColor); QString ColorToHTML(const QColor &AColor);
QString GetStyleName(PHighlighter Highlighter, QString GetStyleName(PSyntaxer Highlighter,
PTokenAttribute Attri); PTokenAttribute Attri);
QString MakeValidName(const QString &Name); QString MakeValidName(const QString &Name);
bool StyleNameCallback(PHighlighter Highlighter, PTokenAttribute Attri, bool StyleNameCallback(PSyntaxer Highlighter, PTokenAttribute Attri,
const QString& UniqueAttriName, QList<void *> params); const QString& UniqueAttriName, QList<void *> params);
// SynExporter interface // SynExporter interface

View File

@ -20,7 +20,7 @@
namespace QSynedit { namespace QSynedit {
const QSet<QString> ASMHighlighter::Registers { const QSet<QString> ASMSyntaxer::Registers {
"ah","al","ax","eax", "ah","al","ax","eax",
"bh","bl","bx","ebx", "bh","bl","bx","ebx",
"ch","cl","cx","ecx", "ch","cl","cx","ecx",
@ -37,7 +37,7 @@ const QSet<QString> ASMHighlighter::Registers {
"r15h","r15l","r15w","r15d" "r15h","r15l","r15w","r15d"
}; };
const QSet<QString> ASMHighlighter::Keywords { const QSet<QString> ASMSyntaxer::Keywords {
"movb","movw","movl","movq", "movb","movw","movl","movq",
"leab","leaw","leal","leaq", "leab","leaw","leal","leaq",
"incb","incw","incl","incq", "incb","incw","incl","incq",
@ -96,7 +96,7 @@ const QSet<QString> ASMHighlighter::Keywords {
ASMHighlighter::ASMHighlighter() ASMSyntaxer::ASMSyntaxer()
{ {
mNumberAttribute = std::make_shared<TokenAttribute>(SYNS_AttrNumber, TokenType::Number); mNumberAttribute = std::make_shared<TokenAttribute>(SYNS_AttrNumber, TokenType::Number);
addAttribute(mNumberAttribute); addAttribute(mNumberAttribute);
@ -108,17 +108,17 @@ ASMHighlighter::ASMHighlighter()
addAttribute(mRegisterAttribute); addAttribute(mRegisterAttribute);
} }
const PTokenAttribute &ASMHighlighter::numberAttribute() const const PTokenAttribute &ASMSyntaxer::numberAttribute() const
{ {
return mNumberAttribute; return mNumberAttribute;
} }
const PTokenAttribute &ASMHighlighter::registerAttribute() const const PTokenAttribute &ASMSyntaxer::registerAttribute() const
{ {
return mRegisterAttribute; return mRegisterAttribute;
} }
void ASMHighlighter::CommentProc() void ASMSyntaxer::CommentProc()
{ {
mTokenID = TokenId::Comment; mTokenID = TokenId::Comment;
do { do {
@ -126,7 +126,7 @@ void ASMHighlighter::CommentProc()
} while (! (mLine[mRun]==0 || mLine[mRun] == '\r' || mLine[mRun]=='\n')); } while (! (mLine[mRun]==0 || mLine[mRun] == '\r' || mLine[mRun]=='\n'));
} }
void ASMHighlighter::CRProc() void ASMSyntaxer::CRProc()
{ {
mTokenID = TokenId::Space; mTokenID = TokenId::Space;
mRun++; mRun++;
@ -134,7 +134,7 @@ void ASMHighlighter::CRProc()
mRun++; mRun++;
} }
void ASMHighlighter::GreaterProc() void ASMSyntaxer::GreaterProc()
{ {
mRun++; mRun++;
mTokenID = TokenId::Symbol; mTokenID = TokenId::Symbol;
@ -142,7 +142,7 @@ void ASMHighlighter::GreaterProc()
mRun++; mRun++;
} }
void ASMHighlighter::IdentProc(IdentPrefix prefix) void ASMSyntaxer::IdentProc(IdentPrefix prefix)
{ {
int start = mRun; int start = mRun;
while (isIdentChar(mLine[mRun])) { while (isIdentChar(mLine[mRun])) {
@ -171,13 +171,13 @@ void ASMHighlighter::IdentProc(IdentPrefix prefix)
} }
} }
void ASMHighlighter::LFProc() void ASMSyntaxer::LFProc()
{ {
mTokenID = TokenId::Space; mTokenID = TokenId::Space;
mRun++; mRun++;
} }
void ASMHighlighter::LowerProc() void ASMSyntaxer::LowerProc()
{ {
mRun++; mRun++;
mTokenID = TokenId::Symbol; mTokenID = TokenId::Symbol;
@ -185,12 +185,12 @@ void ASMHighlighter::LowerProc()
mRun++; mRun++;
} }
void ASMHighlighter::NullProc() void ASMSyntaxer::NullProc()
{ {
mTokenID = TokenId::Null; mTokenID = TokenId::Null;
} }
void ASMHighlighter::NumberProc() void ASMSyntaxer::NumberProc()
{ {
mRun++; mRun++;
mTokenID = TokenId::Number; mTokenID = TokenId::Number;
@ -204,7 +204,7 @@ void ASMHighlighter::NumberProc()
} }
} }
void ASMHighlighter::SingleQuoteStringProc() void ASMSyntaxer::SingleQuoteStringProc()
{ {
mTokenID = TokenId::String; mTokenID = TokenId::String;
if ((mRun+2 < mLineString.size()) && (mLine[mRun + 1] == '\'') && (mLine[mRun + 2] == '\'')) if ((mRun+2 < mLineString.size()) && (mLine[mRun + 1] == '\'') && (mLine[mRun + 2] == '\''))
@ -218,7 +218,7 @@ void ASMHighlighter::SingleQuoteStringProc()
mRun++; mRun++;
} }
void ASMHighlighter::SlashProc() void ASMSyntaxer::SlashProc()
{ {
mRun++; mRun++;
if (mLine[mRun] == '/') { if (mLine[mRun] == '/') {
@ -232,7 +232,7 @@ void ASMHighlighter::SlashProc()
mTokenID = TokenId::Symbol; mTokenID = TokenId::Symbol;
} }
void ASMHighlighter::SpaceProc() void ASMSyntaxer::SpaceProc()
{ {
mTokenID = TokenId::Space; mTokenID = TokenId::Space;
while (true) { while (true) {
@ -244,7 +244,7 @@ void ASMHighlighter::SpaceProc()
} }
} }
void ASMHighlighter::StringProc() void ASMSyntaxer::StringProc()
{ {
mTokenID = TokenId::String; mTokenID = TokenId::String;
if ((mRun+2 < mLineString.size()) && (mLine[mRun + 1] == '\"') && (mLine[mRun + 2] == '\"')) if ((mRun+2 < mLineString.size()) && (mLine[mRun + 1] == '\"') && (mLine[mRun + 2] == '\"'))
@ -262,19 +262,19 @@ void ASMHighlighter::StringProc()
mRun++; mRun++;
} }
void ASMHighlighter::SymbolProc() void ASMSyntaxer::SymbolProc()
{ {
mRun++; mRun++;
mTokenID = TokenId::Symbol; mTokenID = TokenId::Symbol;
} }
void ASMHighlighter::UnknownProc() void ASMSyntaxer::UnknownProc()
{ {
mRun++; mRun++;
mTokenID = TokenId::Unknown; mTokenID = TokenId::Unknown;
} }
bool ASMHighlighter::isIdentStartChar(const QChar &ch) bool ASMSyntaxer::isIdentStartChar(const QChar &ch)
{ {
if (ch == '_') { if (ch == '_') {
return true; return true;
@ -288,27 +288,27 @@ bool ASMHighlighter::isIdentStartChar(const QChar &ch)
return false; return false;
} }
bool ASMHighlighter::eol() const bool ASMSyntaxer::eol() const
{ {
return mTokenID == TokenId::Null; return mTokenID == TokenId::Null;
} }
QString ASMHighlighter::languageName() QString ASMSyntaxer::languageName()
{ {
return "asm"; return "asm";
} }
ProgrammingLanguage ASMHighlighter::language() ProgrammingLanguage ASMSyntaxer::language()
{ {
return ProgrammingLanguage::Asssembly; return ProgrammingLanguage::Asssembly;
} }
QString ASMHighlighter::getToken() const QString ASMSyntaxer::getToken() const
{ {
return mLineString.mid(mTokenPos,mRun-mTokenPos); return mLineString.mid(mTokenPos,mRun-mTokenPos);
} }
const PTokenAttribute &ASMHighlighter::getTokenAttribute() const const PTokenAttribute &ASMSyntaxer::getTokenAttribute() const
{ {
switch(mTokenID) { switch(mTokenID) {
case TokenId::Comment: case TokenId::Comment:
@ -338,12 +338,12 @@ const PTokenAttribute &ASMHighlighter::getTokenAttribute() const
} }
} }
int ASMHighlighter::getTokenPos() int ASMSyntaxer::getTokenPos()
{ {
return mTokenPos; return mTokenPos;
} }
void ASMHighlighter::next() void ASMSyntaxer::next()
{ {
mTokenPos = mRun; mTokenPos = mRun;
switch(mLine[mRun].unicode()) { switch(mLine[mRun].unicode()) {
@ -415,7 +415,7 @@ void ASMHighlighter::next()
} }
} }
void ASMHighlighter::setLine(const QString &newLine, int lineNumber) void ASMSyntaxer::setLine(const QString &newLine, int lineNumber)
{ {
mLineString = newLine; mLineString = newLine;
mLine = mLineString.data(); mLine = mLineString.data();
@ -424,47 +424,47 @@ void ASMHighlighter::setLine(const QString &newLine, int lineNumber)
next(); next();
} }
bool ASMHighlighter::getTokenFinished() const bool ASMSyntaxer::getTokenFinished() const
{ {
return true; return true;
} }
bool ASMHighlighter::isLastLineCommentNotFinished(int /*state*/) const bool ASMSyntaxer::isLastLineCommentNotFinished(int /*state*/) const
{ {
return true; return true;
} }
bool ASMHighlighter::isLastLineStringNotFinished(int /*state*/) const bool ASMSyntaxer::isLastLineStringNotFinished(int /*state*/) const
{ {
return true; return true;
} }
SyntaxerState ASMHighlighter::getState() const SyntaxerState ASMSyntaxer::getState() const
{ {
return SyntaxerState(); return SyntaxerState();
} }
void ASMHighlighter::setState(const SyntaxerState&) void ASMSyntaxer::setState(const SyntaxerState&)
{ {
} }
void ASMHighlighter::resetState() void ASMSyntaxer::resetState()
{ {
} }
QSet<QString> ASMHighlighter::keywords() const QSet<QString> ASMSyntaxer::keywords() const
{ {
return Keywords; return Keywords;
} }
const PTokenAttribute &ASMHighlighter::directiveAttribute() const const PTokenAttribute &ASMSyntaxer::directiveAttribute() const
{ {
return mDirectiveAttribute; return mDirectiveAttribute;
} }
const PTokenAttribute &ASMHighlighter::labelAttribute() const const PTokenAttribute &ASMSyntaxer::labelAttribute() const
{ {
return mLabelAttribute; return mLabelAttribute;
} }

View File

@ -14,14 +14,14 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef SYNEDITASMHIGHLIGHTER_H #ifndef QSYNEDIT_ASM_SYNTAXER_H
#define SYNEDITASMHIGHLIGHTER_H #define QSYNEDIT_ASM_SYNTAXER_H
#include "base.h" #include "syntaxer.h"
namespace QSynedit { namespace QSynedit {
class ASMHighlighter : public Highlighter class ASMSyntaxer : public Syntaxer
{ {
enum class TokenId { enum class TokenId {
Comment, Comment,
@ -44,7 +44,7 @@ class ASMHighlighter : public Highlighter
}; };
public: public:
explicit ASMHighlighter(); explicit ASMSyntaxer();
const PTokenAttribute &numberAttribute() const; const PTokenAttribute &numberAttribute() const;
const PTokenAttribute &directiveAttribute() const; const PTokenAttribute &directiveAttribute() const;
const PTokenAttribute &labelAttribute() const; const PTokenAttribute &labelAttribute() const;

View File

@ -49,12 +49,12 @@ void HighlighterSchema::setStartExpr(const QString &value)
StartExpr = value; StartExpr = value;
} }
PHighlighter HighlighterSchema::getHighlighter() const PSyntaxer HighlighterSchema::getHighlighter() const
{ {
return mHighlighter; return mHighlighter;
} }
void HighlighterSchema::setHighlighter(const PHighlighter &highlighter) void HighlighterSchema::setHighlighter(const PSyntaxer &highlighter)
{ {
mHighlighter = highlighter; mHighlighter = highlighter;
} }

View File

@ -16,7 +16,7 @@
*/ */
#ifndef SYNHIGHLIGHTCOMPOSITION_H #ifndef SYNHIGHLIGHTCOMPOSITION_H
#define SYNHIGHLIGHTCOMPOSITION_H #define SYNHIGHLIGHTCOMPOSITION_H
#include "base.h" #include "syntaxer.h"
#include <memory> #include <memory>
#include <QObject> #include <QObject>
@ -37,8 +37,8 @@ public:
QString getStartExpr() const; QString getStartExpr() const;
void setStartExpr(const QString &value); void setStartExpr(const QString &value);
PHighlighter getHighlighter() const; PSyntaxer getHighlighter() const;
void setHighlighter(const PHighlighter &highlighter); void setHighlighter(const PSyntaxer &highlighter);
PTokenAttribute getMarkerAttribute() const; PTokenAttribute getMarkerAttribute() const;
@ -51,7 +51,7 @@ public:
private: private:
QString mEndExpr; QString mEndExpr;
QString StartExpr; QString StartExpr;
PHighlighter mHighlighter; PSyntaxer mHighlighter;
PTokenAttribute mMarkerAttribute; PTokenAttribute mMarkerAttribute;
QString mSchemeName; QString mSchemeName;
int mCaseSensitive; int mCaseSensitive;

View File

@ -34,7 +34,7 @@ static const QSet<QString> CppStatementKeyWords {
const QSet<QString> CppHighlighter::Keywords { const QSet<QString> CppSyntaxer::Keywords {
"and", "and",
"and_eq", "and_eq",
"bitand", "bitand",
@ -141,7 +141,7 @@ const QSet<QString> CppHighlighter::Keywords {
"nullptr", "nullptr",
}; };
CppHighlighter::CppHighlighter(): Highlighter() CppSyntaxer::CppSyntaxer(): Syntaxer()
{ {
mAsmAttribute = std::make_shared<TokenAttribute>(SYNS_AttrAssembler, mAsmAttribute = std::make_shared<TokenAttribute>(SYNS_AttrAssembler,
TokenType::Embeded); TokenType::Embeded);
@ -190,77 +190,77 @@ CppHighlighter::CppHighlighter(): Highlighter()
resetState(); resetState();
} }
const PTokenAttribute &CppHighlighter::asmAttribute() const const PTokenAttribute &CppSyntaxer::asmAttribute() const
{ {
return mAsmAttribute; return mAsmAttribute;
} }
const PTokenAttribute &CppHighlighter::preprocessorAttribute() const const PTokenAttribute &CppSyntaxer::preprocessorAttribute() const
{ {
return mPreprocessorAttribute; return mPreprocessorAttribute;
} }
const PTokenAttribute &CppHighlighter::invalidAttribute() const const PTokenAttribute &CppSyntaxer::invalidAttribute() const
{ {
return mInvalidAttribute; return mInvalidAttribute;
} }
const PTokenAttribute &CppHighlighter::numberAttribute() const const PTokenAttribute &CppSyntaxer::numberAttribute() const
{ {
return mNumberAttribute; return mNumberAttribute;
} }
const PTokenAttribute &CppHighlighter::floatAttribute() const const PTokenAttribute &CppSyntaxer::floatAttribute() const
{ {
return mFloatAttribute; return mFloatAttribute;
} }
const PTokenAttribute &CppHighlighter::hexAttribute() const const PTokenAttribute &CppSyntaxer::hexAttribute() const
{ {
return mHexAttribute; return mHexAttribute;
} }
const PTokenAttribute &CppHighlighter::octAttribute() const const PTokenAttribute &CppSyntaxer::octAttribute() const
{ {
return mOctAttribute; return mOctAttribute;
} }
const PTokenAttribute &CppHighlighter::stringEscapeSequenceAttribute() const const PTokenAttribute &CppSyntaxer::stringEscapeSequenceAttribute() const
{ {
return mStringEscapeSequenceAttribute; return mStringEscapeSequenceAttribute;
} }
const PTokenAttribute &CppHighlighter::charAttribute() const const PTokenAttribute &CppSyntaxer::charAttribute() const
{ {
return mCharAttribute; return mCharAttribute;
} }
const PTokenAttribute &CppHighlighter::variableAttribute() const const PTokenAttribute &CppSyntaxer::variableAttribute() const
{ {
return mVariableAttribute; return mVariableAttribute;
} }
const PTokenAttribute &CppHighlighter::functionAttribute() const const PTokenAttribute &CppSyntaxer::functionAttribute() const
{ {
return mFunctionAttribute; return mFunctionAttribute;
} }
const PTokenAttribute &CppHighlighter::classAttribute() const const PTokenAttribute &CppSyntaxer::classAttribute() const
{ {
return mClassAttribute; return mClassAttribute;
} }
const PTokenAttribute &CppHighlighter::globalVarAttribute() const const PTokenAttribute &CppSyntaxer::globalVarAttribute() const
{ {
return mGlobalVarAttribute; return mGlobalVarAttribute;
} }
const PTokenAttribute &CppHighlighter::localVarAttribute() const const PTokenAttribute &CppSyntaxer::localVarAttribute() const
{ {
return mLocalVarAttribute; return mLocalVarAttribute;
} }
CppHighlighter::TokenId CppHighlighter::getTokenId() CppSyntaxer::TokenId CppSyntaxer::getTokenId()
{ {
if ((mRange.state == RangeState::rsAsm || mRange.state == RangeState::rsAsmBlock) if ((mRange.state == RangeState::rsAsm || mRange.state == RangeState::rsAsmBlock)
&& !mAsmStart && !(mTokenId == TokenId::Comment || mTokenId == TokenId::Space && !mAsmStart && !(mTokenId == TokenId::Comment || mTokenId == TokenId::Space
@ -271,7 +271,7 @@ CppHighlighter::TokenId CppHighlighter::getTokenId()
} }
} }
void CppHighlighter::andSymbolProc() void CppSyntaxer::andSymbolProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize) { if (mRun+1<mLineSize) {
@ -287,7 +287,7 @@ void CppHighlighter::andSymbolProc()
mRun+=1; mRun+=1;
} }
void CppHighlighter::ansiCppProc() void CppSyntaxer::ansiCppProc()
{ {
mTokenId = TokenId::Comment; mTokenId = TokenId::Comment;
if (mRun>=mLineSize) { if (mRun>=mLineSize) {
@ -306,7 +306,7 @@ void CppHighlighter::ansiCppProc()
} }
} }
void CppHighlighter::ansiCProc() void CppSyntaxer::ansiCProc()
{ {
bool finishProcess = false; bool finishProcess = false;
mTokenId = TokenId::Comment; mTokenId = TokenId::Comment;
@ -341,7 +341,7 @@ void CppHighlighter::ansiCProc()
} }
} }
void CppHighlighter::asciiCharProc() void CppSyntaxer::asciiCharProc()
{ {
mTokenId = TokenId::Char; mTokenId = TokenId::Char;
do { do {
@ -357,13 +357,13 @@ void CppHighlighter::asciiCharProc()
mRange.state = RangeState::rsUnknown; mRange.state = RangeState::rsUnknown;
} }
void CppHighlighter::atSymbolProc() void CppSyntaxer::atSymbolProc()
{ {
mTokenId = TokenId::Unknown; mTokenId = TokenId::Unknown;
mRun+=1; mRun+=1;
} }
void CppHighlighter::braceCloseProc() void CppSyntaxer::braceCloseProc()
{ {
mRun += 1; mRun += 1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
@ -385,7 +385,7 @@ void CppHighlighter::braceCloseProc()
popIndents(IndentForBrace); popIndents(IndentForBrace);
} }
void CppHighlighter::braceOpenProc() void CppSyntaxer::braceOpenProc()
{ {
mRun += 1; mRun += 1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
@ -412,7 +412,7 @@ void CppHighlighter::braceOpenProc()
} }
} }
void CppHighlighter::colonProc() void CppSyntaxer::colonProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize && mLine[mRun+1]==':') { if (mRun+1<mLineSize && mLine[mRun+1]==':') {
@ -422,13 +422,13 @@ void CppHighlighter::colonProc()
} }
} }
void CppHighlighter::commaProc() void CppSyntaxer::commaProc()
{ {
mRun+=1; mRun+=1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
} }
void CppHighlighter::directiveProc() void CppSyntaxer::directiveProc()
{ {
QString preContents = mLine.left(mRun).trimmed(); QString preContents = mLine.left(mRun).trimmed();
if (!preContents.isEmpty()) { // '#' is not first non-space char on the line, treat it as an invalid char if (!preContents.isEmpty()) { // '#' is not first non-space char on the line, treat it as an invalid char
@ -457,7 +457,7 @@ void CppHighlighter::directiveProc()
mRange.state = RangeState::rsUnknown; mRange.state = RangeState::rsUnknown;
} }
void CppHighlighter::defineIdentProc() void CppSyntaxer::defineIdentProc()
{ {
mTokenId = TokenId::Identifier; mTokenId = TokenId::Identifier;
while(mRun < mLineSize && isIdentChar(mLine[mRun])) while(mRun < mLineSize && isIdentChar(mLine[mRun]))
@ -465,7 +465,7 @@ void CppHighlighter::defineIdentProc()
mRange.state = RangeState::rsDefineRemaining; mRange.state = RangeState::rsDefineRemaining;
} }
void CppHighlighter::defineRemainingProc() void CppSyntaxer::defineRemainingProc()
{ {
mTokenId = TokenId::Directive; mTokenId = TokenId::Directive;
do { do {
@ -495,7 +495,7 @@ void CppHighlighter::defineRemainingProc()
mRange.state=RangeState::rsUnknown; mRange.state=RangeState::rsUnknown;
} }
void CppHighlighter::directiveEndProc() void CppSyntaxer::directiveEndProc()
{ {
mTokenId = TokenId::Directive; mTokenId = TokenId::Directive;
if (mRun >= mLineSize) { if (mRun >= mLineSize) {
@ -529,7 +529,7 @@ void CppHighlighter::directiveEndProc()
} while (mRun < mLineSize); } while (mRun < mLineSize);
} }
void CppHighlighter::equalProc() void CppSyntaxer::equalProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize && mLine[mRun+1] == '=') { if (mRun+1<mLineSize && mLine[mRun+1] == '=') {
@ -539,7 +539,7 @@ void CppHighlighter::equalProc()
} }
} }
void CppHighlighter::greaterProc() void CppSyntaxer::greaterProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize) { if (mRun+1<mLineSize) {
@ -559,7 +559,7 @@ void CppHighlighter::greaterProc()
mRun+=1; mRun+=1;
} }
void CppHighlighter::identProc() void CppSyntaxer::identProc()
{ {
int wordEnd = mRun; int wordEnd = mRun;
while (wordEnd<mLineSize && isIdentChar(mLine[wordEnd])) { while (wordEnd<mLineSize && isIdentChar(mLine[wordEnd])) {
@ -577,7 +577,7 @@ void CppHighlighter::identProc()
} }
} }
void CppHighlighter::lowerProc() void CppSyntaxer::lowerProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize) { if (mRun+1<mLineSize) {
@ -597,7 +597,7 @@ void CppHighlighter::lowerProc()
mRun+=1; mRun+=1;
} }
void CppHighlighter::minusProc() void CppSyntaxer::minusProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize) { if (mRun+1<mLineSize) {
@ -620,7 +620,7 @@ void CppHighlighter::minusProc()
mRun += 1; mRun += 1;
} }
void CppHighlighter::modSymbolProc() void CppSyntaxer::modSymbolProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize && mLine[mRun+1]=='=') { if (mRun+1<mLineSize && mLine[mRun+1]=='=') {
@ -630,7 +630,7 @@ void CppHighlighter::modSymbolProc()
} }
} }
void CppHighlighter::notSymbolProc() void CppSyntaxer::notSymbolProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize && mLine[mRun+1]=='=') { if (mRun+1<mLineSize && mLine[mRun+1]=='=') {
@ -640,7 +640,7 @@ void CppHighlighter::notSymbolProc()
} }
} }
void CppHighlighter::nullProc() void CppSyntaxer::nullProc()
{ {
if ( if (
(mRange.state == RangeState::rsCppComment (mRange.state == RangeState::rsCppComment
@ -656,7 +656,7 @@ void CppHighlighter::nullProc()
mTokenId = TokenId::Null; mTokenId = TokenId::Null;
} }
void CppHighlighter::numberProc() void CppSyntaxer::numberProc()
{ {
int idx1; // token[1] int idx1; // token[1]
idx1 = mRun; idx1 = mRun;
@ -827,7 +827,7 @@ void CppHighlighter::numberProc()
} }
} }
void CppHighlighter::orSymbolProc() void CppSyntaxer::orSymbolProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize) { if (mRun+1<mLineSize) {
@ -843,7 +843,7 @@ void CppHighlighter::orSymbolProc()
mRun+=1; mRun+=1;
} }
void CppHighlighter::plusProc() void CppSyntaxer::plusProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize) { if (mRun+1<mLineSize) {
@ -859,7 +859,7 @@ void CppHighlighter::plusProc()
mRun+=1; mRun+=1;
} }
void CppHighlighter::pointProc() void CppSyntaxer::pointProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize && mLine[mRun+1] == '*' ) { if (mRun+1<mLineSize && mLine[mRun+1] == '*' ) {
@ -873,13 +873,13 @@ void CppHighlighter::pointProc()
} }
} }
void CppHighlighter::questionProc() void CppSyntaxer::questionProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
mRun+=1; mRun+=1;
} }
void CppHighlighter::rawStringProc() void CppSyntaxer::rawStringProc()
{ {
bool noEscaping = false; bool noEscaping = false;
if (mRange.state == RangeState::rsRawStringNotEscaping) if (mRange.state == RangeState::rsRawStringNotEscaping)
@ -905,7 +905,7 @@ void CppHighlighter::rawStringProc()
mRange.state = RangeState::rsUnknown; mRange.state = RangeState::rsUnknown;
} }
void CppHighlighter::roundCloseProc() void CppSyntaxer::roundCloseProc()
{ {
mRun += 1; mRun += 1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
@ -915,7 +915,7 @@ void CppHighlighter::roundCloseProc()
popIndents(IndentForParenthesis); popIndents(IndentForParenthesis);
} }
void CppHighlighter::roundOpenProc() void CppSyntaxer::roundOpenProc()
{ {
mRun += 1; mRun += 1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
@ -923,7 +923,7 @@ void CppHighlighter::roundOpenProc()
pushIndents(IndentForParenthesis); pushIndents(IndentForParenthesis);
} }
void CppHighlighter::semiColonProc() void CppSyntaxer::semiColonProc()
{ {
mRun += 1; mRun += 1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
@ -934,7 +934,7 @@ void CppHighlighter::semiColonProc()
} }
} }
void CppHighlighter::slashProc() void CppSyntaxer::slashProc()
{ {
if (mRun+1<mLineSize) { if (mRun+1<mLineSize) {
switch(mLine[mRun+1].unicode()) { switch(mLine[mRun+1].unicode()) {
@ -968,7 +968,7 @@ void CppHighlighter::slashProc()
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
} }
void CppHighlighter::backSlashProc() void CppSyntaxer::backSlashProc()
{ {
if (mRun+1==mLineSize-1) { if (mRun+1==mLineSize-1) {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
@ -978,7 +978,7 @@ void CppHighlighter::backSlashProc()
mRun+=1; mRun+=1;
} }
void CppHighlighter::spaceProc() void CppSyntaxer::spaceProc()
{ {
mRun += 1; mRun += 1;
mTokenId = TokenId::Space; mTokenId = TokenId::Space;
@ -987,7 +987,7 @@ void CppHighlighter::spaceProc()
mRange.state = RangeState::rsUnknown; mRange.state = RangeState::rsUnknown;
} }
void CppHighlighter::squareCloseProc() void CppSyntaxer::squareCloseProc()
{ {
mRun+=1; mRun+=1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
@ -997,7 +997,7 @@ void CppHighlighter::squareCloseProc()
popIndents(IndentForBracket); popIndents(IndentForBracket);
} }
void CppHighlighter::squareOpenProc() void CppSyntaxer::squareOpenProc()
{ {
mRun+=1; mRun+=1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
@ -1005,7 +1005,7 @@ void CppHighlighter::squareOpenProc()
pushIndents(IndentForBracket); pushIndents(IndentForBracket);
} }
void CppHighlighter::starProc() void CppSyntaxer::starProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize && mLine[mRun+1] == '=') { if (mRun+1<mLineSize && mLine[mRun+1] == '=') {
@ -1015,7 +1015,7 @@ void CppHighlighter::starProc()
} }
} }
void CppHighlighter::stringEndProc() void CppSyntaxer::stringEndProc()
{ {
mTokenId = TokenId::String; mTokenId = TokenId::String;
if (mRun>=mLineSize) { if (mRun>=mLineSize) {
@ -1070,7 +1070,7 @@ void CppHighlighter::stringEndProc()
} }
} }
void CppHighlighter::stringEscapeSeqProc() void CppSyntaxer::stringEscapeSeqProc()
{ {
mTokenId = TokenId::StringEscapeSeq; mTokenId = TokenId::StringEscapeSeq;
mRun+=1; mRun+=1;
@ -1162,7 +1162,7 @@ void CppHighlighter::stringEscapeSeqProc()
mRange.state = RangeState::rsString; mRange.state = RangeState::rsString;
} }
void CppHighlighter::stringProc() void CppSyntaxer::stringProc()
{ {
if (mRun >= mLineSize) { if (mRun >= mLineSize) {
mRange.state = RangeState::rsUnknown; mRange.state = RangeState::rsUnknown;
@ -1217,7 +1217,7 @@ void CppHighlighter::stringProc()
mRange.state = RangeState::rsUnknown; mRange.state = RangeState::rsUnknown;
} }
void CppHighlighter::stringStartProc() void CppSyntaxer::stringStartProc()
{ {
mTokenId = TokenId::String; mTokenId = TokenId::String;
mRun += 1; mRun += 1;
@ -1228,19 +1228,19 @@ void CppHighlighter::stringStartProc()
stringProc(); stringProc();
} }
void CppHighlighter::tildeProc() void CppSyntaxer::tildeProc()
{ {
mRun+=1; mRun+=1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
} }
void CppHighlighter::unknownProc() void CppSyntaxer::unknownProc()
{ {
mRun+=1; mRun+=1;
mTokenId = TokenId::Unknown; mTokenId = TokenId::Unknown;
} }
void CppHighlighter::xorSymbolProc() void CppSyntaxer::xorSymbolProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mRun+1<mLineSize && mLine[mRun+1]=='=') { if (mRun+1<mLineSize && mLine[mRun+1]=='=') {
@ -1250,7 +1250,7 @@ void CppHighlighter::xorSymbolProc()
} }
} }
void CppHighlighter::processChar() void CppSyntaxer::processChar()
{ {
if (mRun>=mLineSize) { if (mRun>=mLineSize) {
nullProc(); nullProc();
@ -1371,7 +1371,7 @@ void CppHighlighter::processChar()
} }
} }
void CppHighlighter::popIndents(int indentType) void CppSyntaxer::popIndents(int indentType)
{ {
while (!mRange.indents.isEmpty() && mRange.indents.back()!=indentType) { while (!mRange.indents.isEmpty() && mRange.indents.back()!=indentType) {
mRange.indents.pop_back(); mRange.indents.pop_back();
@ -1385,7 +1385,7 @@ void CppHighlighter::popIndents(int indentType)
} }
} }
void CppHighlighter::pushIndents(int indentType) void CppSyntaxer::pushIndents(int indentType)
{ {
int idx = mRange.indents.length(); int idx = mRange.indents.length();
if (idx<mRange.firstIndentThisLine) if (idx<mRange.firstIndentThisLine)
@ -1393,22 +1393,22 @@ void CppHighlighter::pushIndents(int indentType)
mRange.indents.push_back(indentType); mRange.indents.push_back(indentType);
} }
const QSet<QString> &CppHighlighter::customTypeKeywords() const const QSet<QString> &CppSyntaxer::customTypeKeywords() const
{ {
return mCustomTypeKeywords; return mCustomTypeKeywords;
} }
void CppHighlighter::setCustomTypeKeywords(const QSet<QString> &newCustomTypeKeywords) void CppSyntaxer::setCustomTypeKeywords(const QSet<QString> &newCustomTypeKeywords)
{ {
mCustomTypeKeywords = newCustomTypeKeywords; mCustomTypeKeywords = newCustomTypeKeywords;
} }
bool CppHighlighter::supportBraceLevel() bool CppSyntaxer::supportBraceLevel()
{ {
return true; return true;
} }
bool CppHighlighter::getTokenFinished() const bool CppSyntaxer::getTokenFinished() const
{ {
if (mTokenId == TokenId::Comment if (mTokenId == TokenId::Comment
|| mTokenId == TokenId::String || mTokenId == TokenId::String
@ -1418,7 +1418,7 @@ bool CppHighlighter::getTokenFinished() const
return true; return true;
} }
bool CppHighlighter::isLastLineCommentNotFinished(int state) const bool CppSyntaxer::isLastLineCommentNotFinished(int state) const
{ {
return (state == RangeState::rsAnsiC || return (state == RangeState::rsAnsiC ||
state == RangeState::rsAnsiCAsm || state == RangeState::rsAnsiCAsm ||
@ -1427,22 +1427,22 @@ bool CppHighlighter::isLastLineCommentNotFinished(int state) const
state == RangeState::rsCppComment); state == RangeState::rsCppComment);
} }
bool CppHighlighter::isLastLineStringNotFinished(int state) const bool CppSyntaxer::isLastLineStringNotFinished(int state) const
{ {
return state == RangeState::rsMultiLineString; return state == RangeState::rsMultiLineString;
} }
bool CppHighlighter::eol() const bool CppSyntaxer::eol() const
{ {
return mTokenId == TokenId::Null; return mTokenId == TokenId::Null;
} }
QString CppHighlighter::getToken() const QString CppSyntaxer::getToken() const
{ {
return mLine.mid(mTokenPos,mRun-mTokenPos); return mLine.mid(mTokenPos,mRun-mTokenPos);
} }
const PTokenAttribute &CppHighlighter::getTokenAttribute() const const PTokenAttribute &CppSyntaxer::getTokenAttribute() const
{ {
switch (mTokenId) { switch (mTokenId) {
case TokenId::Asm: case TokenId::Asm:
@ -1483,12 +1483,12 @@ const PTokenAttribute &CppHighlighter::getTokenAttribute() const
} }
} }
int CppHighlighter::getTokenPos() int CppSyntaxer::getTokenPos()
{ {
return mTokenPos; return mTokenPos;
} }
void CppHighlighter::next() void CppSyntaxer::next()
{ {
mAsmStart = false; mAsmStart = false;
mTokenPos = mRun; mTokenPos = mRun;
@ -1574,7 +1574,7 @@ void CppHighlighter::next()
//qDebug()<<"1-1-1"; //qDebug()<<"1-1-1";
} }
void CppHighlighter::setLine(const QString &newLine, int lineNumber) void CppSyntaxer::setLine(const QString &newLine, int lineNumber)
{ {
mLine = newLine; mLine = newLine;
mLineSize = mLine.size(); mLineSize = mLine.size();
@ -1588,12 +1588,12 @@ void CppHighlighter::setLine(const QString &newLine, int lineNumber)
next(); next();
} }
bool CppHighlighter::isKeyword(const QString &word) bool CppSyntaxer::isKeyword(const QString &word)
{ {
return Keywords.contains(word) || mCustomTypeKeywords.contains(word); return Keywords.contains(word) || mCustomTypeKeywords.contains(word);
} }
void CppHighlighter::setState(const SyntaxerState& rangeState) void CppSyntaxer::setState(const SyntaxerState& rangeState)
{ {
mRange = rangeState; mRange = rangeState;
// current line's left / right parenthesis count should be reset before parsing each line // current line's left / right parenthesis count should be reset before parsing each line
@ -1604,7 +1604,7 @@ void CppHighlighter::setState(const SyntaxerState& rangeState)
mRange.matchingIndents.clear(); mRange.matchingIndents.clear();
} }
void CppHighlighter::resetState() void CppSyntaxer::resetState()
{ {
mRange.state = RangeState::rsUnknown; mRange.state = RangeState::rsUnknown;
mRange.braceLevel = 0; mRange.braceLevel = 0;
@ -1620,34 +1620,34 @@ void CppHighlighter::resetState()
mAsmStart = false; mAsmStart = false;
} }
QString CppHighlighter::languageName() QString CppSyntaxer::languageName()
{ {
return "cpp"; return "cpp";
} }
ProgrammingLanguage CppHighlighter::language() ProgrammingLanguage CppSyntaxer::language()
{ {
return ProgrammingLanguage::Cpp; return ProgrammingLanguage::Cpp;
} }
SyntaxerState CppHighlighter::getState() const SyntaxerState CppSyntaxer::getState() const
{ {
return mRange; return mRange;
} }
bool CppHighlighter::isIdentChar(const QChar &ch) const bool CppSyntaxer::isIdentChar(const QChar &ch) const
{ {
return ch=='_' || ch.isDigit() || ch.isLetter(); return ch=='_' || ch.isDigit() || ch.isLetter();
} }
QSet<QString> CppHighlighter::keywords() const QSet<QString> CppSyntaxer::keywords() const
{ {
QSet<QString> set=Keywords; QSet<QString> set=Keywords;
set.unite(mCustomTypeKeywords); set.unite(mCustomTypeKeywords);
return set; return set;
} }
QString CppHighlighter::foldString() QString CppSyntaxer::foldString()
{ {
return "...}"; return "...}";
} }

View File

@ -16,12 +16,12 @@
*/ */
#ifndef SYNEDITCPPHIGHLIGHTER_H #ifndef SYNEDITCPPHIGHLIGHTER_H
#define SYNEDITCPPHIGHLIGHTER_H #define SYNEDITCPPHIGHLIGHTER_H
#include "base.h" #include "syntaxer.h"
#include <QSet> #include <QSet>
namespace QSynedit { namespace QSynedit {
class CppHighlighter: public Highlighter class CppSyntaxer: public Syntaxer
{ {
enum class TokenId { enum class TokenId {
Asm, Asm,
@ -54,7 +54,7 @@ class CppHighlighter: public Highlighter
}; };
public: public:
explicit CppHighlighter(); explicit CppSyntaxer();
const PTokenAttribute &asmAttribute() const; const PTokenAttribute &asmAttribute() const;

View File

@ -1,9 +1,9 @@
#ifndef CUSTOMHIGHLIGHTERV1_H #ifndef CUSTOMHIGHLIGHTERV1_H
#define CUSTOMHIGHLIGHTERV1_H #define CUSTOMHIGHLIGHTERV1_H
#include "base.h" #include "syntaxer.h"
namespace QSynedit { namespace QSynedit {
class CustomHighlighterV1:public Highlighter class CustomHighlighterV1:public Syntaxer
{ {
public: public:
enum RangeState { enum RangeState {

View File

@ -29,7 +29,7 @@ static const QSet<QString> GLSLStatementKeyWords {
"while" "while"
}; };
const QSet<QString> GLSLHighlighter::Keywords { const QSet<QString> GLSLSyntaxer::Keywords {
"const", "uniform", "buffer", "shared", "attribute", "varying", "const", "uniform", "buffer", "shared", "attribute", "varying",
"coherent", "volatile", "restrict", "readonly", "writeonly", "coherent", "volatile", "restrict", "readonly", "writeonly",
"atomic_uint", "atomic_uint",
@ -81,7 +81,7 @@ const QSet<QString> GLSLHighlighter::Keywords {
"struct" "struct"
}; };
GLSLHighlighter::GLSLHighlighter(): Highlighter() GLSLSyntaxer::GLSLSyntaxer(): Syntaxer()
{ {
mAsmAttribute = std::make_shared<TokenAttribute>(SYNS_AttrAssembler, mAsmAttribute = std::make_shared<TokenAttribute>(SYNS_AttrAssembler,
TokenType::Embeded); TokenType::Embeded);
@ -131,77 +131,77 @@ GLSLHighlighter::GLSLHighlighter(): Highlighter()
resetState(); resetState();
} }
const PTokenAttribute &GLSLHighlighter::asmAttribute() const const PTokenAttribute &GLSLSyntaxer::asmAttribute() const
{ {
return mAsmAttribute; return mAsmAttribute;
} }
const PTokenAttribute &GLSLHighlighter::preprocessorAttribute() const const PTokenAttribute &GLSLSyntaxer::preprocessorAttribute() const
{ {
return mPreprocessorAttribute; return mPreprocessorAttribute;
} }
const PTokenAttribute &GLSLHighlighter::invalidAttribute() const const PTokenAttribute &GLSLSyntaxer::invalidAttribute() const
{ {
return mInvalidAttribute; return mInvalidAttribute;
} }
const PTokenAttribute &GLSLHighlighter::numberAttribute() const const PTokenAttribute &GLSLSyntaxer::numberAttribute() const
{ {
return mNumberAttribute; return mNumberAttribute;
} }
const PTokenAttribute &GLSLHighlighter::floatAttribute() const const PTokenAttribute &GLSLSyntaxer::floatAttribute() const
{ {
return mFloatAttribute; return mFloatAttribute;
} }
const PTokenAttribute &GLSLHighlighter::hexAttribute() const const PTokenAttribute &GLSLSyntaxer::hexAttribute() const
{ {
return mHexAttribute; return mHexAttribute;
} }
const PTokenAttribute &GLSLHighlighter::octAttribute() const const PTokenAttribute &GLSLSyntaxer::octAttribute() const
{ {
return mOctAttribute; return mOctAttribute;
} }
const PTokenAttribute &GLSLHighlighter::stringEscapeSequenceAttribute() const const PTokenAttribute &GLSLSyntaxer::stringEscapeSequenceAttribute() const
{ {
return mStringEscapeSequenceAttribute; return mStringEscapeSequenceAttribute;
} }
const PTokenAttribute &GLSLHighlighter::charAttribute() const const PTokenAttribute &GLSLSyntaxer::charAttribute() const
{ {
return mCharAttribute; return mCharAttribute;
} }
const PTokenAttribute &GLSLHighlighter::variableAttribute() const const PTokenAttribute &GLSLSyntaxer::variableAttribute() const
{ {
return mVariableAttribute; return mVariableAttribute;
} }
const PTokenAttribute &GLSLHighlighter::functionAttribute() const const PTokenAttribute &GLSLSyntaxer::functionAttribute() const
{ {
return mFunctionAttribute; return mFunctionAttribute;
} }
const PTokenAttribute &GLSLHighlighter::classAttribute() const const PTokenAttribute &GLSLSyntaxer::classAttribute() const
{ {
return mClassAttribute; return mClassAttribute;
} }
const PTokenAttribute &GLSLHighlighter::globalVarAttribute() const const PTokenAttribute &GLSLSyntaxer::globalVarAttribute() const
{ {
return mGlobalVarAttribute; return mGlobalVarAttribute;
} }
const PTokenAttribute &GLSLHighlighter::localVarAttribute() const const PTokenAttribute &GLSLSyntaxer::localVarAttribute() const
{ {
return mLocalVarAttribute; return mLocalVarAttribute;
} }
GLSLHighlighter::TokenId GLSLHighlighter::getTokenId() GLSLSyntaxer::TokenId GLSLSyntaxer::getTokenId()
{ {
if ((mRange.state == RangeState::rsAsm || mRange.state == RangeState::rsAsmBlock) if ((mRange.state == RangeState::rsAsm || mRange.state == RangeState::rsAsmBlock)
&& !mAsmStart && !(mTokenId == TokenId::Comment || mTokenId == TokenId::Space && !mAsmStart && !(mTokenId == TokenId::Comment || mTokenId == TokenId::Space
@ -212,7 +212,7 @@ GLSLHighlighter::TokenId GLSLHighlighter::getTokenId()
} }
} }
void GLSLHighlighter::andSymbolProc() void GLSLSyntaxer::andSymbolProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
switch (mLine[mRun+1].unicode()) { switch (mLine[mRun+1].unicode()) {
@ -227,7 +227,7 @@ void GLSLHighlighter::andSymbolProc()
} }
} }
void GLSLHighlighter::ansiCppProc() void GLSLSyntaxer::ansiCppProc()
{ {
mTokenId = TokenId::Comment; mTokenId = TokenId::Comment;
if (mLine[mRun]==0) { if (mLine[mRun]==0) {
@ -246,7 +246,7 @@ void GLSLHighlighter::ansiCppProc()
} }
} }
void GLSLHighlighter::ansiCProc() void GLSLSyntaxer::ansiCProc()
{ {
bool finishProcess = false; bool finishProcess = false;
mTokenId = TokenId::Comment; mTokenId = TokenId::Comment;
@ -281,7 +281,7 @@ void GLSLHighlighter::ansiCProc()
} }
} }
void GLSLHighlighter::asciiCharProc() void GLSLSyntaxer::asciiCharProc()
{ {
mTokenId = TokenId::Char; mTokenId = TokenId::Char;
do { do {
@ -297,13 +297,13 @@ void GLSLHighlighter::asciiCharProc()
mRange.state = RangeState::rsUnknown; mRange.state = RangeState::rsUnknown;
} }
void GLSLHighlighter::atSymbolProc() void GLSLSyntaxer::atSymbolProc()
{ {
mTokenId = TokenId::Unknown; mTokenId = TokenId::Unknown;
mRun+=1; mRun+=1;
} }
void GLSLHighlighter::braceCloseProc() void GLSLSyntaxer::braceCloseProc()
{ {
mRun += 1; mRun += 1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
@ -325,7 +325,7 @@ void GLSLHighlighter::braceCloseProc()
popIndents(IndentForBrace); popIndents(IndentForBrace);
} }
void GLSLHighlighter::braceOpenProc() void GLSLSyntaxer::braceOpenProc()
{ {
mRun += 1; mRun += 1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
@ -352,7 +352,7 @@ void GLSLHighlighter::braceOpenProc()
} }
} }
void GLSLHighlighter::colonProc() void GLSLSyntaxer::colonProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mLine[mRun+1]==':') { if (mLine[mRun+1]==':') {
@ -362,13 +362,13 @@ void GLSLHighlighter::colonProc()
} }
} }
void GLSLHighlighter::commaProc() void GLSLSyntaxer::commaProc()
{ {
mRun+=1; mRun+=1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
} }
void GLSLHighlighter::directiveProc() void GLSLSyntaxer::directiveProc()
{ {
QString preContents = mLineString.left(mRun).trimmed(); QString preContents = mLineString.left(mRun).trimmed();
if (!preContents.isEmpty()) { // '#' is not first non-space char on the line, treat it as an invalid char if (!preContents.isEmpty()) { // '#' is not first non-space char on the line, treat it as an invalid char
@ -411,7 +411,7 @@ void GLSLHighlighter::directiveProc()
// } while (mLine[mRun]!=0); // } while (mLine[mRun]!=0);
} }
void GLSLHighlighter::directiveEndProc() void GLSLSyntaxer::directiveEndProc()
{ {
mTokenId = TokenId::Directive; mTokenId = TokenId::Directive;
if (mLine[mRun] == 0) { if (mLine[mRun] == 0) {
@ -443,7 +443,7 @@ void GLSLHighlighter::directiveEndProc()
} while (mLine[mRun]!=0); } while (mLine[mRun]!=0);
} }
void GLSLHighlighter::equalProc() void GLSLSyntaxer::equalProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mLine[mRun+1] == '=') { if (mLine[mRun+1] == '=') {
@ -453,7 +453,7 @@ void GLSLHighlighter::equalProc()
} }
} }
void GLSLHighlighter::greaterProc() void GLSLSyntaxer::greaterProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
switch (mLine[mRun + 1].unicode()) { switch (mLine[mRun + 1].unicode()) {
@ -472,7 +472,7 @@ void GLSLHighlighter::greaterProc()
} }
} }
void GLSLHighlighter::identProc() void GLSLSyntaxer::identProc()
{ {
int wordEnd = mRun; int wordEnd = mRun;
while (isIdentChar(mLine[wordEnd])) { while (isIdentChar(mLine[wordEnd])) {
@ -490,7 +490,7 @@ void GLSLHighlighter::identProc()
} }
} }
void GLSLHighlighter::lowerProc() void GLSLSyntaxer::lowerProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
switch(mLine[mRun+1].unicode()) { switch(mLine[mRun+1].unicode()) {
@ -509,7 +509,7 @@ void GLSLHighlighter::lowerProc()
} }
} }
void GLSLHighlighter::minusProc() void GLSLSyntaxer::minusProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
switch(mLine[mRun+1].unicode()) { switch(mLine[mRun+1].unicode()) {
@ -531,7 +531,7 @@ void GLSLHighlighter::minusProc()
} }
} }
void GLSLHighlighter::modSymbolProc() void GLSLSyntaxer::modSymbolProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
switch(mLine[mRun + 1].unicode()) { switch(mLine[mRun + 1].unicode()) {
@ -543,7 +543,7 @@ void GLSLHighlighter::modSymbolProc()
} }
} }
void GLSLHighlighter::notSymbolProc() void GLSLSyntaxer::notSymbolProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
switch(mLine[mRun + 1].unicode()) { switch(mLine[mRun + 1].unicode()) {
@ -555,7 +555,7 @@ void GLSLHighlighter::notSymbolProc()
} }
} }
void GLSLHighlighter::nullProc() void GLSLSyntaxer::nullProc()
{ {
if ((mRun-1>=0) && isSpaceChar(mLine[mRun-1]) && if ((mRun-1>=0) && isSpaceChar(mLine[mRun-1]) &&
(mRange.state == RangeState::rsCppComment (mRange.state == RangeState::rsCppComment
@ -568,7 +568,7 @@ void GLSLHighlighter::nullProc()
mTokenId = TokenId::Null; mTokenId = TokenId::Null;
} }
void GLSLHighlighter::numberProc() void GLSLSyntaxer::numberProc()
{ {
int idx1; // token[1] int idx1; // token[1]
idx1 = mRun; idx1 = mRun;
@ -738,7 +738,7 @@ void GLSLHighlighter::numberProc()
} }
} }
void GLSLHighlighter::orSymbolProc() void GLSLSyntaxer::orSymbolProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
switch ( mLine[mRun+1].unicode()) { switch ( mLine[mRun+1].unicode()) {
@ -753,7 +753,7 @@ void GLSLHighlighter::orSymbolProc()
} }
} }
void GLSLHighlighter::plusProc() void GLSLSyntaxer::plusProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
switch(mLine[mRun+1].unicode()){ switch(mLine[mRun+1].unicode()){
@ -768,7 +768,7 @@ void GLSLHighlighter::plusProc()
} }
} }
void GLSLHighlighter::pointProc() void GLSLSyntaxer::pointProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mLine[mRun+1] == '*' ) { if (mLine[mRun+1] == '*' ) {
@ -782,13 +782,13 @@ void GLSLHighlighter::pointProc()
} }
} }
void GLSLHighlighter::questionProc() void GLSLSyntaxer::questionProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
mRun+=1; mRun+=1;
} }
void GLSLHighlighter::rawStringProc() void GLSLSyntaxer::rawStringProc()
{ {
bool noEscaping = false; bool noEscaping = false;
if (mRange.state == RangeState::rsRawStringNotEscaping) if (mRange.state == RangeState::rsRawStringNotEscaping)
@ -814,7 +814,7 @@ void GLSLHighlighter::rawStringProc()
mRange.state = RangeState::rsUnknown; mRange.state = RangeState::rsUnknown;
} }
void GLSLHighlighter::roundCloseProc() void GLSLSyntaxer::roundCloseProc()
{ {
mRun += 1; mRun += 1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
@ -824,7 +824,7 @@ void GLSLHighlighter::roundCloseProc()
popIndents(IndentForParenthesis); popIndents(IndentForParenthesis);
} }
void GLSLHighlighter::roundOpenProc() void GLSLSyntaxer::roundOpenProc()
{ {
mRun += 1; mRun += 1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
@ -832,7 +832,7 @@ void GLSLHighlighter::roundOpenProc()
pushIndents(IndentForParenthesis); pushIndents(IndentForParenthesis);
} }
void GLSLHighlighter::semiColonProc() void GLSLSyntaxer::semiColonProc()
{ {
mRun += 1; mRun += 1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
@ -843,7 +843,7 @@ void GLSLHighlighter::semiColonProc()
} }
} }
void GLSLHighlighter::slashProc() void GLSLSyntaxer::slashProc()
{ {
switch(mLine[mRun+1].unicode()) { switch(mLine[mRun+1].unicode()) {
case '/': // Cpp style comment case '/': // Cpp style comment
@ -876,7 +876,7 @@ void GLSLHighlighter::slashProc()
} }
} }
void GLSLHighlighter::spaceProc() void GLSLSyntaxer::spaceProc()
{ {
mRun += 1; mRun += 1;
mTokenId = TokenId::Space; mTokenId = TokenId::Space;
@ -885,7 +885,7 @@ void GLSLHighlighter::spaceProc()
mRange.state = RangeState::rsUnknown; mRange.state = RangeState::rsUnknown;
} }
void GLSLHighlighter::squareCloseProc() void GLSLSyntaxer::squareCloseProc()
{ {
mRun+=1; mRun+=1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
@ -895,7 +895,7 @@ void GLSLHighlighter::squareCloseProc()
popIndents(IndentForBracket); popIndents(IndentForBracket);
} }
void GLSLHighlighter::squareOpenProc() void GLSLSyntaxer::squareOpenProc()
{ {
mRun+=1; mRun+=1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
@ -903,7 +903,7 @@ void GLSLHighlighter::squareOpenProc()
pushIndents(IndentForBracket); pushIndents(IndentForBracket);
} }
void GLSLHighlighter::starProc() void GLSLSyntaxer::starProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mLine[mRun+1] == '=') { if (mLine[mRun+1] == '=') {
@ -913,7 +913,7 @@ void GLSLHighlighter::starProc()
} }
} }
void GLSLHighlighter::stringEndProc() void GLSLSyntaxer::stringEndProc()
{ {
mTokenId = TokenId::String; mTokenId = TokenId::String;
if (mLine[mRun]==0) { if (mLine[mRun]==0) {
@ -965,7 +965,7 @@ void GLSLHighlighter::stringEndProc()
} }
} }
void GLSLHighlighter::stringEscapeSeqProc() void GLSLSyntaxer::stringEscapeSeqProc()
{ {
mTokenId = TokenId::StringEscapeSeq; mTokenId = TokenId::StringEscapeSeq;
mRun+=1; mRun+=1;
@ -1047,7 +1047,7 @@ void GLSLHighlighter::stringEscapeSeqProc()
mRange.state = RangeState::rsString; mRange.state = RangeState::rsString;
} }
void GLSLHighlighter::stringProc() void GLSLSyntaxer::stringProc()
{ {
if (mLine[mRun] == 0) { if (mLine[mRun] == 0) {
mRange.state = RangeState::rsUnknown; mRange.state = RangeState::rsUnknown;
@ -1099,7 +1099,7 @@ void GLSLHighlighter::stringProc()
mRange.state = RangeState::rsUnknown; mRange.state = RangeState::rsUnknown;
} }
void GLSLHighlighter::stringStartProc() void GLSLSyntaxer::stringStartProc()
{ {
mTokenId = TokenId::String; mTokenId = TokenId::String;
mRun += 1; mRun += 1;
@ -1110,19 +1110,19 @@ void GLSLHighlighter::stringStartProc()
stringProc(); stringProc();
} }
void GLSLHighlighter::tildeProc() void GLSLSyntaxer::tildeProc()
{ {
mRun+=1; mRun+=1;
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
} }
void GLSLHighlighter::unknownProc() void GLSLSyntaxer::unknownProc()
{ {
mRun+=1; mRun+=1;
mTokenId = TokenId::Unknown; mTokenId = TokenId::Unknown;
} }
void GLSLHighlighter::xorSymbolProc() void GLSLSyntaxer::xorSymbolProc()
{ {
mTokenId = TokenId::Symbol; mTokenId = TokenId::Symbol;
if (mLine[mRun+1]=='=') { if (mLine[mRun+1]=='=') {
@ -1132,7 +1132,7 @@ void GLSLHighlighter::xorSymbolProc()
} }
} }
void GLSLHighlighter::processChar() void GLSLSyntaxer::processChar()
{ {
switch(mLine[mRun].unicode()) { switch(mLine[mRun].unicode()) {
case '&': case '&':
@ -1249,7 +1249,7 @@ void GLSLHighlighter::processChar()
} }
} }
void GLSLHighlighter::popIndents(int indentType) void GLSLSyntaxer::popIndents(int indentType)
{ {
while (!mRange.indents.isEmpty() && mRange.indents.back()!=indentType) { while (!mRange.indents.isEmpty() && mRange.indents.back()!=indentType) {
mRange.indents.pop_back(); mRange.indents.pop_back();
@ -1263,7 +1263,7 @@ void GLSLHighlighter::popIndents(int indentType)
} }
} }
void GLSLHighlighter::pushIndents(int indentType) void GLSLSyntaxer::pushIndents(int indentType)
{ {
int idx = mRange.indents.length(); int idx = mRange.indents.length();
if (idx<mRange.firstIndentThisLine) if (idx<mRange.firstIndentThisLine)
@ -1271,7 +1271,7 @@ void GLSLHighlighter::pushIndents(int indentType)
mRange.indents.push_back(indentType); mRange.indents.push_back(indentType);
} }
bool GLSLHighlighter::getTokenFinished() const bool GLSLSyntaxer::getTokenFinished() const
{ {
if (mTokenId == TokenId::Comment if (mTokenId == TokenId::Comment
|| mTokenId == TokenId::String || mTokenId == TokenId::String
@ -1281,7 +1281,7 @@ bool GLSLHighlighter::getTokenFinished() const
return true; return true;
} }
bool GLSLHighlighter::isLastLineCommentNotFinished(int state) const bool GLSLSyntaxer::isLastLineCommentNotFinished(int state) const
{ {
return (state == RangeState::rsAnsiC || return (state == RangeState::rsAnsiC ||
state == RangeState::rsAnsiCAsm || state == RangeState::rsAnsiCAsm ||
@ -1290,22 +1290,22 @@ bool GLSLHighlighter::isLastLineCommentNotFinished(int state) const
state == RangeState::rsCppComment); state == RangeState::rsCppComment);
} }
bool GLSLHighlighter::isLastLineStringNotFinished(int state) const bool GLSLSyntaxer::isLastLineStringNotFinished(int state) const
{ {
return state == RangeState::rsMultiLineString; return state == RangeState::rsMultiLineString;
} }
bool GLSLHighlighter::eol() const bool GLSLSyntaxer::eol() const
{ {
return mTokenId == TokenId::Null; return mTokenId == TokenId::Null;
} }
QString GLSLHighlighter::getToken() const QString GLSLSyntaxer::getToken() const
{ {
return mLineString.mid(mTokenPos,mRun-mTokenPos); return mLineString.mid(mTokenPos,mRun-mTokenPos);
} }
const PTokenAttribute &GLSLHighlighter::getTokenAttribute() const const PTokenAttribute &GLSLSyntaxer::getTokenAttribute() const
{ {
switch (mTokenId) { switch (mTokenId) {
case TokenId::Asm: case TokenId::Asm:
@ -1346,12 +1346,12 @@ const PTokenAttribute &GLSLHighlighter::getTokenAttribute() const
} }
} }
int GLSLHighlighter::getTokenPos() int GLSLSyntaxer::getTokenPos()
{ {
return mTokenPos; return mTokenPos;
} }
void GLSLHighlighter::next() void GLSLSyntaxer::next()
{ {
mAsmStart = false; mAsmStart = false;
mTokenPos = mRun; mTokenPos = mRun;
@ -1409,7 +1409,7 @@ void GLSLHighlighter::next()
} while (mTokenId!=TokenId::Null && mRun<=mTokenPos); } while (mTokenId!=TokenId::Null && mRun<=mTokenPos);
} }
void GLSLHighlighter::setLine(const QString &newLine, int lineNumber) void GLSLSyntaxer::setLine(const QString &newLine, int lineNumber)
{ {
mLineString = newLine; mLineString = newLine;
mLine = mLineString.data(); mLine = mLineString.data();
@ -1424,12 +1424,12 @@ void GLSLHighlighter::setLine(const QString &newLine, int lineNumber)
next(); next();
} }
bool GLSLHighlighter::isKeyword(const QString &word) bool GLSLSyntaxer::isKeyword(const QString &word)
{ {
return Keywords.contains(word); return Keywords.contains(word);
} }
void GLSLHighlighter::setState(const SyntaxerState& rangeState) void GLSLSyntaxer::setState(const SyntaxerState& rangeState)
{ {
mRange = rangeState; mRange = rangeState;
// current line's left / right parenthesis count should be reset before parsing each line // current line's left / right parenthesis count should be reset before parsing each line
@ -1441,7 +1441,7 @@ void GLSLHighlighter::setState(const SyntaxerState& rangeState)
mRange.matchingIndents.clear(); mRange.matchingIndents.clear();
} }
void GLSLHighlighter::resetState() void GLSLSyntaxer::resetState()
{ {
mRange.state = RangeState::rsUnknown; mRange.state = RangeState::rsUnknown;
mRange.braceLevel = 0; mRange.braceLevel = 0;
@ -1457,32 +1457,32 @@ void GLSLHighlighter::resetState()
mAsmStart = false; mAsmStart = false;
} }
QString GLSLHighlighter::languageName() QString GLSLSyntaxer::languageName()
{ {
return "glsl"; return "glsl";
} }
ProgrammingLanguage GLSLHighlighter::language() ProgrammingLanguage GLSLSyntaxer::language()
{ {
return ProgrammingLanguage::GLSL; return ProgrammingLanguage::GLSL;
} }
SyntaxerState GLSLHighlighter::getState() const SyntaxerState GLSLSyntaxer::getState() const
{ {
return mRange; return mRange;
} }
bool GLSLHighlighter::isIdentChar(const QChar &ch) const bool GLSLSyntaxer::isIdentChar(const QChar &ch) const
{ {
return ch=='_' || (ch>='a' && ch<='z') || (ch>='A' && ch<='Z') || (ch>='0' && ch<='9'); return ch=='_' || (ch>='a' && ch<='z') || (ch>='A' && ch<='Z') || (ch>='0' && ch<='9');
} }
QSet<QString> GLSLHighlighter::keywords() const QSet<QString> GLSLSyntaxer::keywords() const
{ {
return Keywords; return Keywords;
} }
bool GLSLHighlighter::supportBraceLevel() bool GLSLSyntaxer::supportBraceLevel()
{ {
return true; return true;
} }

View File

@ -16,12 +16,12 @@
*/ */
#ifndef SYNEDITGLSLHIGHLIGHTER_H #ifndef SYNEDITGLSLHIGHLIGHTER_H
#define SYNEDITGLSLHIGHLIGHTER_H #define SYNEDITGLSLHIGHLIGHTER_H
#include "base.h" #include "syntaxer.h"
#include <QSet> #include <QSet>
namespace QSynedit { namespace QSynedit {
class GLSLHighlighter: public Highlighter class GLSLSyntaxer: public Syntaxer
{ {
enum class TokenId { enum class TokenId {
Asm, Asm,
@ -54,7 +54,7 @@ class GLSLHighlighter: public Highlighter
}; };
public: public:
explicit GLSLHighlighter(); explicit GLSLSyntaxer();
const PTokenAttribute &asmAttribute() const; const PTokenAttribute &asmAttribute() const;

View File

@ -14,12 +14,12 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include "makefilehighlighter.h" #include "makefile.h"
#include "../Constants.h" #include "../Constants.h"
//#include <QDebug> //#include <QDebug>
namespace QSynedit { namespace QSynedit {
const QSet<QString> MakefileHighlighter::Directives { const QSet<QString> MakefileSyntaxer::Directives {
"abspath", "abspath",
"addprefix", "addprefix",
"addsuffix", "addsuffix",
@ -180,7 +180,7 @@ const QSet<QString> MakefileHighlighter::Directives {
"YFLAGS", "YFLAGS",
}; };
MakefileHighlighter::MakefileHighlighter() MakefileSyntaxer::MakefileSyntaxer()
{ {
mTargetAttribute = std::make_shared<TokenAttribute>(SYNS_AttrClass, TokenType::Identifier); mTargetAttribute = std::make_shared<TokenAttribute>(SYNS_AttrClass, TokenType::Identifier);
addAttribute(mTargetAttribute); addAttribute(mTargetAttribute);
@ -196,27 +196,27 @@ MakefileHighlighter::MakefileHighlighter()
addAttribute(mExpressionAttribute); addAttribute(mExpressionAttribute);
} }
void MakefileHighlighter::procSpace() void MakefileSyntaxer::procSpace()
{ {
mTokenID = TokenId::Space; mTokenID = TokenId::Space;
while (mLine[mRun]!=0 && mLine[mRun]<=32) while (mLine[mRun]!=0 && mLine[mRun]<=32)
mRun++; mRun++;
} }
void MakefileHighlighter::procNumber() void MakefileSyntaxer::procNumber()
{ {
while (isNumberChar(mLine[mRun])) while (isNumberChar(mLine[mRun]))
mRun++; mRun++;
mTokenID = TokenId::Number; mTokenID = TokenId::Number;
} }
void MakefileHighlighter::procNull() void MakefileSyntaxer::procNull()
{ {
mTokenID = TokenId::Null; mTokenID = TokenId::Null;
mState = RangeState::Unknown; mState = RangeState::Unknown;
} }
void MakefileHighlighter::procString(bool inExpression ) void MakefileSyntaxer::procString(bool inExpression )
{ {
mTokenID = TokenId::String; mTokenID = TokenId::String;
while (mLine[mRun] != 0) { while (mLine[mRun] != 0) {
@ -238,7 +238,7 @@ void MakefileHighlighter::procString(bool inExpression )
} }
void MakefileHighlighter::procStringStart(StringStartType type,bool inExpression ) void MakefileSyntaxer::procStringStart(StringStartType type,bool inExpression )
{ {
mRun++; mRun++;
pushState(); pushState();
@ -253,7 +253,7 @@ void MakefileHighlighter::procStringStart(StringStartType type,bool inExpression
procString(inExpression); procString(inExpression);
} }
void MakefileHighlighter::procExpressionStart(ExpressionStartType type) void MakefileSyntaxer::procExpressionStart(ExpressionStartType type)
{ {
mRun+=2; //skip '$(' or '${' mRun+=2; //skip '$(' or '${'
pushState(); pushState();
@ -268,20 +268,20 @@ void MakefileHighlighter::procExpressionStart(ExpressionStartType type)
mTokenID = TokenId::Expression; mTokenID = TokenId::Expression;
} }
void MakefileHighlighter::procExpressionEnd() void MakefileSyntaxer::procExpressionEnd()
{ {
mTokenID = TokenId::Expression; mTokenID = TokenId::Expression;
mRun+=1; mRun+=1;
popState(); popState();
} }
void MakefileHighlighter::procSymbol() void MakefileSyntaxer::procSymbol()
{ {
mTokenID = TokenId::Symbol; mTokenID = TokenId::Symbol;
mRun+=1; mRun+=1;
} }
void MakefileHighlighter::procVariableExpression() void MakefileSyntaxer::procVariableExpression()
{ {
mRun+=1; //skip $ mRun+=1; //skip $
while (isIdentStartChar(mLine[mRun])) while (isIdentStartChar(mLine[mRun]))
@ -289,7 +289,7 @@ void MakefileHighlighter::procVariableExpression()
mTokenID = TokenId::Variable; mTokenID = TokenId::Variable;
} }
void MakefileHighlighter::procAutoVariable() void MakefileSyntaxer::procAutoVariable()
{ {
mRun+=1; //skip $ mRun+=1; //skip $
switch(mLine[mRun].unicode()) { switch(mLine[mRun].unicode()) {
@ -311,14 +311,14 @@ void MakefileHighlighter::procAutoVariable()
} }
} }
void MakefileHighlighter::procAssignment() void MakefileSyntaxer::procAssignment()
{ {
mTokenID = TokenId::Symbol; mTokenID = TokenId::Symbol;
mRun++; mRun++;
mState = RangeState::Assignment; mState = RangeState::Assignment;
} }
void MakefileHighlighter::procDollar() void MakefileSyntaxer::procDollar()
{ {
if (mLine[mRun+1]=='(') { if (mLine[mRun+1]=='(') {
procExpressionStart(ExpressionStartType::Parenthesis); procExpressionStart(ExpressionStartType::Parenthesis);
@ -331,14 +331,14 @@ void MakefileHighlighter::procDollar()
} }
} }
void MakefileHighlighter::procComment() void MakefileSyntaxer::procComment()
{ {
mRun++; //skip # mRun++; //skip #
mRun = mLineString.length(); mRun = mLineString.length();
mTokenID = TokenId::Comment; mTokenID = TokenId::Comment;
} }
void MakefileHighlighter::procIdentifier() void MakefileSyntaxer::procIdentifier()
{ {
int start = mRun; int start = mRun;
while (isIdentChar(mLine[mRun])) { while (isIdentChar(mLine[mRun])) {
@ -374,12 +374,12 @@ void MakefileHighlighter::procIdentifier()
} }
void MakefileHighlighter::pushState() void MakefileSyntaxer::pushState()
{ {
mStates.push_back(mState); mStates.push_back(mState);
} }
void MakefileHighlighter::popState() void MakefileSyntaxer::popState()
{ {
if (!mStates.empty()) { if (!mStates.empty()) {
mState = mStates.back(); mState = mStates.back();
@ -387,7 +387,7 @@ void MakefileHighlighter::popState()
} }
} }
bool MakefileHighlighter::isIdentChar(const QChar &ch) const bool MakefileSyntaxer::isIdentChar(const QChar &ch) const
{ {
if ((ch>='0') && (ch <= '9')) { if ((ch>='0') && (ch <= '9')) {
return true; return true;
@ -411,27 +411,27 @@ bool MakefileHighlighter::isIdentChar(const QChar &ch) const
return false; return false;
} }
bool MakefileHighlighter::eol() const bool MakefileSyntaxer::eol() const
{ {
return mTokenID == TokenId::Null; return mTokenID == TokenId::Null;
} }
QString MakefileHighlighter::languageName() QString MakefileSyntaxer::languageName()
{ {
return "makefile"; return "makefile";
} }
ProgrammingLanguage MakefileHighlighter::language() ProgrammingLanguage MakefileSyntaxer::language()
{ {
return ProgrammingLanguage::Makefile; return ProgrammingLanguage::Makefile;
} }
QString MakefileHighlighter::getToken() const QString MakefileSyntaxer::getToken() const
{ {
return mLineString.mid(mTokenPos,mRun-mTokenPos); return mLineString.mid(mTokenPos,mRun-mTokenPos);
} }
const PTokenAttribute &MakefileHighlighter::getTokenAttribute() const const PTokenAttribute &MakefileSyntaxer::getTokenAttribute() const
{ {
/* /*
Directive, Directive,
@ -467,12 +467,12 @@ const PTokenAttribute &MakefileHighlighter::getTokenAttribute() const
} }
} }
int MakefileHighlighter::getTokenPos() int MakefileSyntaxer::getTokenPos()
{ {
return mTokenPos; return mTokenPos;
} }
void MakefileHighlighter::next() void MakefileSyntaxer::next()
{ {
mTokenPos = mRun; mTokenPos = mRun;
if (mLine[mRun].unicode()==0) { if (mLine[mRun].unicode()==0) {
@ -638,7 +638,7 @@ void MakefileHighlighter::next()
} }
} }
void MakefileHighlighter::setLine(const QString &newLine, int lineNumber) void MakefileSyntaxer::setLine(const QString &newLine, int lineNumber)
{ {
mLineString = newLine; mLineString = newLine;
mLine = mLineString.data(); mLine = mLineString.data();
@ -647,41 +647,41 @@ void MakefileHighlighter::setLine(const QString &newLine, int lineNumber)
next(); next();
} }
bool MakefileHighlighter::getTokenFinished() const bool MakefileSyntaxer::getTokenFinished() const
{ {
return true; return true;
} }
bool MakefileHighlighter::isLastLineCommentNotFinished(int /*state*/) const bool MakefileSyntaxer::isLastLineCommentNotFinished(int /*state*/) const
{ {
return false; return false;
} }
bool MakefileHighlighter::isLastLineStringNotFinished(int /*state*/) const bool MakefileSyntaxer::isLastLineStringNotFinished(int /*state*/) const
{ {
return false; return false;
} }
SyntaxerState MakefileHighlighter::getState() const SyntaxerState MakefileSyntaxer::getState() const
{ {
SyntaxerState state; SyntaxerState state;
state.state = (int)mState; state.state = (int)mState;
return state; return state;
} }
void MakefileHighlighter::setState(const SyntaxerState & rangeState) void MakefileSyntaxer::setState(const SyntaxerState & rangeState)
{ {
mState = (RangeState)rangeState.state; mState = (RangeState)rangeState.state;
mStates.clear(); mStates.clear();
} }
void MakefileHighlighter::resetState() void MakefileSyntaxer::resetState()
{ {
mState = RangeState::Unknown; mState = RangeState::Unknown;
mStates.clear(); mStates.clear();
} }
QSet<QString> MakefileHighlighter::keywords() const QSet<QString> MakefileSyntaxer::keywords() const
{ {
return Directives; return Directives;
} }

View File

@ -14,16 +14,16 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef MAKEFILEHIGHLIGHTER_H #ifndef MAKEFILE_H
#define MAKEFILEHIGHLIGHTER_H #define MAKEFILE_H
#include "base.h" #include "syntaxer.h"
#include <QVector> #include <QVector>
namespace QSynedit { namespace QSynedit {
class MakefileHighlighter : public Highlighter class MakefileSyntaxer : public Syntaxer
{ {
enum class TokenId { enum class TokenId {
Null, Null,
@ -66,7 +66,7 @@ class MakefileHighlighter : public Highlighter
public: public:
explicit MakefileHighlighter(); explicit MakefileSyntaxer();
static const QSet<QString> Directives; static const QSet<QString> Directives;
private: private:
@ -156,4 +156,4 @@ public:
}; };
} }
#endif // MAKEFILEHIGHLIGHTER_H #endif // MAKEFILE_H

View File

@ -14,11 +14,11 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include "base.h" #include "syntaxer.h"
#include "../Constants.h" #include "../Constants.h"
namespace QSynedit { namespace QSynedit {
Highlighter::Highlighter() : Syntaxer::Syntaxer() :
mEnabled(true), mEnabled(true),
mWordBreakChars{ WordBreakChars } mWordBreakChars{ WordBreakChars }
{ {
@ -42,78 +42,78 @@ Highlighter::Highlighter() :
addAttribute(mSymbolAttribute); addAttribute(mSymbolAttribute);
} }
const QMap<QString, PTokenAttribute>& Highlighter::attributes() const const QMap<QString, PTokenAttribute>& Syntaxer::attributes() const
{ {
return mAttributes; return mAttributes;
} }
const QSet<QChar>& Highlighter::wordBreakChars() const const QSet<QChar>& Syntaxer::wordBreakChars() const
{ {
return mWordBreakChars; return mWordBreakChars;
} }
const PTokenAttribute& Highlighter::identifierAttribute() const const PTokenAttribute& Syntaxer::identifierAttribute() const
{ {
return mIdentifierAttribute; return mIdentifierAttribute;
} }
const PTokenAttribute &Highlighter::keywordAttribute() const const PTokenAttribute &Syntaxer::keywordAttribute() const
{ {
return mKeywordAttribute; return mKeywordAttribute;
} }
const PTokenAttribute &Highlighter::commentAttribute() const const PTokenAttribute &Syntaxer::commentAttribute() const
{ {
return mCommentAttribute; return mCommentAttribute;
} }
const PTokenAttribute& Highlighter::stringAttribute() const const PTokenAttribute& Syntaxer::stringAttribute() const
{ {
return mStringAttribute; return mStringAttribute;
} }
const PTokenAttribute& Highlighter::whitespaceAttribute() const const PTokenAttribute& Syntaxer::whitespaceAttribute() const
{ {
return mWhitespaceAttribute; return mWhitespaceAttribute;
} }
const PTokenAttribute& Highlighter::symbolAttribute() const const PTokenAttribute& Syntaxer::symbolAttribute() const
{ {
return mSymbolAttribute; return mSymbolAttribute;
} }
bool Highlighter::isKeyword(const QString &) bool Syntaxer::isKeyword(const QString &)
{ {
return false; return false;
} }
void Highlighter::nextToEol() void Syntaxer::nextToEol()
{ {
while (!eol()) while (!eol())
next(); next();
} }
QSet<QString> Highlighter::keywords() const QSet<QString> Syntaxer::keywords() const
{ {
return QSet<QString>(); return QSet<QString>();
} }
QString Highlighter::foldString() QString Syntaxer::foldString()
{ {
return " ... }"; return " ... }";
} }
bool Highlighter::supportBraceLevel() bool Syntaxer::supportBraceLevel()
{ {
return false; return false;
} }
bool Highlighter::isSpaceChar(const QChar &ch) bool Syntaxer::isSpaceChar(const QChar &ch)
{ {
return ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n'; return ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n';
} }
bool Highlighter::isWordBreakChar(const QChar &ch) bool Syntaxer::isWordBreakChar(const QChar &ch)
{ {
switch (ch.unicode()) { switch (ch.unicode()) {
case '.': case '.':
@ -147,7 +147,7 @@ bool Highlighter::isWordBreakChar(const QChar &ch)
} }
} }
bool Highlighter::isIdentChar(const QChar &ch) const bool Syntaxer::isIdentChar(const QChar &ch) const
{ {
if (ch == '_') { if (ch == '_') {
return true; return true;
@ -164,32 +164,32 @@ bool Highlighter::isIdentChar(const QChar &ch) const
return false; return false;
} }
void Highlighter::addAttribute(PTokenAttribute attribute) void Syntaxer::addAttribute(PTokenAttribute attribute)
{ {
mAttributes[attribute->name()]=attribute; mAttributes[attribute->name()]=attribute;
} }
void Highlighter::clearAttributes() void Syntaxer::clearAttributes()
{ {
mAttributes.clear(); mAttributes.clear();
} }
int Highlighter::attributesCount() const int Syntaxer::attributesCount() const
{ {
return mAttributes.size(); return mAttributes.size();
} }
PTokenAttribute Highlighter::getAttribute(const QString& name) const PTokenAttribute Syntaxer::getAttribute(const QString& name) const
{ {
return mAttributes.value(name,PTokenAttribute()); return mAttributes.value(name,PTokenAttribute());
} }
bool Highlighter::enabled() const bool Syntaxer::enabled() const
{ {
return mEnabled; return mEnabled;
} }
void Highlighter::setEnabled(bool value) void Syntaxer::setEnabled(bool value)
{ {
if (value != mEnabled) { if (value != mEnabled) {
mEnabled = value; mEnabled = value;

View File

@ -14,8 +14,8 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef SYNHIGHLIGTERBASE_H #ifndef QSYNEDIT_SYNTAXER_H
#define SYNHIGHLIGTERBASE_H #define QSYNEDIT_SYNTAXER_H
#include <QColor> #include <QColor>
#include <QObject> #include <QObject>
@ -115,9 +115,9 @@ private:
typedef std::shared_ptr<TokenAttribute> PTokenAttribute; typedef std::shared_ptr<TokenAttribute> PTokenAttribute;
class Highlighter { class Syntaxer {
public: public:
explicit Highlighter(); explicit Syntaxer();
const QMap<QString, PTokenAttribute>& attributes() const; const QMap<QString, PTokenAttribute>& attributes() const;
@ -183,8 +183,7 @@ private:
QSet<QChar> mWordBreakChars; QSet<QChar> mWordBreakChars;
}; };
using PHighlighter = std::shared_ptr<Highlighter>; using PSyntaxer = std::shared_ptr<Syntaxer>;
using HighlighterList = QVector<PHighlighter>; using SyntaxerList = QVector<PSyntaxer>;
} }
#endif // SYNHIGHLIGTERBASE_H #endif // SYNHIGHLIGTERBASE_H