Skip to content

Commit 1dd38c2

Browse files
committed
Use different color for control flow keywords in GDScript syntax highlighting
This matches the Godot script editor's behavior. Note that this does not apply to C# and shaders (which currently use GLSL highlighting), as it would require copying their respective highlighters to this repository and modifying them.
1 parent 0260c0b commit 1dd38c2

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

_extensions/gdscript.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def innerstring_rules(ttype):
8585
Operator,
8686
),
8787
include("keywords"),
88+
include("control_flow_keywords"),
8889
(r"(func)((?:\s|\\\s)+)", bygroups(Keyword, Text), "funcname"),
8990
(r"(class)((?:\s|\\\s)+)", bygroups(Keyword, Text), "classname"),
9091
include("builtins"),
@@ -155,21 +156,33 @@ def innerstring_rules(ttype):
155156
"enum",
156157
"static",
157158
"var",
159+
"super",
160+
),
161+
suffix=r"\b",
162+
),
163+
Keyword,
164+
),
165+
],
166+
"control_flow_keywords": [
167+
(
168+
words(
169+
(
158170
"break",
159171
"continue",
160-
"if",
161172
"elif",
162173
"else",
174+
"if",
163175
"for",
176+
"match",
164177
"pass",
165178
"return",
166-
"match",
167179
"while",
168-
"super",
169180
),
170181
suffix=r"\b",
171182
),
172-
Keyword,
183+
# Custom control flow class used to give control flow keywords a different color,
184+
# like in the Godot editor.
185+
Keyword.ControlFlow,
173186
),
174187
],
175188
"builtins": [

_static/css/custom.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
--highlight-comment-color: #408090;
9696
--highlight-keyword-color: #007020;
9797
--highlight-keyword2-color: #902000;
98+
--highlight-control-flow-keyword-color: #902060;
9899
--highlight-number-color: #208050;
99100
--highlight-decorator-color: #4070a0;
100101
--highlight-type-color: #007020;
@@ -223,6 +224,7 @@
223224
--highlight-comment-color: rgba(204, 206, 211, 0.5);
224225
--highlight-keyword-color: #ff7085;
225226
--highlight-keyword2-color: #42ffc2;
227+
--highlight-control-flow-keyword-color: #ff8ccc;
226228
--highlight-number-color: #a1ffe0;
227229
--highlight-decorator-color: #ffb373;
228230
--highlight-type-color: #8effda;
@@ -877,6 +879,10 @@ code,
877879
color: var(--highlight-keyword-color);
878880
}
879881

882+
.highlight .k-ControlFlow /* Keyword.ControlFlow */ {
883+
color: var(--highlight-control-flow-keyword-color);
884+
}
885+
880886
.highlight .ch /* Comment.Hashbang */,
881887
.highlight .cp /* Comment.Preproc */ {
882888
color: var(--highlight-keyword2-color);

0 commit comments

Comments
 (0)