work save: asm highlighter

This commit is contained in:
royqh1979@gmail.com 2021-07-02 10:32:29 +08:00
parent b8c1e937bf
commit 7e00a48560
10 changed files with 245 additions and 35 deletions

View File

@ -2,6 +2,7 @@
#include <QFileInfo> #include <QFileInfo>
#include <QObject> #include <QObject>
#include "qsynedit/highlighter/cpp.h" #include "qsynedit/highlighter/cpp.h"
#include "qsynedit/highlighter/asm.h"
#include "qsynedit/Constants.h" #include "qsynedit/Constants.h"
#include "colorscheme.h" #include "colorscheme.h"
@ -57,7 +58,7 @@ PSynHighlighter HighlighterManager::getCppHighlighter()
highlighter->numberAttribute()->setForeground(0x1750EB); highlighter->numberAttribute()->setForeground(0x1750EB);
highlighter->octAttribute()->setForeground(QColorConstants::Svg::purple); highlighter->octAttribute()->setForeground(QColorConstants::Svg::purple);
highlighter->direcAttribute()->setForeground(0x1f542e); highlighter->direcAttribute()->setForeground(0x1f542e);
highlighter->keyAttribute()->setForeground(0x0033b3); highlighter->keywordAttribute()->setForeground(0x0033b3);
highlighter->whitespaceAttribute()->setForeground(QColorConstants::Svg::silver); highlighter->whitespaceAttribute()->setForeground(QColorConstants::Svg::silver);
highlighter->stringAttribute()->setForeground(0x007d17); highlighter->stringAttribute()->setForeground(0x007d17);
highlighter->stringEscapeSequenceAttribute()->setForeground(QColorConstants::Svg::red); highlighter->stringEscapeSequenceAttribute()->setForeground(QColorConstants::Svg::red);
@ -66,11 +67,28 @@ PSynHighlighter HighlighterManager::getCppHighlighter()
return pHighlighter; return pHighlighter;
} }
PSynHighlighter HighlighterManager::getAsmHighlighter()
{
SynEditASMHighlighter* highlighter = new SynEditASMHighlighter();
PSynHighlighter pHighlighter(highlighter);
highlighter->commentAttribute()->setForeground(0x8C8C8C);
highlighter->commentAttribute()->setStyles(SynFontStyle::fsItalic);
highlighter->identifierAttribute()->setForeground(0x080808);
highlighter->keywordAttribute()->setForeground(0x0033b3);
highlighter->numberAttribute()->setForeground(0x1750EB);
highlighter->whitespaceAttribute()->setForeground(QColorConstants::Svg::silver);
highlighter->stringAttribute()->setForeground(0x007d17);
highlighter->symbolAttribute()->setForeground(0xc10000);
return pHighlighter;
}
void HighlighterManager::applyColorScheme(PSynHighlighter highlighter, const QString &schemeName) void HighlighterManager::applyColorScheme(PSynHighlighter highlighter, const QString &schemeName)
{ {
if (!highlighter) if (!highlighter)
return; return;
if (highlighter->getName() == SYN_HIGHLIGHTER_CPP) { if ( (highlighter->getName() == SYN_HIGHLIGHTER_CPP)
|| (highlighter->getName() == SYN_HIGHLIGHTER_ASM)
) {
for (QString name: highlighter->attributes().keys()) { for (QString name: highlighter->attributes().keys()) {
PColorSchemeItem item = pColorManager->getItem(schemeName,name); PColorSchemeItem item = pColorManager->getItem(schemeName,name);
if (item) { if (item) {

View File

@ -10,6 +10,7 @@ public:
PSynHighlighter getHighlighter(const QString& filename); PSynHighlighter getHighlighter(const QString& filename);
PSynHighlighter copyHighlighter(PSynHighlighter highlighter); PSynHighlighter copyHighlighter(PSynHighlighter highlighter);
PSynHighlighter getCppHighlighter(); PSynHighlighter getCppHighlighter();
PSynHighlighter getAsmHighlighter();
void applyColorScheme(PSynHighlighter highlighter, const QString& schemeName); void applyColorScheme(PSynHighlighter highlighter, const QString& schemeName);
}; };

View File

@ -40,6 +40,8 @@ void CompilerManager::compile(const QString& filename, const QByteArray& encodin
if (mCompiler!=nullptr) { if (mCompiler!=nullptr) {
return; return;
} }
if (!pSettings->compilerSets().defaultSet())
return;
mCompileErrorCount = 0; mCompileErrorCount = 0;
mCompiler = new FileCompiler(filename,encoding,silent,onlyCheckSyntax); mCompiler = new FileCompiler(filename,encoding,silent,onlyCheckSyntax);
mCompiler->setRebuild(rebuild); mCompiler->setRebuild(rebuild);
@ -58,6 +60,8 @@ void CompilerManager::checkSyntax(const QString &filename, const QString &conten
if (mBackgroundSyntaxChecker!=nullptr) { if (mBackgroundSyntaxChecker!=nullptr) {
return; return;
} }
if (!pSettings->compilerSets().defaultSet())
return;
mSyntaxCheckErrorCount = 0; mSyntaxCheckErrorCount = 0;
mBackgroundSyntaxChecker = new StdinCompiler(filename,content,true,true); mBackgroundSyntaxChecker = new StdinCompiler(filename,content,true,true);
connect(mBackgroundSyntaxChecker, &Compiler::compileFinished, this ,&CompilerManager::onSyntaxCheckFinished); connect(mBackgroundSyntaxChecker, &Compiler::compileFinished, this ,&CompilerManager::onSyntaxCheckFinished);

View File

@ -636,9 +636,12 @@ void Editor::onModificationChanged(bool) {
void Editor::onStatusChanged(SynStatusChanges changes) void Editor::onStatusChanged(SynStatusChanges changes)
{ {
if (!changes.testFlag(SynStatusChange::scOpenFile) && (lines()->count()!=mLineCount) if (!changes.testFlag(SynStatusChange::scOpenFile)
&& !changes.testFlag(SynStatusChange::scReadOnly)
&& !changes.testFlag(SynStatusChange::scInsertMode)
&& (lines()->count()!=mLineCount)
&& (lines()->count()!=0) && ((mLineCount>0) || (lines()->count()>1))) { && (lines()->count()!=0) && ((mLineCount>0) || (lines()->count()>1))) {
if (pSettings->editor().syntaxCheck() && pSettings->editor().syntaxCheckWhenLineChanged()) if (!readOnly() && pSettings->editor().syntaxCheck() && pSettings->editor().syntaxCheckWhenLineChanged())
pMainWindow->checkSyntaxInBack(this); pMainWindow->checkSyntaxInBack(this);
} }
mLineCount = lines()->count(); mLineCount = lines()->count();

View File

@ -210,6 +210,7 @@ public:
void setCaretXYCentered(bool ForceToMiddle, const BufferCoord& value); void setCaretXYCentered(bool ForceToMiddle, const BufferCoord& value);
void uncollapseAroundLine(int line); void uncollapseAroundLine(int line);
PSynEditFoldRange foldHidesLine(int line); PSynEditFoldRange foldHidesLine(int line);
void setSelText(const QString& Value);
int maxScrollWidth() const; int maxScrollWidth() const;
int maxScrollHeight() const; int maxScrollHeight() const;
@ -429,7 +430,6 @@ private:
void SetSelTextPrimitive(const QString& aValue); void SetSelTextPrimitive(const QString& aValue);
void SetSelTextPrimitiveEx(SynSelectionMode PasteMode, void SetSelTextPrimitiveEx(SynSelectionMode PasteMode,
const QString& Value, bool AddToUndoList); const QString& Value, bool AddToUndoList);
void setSelText(const QString& Value);
void DoLinesDeleted(int FirstLine, int Count); void DoLinesDeleted(int FirstLine, int Count);
void DoLinesInserted(int FirstLine, int Count); void DoLinesInserted(int FirstLine, int Count);
void ProperSetLine(int ALine, const QString& ALineText); void ProperSetLine(int ALine, const QString& ALineText);

View File

@ -37,6 +37,31 @@ const QSet<QString> SynEditASMHighlighter::Keywords {
SynEditASMHighlighter::SynEditASMHighlighter()
{
mCommentAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrComment);
mCommentAttribute->setStyles(SynFontStyle::fsItalic);
addAttribute(mCommentAttribute);
mIdentifierAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrIdentifier);
addAttribute(mIdentifierAttribute);
mKeywordAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrReservedWord);
mKeywordAttribute->setStyles(SynFontStyle::fsBold);
addAttribute(mKeywordAttribute);
mNumberAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrNumber);
addAttribute(mNumberAttribute);
mWhitespaceAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrSpace);
addAttribute(mWhitespaceAttribute);
mStringAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrString);
addAttribute(mStringAttribute);
mSymbolAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrSymbol);
addAttribute(mSymbolAttribute);
}
PSynHighlighterAttribute SynEditASMHighlighter::numberAttribute()
{
return mNumberAttribute;
}
void SynEditASMHighlighter::CommentProc() void SynEditASMHighlighter::CommentProc()
{ {
mTokenID = TokenKind::Comment; mTokenID = TokenKind::Comment;
@ -53,6 +78,128 @@ void SynEditASMHighlighter::CRProc()
mRun++; mRun++;
} }
void SynEditASMHighlighter::GreaterProc()
{
mRun++;
mTokenID = TokenKind::Symbol;
if (mLine[mRun] == '=')
mRun++;
}
void SynEditASMHighlighter::IdentProc()
{
int start = mRun;
while (isIdentChar(mLine[mRun])) {
mRun++;
}
QString s = mLineString.mid(start,mRun-start);
if (Keywords.contains(s)) {
mTokenID = TokenKind::Key;
} else {
mTokenID = TokenKind::Identifier;
}
}
void SynEditASMHighlighter::LFProc()
{
mTokenID = TokenKind::Space;
mRun++;
}
void SynEditASMHighlighter::LowerProc()
{
mRun++;
mTokenID = TokenKind::Symbol;
if (mLine[mRun]=='=' || mLine[mRun]== '>')
mRun++;
}
void SynEditASMHighlighter::NullProc()
{
mTokenID = TokenKind::Null;
}
void SynEditASMHighlighter::NumberProc()
{
mRun++;
mTokenID = TokenKind::Number;
while (true) {
QChar ch = mLine[mRun];
if (!((ch>=0 && ch<=9) || (ch=='.') || (ch >= 'a' && ch<='f')
|| (ch=='h') || (ch >= 'A' && ch<='F') || (ch == 'H')))
break;
mRun++;
}
}
void SynEditASMHighlighter::SingleQuoteStringProc()
{
mTokenID = TokenKind::String;
if ((mRun+2 < mLineString.size()) && (mLine[mRun + 1] == '\'') && (mLine[mRun + 2] == '\''))
mRun += 2;
while (true) {
if (mLine[mRun] == 0 || mLine[mRun] == '\r' || mLine[mRun] == '\n' || mLine[mRun] == '\'')
break;
mRun++;
}
if (mLine[mRun]!=0)
mRun++;
}
void SynEditASMHighlighter::SlashProc()
{
mRun++;
if (mLine[mRun] == '/') {
mTokenID = TokenKind::Comment;
while (true) {
mRun++;
if (mLine[mRun] == 0 || mLine[mRun] == '\r' || mLine[mRun] == '\n')
break;
}
} else
mTokenID = TokenKind::Symbol;
}
void SynEditASMHighlighter::SpaceProc()
{
mTokenID = TokenKind::Space;
while (true) {
mRun++;
if (mLine[mRun] == 0 || mLine[mRun] == '\r' || mLine[mRun] == '\n')
break;
if (mLine[mRun] > 32)
break;
}
}
void SynEditASMHighlighter::StringProc()
{
mTokenID = TokenKind::String;
if ((mRun+2 < mLineString.size()) && (mLine[mRun + 1] == '\"') && (mLine[mRun + 2] == '\"'))
mRun += 2;
while (true) {
if (mLine[mRun] == 0 || mLine[mRun] == '\r' || mLine[mRun] == '\n')
break;
if (mLine[mRun] == '\"')
break;
mRun += 1;
}
if (mLine[mRun]!=0)
mRun++;
}
void SynEditASMHighlighter::SymbolProc()
{
mRun++;
mTokenID = TokenKind::Symbol;
}
void SynEditASMHighlighter::UnknownProc()
{
mRun++;
mTokenID = TokenKind::Unknown;
}
bool SynEditASMHighlighter::eol() const bool SynEditASMHighlighter::eol() const
{ {
return mTokenID == TokenKind::Null; return mTokenID == TokenKind::Null;
@ -124,6 +271,11 @@ SynHighlighterTokenType SynEditASMHighlighter::getTokenType()
return SynHighlighterTokenType::Default; return SynHighlighterTokenType::Default;
} }
int SynEditASMHighlighter::getTokenPos()
{
return mTokenPos;
}
void SynEditASMHighlighter::next() void SynEditASMHighlighter::next()
{ {
mTokenPos = mRun; mTokenPos = mRun;
@ -203,3 +355,33 @@ QString SynEditASMHighlighter::getName() const
{ {
return SYN_HIGHLIGHTER_CPP; return SYN_HIGHLIGHTER_CPP;
} }
bool SynEditASMHighlighter::getTokenFinished() const
{
return true;
}
bool SynEditASMHighlighter::isLastLineCommentNotFinished(int state) const
{
return true;
}
bool SynEditASMHighlighter::isLastLineStringNotFinished(int state) const
{
return true;
}
SynRangeState SynEditASMHighlighter::getRangeState() const
{
return {0,0};
}
void SynEditASMHighlighter::setState(SynRangeState , int , int , int)
{
}
void SynEditASMHighlighter::resetState()
{
}

View File

@ -18,25 +18,8 @@ class SynEditASMHighlighter : public SynHighlighter
Unknown Unknown
}; };
public: public:
explicit SynEditASMHighlighter() explicit SynEditASMHighlighter();
{ PSynHighlighterAttribute numberAttribute();
mCommentAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrComment);
mCommentAttribute->setStyles(SynFontStyle::fsItalic);
addAttribute(mCommentAttribute);
mIdentifierAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrIdentifier);
addAttribute(mIdentifierAttribute);
mKeywordAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrReservedWord);
mKeywordAttribute->setStyles(SynFontStyle::fsBold);
addAttribute(mKeywordAttribute);
mNumberAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrNumber);
addAttribute(mNumberAttribute);
mWhitespaceAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrSpace);
addAttribute(mWhitespaceAttribute);
mStringAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrString);
addAttribute(mStringAttribute);
mSymbolAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrSymbol);
addAttribute(mSymbolAttribute);
}
static const QSet<QString> Keywords; static const QSet<QString> Keywords;
private: private:
@ -53,6 +36,19 @@ private:
private: private:
void CommentProc(); void CommentProc();
void CRProc(); void CRProc();
void GreaterProc();
void IdentProc();
void LFProc();
void LowerProc();
void NullProc();
void NumberProc();
void SingleQuoteStringProc();
void SlashProc();
void SpaceProc();
void StringProc();
void SymbolProc();
void UnknownProc();
// SynHighlighter interface // SynHighlighter interface
public: public:
@ -72,6 +68,15 @@ public:
public: public:
SynHighlighterClass getClass() const override; SynHighlighterClass getClass() const override;
QString getName() const override; QString getName() const override;
// SynHighlighter interface
public:
bool getTokenFinished() const override;
bool isLastLineCommentNotFinished(int state) const override;
bool isLastLineStringNotFinished(int state) const override;
SynRangeState getRangeState() const override;
void setState(SynRangeState rangeState, int braceLevel, int bracketLevel, int parenthesisLevel) override;
void resetState() override;
}; };
#endif // SYNEDITASMHIGHLIGHTER_H #endif // SYNEDITASMHIGHLIGHTER_H

