Skip to content

Commit

Permalink
Improve Batch variable highlighting on error, issue #332.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Jun 23, 2021
1 parent cfb6eda commit 9164ccd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 6 additions & 4 deletions scintilla/lexers/LexBatch.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ constexpr bool IsTildeExpansion(int ch) noexcept {

bool DetectBatchVariable(StyleContext &sc, int &outerStyle, int &varQuoteChar) {
varQuoteChar = '\0';
if (!IsGraphic(sc.chNext) || sc.chNext == '!' || (sc.ch == '!' && sc.chNext == '%')) {
if (!IsGraphic(sc.chNext) || (sc.ch == '!' && (sc.chNext == '%' || sc.chNext == '!'))) {
return false;
}

Expand All @@ -163,7 +163,7 @@ bool DetectBatchVariable(StyleContext &sc, int &outerStyle, int &varQuoteChar) {
return true;
}
if (sc.chNext == '*' || IsADigit(sc.chNext)) {
// %*, %1 ... %9
// %*, %0 ... %9
sc.Forward();
} else if (sc.chNext == '~' || sc.chNext == '%') {
sc.Forward();
Expand Down Expand Up @@ -254,7 +254,7 @@ void ColouriseBatchDoc(Sci_PositionU startPos, Sci_Position length, int initStyl
break;

case SCE_BAT_IDENTIFIER:
if (sc.ch == '.' && sc.LengthCurrent() == 4 && sc.styler.MatchIgnoreCase(sc.styler.GetStartSegment(), "echo")) {
if (sc.ch == '.' && sc.LengthCurrent() == 4 && styler.MatchIgnoreCase(styler.GetStartSegment(), "echo")) {
parenBefore = parenCount;
command = Command::Echo;
sc.ChangeState(SCE_BAT_WORD);
Expand Down Expand Up @@ -334,8 +334,10 @@ void ColouriseBatchDoc(Sci_PositionU startPos, Sci_Position length, int initStyl
varQuoteChar = '\0';
sc.Forward();
} else if (IsEOLChar(sc.ch) || sc.ch == GetStringQuote(outerStyle)) {
// something went wrong
// something went wrong, e.g. ! without EnableDelayedExpansion.
varQuoteChar = '\0';
sc.ChangeState(outerStyle);
sc.Rewind();
}
}
if (varQuoteChar == '\0') {
Expand Down
12 changes: 12 additions & 0 deletions scintilla/lexlib/StyleContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,18 @@ class StyleContext final {
styler.GetRangeLowered(styler.GetStartSegment(), currentPos, s, len);
}

void Rewind() noexcept {
currentPos = styler.GetStartSegment();
chPrev = 0;
if (!multiByteAccess) {
ch = static_cast<unsigned char>(styler[currentPos]);
} else {
ch = styler.GetCharacterAndWidth(currentPos, &widthNext);
width = widthNext;
}
Forward();
}

bool LineEndsWith(char ch0) const noexcept {
return chPrev == static_cast<unsigned char>(ch0)
|| (chPrev == '\r' && ch == '\n' && currentPos >= 2 && ch0 == styler[currentPos - 2]);
Expand Down

0 comments on commit 9164ccd

Please # to comment.