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 <QObject>
#include "qsynedit/highlighter/cpp.h"
#include "qsynedit/highlighter/asm.h"
#include "qsynedit/Constants.h"
#include "colorscheme.h"
@ -57,7 +58,7 @@ PSynHighlighter HighlighterManager::getCppHighlighter()
highlighter->numberAttribute()->setForeground(0x1750EB);
highlighter->octAttribute()->setForeground(QColorConstants::Svg::purple);
highlighter->direcAttribute()->setForeground(0x1f542e);
highlighter->keyAttribute()->setForeground(0x0033b3);
highlighter->keywordAttribute()->setForeground(0x0033b3);
highlighter->whitespaceAttribute()->setForeground(QColorConstants::Svg::silver);
highlighter->stringAttribute()->setForeground(0x007d17);
highlighter->stringEscapeSequenceAttribute()->setForeground(QColorConstants::Svg::red);
@ -66,11 +67,28 @@ PSynHighlighter HighlighterManager::getCppHighlighter()
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)
{
if (!highlighter)
return;
if (highlighter->getName() == SYN_HIGHLIGHTER_CPP) {
if ( (highlighter->getName() == SYN_HIGHLIGHTER_CPP)
|| (highlighter->getName() == SYN_HIGHLIGHTER_ASM)
) {
for (QString name: highlighter->attributes().keys()) {
PColorSchemeItem item = pColorManager->getItem(schemeName,name);
if (item) {

View File

@ -10,6 +10,7 @@ public:
PSynHighlighter getHighlighter(const QString& filename);
PSynHighlighter copyHighlighter(PSynHighlighter highlighter);
PSynHighlighter getCppHighlighter();
PSynHighlighter getAsmHighlighter();
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) {
return;
}
if (!pSettings->compilerSets().defaultSet())
return;
mCompileErrorCount = 0;
mCompiler = new FileCompiler(filename,encoding,silent,onlyCheckSyntax);
mCompiler->setRebuild(rebuild);
@ -58,6 +60,8 @@ void CompilerManager::checkSyntax(const QString &filename, const QString &conten
if (mBackgroundSyntaxChecker!=nullptr) {
return;
}
if (!pSettings->compilerSets().defaultSet())
return;
mSyntaxCheckErrorCount = 0;
mBackgroundSyntaxChecker = new StdinCompiler(filename,content,true,true);
connect(mBackgroundSyntaxChecker, &Compiler::compileFinished, this ,&CompilerManager::onSyntaxCheckFinished);

View File

@ -636,9 +636,12 @@ void Editor::onModificationChanged(bool) {
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))) {
if (pSettings->editor().syntaxCheck() && pSettings->editor().syntaxCheckWhenLineChanged())
if (!readOnly() && pSettings->editor().syntaxCheck() && pSettings->editor().syntaxCheckWhenLineChanged())
pMainWindow->checkSyntaxInBack(this);
}
mLineCount = lines()->count();

View File

@ -210,6 +210,7 @@ public:
void setCaretXYCentered(bool ForceToMiddle, const BufferCoord& value);
void uncollapseAroundLine(int line);
PSynEditFoldRange foldHidesLine(int line);
void setSelText(const QString& Value);
int maxScrollWidth() const;
int maxScrollHeight() const;
@ -429,7 +430,6 @@ private:
void SetSelTextPrimitive(const QString& aValue);
void SetSelTextPrimitiveEx(SynSelectionMode PasteMode,
const QString& Value, bool AddToUndoList);
void setSelText(const QString& Value);
void DoLinesDeleted(int FirstLine, int Count);
void DoLinesInserted(int FirstLine, int Count);
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()
{
mTokenID = TokenKind::Comment;
@ -53,6 +78,128 @@ void SynEditASMHighlighter::CRProc()
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
{
return mTokenID == TokenKind::Null;
@ -124,6 +271,11 @@ SynHighlighterTokenType SynEditASMHighlighter::getTokenType()
return SynHighlighterTokenType::Default;
}
int SynEditASMHighlighter::getTokenPos()
{
return mTokenPos;
}
void SynEditASMHighlighter::next()
{
mTokenPos = mRun;
@ -203,3 +355,33 @@ QString SynEditASMHighlighter::getName() const
{
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
};
public:
explicit 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);
}
explicit SynEditASMHighlighter();
PSynHighlighterAttribute numberAttribute();
static const QSet<QString> Keywords;
private:
@ -53,6 +36,19 @@ private:
private:
void CommentProc();
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
public:
@ -72,6 +68,15 @@ public:
public:
SynHighlighterClass getClass() 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

View File

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

View File

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

View File

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