@@ -53,7 +53,6 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
53
53
bool in_keyword = false ;
54
54
bool in_word = false ;
55
55
bool in_number = false ;
56
- bool in_raw_string = false ;
57
56
bool in_node_path = false ;
58
57
bool in_node_ref = false ;
59
58
bool in_annotation = false ;
@@ -127,6 +126,7 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
127
126
if (from != line_length) {
128
127
// Check if we are in entering a region.
129
128
if (in_region == -1 ) {
129
+ const bool r_prefix = from > 0 && str[from - 1 ] == ' r' ;
130
130
for (int c = 0 ; c < color_regions.size (); c++) {
131
131
// Check there is enough room.
132
132
int chars_left = line_length - from;
@@ -136,6 +136,10 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
136
136
continue ;
137
137
}
138
138
139
+ if (color_regions[c].is_string && color_regions[c].r_prefix != r_prefix) {
140
+ continue ;
141
+ }
142
+
139
143
// Search the line.
140
144
bool match = true ;
141
145
const char32_t *start_key = color_regions[c].start_key .get_data ();
@@ -154,7 +158,7 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
154
158
// Check if it's the whole line.
155
159
if (end_key_length == 0 || color_regions[c].line_only || from + end_key_length > line_length) {
156
160
// Don't skip comments, for highlighting markers.
157
- if (color_regions[in_region].type == ColorRegion::TYPE_COMMENT ) {
161
+ if (color_regions[in_region].is_comment ) {
158
162
break ;
159
163
}
160
164
if (from + end_key_length > line_length) {
@@ -176,7 +180,7 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
176
180
}
177
181
178
182
// Don't skip comments, for highlighting markers.
179
- if (j == line_length && color_regions[in_region].type != ColorRegion::TYPE_COMMENT ) {
183
+ if (j == line_length && ! color_regions[in_region].is_comment ) {
180
184
continue ;
181
185
}
182
186
}
@@ -198,7 +202,7 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
198
202
highlighter_info[" color" ] = region_color;
199
203
color_map[j] = highlighter_info;
200
204
201
- if (color_regions[in_region].type == ColorRegion::TYPE_COMMENT ) {
205
+ if (color_regions[in_region].is_comment ) {
202
206
int marker_start_pos = from;
203
207
int marker_len = 0 ;
204
208
while (from <= line_length) {
@@ -242,15 +246,15 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
242
246
}
243
247
244
248
if (str[from] == ' \\ ' ) {
245
- if (!in_raw_string ) {
249
+ if (!color_regions[in_region]. r_prefix ) {
246
250
Dictionary escape_char_highlighter_info;
247
251
escape_char_highlighter_info[" color" ] = symbol_color;
248
252
color_map[from] = escape_char_highlighter_info;
249
253
}
250
254
251
255
from++;
252
256
253
- if (!in_raw_string ) {
257
+ if (!color_regions[in_region]. r_prefix ) {
254
258
int esc_len = 0 ;
255
259
if (str[from] == ' u' ) {
256
260
esc_len = 4 ;
@@ -556,12 +560,6 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
556
560
}
557
561
}
558
562
559
- if (!in_raw_string && in_region == -1 && str[j] == ' r' && j < line_length - 1 && (str[j + 1 ] == ' "' || str[j + 1 ] == ' \' ' )) {
560
- in_raw_string = true ;
561
- } else if (in_raw_string && in_region == -1 ) {
562
- in_raw_string = false ;
563
- }
564
-
565
563
// Keep symbol color for binary '&&'. In the case of '&&&' use StringName color for the last ampersand.
566
564
if (!in_string_name && in_region == -1 && str[j] == ' &' && !is_binary_op) {
567
565
if (j >= 2 && str[j - 1 ] == ' &' && str[j - 2 ] != ' &' && prev_is_binary_op) {
@@ -593,7 +591,9 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
593
591
in_annotation = false ;
594
592
}
595
593
596
- if (in_raw_string) {
594
+ const bool in_raw_string_prefix = in_region == -1 && str[j] == ' r' && j + 1 < line_length && (str[j + 1 ] == ' "' || str[j + 1 ] == ' \' ' );
595
+
596
+ if (in_raw_string_prefix) {
597
597
color = string_color;
598
598
} else if (in_node_ref) {
599
599
next_type = NODE_REF;
@@ -795,6 +795,10 @@ void GDScriptSyntaxHighlighter::_update_cache() {
795
795
add_color_region (ColorRegion::TYPE_STRING, " '" , " '" , string_color);
796
796
add_color_region (ColorRegion::TYPE_MULTILINE_STRING, " \"\"\" " , " \"\"\" " , string_color);
797
797
add_color_region (ColorRegion::TYPE_MULTILINE_STRING, " '''" , " '''" , string_color);
798
+ add_color_region (ColorRegion::TYPE_STRING, " \" " , " \" " , string_color, false , true );
799
+ add_color_region (ColorRegion::TYPE_STRING, " '" , " '" , string_color, false , true );
800
+ add_color_region (ColorRegion::TYPE_MULTILINE_STRING, " \"\"\" " , " \"\"\" " , string_color, false , true );
801
+ add_color_region (ColorRegion::TYPE_MULTILINE_STRING, " '''" , " '''" , string_color, false , true );
798
802
799
803
const Ref<Script> scr = _get_edited_resource ();
800
804
if (scr.is_valid ()) {
@@ -927,7 +931,7 @@ void GDScriptSyntaxHighlighter::_update_cache() {
927
931
}
928
932
}
929
933
930
- void GDScriptSyntaxHighlighter::add_color_region (ColorRegion::Type p_type, const String &p_start_key, const String &p_end_key, const Color &p_color, bool p_line_only) {
934
+ void GDScriptSyntaxHighlighter::add_color_region (ColorRegion::Type p_type, const String &p_start_key, const String &p_end_key, const Color &p_color, bool p_line_only, bool p_r_prefix ) {
931
935
ERR_FAIL_COND_MSG (p_start_key.is_empty (), " Color region start key cannot be empty." );
932
936
ERR_FAIL_COND_MSG (!is_symbol (p_start_key[0 ]), " Color region start key must start with a symbol." );
933
937
@@ -936,9 +940,9 @@ void GDScriptSyntaxHighlighter::add_color_region(ColorRegion::Type p_type, const
936
940
}
937
941
938
942
int at = 0 ;
939
- for (int i = 0 ; i < color_regions. size (); i++ ) {
940
- ERR_FAIL_COND_MSG (color_regions[i] .start_key == p_start_key, " Color region with start key '" + p_start_key + " ' already exists." );
941
- if (p_start_key.length () < color_regions[i] .start_key .length ()) {
943
+ for (const ColorRegion ®ion : color_regions) {
944
+ ERR_FAIL_COND_MSG (region .start_key == p_start_key && region. r_prefix == p_r_prefix , " Color region with start key '" + p_start_key + " ' already exists." );
945
+ if (p_start_key.length () < region .start_key .length ()) {
942
946
at++;
943
947
} else {
944
948
break ;
@@ -951,6 +955,9 @@ void GDScriptSyntaxHighlighter::add_color_region(ColorRegion::Type p_type, const
951
955
color_region.start_key = p_start_key;
952
956
color_region.end_key = p_end_key;
953
957
color_region.line_only = p_line_only;
958
+ color_region.r_prefix = p_r_prefix;
959
+ color_region.is_string = p_type == ColorRegion::TYPE_STRING || p_type == ColorRegion::TYPE_MULTILINE_STRING;
960
+ color_region.is_comment = p_type == ColorRegion::TYPE_COMMENT || p_type == ColorRegion::TYPE_CODE_REGION;
954
961
color_regions.insert (at, color_region);
955
962
clear_highlighting_cache ();
956
963
}
0 commit comments