- refactor: brace states in parser
- changer: colors for braces in VS Code color scheme
This commit is contained in:
parent
bc1c92e7b5
commit
bfa5835cfa
|
@ -171,15 +171,15 @@
|
|||
"foreground" : "#C0C0C0"
|
||||
},
|
||||
"brace/parenthesis/bracket level 1" : {
|
||||
"foreground" : "#569CD6"
|
||||
"foreground" : "#569CD6"
|
||||
},
|
||||
"brace/parenthesis/bracket level 2" : {
|
||||
"foreground" : "#D4D4D4"
|
||||
},
|
||||
"brace/parenthesis/bracket level 3" : {
|
||||
"foreground" : "#D69D85"
|
||||
"foreground" : "#D69D85"
|
||||
},
|
||||
"brace/parenthesis/bracket level 4" : {
|
||||
"foreground" : "#DCDCAA"
|
||||
"foreground" : "#4EC9B0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2873,7 +2873,8 @@ int SynEdit::scanFrom(int Index, int canStopIndex)
|
|||
)
|
||||
return Result;// avoid the final Decrement
|
||||
}
|
||||
mLines->setRange(Result,iRange);
|
||||
mLines->setRange(Result,iRange, mHighlighter->getLeftBraces(),
|
||||
mHighlighter->getRightBraces());
|
||||
Result ++ ;
|
||||
} while (Result < mLines->count());
|
||||
Result--;
|
||||
|
@ -2887,7 +2888,9 @@ void SynEdit::scanRanges()
|
|||
for (int i =0;i<mLines->count();i++) {
|
||||
mHighlighter->setLine(mLines->getString(i), i);
|
||||
mHighlighter->nextToEol();
|
||||
mLines->setRange(i, mHighlighter->getRangeState());
|
||||
mLines->setRange(i, mHighlighter->getRangeState(),
|
||||
mHighlighter->getLeftBraces(),
|
||||
mHighlighter->getRightBraces());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ int SynEditStringList::lineColumns(int Index)
|
|||
int SynEditStringList::leftBraces(int Index)
|
||||
{
|
||||
if (Index>=0 && Index < mList.size()) {
|
||||
return mList[Index]->fRange.leftBraces;
|
||||
return mList[Index]->fLeftBraces;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ int SynEditStringList::leftBraces(int Index)
|
|||
int SynEditStringList::rightBraces(int Index)
|
||||
{
|
||||
if (Index>=0 && Index < mList.size()) {
|
||||
return mList[Index]->fRange.rightBraces;
|
||||
return mList[Index]->fRightBraces;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
@ -165,13 +165,15 @@ void SynEditStringList::setAppendNewLineAtEOF(bool appendNewLineAtEOF)
|
|||
mAppendNewLineAtEOF = appendNewLineAtEOF;
|
||||
}
|
||||
|
||||
void SynEditStringList::setRange(int Index, const SynRangeState& ARange)
|
||||
void SynEditStringList::setRange(int Index, const SynRangeState& ARange, int ALeftBraces, int ARightBraces)
|
||||
{
|
||||
if (Index<0 || Index>=mList.count()) {
|
||||
ListIndexOutOfBounds(Index);
|
||||
}
|
||||
beginUpdate();
|
||||
mList[Index]->fRange = ARange;
|
||||
mList[Index]->fLeftBraces = ALeftBraces;
|
||||
mList[Index]->fRightBraces = ARightBraces;
|
||||
endUpdate();
|
||||
}
|
||||
|
||||
|
@ -675,7 +677,7 @@ void SynEditStringList::invalidAllLineColumns()
|
|||
SynEditStringRec::SynEditStringRec():
|
||||
fString(),
|
||||
fObject(nullptr),
|
||||
fRange{0,0,0,0,0,0,0},
|
||||
fRange{0,0,0,0,0},
|
||||
fColumns(-1)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@ struct SynEditStringRec {
|
|||
QString fString;
|
||||
void * fObject;
|
||||
SynRangeState fRange;
|
||||
int fLeftBraces;
|
||||
int fRightBraces;
|
||||
int fColumns; //
|
||||
|
||||
public:
|
||||
|
@ -57,7 +59,7 @@ public:
|
|||
int lengthOfLongestLine();
|
||||
QString lineBreak();
|
||||
const SynRangeState& ranges(int Index);
|
||||
void setRange(int Index, const SynRangeState& ARange);
|
||||
void setRange(int Index, const SynRangeState& ARange, int leftBraces, int rightBraces);
|
||||
QString getString(int Index);
|
||||
int count();
|
||||
void* getObject(int Index);
|
||||
|
|
|
@ -373,7 +373,7 @@ bool SynEditASMHighlighter::isLastLineStringNotFinished(int state) const
|
|||
|
||||
SynRangeState SynEditASMHighlighter::getRangeState() const
|
||||
{
|
||||
return {0,0,0,0,0,0,0};
|
||||
return {0,0,0,0,0};
|
||||
}
|
||||
|
||||
void SynEditASMHighlighter::setState(const SynRangeState&)
|
||||
|
|
|
@ -64,6 +64,16 @@ void SynHighlighter::nextToEol()
|
|||
next();
|
||||
}
|
||||
|
||||
int SynHighlighter::getLeftBraces()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SynHighlighter::getRightBraces()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool SynHighlighter::isSpaceChar(const QChar &ch)
|
||||
{
|
||||
return ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n';
|
||||
|
@ -215,7 +225,5 @@ bool SynRangeState::operator==(const SynRangeState &s2)
|
|||
&& (spaceState == s2.spaceState)
|
||||
&& (braceLevel == s2.braceLevel)
|
||||
&& (bracketLevel == s2.bracketLevel)
|
||||
&& (parenthesisLevel == s2.parenthesisLevel)
|
||||
&& (leftBraces == s2.leftBraces)
|
||||
&& (rightBraces == s2.rightBraces);
|
||||
&& (parenthesisLevel == s2.parenthesisLevel);
|
||||
}
|
||||
|
|
|
@ -16,8 +16,6 @@ struct SynRangeState {
|
|||
int braceLevel;
|
||||
int bracketLevel;
|
||||
int parenthesisLevel;
|
||||
int leftBraces;
|
||||
int rightBraces;
|
||||
bool operator==(const SynRangeState& s2);
|
||||
};
|
||||
|
||||
|
@ -110,6 +108,9 @@ public:
|
|||
virtual void setLine(const QString& newLine, int lineNumber) = 0;
|
||||
virtual void resetState() = 0;
|
||||
|
||||
virtual int getLeftBraces();
|
||||
virtual int getRightBraces();
|
||||
|
||||
virtual QString languageName() = 0;
|
||||
virtual SynHighlighterLanguage language() = 0;
|
||||
|
||||
|
|
|
@ -158,8 +158,8 @@ SynEditCppHighlighter::SynEditCppHighlighter(): SynHighlighter()
|
|||
mRange.braceLevel = 0;
|
||||
mRange.bracketLevel = 0;
|
||||
mRange.parenthesisLevel = 0;
|
||||
mRange.leftBraces = 0;
|
||||
mRange.rightBraces = 0;
|
||||
mLeftBraces = 0;
|
||||
mRightBraces = 0;
|
||||
mAsmStart = false;
|
||||
}
|
||||
|
||||
|
@ -368,10 +368,10 @@ void SynEditCppHighlighter::braceCloseProc()
|
|||
}
|
||||
|
||||
mRange.braceLevel -= 1;
|
||||
if (mRange.leftBraces>0) {
|
||||
mRange.leftBraces--;
|
||||
if (mLeftBraces>0) {
|
||||
mLeftBraces--;
|
||||
} else {
|
||||
mRange.rightBraces++ ;
|
||||
mRightBraces++ ;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -385,7 +385,7 @@ void SynEditCppHighlighter::braceOpenProc()
|
|||
mAsmStart = true;
|
||||
}
|
||||
mRange.braceLevel += 1;
|
||||
mRange.leftBraces++;
|
||||
mLeftBraces++;
|
||||
}
|
||||
|
||||
void SynEditCppHighlighter::colonProc()
|
||||
|
@ -1479,8 +1479,8 @@ void SynEditCppHighlighter::setLine(const QString &newLine, int lineNumber)
|
|||
mLine = mLineString.data();
|
||||
mLineNumber = lineNumber;
|
||||
mRun = 0;
|
||||
mRange.leftBraces = 0;
|
||||
mRange.rightBraces = 0;
|
||||
mLeftBraces = 0;
|
||||
mRightBraces = 0;
|
||||
next();
|
||||
}
|
||||
|
||||
|
@ -1544,8 +1544,6 @@ SynHighlighterTokenType SynEditCppHighlighter::getTokenType()
|
|||
void SynEditCppHighlighter::setState(const SynRangeState& rangeState)
|
||||
{
|
||||
mRange = rangeState;
|
||||
mRange.leftBraces = 0;
|
||||
mRange.rightBraces = 0;
|
||||
}
|
||||
|
||||
void SynEditCppHighlighter::resetState()
|
||||
|
@ -1555,8 +1553,6 @@ void SynEditCppHighlighter::resetState()
|
|||
mRange.braceLevel = 0;
|
||||
mRange.bracketLevel = 0;
|
||||
mRange.parenthesisLevel = 0;
|
||||
mRange.leftBraces = 0;
|
||||
mRange.rightBraces = 0;
|
||||
}
|
||||
|
||||
SynHighlighterClass SynEditCppHighlighter::getClass() const
|
||||
|
@ -1579,6 +1575,16 @@ SynHighlighterLanguage SynEditCppHighlighter::language()
|
|||
return SynHighlighterLanguage::Cpp;
|
||||
}
|
||||
|
||||
int SynEditCppHighlighter::getLeftBraces()
|
||||
{
|
||||
return mLeftBraces;
|
||||
}
|
||||
|
||||
int SynEditCppHighlighter::getRightBraces()
|
||||
{
|
||||
return mRightBraces;
|
||||
}
|
||||
|
||||
SynRangeState SynEditCppHighlighter::getRangeState() const
|
||||
{
|
||||
return mRange;
|
||||
|
|
|
@ -140,6 +140,8 @@ private:
|
|||
int mTokenId;
|
||||
ExtTokenKind mExtTokenId;
|
||||
int mLineNumber;
|
||||
int mLeftBraces;
|
||||
int mRightBraces;
|
||||
|
||||
PSynHighlighterAttribute mAsmAttribute;
|
||||
PSynHighlighterAttribute mDirecAttribute;
|
||||
|
@ -156,8 +158,6 @@ private:
|
|||
PSynHighlighterAttribute mGlobalVarAttribute;
|
||||
PSynHighlighterAttribute mLocalVarAttribute;
|
||||
|
||||
|
||||
|
||||
// SynHighligterBase interface
|
||||
public:
|
||||
bool getTokenFinished() const override;
|
||||
|
@ -180,6 +180,9 @@ public:
|
|||
QString languageName() override;
|
||||
SynHighlighterLanguage language() override;
|
||||
|
||||
int getLeftBraces() override;
|
||||
int getRightBraces() override;
|
||||
|
||||
// SynHighlighter interface
|
||||
public:
|
||||
SynRangeState getRangeState() const override;
|
||||
|
|
Loading…
Reference in New Issue