Skip to content

Commit f4571f9

Browse files
committed
Unify lexer option property as lexer.lang.
1 parent 358db16 commit f4571f9

2 files changed

Lines changed: 25 additions & 16 deletions

File tree

‎scintilla/lexers/LexProps.cxx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void ColourisePropsDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initS
4040
// For properties files, set to 0 to style all lines that start with whitespace in the default style.
4141
// This is not suitable for SciTE .properties files which use indentation for flow control but
4242
// can be used for RFC2822 text where indentation is used for continuation lines.
43-
const bool allowInitialSpaces = styler.GetPropertyBool("lexer.props.allow.initial.spaces", true);
43+
constexpr bool allowInitialSpaces = true; //styler.GetPropertyBool("lexer.lang", true);
4444

4545
const Sci_Position endPos = startPos + lengthDoc;
4646
const Sci_Line maxLines = styler.GetLine((endPos == styler.Length()) ? endPos : endPos - 1);
@@ -60,7 +60,7 @@ void ColourisePropsDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initS
6060
while (lineCurrent <= maxLines) {
6161
Sci_PositionU i = lineStartCurrent;
6262
unsigned char ch = styler[i];
63-
if (allowInitialSpaces) {
63+
if constexpr (allowInitialSpaces) {
6464
const Sci_PositionU lineEndPos = lineStartNext - 1;
6565
while (i < lineEndPos && isspacechar(ch)) {
6666
ch = styler[++i];
@@ -82,7 +82,7 @@ void ColourisePropsDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initS
8282
if (isAssignChar(chNext)) {
8383
styler.ColorTo(i + 1, SCE_PROPS_ASSIGNMENT);
8484
}
85-
} else if (allowInitialSpaces || !isspacechar(ch)) {
85+
} else if constexpr (allowInitialSpaces || !isspacechar(ch)) {
8686
while (i < lineStartNext) {
8787
ch = styler[i];
8888
if (isAssignChar(ch)) {

‎scintilla/lexers/LexSQL.cxx‎

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,16 @@ enum {
3939
};
4040
//KeywordIndex--Autogenerated -- end of section automatically generated
4141

42-
constexpr bool IsSqlWordChar(int ch, bool sqlAllowDottedWord) noexcept {
43-
return IsAlphaNumeric(ch) || ch == '_' || (sqlAllowDottedWord && ch == '.');
42+
enum SqlOption {
43+
SqlOption_BackticksIdentifier = 1,
44+
SqlOption_NumberSignComment = 2,
45+
SqlOption_BackslashEscapes = 4,
46+
SqlOption_AllowDottedWord = 8,
47+
SqlOption_Default = SqlOption_BackticksIdentifier | SqlOption_NumberSignComment | SqlOption_BackslashEscapes,
48+
};
49+
50+
constexpr bool IsSqlWordChar(int ch, SqlOption option) noexcept {
51+
return IsAlphaNumeric(ch) || ch == '_' || ((option & SqlOption_AllowDottedWord) && ch == '.');
4452
}
4553

4654
constexpr bool IsANumberChar(int ch, int chPrev) noexcept {
@@ -68,10 +76,11 @@ void ColouriseSqlDoc(Sci_PositionU startPos, Sci_Position length, int initStyle,
6876
//const WordList &kw_user3 = keywordLists[6];
6977
//const WordList &kw_user4 = keywordLists[7];
7078

71-
const bool sqlBackticksIdentifier = styler.GetPropertyBool("lexer.sql.backticks.identifier", true);
72-
const bool sqlNumbersignComment = styler.GetPropertyBool("lexer.sql.numbersign.comment", true);
73-
const bool sqlBackslashEscapes = styler.GetPropertyBool("lexer.sql.backslash.escapes", true);
74-
const bool sqlAllowDottedWord = styler.GetPropertyBool("lexer.sql.allow.dotted.word", false);
79+
// const bool sqlBackticksIdentifier = styler.GetPropertyBool("lexer.sql.backticks.identifier", true);
80+
// const bool sqlNumbersignComment = styler.GetPropertyBool("lexer.sql.numbersign.comment", true);
81+
// const bool sqlBackslashEscapes = styler.GetPropertyBool("lexer.sql.backslash.escapes", true);
82+
// const bool sqlAllowDottedWord = styler.GetPropertyBool("lexer.sql.allow.dotted.word", false);
83+
const SqlOption option = static_cast<SqlOption>(styler.GetPropertyInt("lexer.lang", SqlOption_Default));
7584

7685
StyleContext sc(startPos, length, initStyle, styler);
7786
//int styleBeforeDCKeyword = SCE_SQL_DEFAULT;
@@ -114,7 +123,7 @@ void ColouriseSqlDoc(Sci_PositionU startPos, Sci_Position length, int initStyle,
114123
}
115124
break;
116125
case SCE_SQL_IDENTIFIER:
117-
if (!IsSqlWordChar(sc.ch, sqlAllowDottedWord)) {
126+
if (!IsSqlWordChar(sc.ch, option)) {
118127
constexpr int nextState = SCE_SQL_DEFAULT;
119128
char s[MaxKeywordSize];
120129
const int chNext = sc.GetDocNextChar();
@@ -148,8 +157,8 @@ void ColouriseSqlDoc(Sci_PositionU startPos, Sci_Position length, int initStyle,
148157
}
149158
break;
150159
case SCE_SQL_QUOTEDIDENTIFIER:
151-
if (sc.ch == 0x60) {
152-
if (sc.chNext == 0x60) {
160+
if (sc.ch == '`') {
161+
if (sc.chNext == '`') {
153162
sc.Forward(); // Ignore it
154163
} else {
155164
sc.ForwardSetState(SCE_SQL_DEFAULT);
@@ -171,7 +180,7 @@ void ColouriseSqlDoc(Sci_PositionU startPos, Sci_Position length, int initStyle,
171180
}
172181
break;
173182
case SCE_SQL_STRING_SQ:
174-
if ((sqlBackslashEscapes && sc.ch == '\\') || (sc.ch == '\'' && sc.chNext == '\'')) {
183+
if (((option & SqlOption_BackslashEscapes) && sc.ch == '\\') || (sc.ch == '\'' && sc.chNext == '\'')) {
175184
// Escape sequence
176185
sc.SetState(SCE_SQL_ESCAPECHAR);
177186
sc.Forward();
@@ -183,7 +192,7 @@ void ColouriseSqlDoc(Sci_PositionU startPos, Sci_Position length, int initStyle,
183192
}
184193
break;
185194
case SCE_SQL_STRING_DQ:
186-
if ((sqlBackslashEscapes && sc.ch == '\\') || (sc.ch == '\"' && sc.chNext == '\"')) {
195+
if (((option & SqlOption_BackslashEscapes) && sc.ch == '\\') || (sc.ch == '\"' && sc.chNext == '\"')) {
187196
// Escape sequence
188197
sc.SetState(SCE_SQL_ESCAPECHAR);
189198
sc.Forward();
@@ -250,7 +259,7 @@ void ColouriseSqlDoc(Sci_PositionU startPos, Sci_Position length, int initStyle,
250259
sc.SetState(SCE_SQL_VARIABLE);
251260
} else if (iswordstart(sc.ch)) {
252261
sc.SetState(SCE_SQL_IDENTIFIER);
253-
} else if (sc.ch == 0x60 && sqlBackticksIdentifier) {
262+
} else if (sc.ch == '`' && (option & SqlOption_BackticksIdentifier)) {
254263
sc.SetState(SCE_SQL_QUOTEDIDENTIFIER);
255264
} else if (sc.Match('/', '*')) {
256265
sc.SetState(SCE_SQL_COMMENT);
@@ -261,7 +270,7 @@ void ColouriseSqlDoc(Sci_PositionU startPos, Sci_Position length, int initStyle,
261270
// Perhaps we should enforce that with proper property:
262271
//~} else if (sc.Match('-', '-', ' ')) {
263272
sc.SetState(SCE_SQL_COMMENTLINE);
264-
} else if (sc.ch == '#' && sqlNumbersignComment) {
273+
} else if (sc.ch == '#' && (option & SqlOption_NumberSignComment)) {
265274
sc.SetState(SCE_SQL_COMMENTLINEDOC);
266275
} else if (sc.ch == '\'') {
267276
sc.SetState(SCE_SQL_STRING_SQ);

0 commit comments

Comments
 (0)