code clean

This commit is contained in:
Roy Qu 2024-04-10 21:10:26 +08:00
parent 7abbe2f6b5
commit ffafcd4416
8 changed files with 51 additions and 279 deletions

View File

@ -81,12 +81,6 @@ bool enumTokenAttributes(PSyntaxer syntaxer, bool skipDuplicates,
tokenAttriProc, params, syntaxerList); tokenAttriProc, params, syntaxerList);
} }
int mulDiv(int a, int b, int c)
{
//todo: handle overflow?
return a*b/c;
}
FontStyles getFontStyles(const QFont &font) FontStyles getFontStyles(const QFont &font)
{ {
FontStyles styles; FontStyles styles;

View File

@ -37,7 +37,6 @@ class QColor;
namespace QSynedit { namespace QSynedit {
int minMax(int x, int mi, int ma); int minMax(int x, int mi, int ma);
int mulDiv(int a, int b, int c);
BufferCoord maxBufferCoord(const BufferCoord& P1, const BufferCoord& P2); BufferCoord maxBufferCoord(const BufferCoord& P1, const BufferCoord& P2);
BufferCoord minBufferCoord(const BufferCoord& P1, const BufferCoord& P2); BufferCoord minBufferCoord(const BufferCoord& P1, const BufferCoord& P2);

View File

@ -220,110 +220,10 @@ CppSyntaxer::CppSyntaxer(): Syntaxer()
resetState(); resetState();
} }
const PTokenAttribute &CppSyntaxer::preprocessorAttribute() const
{
return mPreprocessorAttribute;
}
const PTokenAttribute &CppSyntaxer::invalidAttribute() const
{
return mInvalidAttribute;
}
const PTokenAttribute &CppSyntaxer::numberAttribute() const
{
return mNumberAttribute;
}
const PTokenAttribute &CppSyntaxer::floatAttribute() const
{
return mFloatAttribute;
}
const PTokenAttribute &CppSyntaxer::hexAttribute() const
{
return mHexAttribute;
}
const PTokenAttribute &CppSyntaxer::octAttribute() const
{
return mOctAttribute;
}
const PTokenAttribute &CppSyntaxer::stringEscapeSequenceAttribute() const
{
return mStringEscapeSequenceAttribute;
}
const PTokenAttribute &CppSyntaxer::charAttribute() const
{
return mCharAttribute;
}
const PTokenAttribute &CppSyntaxer::variableAttribute() const
{
return mVariableAttribute;
}
const PTokenAttribute &CppSyntaxer::functionAttribute() const
{
return mFunctionAttribute;
}
const PTokenAttribute &CppSyntaxer::classAttribute() const
{
return mClassAttribute;
}
const PTokenAttribute &CppSyntaxer::globalVarAttribute() const
{
return mGlobalVarAttribute;
}
const PTokenAttribute &CppSyntaxer::localVarAttribute() const
{
return mLocalVarAttribute;
}
bool CppSyntaxer::isStringToNextLine(int state)
{
return state == RangeState::rsStringNextLine;
}
bool CppSyntaxer::isRawStringStart(int state)
{
return state == RangeState::rsRawString;
}
bool CppSyntaxer::isRawStringNoEscape(int state)
{
return state == RangeState::rsRawStringNotEscaping;
}
bool CppSyntaxer::isRawStringEnd(int state)
{
return state == RangeState::rsRawStringEnd;
}
bool CppSyntaxer::isCharNotFinished(int state)
{
return state == RangeState::rsChar || state == RangeState::rsCharEscaping;
}
bool CppSyntaxer::isCharEscaping(int state)
{
return state == RangeState::rsCharEscaping;
}
bool CppSyntaxer::isInAttribute(const SyntaxState &state) bool CppSyntaxer::isInAttribute(const SyntaxState &state)
{ {
return state.extraData.contains(DATA_KEY_IN_ATTRIBUTE) return state.extraData.contains(DATA_KEY_IN_ATTRIBUTE)
&& state.extraData[DATA_KEY_IN_ATTRIBUTE].toBool(); && state.extraData[DATA_KEY_IN_ATTRIBUTE].toBool();
}
CppSyntaxer::TokenId CppSyntaxer::getTokenId()
{
return mTokenId;
} }
void CppSyntaxer::procAndSymbol() void CppSyntaxer::procAndSymbol()

View File

@ -60,31 +60,31 @@ public:
CppSyntaxer(const CppSyntaxer&)=delete; CppSyntaxer(const CppSyntaxer&)=delete;
CppSyntaxer operator=(const CppSyntaxer&)=delete; CppSyntaxer operator=(const CppSyntaxer&)=delete;
const PTokenAttribute &preprocessorAttribute() const; const PTokenAttribute &preprocessorAttribute() const { return mPreprocessorAttribute; }
const PTokenAttribute &invalidAttribute() const; const PTokenAttribute &invalidAttribute() const { return mInvalidAttribute; }
const PTokenAttribute &numberAttribute() const; const PTokenAttribute &numberAttribute() const { return mNumberAttribute; }
const PTokenAttribute &floatAttribute() const; const PTokenAttribute &floatAttribute() const { return mFloatAttribute; }
const PTokenAttribute &hexAttribute() const; const PTokenAttribute &hexAttribute() const { return mHexAttribute; }
const PTokenAttribute &octAttribute() const; const PTokenAttribute &octAttribute() const { return mOctAttribute; }
const PTokenAttribute &stringEscapeSequenceAttribute() const; const PTokenAttribute &stringEscapeSequenceAttribute() const { return mStringEscapeSequenceAttribute; }
const PTokenAttribute &charAttribute() const; const PTokenAttribute &charAttribute() const { return mCharAttribute; }
const PTokenAttribute &variableAttribute() const; const PTokenAttribute &variableAttribute() const { return mVariableAttribute; }
const PTokenAttribute &functionAttribute() const; const PTokenAttribute &functionAttribute() const { return mFunctionAttribute; }
const PTokenAttribute &classAttribute() const; const PTokenAttribute &classAttribute() const { return mClassAttribute; }
const PTokenAttribute &globalVarAttribute() const; const PTokenAttribute &globalVarAttribute() const { return mGlobalVarAttribute; }
const PTokenAttribute &localVarAttribute() const; const PTokenAttribute &localVarAttribute() const { return mLocalVarAttribute; }
static const QSet<QString> Keywords; static const QSet<QString> Keywords;
@ -92,15 +92,15 @@ public:
static const QSet<QString> StandardAttributes; static const QSet<QString> StandardAttributes;
bool isStringToNextLine(int state); bool isStringToNextLine(int state) { return state == RangeState::rsStringNextLine; }
bool isRawStringStart(int state); bool isRawStringStart(int state) { return state == RangeState::rsRawString; }
bool isRawStringNoEscape(int state); bool isRawStringNoEscape(int state) { return state == RangeState::rsRawStringNotEscaping; }
bool isRawStringEnd(int state); bool isRawStringEnd(int state) { return state == RangeState::rsRawStringEnd; }
bool isCharNotFinished(int state); bool isCharNotFinished(int state) { return state == RangeState::rsChar || state == RangeState::rsCharEscaping; }
bool isCharEscaping(int state); bool isCharEscaping(int state) { return state == RangeState::rsCharEscaping; }
bool isInAttribute(const SyntaxState &state); bool isInAttribute(const SyntaxState &state);
TokenId getTokenId(); TokenId getTokenId() { return mTokenId; }
private: private:
void procAndSymbol(); void procAndSymbol();
void procCppStyleComment(); void procCppStyleComment();
@ -159,7 +159,6 @@ private:
private: private:
SyntaxState mRange; SyntaxState mRange;
// SynRangeState mSpaceRange;
QString mLine; QString mLine;
int mLineSize; int mLineSize;
int mRun; int mRun;

View File

@ -41,46 +41,6 @@ Syntaxer::Syntaxer() :
addAttribute(mSymbolAttribute); addAttribute(mSymbolAttribute);
} }
QMap<QString, PTokenAttribute> Syntaxer::attributes() const
{
return mAttributes;
}
const QSet<QChar>& Syntaxer::wordBreakChars() const
{
return mWordBreakChars;
}
const PTokenAttribute& Syntaxer::identifierAttribute() const
{
return mIdentifierAttribute;
}
const PTokenAttribute &Syntaxer::keywordAttribute() const
{
return mKeywordAttribute;
}
const PTokenAttribute &Syntaxer::commentAttribute() const
{
return mCommentAttribute;
}
const PTokenAttribute& Syntaxer::stringAttribute() const
{
return mStringAttribute;
}
const PTokenAttribute& Syntaxer::whitespaceAttribute() const
{
return mWhitespaceAttribute;
}
const PTokenAttribute& Syntaxer::symbolAttribute() const
{
return mSymbolAttribute;
}
bool Syntaxer::isKeyword(const QString &) bool Syntaxer::isKeyword(const QString &)
{ {
return false; return false;
@ -153,48 +113,17 @@ bool Syntaxer::isWordBreakChar(const QChar &ch)
bool Syntaxer::isIdentChar(const QChar &ch) const bool Syntaxer::isIdentChar(const QChar &ch) const
{ {
if (ch == '_') { return (ch == '_')
return true; || ((ch>='0') && (ch <= '9'))
} || ((ch>='a') && (ch <= 'z'))
if ((ch>='0') && (ch <= '9')) { || ((ch>='A') && (ch <= 'Z'));
return true;
}
if ((ch>='a') && (ch <= 'z')) {
return true;
}
if ((ch>='A') && (ch <= 'Z')) {
return true;
}
return false;
} }
bool Syntaxer::isIdentStartChar(const QChar &ch) const bool Syntaxer::isIdentStartChar(const QChar &ch) const
{ {
if (ch == '_') { return (ch == '_')
return true; || ((ch>='a') && (ch <= 'z'))
} || ((ch>='A') && (ch <= 'Z'));
if ((ch>='a') && (ch <= 'z')) {
return true;
}
if ((ch>='A') && (ch <= 'Z')) {
return true;
}
return false;
}
void Syntaxer::addAttribute(PTokenAttribute attribute)
{
mAttributes[attribute->name()]=attribute;
}
void Syntaxer::clearAttributes()
{
mAttributes.clear();
}
int Syntaxer::attributesCount() const
{
return mAttributes.size();
} }
PTokenAttribute Syntaxer::getAttribute(const QString& name) const PTokenAttribute Syntaxer::getAttribute(const QString& name) const
@ -217,48 +146,6 @@ QString Syntaxer::blockCommentEndSymbol()
return QString(); return QString();
} }
FontStyles TokenAttribute::styles() const
{
return mStyles;
}
void TokenAttribute::setStyles(const FontStyles &styles)
{
if (mStyles!=styles) {
mStyles = styles;
}
}
const QColor& TokenAttribute::foreground() const
{
return mForeground;
}
void TokenAttribute::setForeground(const QColor &color)
{
mForeground = color;
}
const QColor &TokenAttribute::background() const
{
return mBackground;
}
void TokenAttribute::setBackground(const QColor &background)
{
mBackground = background;
}
TokenType TokenAttribute::tokenType() const
{
return mTokenType;
}
QString TokenAttribute::name() const
{
return mName;
}
TokenAttribute::TokenAttribute(const QString &name, TokenType tokenType): TokenAttribute::TokenAttribute(const QString &name, TokenType tokenType):
mForeground(QColor()), mForeground(QColor()),
mBackground(QColor()), mBackground(QColor()),
@ -280,11 +167,9 @@ bool SyntaxState::operator==(const SyntaxState &s2)
&& (braceLevel == s2.braceLevel) // current braces embedding level (needed by rainbow color) && (braceLevel == s2.braceLevel) // current braces embedding level (needed by rainbow color)
&& (bracketLevel == s2.bracketLevel) // current brackets embedding level (needed by rainbow color) && (bracketLevel == s2.bracketLevel) // current brackets embedding level (needed by rainbow color)
&& (parenthesisLevel == s2.parenthesisLevel) // current parenthesis embedding level (needed by rainbow color) && (parenthesisLevel == s2.parenthesisLevel) // current parenthesis embedding level (needed by rainbow color)
&& (indents == s2.indents) && (indents == s2.indents)
&& (lastUnindent == s2.lastUnindent) && (lastUnindent == s2.lastUnindent)
; ;
} }
IndentInfo SyntaxState::getLastIndent() IndentInfo SyntaxState::getLastIndent()

