Skip to content

Commit

Permalink
Remove extra scalar variable styles in Perl lexer.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed May 20, 2023
1 parent 2e24328 commit a397480
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 58 deletions.
8 changes: 0 additions & 8 deletions scintilla/include/SciLexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,6 @@
#define SCE_PL_SUB_PROTOTYPE 43
#define SCE_PL_STRING_VAR 44
#define SCE_PL_XLAT 45
#define SCE_PL_REGEX_VAR 46
#define SCE_PL_REGSUBST_VAR 47
#define SCE_PL_BACKTICKS_VAR 49
#define SCE_PL_HERE_QQ_VAR 52
#define SCE_PL_HERE_QX_VAR 53
#define SCE_PL_STRING_QQ_VAR 55
#define SCE_PL_STRING_QX_VAR 56
#define SCE_PL_STRING_QR_VAR 57
#define SCE_RB_DEFAULT 0
#define SCE_RB_COMMENTLINE 1
#define SCE_RB_ERROR 2
Expand Down
9 changes: 0 additions & 9 deletions scintilla/include/SciLexer.iface
Original file line number Diff line number Diff line change
Expand Up @@ -465,17 +465,8 @@ val SCE_PL_POD=40
val SCE_PL_POD_VERB=41
val SCE_PL_DATASECTION=42
val SCE_PL_SUB_PROTOTYPE=43
# = SCE_PL_STRING_DQ + 29
val SCE_PL_STRING_VAR=44
val SCE_PL_XLAT=45
val SCE_PL_REGEX_VAR=46
val SCE_PL_REGSUBST_VAR=47
val SCE_PL_BACKTICKS_VAR=49
val SCE_PL_HERE_QQ_VAR=52
val SCE_PL_HERE_QX_VAR=53
val SCE_PL_STRING_QQ_VAR=55
val SCE_PL_STRING_QX_VAR=56
val SCE_PL_STRING_QR_VAR=57
# Lexical states for SCLEX_RUBY
lex Ruby=SCLEX_RUBY SCE_RB_
val SCE_RB_DEFAULT=
Expand Down
42 changes: 11 additions & 31 deletions scintilla/lexers/LexPerl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,6 @@ enum {
#define SUB_HAS_MODULE 3 // sub name can have a ::identifier part
#define SUB_HAS_SUB 4 // 'sub' keyword

// all interpolated styles are different from their parent styles by a constant difference
// we also assume SCE_PL_STRING_VAR is the interpolated style with the smallest value
#define INTERPOLATE_SHIFT (SCE_PL_STRING_VAR - SCE_PL_STRING_DQ)
static_assert(INTERPOLATE_SHIFT == SCE_PL_REGEX_VAR - SCE_PL_REGEX);
static_assert(INTERPOLATE_SHIFT == SCE_PL_REGSUBST_VAR - SCE_PL_REGSUBST);
static_assert(INTERPOLATE_SHIFT == SCE_PL_BACKTICKS_VAR - SCE_PL_BACKTICKS);
static_assert(INTERPOLATE_SHIFT == SCE_PL_HERE_QQ_VAR - SCE_PL_HERE_QQ);
static_assert(INTERPOLATE_SHIFT == SCE_PL_HERE_QX_VAR - SCE_PL_HERE_QX);
static_assert(INTERPOLATE_SHIFT == SCE_PL_STRING_QQ_VAR - SCE_PL_STRING_QQ);
static_assert(INTERPOLATE_SHIFT == SCE_PL_STRING_QX_VAR - SCE_PL_STRING_QX);
static_assert(INTERPOLATE_SHIFT == SCE_PL_STRING_QR_VAR - SCE_PL_STRING_QR);

bool isPerlKeyword(LexAccessor &styler, Sci_PositionU start, Sci_PositionU end, const WordList &keywords) noexcept {
// old-style keyword matcher; needed because GetCurrent() needs
// current segment to be committed, but we may abandon early...
Expand Down Expand Up @@ -379,7 +367,7 @@ void InterpolateSegment(StyleContext &sc, int maxSeg, bool isPattern = false) {
// interpolate a segment (with no active backslashes or delimiters within)
// switch in or out of an interpolation style or continue current style
// commit variable patterns if found, trim segment, repeat until done

const int outer = sc.state;
while (maxSeg > 0) {
bool isVar = false;
int sLen = 0;
Expand Down Expand Up @@ -449,19 +437,22 @@ void InterpolateSegment(StyleContext &sc, int maxSeg, bool isPattern = false) {
}
}
if (isVar) { // commit as interpolated variable or normal character
if (sc.state < SCE_PL_STRING_VAR)
sc.SetState(sc.state + INTERPOLATE_SHIFT);
if (sc.state != SCE_PL_STRING_VAR) {
sc.SetState(SCE_PL_STRING_VAR);
}
sc.Forward(sLen);
maxSeg -= sLen;
} else {
if (sc.state >= SCE_PL_STRING_VAR)
sc.SetState(sc.state - INTERPOLATE_SHIFT);
if (sc.state == SCE_PL_STRING_VAR) {
sc.SetState(outer);
}
sc.Forward();
maxSeg--;
}
}
if (sc.state >= SCE_PL_STRING_VAR)
sc.SetState(sc.state - INTERPOLATE_SHIFT);
if (sc.state == SCE_PL_STRING_VAR) {
sc.SetState(outer);
}
}

constexpr bool IsPerlSingleCharOperator(int ch) noexcept {
Expand Down Expand Up @@ -585,8 +576,6 @@ void ColourisePerlDoc(Sci_PositionU startPos, Sci_Position length, int initStyle
|| initStyle == SCE_PL_HERE_QQ
|| initStyle == SCE_PL_HERE_QX
|| initStyle == SCE_PL_FORMAT
|| initStyle == SCE_PL_HERE_QQ_VAR
|| initStyle == SCE_PL_HERE_QX_VAR
) {
// backtrack through multiple styles to reach the delimiter start
const int delim = (initStyle == SCE_PL_FORMAT) ? SCE_PL_FORMAT_IDENT : SCE_PL_HERE_DELIM;
Expand All @@ -603,20 +592,11 @@ void ColourisePerlDoc(Sci_PositionU startPos, Sci_Position length, int initStyle
|| initStyle == SCE_PL_REGEX
|| initStyle == SCE_PL_STRING_QR
|| initStyle == SCE_PL_REGSUBST
|| initStyle == SCE_PL_STRING_VAR
|| initStyle == SCE_PL_STRING_QQ_VAR
|| initStyle == SCE_PL_BACKTICKS_VAR
|| initStyle == SCE_PL_STRING_QX_VAR
|| initStyle == SCE_PL_REGEX_VAR
|| initStyle == SCE_PL_STRING_QR_VAR
|| initStyle == SCE_PL_REGSUBST_VAR
) {
// for interpolation, must backtrack through a mix of two different styles
const int otherStyle = (initStyle >= SCE_PL_STRING_VAR) ?
initStyle - INTERPOLATE_SHIFT : initStyle + INTERPOLATE_SHIFT;
while (startPos > 1) {
const int st = styler.StyleAt(startPos - 1);
if ((st != initStyle) && (st != otherStyle))
if ((st != initStyle) && (st != SCE_PL_STRING_VAR))
break;
startPos--;
}
Expand Down
1 change: 1 addition & 0 deletions src/EditAutoC.c
Original file line number Diff line number Diff line change
Expand Up @@ -3277,6 +3277,7 @@ void InitAutoCompletionCache(LPCEDITLEXER pLex) {
++marker;
do {
AllStringStyleMask[start >> 5] |= (1U << (start & 31));
++start;
} while (start < marker);
#endif
}
Expand Down
10 changes: 0 additions & 10 deletions src/Styles.c
Original file line number Diff line number Diff line change
Expand Up @@ -1705,16 +1705,6 @@ void Style_SetLexer(PEDITLEXER pLexNew, BOOL bLexerChanged) {
Style_SetAllStyle(pLexNew, 0);

switch (rid) {
case NP2LEX_PERL:
#if defined(_WIN64)
SciCall_CopyStyles(SCE_PL_SCALAR, MULTI_STYLE8(SCE_PL_REGEX_VAR, SCE_PL_REGSUBST_VAR, SCE_PL_BACKTICKS_VAR, SCE_PL_HERE_QQ_VAR,
SCE_PL_HERE_QX_VAR, SCE_PL_STRING_QQ_VAR, SCE_PL_STRING_QX_VAR, SCE_PL_STRING_QR_VAR));
#else
SciCall_CopyStyles(SCE_PL_SCALAR, MULTI_STYLE(SCE_PL_REGEX_VAR, SCE_PL_REGSUBST_VAR, SCE_PL_BACKTICKS_VAR, SCE_PL_HERE_QQ_VAR));
SciCall_CopyStyles(SCE_PL_SCALAR, MULTI_STYLE(SCE_PL_HERE_QX_VAR, SCE_PL_STRING_QQ_VAR, SCE_PL_STRING_QX_VAR, SCE_PL_STRING_QR_VAR));
#endif
break;

case NP2LEX_REBOL:
SciCall_CopyStyles(STYLE_LINK, MULTI_STYLE(SCE_REBOL_URL, SCE_REBOL_EMAIL, 0, 0));
break;
Expand Down

0 comments on commit a397480

Please sign in to comment.