View File

@ -140,8 +140,8 @@ SynEditCppHighlighter::SynEditCppHighlighter(): SynHighlighter()
addAttribute(mOctAttribute); addAttribute(mOctAttribute);
mDirecAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrPreprocessor); mDirecAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrPreprocessor);
addAttribute(mDirecAttribute); addAttribute(mDirecAttribute);
mKeyAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrReservedWord); mKeywordAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrReservedWord);
addAttribute(mKeyAttribute); addAttribute(mKeywordAttribute);
mWhitespaceAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrSpace); mWhitespaceAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrSpace);
addAttribute(mWhitespaceAttribute); addAttribute(mWhitespaceAttribute);
mStringAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrString); mStringAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrString);
@ -176,11 +176,6 @@ PSynHighlighterAttribute SynEditCppHighlighter::invalidAttribute() const
return mInvalidAttribute; return mInvalidAttribute;
} }
PSynHighlighterAttribute SynEditCppHighlighter::keyAttribute() const
{
return mKeyAttribute;
}
PSynHighlighterAttribute SynEditCppHighlighter::numberAttribute() const PSynHighlighterAttribute SynEditCppHighlighter::numberAttribute() const
{ {
return mNumberAttribute; return mNumberAttribute;
@ -1369,7 +1364,7 @@ PSynHighlighterAttribute SynEditCppHighlighter::getTokenAttribute() const
case TokenKind::Identifier: case TokenKind::Identifier:
return mIdentifierAttribute; return mIdentifierAttribute;
case TokenKind::Key: case TokenKind::Key:
return mKeyAttribute; return mKeywordAttribute;
case TokenKind::Number: case TokenKind::Number:
return mNumberAttribute; return mNumberAttribute;
case TokenKind::Float: case TokenKind::Float:

View File

@ -56,8 +56,6 @@ public:
PSynHighlighterAttribute invalidAttribute() const; PSynHighlighterAttribute invalidAttribute() const;
PSynHighlighterAttribute keyAttribute() const;
PSynHighlighterAttribute numberAttribute() const; PSynHighlighterAttribute numberAttribute() const;
PSynHighlighterAttribute floatAttribute() const; PSynHighlighterAttribute floatAttribute() const;
@ -148,7 +146,6 @@ private:
PSynHighlighterAttribute mAsmAttribute; PSynHighlighterAttribute mAsmAttribute;
PSynHighlighterAttribute mDirecAttribute; PSynHighlighterAttribute mDirecAttribute;
PSynHighlighterAttribute mInvalidAttribute; PSynHighlighterAttribute mInvalidAttribute;
PSynHighlighterAttribute mKeyAttribute;
PSynHighlighterAttribute mNumberAttribute; PSynHighlighterAttribute mNumberAttribute;
PSynHighlighterAttribute mFloatAttribute; PSynHighlighterAttribute mFloatAttribute;
PSynHighlighterAttribute mHexAttribute; PSynHighlighterAttribute mHexAttribute;

View File

@ -87,6 +87,11 @@ Settings::Environment &Settings::environment()
return mEnvironment; return mEnvironment;
} }
Settings::Executor &Settings::executor()
{
return mExecutor;
}
QString Settings::filename() const QString Settings::filename() const
{ {
return mFilename; return mFilename;