Skip to content

Commit

Permalink
[Zig] Don't highlight format specifier inside identifier string.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Nov 3, 2024
1 parent e426d62 commit 00257cf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
23 changes: 12 additions & 11 deletions scintilla/include/SciLexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1840,17 +1840,18 @@
#define SCE_ZIG_NUMBER 5
#define SCE_ZIG_OPERATOR 6
#define SCE_ZIG_CHARACTER 7
#define SCE_ZIG_STRING 8
#define SCE_ZIG_MULTISTRING 9
#define SCE_ZIG_ESCAPECHAR 10
#define SCE_ZIG_FORMAT_SPECIFIER 11
#define SCE_ZIG_PLACEHOLDER 12
#define SCE_ZIG_IDENTIFIER 13
#define SCE_ZIG_BUILTIN_FUNCTION 14
#define SCE_ZIG_WORD 15
#define SCE_ZIG_TYPE 16
#define SCE_ZIG_FUNCTION 17
#define SCE_ZIG_FUNCTION_DEFINITION 18
#define SCE_ZIG_IDENTIFIER_STRING 8
#define SCE_ZIG_STRING 9
#define SCE_ZIG_MULTISTRING 10
#define SCE_ZIG_ESCAPECHAR 11
#define SCE_ZIG_FORMAT_SPECIFIER 12
#define SCE_ZIG_PLACEHOLDER 13
#define SCE_ZIG_IDENTIFIER 14
#define SCE_ZIG_BUILTIN_FUNCTION 15
#define SCE_ZIG_WORD 16
#define SCE_ZIG_TYPE 17
#define SCE_ZIG_FUNCTION 18
#define SCE_ZIG_FUNCTION_DEFINITION 19
#define SCE_MATHEMATICA_DEFAULT 0
#define SCE_MATHEMATICA_COMMENTLINE 1
#define SCE_MATHEMATICA_COMMENT 2
Expand Down
1 change: 1 addition & 0 deletions scintilla/include/SciLexer.iface
Original file line number Diff line number Diff line change
Expand Up @@ -3150,6 +3150,7 @@ val SCE_ZIG_TASKMARKER=
val SCE_ZIG_NUMBER=
val SCE_ZIG_OPERATOR=
val SCE_ZIG_CHARACTER=
val SCE_ZIG_IDENTIFIER_STRING=
val SCE_ZIG_STRING=
val SCE_ZIG_MULTISTRING=
val SCE_ZIG_ESCAPECHAR=
Expand Down
9 changes: 7 additions & 2 deletions scintilla/lexers/LexZig.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ void ColouriseZigDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initSty
break;

case SCE_ZIG_CHARACTER:
case SCE_ZIG_IDENTIFIER_STRING:
case SCE_ZIG_STRING:
case SCE_ZIG_MULTISTRING:
if (sc.atLineStart) {
Expand All @@ -213,9 +214,10 @@ void ColouriseZigDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initSty
escSeq.digitsLeft = 9;
sc.Forward();
}
} else if ((sc.ch == '\'' && sc.state == SCE_ZIG_CHARACTER) || (sc.ch == '\"' && sc.state == SCE_ZIG_STRING)) {
} else if ((sc.ch == '\'' && sc.state == SCE_ZIG_CHARACTER)
|| (sc.ch == '\"' && (sc.state == SCE_ZIG_STRING || sc.state == SCE_ZIG_IDENTIFIER_STRING))) {
sc.ForwardSetState(SCE_ZIG_DEFAULT);
} else if (sc.state != SCE_ZIG_CHARACTER) {
} else if (sc.state >= SCE_ZIG_STRING) {
if (sc.ch == '{' || sc.ch == '}') {
if (sc.ch == sc.chNext) {
escSeq.resetEscapeState(sc.state);
Expand Down Expand Up @@ -306,6 +308,9 @@ void ColouriseZigDoc(Sci_PositionU startPos, Sci_Position lengthDoc, int initSty
sc.SetState(SCE_ZIG_CHARACTER);
} else if (IsADigit(sc.ch)) {
sc.SetState(SCE_ZIG_NUMBER);
} else if (sc.Match('@', '\"')) {
sc.SetState(SCE_ZIG_IDENTIFIER_STRING);
sc.Forward();
} else if ((sc.ch == '@' && IsIdentifierStartEx(sc.chNext)) || IsIdentifierStartEx(sc.ch)) {
sc.SetState((sc.ch == '@') ? SCE_ZIG_BUILTIN_FUNCTION : SCE_ZIG_IDENTIFIER);
} else if (IsAGraphic(sc.ch)) {
Expand Down
2 changes: 1 addition & 1 deletion src/EditLexers/stlZig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static EDITSTYLE Styles_Zig[] = {
{ SCE_ZIG_FUNCTION, NP2StyleX_Function, L"fore:#A46000" },
{ SCE_ZIG_COMMENTLINE, NP2StyleX_Comment, L"fore:#608060" },
{ MULTI_STYLE(SCE_ZIG_COMMENTLINEDOC, SCE_ZIG_COMMENTLINETOP, 0, 0), NP2StyleX_DocComment, L"fore:#408040" },
{ MULTI_STYLE(SCE_ZIG_CHARACTER, SCE_ZIG_STRING, 0, 0), NP2StyleX_String, L"fore:#008000" },
{ MULTI_STYLE(SCE_ZIG_CHARACTER, SCE_ZIG_STRING, SCE_ZIG_IDENTIFIER_STRING, 0), NP2StyleX_String, L"fore:#008000" },
{ SCE_ZIG_MULTISTRING, NP2StyleX_RawString, L"fore:#008080" },
{ SCE_ZIG_ESCAPECHAR, NP2StyleX_EscapeSequence, L"fore:#0080C0" },
{ SCE_ZIG_FORMAT_SPECIFIER, NP2StyleX_FormatSpecifier, L"fore:#7C5AF3" },
Expand Down

0 comments on commit 00257cf

Please sign in to comment.