refactor: highlighter, work save

This commit is contained in:
Roy Qu 2022-11-23 12:51:23 +08:00
parent e352ef345c
commit b3a986f1ca
12 changed files with 57 additions and 242 deletions

View File

@ -17,6 +17,7 @@
#include "HighlighterManager.h" #include "HighlighterManager.h"
#include <QFileInfo> #include <QFileInfo>
#include <QObject> #include <QObject>
#include "qsynedit/Constants.h"
#include "qsynedit/highlighter/cpp.h" #include "qsynedit/highlighter/cpp.h"
#include "qsynedit/highlighter/asm.h" #include "qsynedit/highlighter/asm.h"
#include "qsynedit/highlighter/glsl.h" #include "qsynedit/highlighter/glsl.h"
@ -79,68 +80,18 @@ QSynedit::PHighlighter HighlighterManager::copyHighlighter(QSynedit::PHighlighte
QSynedit::PHighlighter HighlighterManager::getCppHighlighter() QSynedit::PHighlighter HighlighterManager::getCppHighlighter()
{ {
std::shared_ptr<QSynedit::CppHighlighter> highlighter = std::make_shared<QSynedit::CppHighlighter>(); std::shared_ptr<QSynedit::CppHighlighter> highlighter = std::make_shared<QSynedit::CppHighlighter>();
highlighter->asmAttribute()->setForeground(Qt::blue);
highlighter->charAttribute()->setForeground(Qt::black);
highlighter->commentAttribute()->setForeground(0x8C8C8C);
highlighter->commentAttribute()->setStyles(QSynedit::FontStyle::fsItalic);
highlighter->classAttribute()->setForeground(0x008080);
highlighter->floatAttribute()->setForeground(Qt::darkMagenta);
highlighter->functionAttribute()->setForeground(0x00627A);
highlighter->globalVarAttribute()->setForeground(0x660E7A);
highlighter->hexAttribute()->setForeground(Qt::darkMagenta);
highlighter->identifierAttribute()->setForeground(0x080808);
highlighter->invalidAttribute()->setForeground(Qt::red);
highlighter->localVarAttribute()->setForeground(Qt::black);
highlighter->numberAttribute()->setForeground(0x1750EB);
highlighter->octAttribute()->setForeground(Qt::darkMagenta);
highlighter->preprocessorAttribute()->setForeground(0x1f542e);
highlighter->keywordAttribute()->setForeground(0x0033b3);
highlighter->whitespaceAttribute()->setForeground(Qt::lightGray);
highlighter->stringAttribute()->setForeground(0x007d17);
highlighter->stringEscapeSequenceAttribute()->setForeground(Qt::red);
highlighter->symbolAttribute()->setForeground(0xc10000);
highlighter->variableAttribute()->setForeground(0x400080);
return highlighter; return highlighter;
} }
QSynedit::PHighlighter HighlighterManager::getAsmHighlighter() QSynedit::PHighlighter HighlighterManager::getAsmHighlighter()
{ {
std::shared_ptr<QSynedit::ASMHighlighter> highlighter=std::make_shared<QSynedit::ASMHighlighter>(); std::shared_ptr<QSynedit::ASMHighlighter> highlighter=std::make_shared<QSynedit::ASMHighlighter>();
highlighter->commentAttribute()->setForeground(0x8C8C8C);
highlighter->commentAttribute()->setStyles(QSynedit::FontStyle::fsItalic);
highlighter->identifierAttribute()->setForeground(0x080808);
highlighter->keywordAttribute()->setForeground(0x0033b3);
highlighter->numberAttribute()->setForeground(0x1750EB);
highlighter->whitespaceAttribute()->setForeground(Qt::lightGray);
highlighter->stringAttribute()->setForeground(0x007d17);
highlighter->symbolAttribute()->setForeground(0xc10000);
return highlighter; return highlighter;
} }
QSynedit::PHighlighter HighlighterManager::getGLSLHighlighter() QSynedit::PHighlighter HighlighterManager::getGLSLHighlighter()
{ {
std::shared_ptr<QSynedit::GLSLHighlighter> highlighter=std::make_shared<QSynedit::GLSLHighlighter>(); std::shared_ptr<QSynedit::GLSLHighlighter> highlighter=std::make_shared<QSynedit::GLSLHighlighter>();
highlighter->asmAttribute()->setForeground(Qt::blue);
highlighter->charAttribute()->setForeground(Qt::black);
highlighter->commentAttribute()->setForeground(0x8C8C8C);
highlighter->commentAttribute()->setStyles(QSynedit::FontStyle::fsItalic);
highlighter->classAttribute()->setForeground(0x008080);
highlighter->floatAttribute()->setForeground(Qt::darkMagenta);
highlighter->functionAttribute()->setForeground(0x00627A);
highlighter->globalVarAttribute()->setForeground(0x660E7A);
highlighter->hexAttribute()->setForeground(Qt::darkMagenta);
highlighter->identifierAttribute()->setForeground(0x080808);
highlighter->invalidAttribute()->setForeground(Qt::red);
highlighter->localVarAttribute()->setForeground(Qt::black);
highlighter->numberAttribute()->setForeground(0x1750EB);
highlighter->octAttribute()->setForeground(Qt::darkMagenta);
highlighter->preprocessorAttribute()->setForeground(0x1f542e);
highlighter->keywordAttribute()->setForeground(0x0033b3);
highlighter->whitespaceAttribute()->setForeground(Qt::lightGray);
highlighter->stringAttribute()->setForeground(0x007d17);
highlighter->stringEscapeSequenceAttribute()->setForeground(Qt::red);
highlighter->symbolAttribute()->setForeground(0xc10000);
highlighter->variableAttribute()->setForeground(0x400080);
return highlighter; return highlighter;
} }

View File

@ -227,7 +227,7 @@ PSearchResultTreeItem CppRefacter::findOccurenceInFile(
int start = editor.highlighter()->getTokenPos() + 1; int start = editor.highlighter()->getTokenPos() + 1;
QString token = editor.highlighter()->getToken(); QString token = editor.highlighter()->getToken();
QSynedit::PHighlighterAttribute attr = editor.highlighter()->getTokenAttribute(); QSynedit::PHighlighterAttribute attr = editor.highlighter()->getTokenAttribute();
if (!attr || attr!=editor.highlighter()->commentAttribute()) { if (attr && attr->tokenType()==QSynedit::TokenType::Identifier) {
if (token == statement->command) { if (token == statement->command) {
//same name symbol , test if the same statement; //same name symbol , test if the same statement;
QSynedit::BufferCoord p; QSynedit::BufferCoord p;

View File

@ -972,7 +972,7 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
} }
} }
} }
} else if (mParser->enabled() && attr == highlighter()->identifierAttribute()) { } else if (mParser->enabled() && attr->tokenType() == QSynedit::TokenType::Identifier) {
QSynedit::BufferCoord p{aChar,line}; QSynedit::BufferCoord p{aChar,line};
// BufferCoord pBeginPos,pEndPos; // BufferCoord pBeginPos,pEndPos;
// QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation); // QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation);
@ -1022,7 +1022,7 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
//selection //selection
if (highlighter() && attr) { if (highlighter() && attr) {
if (attr == highlighter()->keywordAttribute()) { if (attr->tokenType() == QSynedit::TokenType::Keyword) {
if (CppTypeKeywords.contains(token) if (CppTypeKeywords.contains(token)
|| ||
( (
@ -1046,9 +1046,9 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
} }
} }
} }
if (((attr == highlighter()->identifierAttribute()) if (((attr->tokenType() == QSynedit::TokenType::Identifier)
|| (attr == highlighter()->keywordAttribute()) || (attr->tokenType() == QSynedit::TokenType::Keyword)
|| (attr->name() == SYNS_AttrPreprocessor) || (attr->tokenType() == QSynedit::TokenType::Preprocessor)
) )
&& (token == mCurrentHighlightedWord)) { && (token == mCurrentHighlightedWord)) {
if (mCurrentHighlighWordForeground.isValid()) if (mCurrentHighlighWordForeground.isValid())
@ -1710,7 +1710,7 @@ void Editor::onStatusChanged(QSynedit::StatusChanges changes)
QSynedit::PHighlighterAttribute attr; QSynedit::PHighlighterAttribute attr;
QString token; QString token;
if (getHighlighterAttriAtRowCol(coord,token,attr) if (getHighlighterAttriAtRowCol(coord,token,attr)
&& attr == highlighter()->symbolAttribute()) { && attr->tokenType() == QSynedit::TokenType::Operator) {
QSynedit::BufferCoord complementCharPos = getMatchingBracketEx(coord); QSynedit::BufferCoord complementCharPos = getMatchingBracketEx(coord);
if (!foldHidesLine(coord.line) if (!foldHidesLine(coord.line)
&& !foldHidesLine(complementCharPos.line)) { && !foldHidesLine(complementCharPos.line)) {
@ -1961,11 +1961,13 @@ QStringList Editor::getExpressionAtPosition(
QSynedit::PHighlighterAttribute attr = highlighter->getTokenAttribute(); QSynedit::PHighlighterAttribute attr = highlighter->getTokenAttribute();
if ( (line == pos.line-1) if ( (line == pos.line-1)
&& (start<=ch) && (ch<=endPos)) { && (start<=ch) && (ch<=endPos)) {
if (attr==highlighter->commentAttribute() || attr == highlighter->stringAttribute()) { if (attr->tokenType() == QSynedit::TokenType::Comment
|| attr->tokenType() == QSynedit::TokenType::String) {
return result; return result;
} }
} }
if (attr!=highlighter->commentAttribute() && attr!=highlighter->whitespaceAttribute()){ if (attr->tokenType() != QSynedit::TokenType::Comment
&& attr->tokenType() != QSynedit::TokenType::Space){
tokens.append(token); tokens.append(token);
} }
highlighter->next(); highlighter->next();
@ -3744,8 +3746,8 @@ void Editor::updateFunctionTip(bool showTip)
if (start>=currentChar) if (start>=currentChar)
break; break;
if (attr != highlighter()->commentAttribute() if (attr->tokenType() != QSynedit::TokenType::Comment
&& attr!=highlighter()->whitespaceAttribute()) { && attr->tokenType() != QSynedit::TokenType::Space) {
if (foundFunctionStart) { if (foundFunctionStart) {
if (attr!=highlighter()->identifierAttribute()) if (attr!=highlighter()->identifierAttribute())
return; // not a function return; // not a function
@ -3755,7 +3757,7 @@ void Editor::updateFunctionTip(bool showTip)
} }
tokens.append(token); tokens.append(token);
positions.append(start); positions.append(start);
} else if (attr == highlighter()->commentAttribute() } else if (attr->tokenType() == QSynedit::TokenType::Comment
&& currentLine == caretPos.line-1 && start<caretPos.ch && currentLine == caretPos.line-1 && start<caretPos.ch
&& start+token.length()>=caretPos.ch) { && start+token.length()>=caretPos.ch) {
return; // in comment, do nothing return; // in comment, do nothing

View File

@ -4594,9 +4594,8 @@ PStatement CppParser::doParseEvalTypeInfo(
pointerLevel++; pointerLevel++;
else if (token == "&") else if (token == "&")
pointerLevel--; pointerLevel--;
else if (highlighter.getTokenAttribute() == highlighter.identifierAttribute()) { else if (highlighter.getTokenAttribute()->tokenType() == QSynedit::TokenType::Identifier) {
if (token!= "const") baseType += token;
baseType += token;
} else if (token == "[") { } else if (token == "[") {
pointerLevel++; pointerLevel++;
bracketLevel++; bracketLevel++;

View File

@ -30,154 +30,29 @@ extern const QChar SoftBreakGlyph;
#define MAX_SCROLL 65535 #define MAX_SCROLL 65535
#define SYN_ATTR_COMMENT 0
#define SYN_ATTR_IDENTIFIER 1
#define SYN_ATTR_KEYWORD 2
#define SYN_ATTR_STRING 3
#define SYN_ATTR_WHITESPACE 4
#define SYN_ATTR_SYMBOL 5
// names for highlighter attributes // names for highlighter attributes
#define SYNS_AttrAreaAIdentifier "Area A Identifier"
#define SYNS_AttrArrowHead "ArrowHead"
#define SYNS_AttrAsm "Asm"
#define SYNS_AttrAsmComment "Asm Comment"
#define SYNS_AttrAsmKey "Asm Key"
#define SYNS_AttrAssembler "Assembler" #define SYNS_AttrAssembler "Assembler"
#define SYNS_AttrAttribute "Attribute"
#define SYNS_AttrAttributeName "Attribute Name"
#define SYNS_AttrAttributeValue "Attribute Value"
#define SYNS_AttrBasicTypes "Basic Types"
#define SYNS_AttrBlock "Block"
#define SYNS_AttrBoolean "Boolean value"
#define SYNS_AttrBrackets "Brackets"
#define SYNS_AttrCDATASection "CDATA Section"
#define SYNS_AttrCharacter "Character" #define SYNS_AttrCharacter "Character"
#define SYNS_AttrClass "Class" #define SYNS_AttrClass "Class"
#define SYNS_AttrColor "Color Value"
#define SYNS_AttrComment "Comment" #define SYNS_AttrComment "Comment"
#define SYNS_AttrCondition "Condition"
#define SYNS_AttrConditionalComment "Conditional Comment"
#define SYNS_AttrDataType "Data Type"
#define SYNS_AttrDebugLines "Debugging Lines"
#define SYNS_AttrDefaultPackage "Default Packages"
#define SYNS_AttrDelimitedIdentifier "Delimited Identifier"
#define SYNS_AttrDir "Direction"
#define SYNS_AttrDirections "Directions"
#define SYNS_AttrDirective "Directive"
#define SYNS_AttrDOCTYPESection "DOCTYPE Section"
#define SYNS_AttrDocumentation "Documentation"
#define SYNS_AttrElementName "Element Name"
#define SYNS_AttrEmbedSQL "Embedded SQL"
#define SYNS_AttrEmbedText "Embedded Text"
#define SYNS_AttrEntityReference "Entity Reference"
#define SYNS_AttrEscapeAmpersand "Escape Ampersand"
#define SYNS_AttrEvent "Event"
#define SYNS_AttrException "Exception"
#define SYNS_AttrFirstTri "FirstTri"
#define SYNS_AttrFloat "Float" #define SYNS_AttrFloat "Float"
#define SYNS_AttrForm "Form"
#define SYNS_AttrFourthTri "FourthTri"
#define SYNS_AttrFunction "Function" #define SYNS_AttrFunction "Function"
#define SYNS_AttrFunctionParameter "Function Parameter"
#define SYNS_AttrGlobalVariable "Global variable" #define SYNS_AttrGlobalVariable "Global variable"
#define SYNS_AttrHexadecimal "Hexadecimal" #define SYNS_AttrHexadecimal "Hexadecimal"
#define SYNS_AttrIcon "Icon Reference"
#define SYNS_AttrIdentifier "Identifier" #define SYNS_AttrIdentifier "Identifier"
#define SYNS_AttrReserveWord_Type "Reserve Word for Types" #define SYNS_AttrReserveWord_Type "Reserve Word for Types"
#define SYNS_AttrIllegalChar "Illegal Char" #define SYNS_AttrIllegalChar "Illegal Char"
#define SYNS_AttrInclude "Include"
#define SYNS_AttrIndicator "Indicator Area"
#define SYNS_AttrIndirect "Indirect"
#define SYNS_AttrInvalidSymbol "Invalid Symbol"
#define SYNS_AttrInternalFunction "Internal Function"
#define SYNS_AttrKey "Key"
#define SYNS_AttrLabel "Label"
#define SYNS_AttrLace "Lace"
#define SYNS_AttrLocalVariable "Local Variable" #define SYNS_AttrLocalVariable "Local Variable"
#define SYNS_AttrLine "Line"
#define SYNS_AttrMacro "Macro"
#define SYNS_AttrMarker "Marker" #define SYNS_AttrMarker "Marker"
#define SYNS_AttrMathMode "Math Mode"
#define SYNS_AttrMessage "Message"
#define SYNS_AttrMiscellaneous "Miscellaneous"
#define SYNS_AttrNamespaceAttrName "Namespace Attribute Name"
#define SYNS_AttrNamespaceAttrValue "Namespace Attribute Value"
#define SYNS_AttrNonReservedKeyword "Non-reserved Keyword"
#define SYNS_AttrNull "Null"
#define SYNS_AttrNumber "Number" #define SYNS_AttrNumber "Number"
#define SYNS_AttrOctal "Octal" #define SYNS_AttrOctal "Octal"
#define SYNS_AttrOperator "Operator"
#define SYNS_AttrOperatorAndSymbols "Operator And Symbols"
#define SYNS_AttrOpLine "OpLine"
#define SYNS_AttrPLSQL "PL/SQL Reserved Word"
#define SYNS_AttrPragma "Pragma"
#define SYNS_AttrPredefined "Predefined"
#define SYNS_AttrPreprocessor "Preprocessor" #define SYNS_AttrPreprocessor "Preprocessor"
#define SYNS_AttrProcessingInstr "Processing Instruction"
#define SYNS_AttrQuad "Quad"
#define SYNS_AttrQualifier "Qualifier"
#define SYNS_AttrRegister "Register"
#define SYNS_AttrReservedWord "Reserved Word" #define SYNS_AttrReservedWord "Reserved Word"
#define SYNS_AttrResultValue "Result Value"
#define SYNS_AttrRoundBracket "Round Bracket"
#define SYNS_AttrRpl "Rpl"
#define SYNS_AttrRplKey "Rpl Key"
#define SYNS_AttrRplComment "Rpl Comment"
#define SYNS_AttrSASM "SASM"
#define SYNS_AttrSASMComment "SASM Comment"
#define SYNS_AttrSASMKey "SASM Key"
#define SYNS_AttrSecondReservedWord "Second Reserved Word"
#define SYNS_AttrSecondTri "SecondTri"
#define SYNS_AttrSection "Section"
#define SYNS_AttrSequence "Sequence Number Area"
#define SYNS_AttrShape "Shape"
#define SYNS_AttrSingleString "Single Quoted String"
#define SYNS_AttrSpace "Space"
#define SYNS_AttrSpecialVariable "Special Variable"
#define SYNS_AttrSQLKey "SQL Keyword"
#define SYNS_AttrSQLPlus "SQL*Plus Command"
#define SYNS_AttrSquareBracket "Square Bracket"
#define SYNS_AttrString "String" #define SYNS_AttrString "String"
#define SYNS_AttrStringEscapeSequences "Escape sequences" #define SYNS_AttrStringEscapeSequences "Escape sequences"
#define SYNS_AttrSymbol "Symbol" #define SYNS_AttrSymbol "Symbol"
#define SYNS_AttrSyntaxError "Syntax Error"
#define SYNS_AttrSystem "System Functions and Variables"
#define SYNS_AttrSystemValue "System Value"
#define SYNS_AttrTagArea "Tag Area"
#define SYNS_AttrTableName "Table Name"
#define SYNS_AttrTerminator "Terminator"
#define SYNS_AttrTeXCommand "TeX Command"
#define SYNS_AttrText "Text"
#define SYNS_AttrTextMathMode "Text in Math Mode"
#define SYNS_AttrThirdTri "ThirdTri"
#define SYNS_AttrTriangle "Triangle"
#define SYNS_AttrUnknownWord "Unknown Word"
#define SYNS_AttrURI "URI"
#define SYNS_AttrUser "User Functions and Variables"
#define SYNS_AttrUserFunction "User Functions"
#define SYNS_AttrValue "Value"
#define SYNS_AttrVariable "Variable" #define SYNS_AttrVariable "Variable"
#define SYNS_AttrVisitedURI "Visited URI" #define SYNS_AttrSpace "Space"
#define SYNS_AttrVrmlAppearance "Vrml_Appearance"
#define SYNS_AttrVrmlAttribute "Vrml_Attribute"
#define SYNS_AttrVrmlDefinition "Vrml_Definition"
#define SYNS_AttrVrmlEvent "Vrml_Event"
#define SYNS_AttrVrmlGrouping "Vrml_Grouping"
#define SYNS_AttrVrmlInterpolator "Vrml_Interpolator"
#define SYNS_AttrVrmlLight "Vrml_Light"
#define SYNS_AttrVrmlNode "Vrml_Node"
#define SYNS_AttrVrmlParameter "Vrml_Parameter"
#define SYNS_AttrVrmlProto "Vrml_Proto"
#define SYNS_AttrVrmlSensor "Vrml_Sensor"
#define SYNS_AttrVrmlShape "Vrml_Shape"
#define SYNS_AttrVrmlShape_Hint "Vrml_Shape_Hint"
#define SYNS_AttrVrmlTime_dependent "Vrml_Time_dependent"
#define SYNS_AttrVrmlViewpoint "Vrml_Viewpoint"
#define SYNS_AttrVrmlWorldInfo "Vrml_WorldInfo"
#define SYNS_AttrWhitespace "Whitespace"
#define SYNS_AttrX3DDocType "X3DDocType"
#define SYNS_AttrX3DHeader "X3DHeader"
// names of exporter output formats // names of exporter output formats
#define SYNS_ExporterFormatHTML "HTML" #define SYNS_ExporterFormatHTML "HTML"
#define SYNS_ExporterFormatRTF "RTF" #define SYNS_ExporterFormatRTF "RTF"

View File

@ -518,9 +518,9 @@ BufferCoord SynEdit::getMatchingBracketEx(BufferCoord APoint)
isCommentOrStringOrChar = false; isCommentOrStringOrChar = false;
if (getHighlighterAttriAtRowCol(p, vDummy, attr)) if (getHighlighterAttriAtRowCol(p, vDummy, attr))
isCommentOrStringOrChar = isCommentOrStringOrChar =
(attr == mHighlighter->stringAttribute()) || (attr->tokenType() == TokenType::String) ||
(attr == mHighlighter->commentAttribute()) || (attr->tokenType() == TokenType::Comment) ||
(attr->name() == SYNS_AttrCharacter); (attr->tokenType() == TokenType::Character);
if ((Test == BracketInc) && (!isCommentOrStringOrChar)) if ((Test == BracketInc) && (!isCommentOrStringOrChar))
NumBrackets++; NumBrackets++;
else if ((Test == BracketDec) && (!isCommentOrStringOrChar)) { else if ((Test == BracketDec) && (!isCommentOrStringOrChar)) {
@ -552,9 +552,9 @@ BufferCoord SynEdit::getMatchingBracketEx(BufferCoord APoint)
isCommentOrStringOrChar = false; isCommentOrStringOrChar = false;
if (getHighlighterAttriAtRowCol(p, vDummy, attr)) if (getHighlighterAttriAtRowCol(p, vDummy, attr))
isCommentOrStringOrChar = isCommentOrStringOrChar =
(attr == mHighlighter->stringAttribute()) || (attr->tokenType() == TokenType::String) ||
(attr == mHighlighter->commentAttribute()) || (attr->tokenType() == TokenType::Comment) ||
(attr->name() == SYNS_AttrCharacter); (attr->tokenType() == TokenType::Character);
else else
isCommentOrStringOrChar = false; isCommentOrStringOrChar = false;
if ((Test == BracketInc) && (!isCommentOrStringOrChar)) if ((Test == BracketInc) && (!isCommentOrStringOrChar))
@ -1294,9 +1294,9 @@ BufferCoord SynEdit::getPreviousLeftBrace(int x, int y)
if (Test=='{' || Test == '}') { if (Test=='{' || Test == '}') {
if (getHighlighterAttriAtRowCol(p, vDummy, attr)) { if (getHighlighterAttriAtRowCol(p, vDummy, attr)) {
isCommentOrStringOrChar = isCommentOrStringOrChar =
(attr == mHighlighter->stringAttribute()) || (attr->tokenType() == TokenType::String) ||
(attr == mHighlighter->commentAttribute()) || (attr->tokenType() == TokenType::Comment) ||
(attr->name() == SYNS_AttrCharacter); (attr->tokenType() == TokenType::Character);
} else } else
isCommentOrStringOrChar = false; isCommentOrStringOrChar = false;
if ((Test == '{') && (! isCommentOrStringOrChar)) if ((Test == '{') && (! isCommentOrStringOrChar))
@ -1588,7 +1588,7 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
HighlighterState rangeAfterFirstToken = mHighlighter->getState(); HighlighterState rangeAfterFirstToken = mHighlighter->getState();
QString firstToken = mHighlighter->getToken(); QString firstToken = mHighlighter->getToken();
PHighlighterAttribute attr = mHighlighter->getTokenAttribute(); PHighlighterAttribute attr = mHighlighter->getTokenAttribute();
if (attr == mHighlighter->keywordAttribute() if (attr->tokenType() == TokenType::Keyword
&& lineText.endsWith(':') && lineText.endsWith(':')
&& ( && (
firstToken == "public" || firstToken == "private" firstToken == "public" || firstToken == "private"
@ -1606,13 +1606,13 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
int additionIndent = 0; int additionIndent = 0;
QVector<int> matchingIndents; QVector<int> matchingIndents;
int l; int l;
if (attr == mHighlighter->symbolAttribute() if (attr->tokenType() == TokenType::Operator
&& (firstToken == '}')) { && (firstToken == '}')) {
// current line starts with '}', we should consider it to calc indents // current line starts with '}', we should consider it to calc indents
matchingIndents = rangeAfterFirstToken.matchingIndents; matchingIndents = rangeAfterFirstToken.matchingIndents;
indentAdded = true; indentAdded = true;
l = startLine; l = startLine;
} else if (attr == mHighlighter->symbolAttribute() } else if (attr->tokenType() == TokenType::Operator
&& (firstToken == '{') && (firstToken == '{')
&& (rangePreceeding.getLastIndent()==sitStatement)) { && (rangePreceeding.getLastIndent()==sitStatement)) {
// current line starts with '{' and last statement not finished, we should consider it to calc indents // current line starts with '{' and last statement not finished, we should consider it to calc indents
@ -1724,7 +1724,7 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
coord.line = startLine; coord.line = startLine;
coord.ch = document()->getString(startLine-1).length(); coord.ch = document()->getString(startLine-1).length();
if (getHighlighterAttriAtRowCol(coord,token,attr) if (getHighlighterAttriAtRowCol(coord,token,attr)
&& attr == mHighlighter->symbolAttribute() && attr->tokenType() == QSynedit::TokenType::Operator
&& token == ":") { && token == ":") {
indentSpaces += tabWidth(); indentSpaces += tabWidth();
indentAdded = true; indentAdded = true;

View File

@ -766,7 +766,7 @@ void SynEditTextPainter::getBraceColorAttr(int level, PHighlighterAttribute &att
{ {
if (!edit->mOptions.testFlag(EditorOption::eoShowRainbowColor)) if (!edit->mOptions.testFlag(EditorOption::eoShowRainbowColor))
return; return;
if (attr != edit->mHighlighter->symbolAttribute()) if (!attr || attr->tokenType() != TokenType::Operator)
return; return;
PHighlighterAttribute oldAttr = attr; PHighlighterAttribute oldAttr = attr;
switch(level % 4) { switch(level % 4) {

View File

@ -57,22 +57,8 @@ const QSet<QString> ASMHighlighter::Keywords {
ASMHighlighter::ASMHighlighter() ASMHighlighter::ASMHighlighter()
{ {
mCommentAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrComment, TokenType::Comment);
mCommentAttribute->setStyles(FontStyle::fsItalic);
addAttribute(mCommentAttribute);
mIdentifierAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrIdentifier, TokenType::Identifier);
addAttribute(mIdentifierAttribute);
mKeywordAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrReservedWord, TokenType::Keyword);
mKeywordAttribute->setStyles(FontStyle::fsBold);
addAttribute(mKeywordAttribute);
mNumberAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrNumber, TokenType::Number); mNumberAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrNumber, TokenType::Number);
addAttribute(mNumberAttribute); addAttribute(mNumberAttribute);
mWhitespaceAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrSpace, TokenType::Space);
addAttribute(mWhitespaceAttribute);
mStringAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrString, TokenType::String);
addAttribute(mStringAttribute);
mSymbolAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrSymbol, TokenType::Operator);
addAttribute(mSymbolAttribute);
} }
PHighlighterAttribute ASMHighlighter::numberAttribute() PHighlighterAttribute ASMHighlighter::numberAttribute()

View File

@ -22,7 +22,24 @@ Highlighter::Highlighter() :
mEnabled(true), mEnabled(true),
mWordBreakChars{ WordBreakChars } mWordBreakChars{ WordBreakChars }
{ {
mCommentAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrComment,
TokenType::Comment);
addAttribute(mCommentAttribute);
mIdentifierAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrIdentifier,
TokenType::Identifier);
addAttribute(mIdentifierAttribute);
mKeywordAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrReservedWord,
TokenType::Keyword);
addAttribute(mKeywordAttribute);
mStringAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrString,
TokenType::String);
addAttribute(mStringAttribute);
mWhitespaceAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrSpace,
TokenType::Space);
addAttribute(mWhitespaceAttribute);
mSymbolAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrSymbol,
TokenType::Operator);
addAttribute(mSymbolAttribute);
} }
const QMap<QString, PHighlighterAttribute>& Highlighter::attributes() const const QMap<QString, PHighlighterAttribute>& Highlighter::attributes() const
@ -35,11 +52,6 @@ const QSet<QChar>& Highlighter::wordBreakChars() const
return mWordBreakChars; return mWordBreakChars;
} }
PHighlighterAttribute Highlighter::commentAttribute() const
{
return mCommentAttribute;
}
PHighlighterAttribute Highlighter::identifierAttribute() const PHighlighterAttribute Highlighter::identifierAttribute() const
{ {
return mIdentifierAttribute; return mIdentifierAttribute;
@ -50,6 +62,11 @@ PHighlighterAttribute Highlighter::keywordAttribute() const
return mKeywordAttribute; return mKeywordAttribute;
} }
PHighlighterAttribute Highlighter::commentAttribute() const
{
return mCommentAttribute;
}
PHighlighterAttribute Highlighter::stringAttribute() const PHighlighterAttribute Highlighter::stringAttribute() const
{ {
return mStringAttribute; return mStringAttribute;

View File

@ -124,13 +124,12 @@ public:
const QSet<QChar>& wordBreakChars() const; const QSet<QChar>& wordBreakChars() const;
PHighlighterAttribute commentAttribute() const;
PHighlighterAttribute identifierAttribute() const; PHighlighterAttribute identifierAttribute() const;
PHighlighterAttribute keywordAttribute() const; PHighlighterAttribute keywordAttribute() const;
PHighlighterAttribute commentAttribute() const;
PHighlighterAttribute stringAttribute() const; PHighlighterAttribute stringAttribute() const;
PHighlighterAttribute whitespaceAttribute() const; PHighlighterAttribute whitespaceAttribute() const;

View File

@ -165,9 +165,6 @@ CppHighlighter::CppHighlighter(): Highlighter()
mHexAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrHexadecimal, mHexAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrHexadecimal,
TokenType::Number); TokenType::Number);
addAttribute(mHexAttribute); addAttribute(mHexAttribute);
mIdentifierAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrIdentifier,
TokenType::Identifier);
addAttribute(mIdentifierAttribute);
mInvalidAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrIllegalChar, mInvalidAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrIllegalChar,
TokenType::Error); TokenType::Error);
addAttribute(mInvalidAttribute); addAttribute(mInvalidAttribute);
@ -184,10 +181,6 @@ CppHighlighter::CppHighlighter(): Highlighter()
TokenType::Preprocessor); TokenType::Preprocessor);
addAttribute(mPreprocessorAttribute); addAttribute(mPreprocessorAttribute);
mKeywordAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrReservedWord,
TokenType::Keyword);
addAttribute(mKeywordAttribute);
mStringEscapeSequenceAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrStringEscapeSequences, mStringEscapeSequenceAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrStringEscapeSequences,
TokenType::String); TokenType::String);
addAttribute(mStringEscapeSequenceAttribute); addAttribute(mStringEscapeSequenceAttribute);

View File

@ -105,9 +105,6 @@ GLSLHighlighter::GLSLHighlighter(): Highlighter()
mHexAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrHexadecimal, mHexAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrHexadecimal,
TokenType::Number); TokenType::Number);
addAttribute(mHexAttribute); addAttribute(mHexAttribute);
mIdentifierAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrIdentifier,
TokenType::Identifier);
addAttribute(mIdentifierAttribute);
mInvalidAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrIllegalChar, mInvalidAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrIllegalChar,
TokenType::Error); TokenType::Error);
addAttribute(mInvalidAttribute); addAttribute(mInvalidAttribute);
@ -124,10 +121,6 @@ GLSLHighlighter::GLSLHighlighter(): Highlighter()
TokenType::Preprocessor); TokenType::Preprocessor);
addAttribute(mPreprocessorAttribute); addAttribute(mPreprocessorAttribute);
mKeywordAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrReservedWord,
TokenType::Keyword);
addAttribute(mKeywordAttribute);
mStringEscapeSequenceAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrStringEscapeSequences, mStringEscapeSequenceAttribute = std::make_shared<HighlighterAttribute>(SYNS_AttrStringEscapeSequences,
TokenType::String); TokenType::String);
addAttribute(mStringEscapeSequenceAttribute); addAttribute(mStringEscapeSequenceAttribute);