View File

@ -93,18 +93,22 @@ public:
TokenAttribute(const TokenAttribute&)=delete; TokenAttribute(const TokenAttribute&)=delete;
TokenAttribute& operator=(const TokenAttribute&)=delete; TokenAttribute& operator=(const TokenAttribute&)=delete;
QString name() const; QString name() const { return mName; }
FontStyles styles() const; FontStyles styles() const { return mStyles; }
void setStyles(const FontStyles &styles); void setStyles(const FontStyles &styles) {
if (mStyles!=styles) {
mStyles = styles;
}
}
const QColor &foreground() const; const QColor &foreground() const { return mForeground; }
void setForeground(const QColor &color); void setForeground(const QColor &color) { mForeground = color; }
const QColor &background() const; const QColor &background() const { return mBackground; }
void setBackground(const QColor &background); void setBackground(const QColor &background) { mBackground = background; }
TokenType tokenType() const; TokenType tokenType() const { return mTokenType; }
private: private:
QColor mForeground; QColor mForeground;
@ -122,21 +126,21 @@ public:
Syntaxer(const Syntaxer&)=delete; Syntaxer(const Syntaxer&)=delete;
Syntaxer& operator=(const Syntaxer&)=delete; Syntaxer& operator=(const Syntaxer&)=delete;
virtual QMap<QString, PTokenAttribute> attributes() const; QMap<QString, PTokenAttribute> attributes() const { return mAttributes; }
const QSet<QChar>& wordBreakChars() const; const QSet<QChar>& wordBreakChars() const { return mWordBreakChars; }
const PTokenAttribute& identifierAttribute() const; const PTokenAttribute& identifierAttribute() const { return mIdentifierAttribute; }
const PTokenAttribute& keywordAttribute() const; const PTokenAttribute& keywordAttribute() const { return mKeywordAttribute; }
const PTokenAttribute& commentAttribute() const; const PTokenAttribute& commentAttribute() const { return mCommentAttribute; }
const PTokenAttribute& stringAttribute() const; const PTokenAttribute& stringAttribute() const { return mStringAttribute; }
const PTokenAttribute& whitespaceAttribute() const; const PTokenAttribute& whitespaceAttribute() const { return mWhitespaceAttribute; }
const PTokenAttribute& symbolAttribute() const; const PTokenAttribute& symbolAttribute() const { return mSymbolAttribute; }
virtual bool isIdentChar(const QChar& ch) const; virtual bool isIdentChar(const QChar& ch) const;
virtual bool isIdentStartChar(const QChar& ch) const; virtual bool isIdentStartChar(const QChar& ch) const;
@ -183,9 +187,9 @@ protected:
PTokenAttribute mWhitespaceAttribute; PTokenAttribute mWhitespaceAttribute;
PTokenAttribute mSymbolAttribute; PTokenAttribute mSymbolAttribute;
void addAttribute(PTokenAttribute attribute); void addAttribute(PTokenAttribute attribute) { mAttributes[attribute->name()]=attribute; }
void clearAttributes(); void clearAttributes() { mAttributes.clear(); }
virtual int attributesCount() const; virtual int attributesCount() const { return mAttributes.size(); }
private: private:
QMap<QString,PTokenAttribute> mAttributes; QMap<QString,PTokenAttribute> mAttributes;

View File

@ -48,14 +48,6 @@ void TextSyntaxer::procNull()
mState = RangeState::Unknown; mState = RangeState::Unknown;
} }
QMap<QString, PTokenAttribute> TextSyntaxer::attributes() const
{
QMap<QString, PTokenAttribute> result;
result.insert(SYNS_AttrText, mTextAttribute);
result.insert(SYNS_AttrSpace, whitespaceAttribute());
return result;
}
bool TextSyntaxer::eol() const bool TextSyntaxer::eol() const
{ {
return mTokenID == TokenId::Null; return mTokenID == TokenId::Null;

View File

@ -61,7 +61,6 @@ private:
void procNull(); void procNull();
public: public:
QMap<QString, PTokenAttribute> attributes() const override;
bool eol() const override; bool eol() const override;
QString languageName() override; QString languageName() override;