You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-10 13:00:37 +00:00
Improvments for SyntaxHighlighters
- Fix immedate Funcion in lamba highlight - Highlight signals as one colour - Highlight node paths as one colour - Highlight escape chars in strings
This commit is contained in:
@@ -60,7 +60,9 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
|
|||||||
bool in_keyword = false;
|
bool in_keyword = false;
|
||||||
bool in_word = false;
|
bool in_word = false;
|
||||||
bool in_function_name = false;
|
bool in_function_name = false;
|
||||||
|
bool in_lambda = false;
|
||||||
bool in_variable_declaration = false;
|
bool in_variable_declaration = false;
|
||||||
|
bool in_signal_declaration = false;
|
||||||
bool in_function_args = false;
|
bool in_function_args = false;
|
||||||
bool in_member_variable = false;
|
bool in_member_variable = false;
|
||||||
bool in_node_path = false;
|
bool in_node_path = false;
|
||||||
@@ -105,6 +107,8 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
|
|||||||
/* color regions */
|
/* color regions */
|
||||||
if (is_a_symbol || in_region != -1) {
|
if (is_a_symbol || in_region != -1) {
|
||||||
int from = j;
|
int from = j;
|
||||||
|
|
||||||
|
if (in_region == -1) {
|
||||||
for (; from < line_length; from++) {
|
for (; from < line_length; from++) {
|
||||||
if (str[from] == '\\') {
|
if (str[from] == '\\') {
|
||||||
from++;
|
from++;
|
||||||
@@ -112,6 +116,7 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (from != line_length) {
|
if (from != line_length) {
|
||||||
/* check if we are in entering a region */
|
/* check if we are in entering a region */
|
||||||
@@ -142,6 +147,12 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
|
|||||||
|
|
||||||
/* check if it's the whole line */
|
/* check if it's the whole line */
|
||||||
if (end_key_length == 0 || color_regions[c].line_only || from + end_key_length > line_length) {
|
if (end_key_length == 0 || color_regions[c].line_only || from + end_key_length > line_length) {
|
||||||
|
if (from + end_key_length > line_length) {
|
||||||
|
// If it's key length and there is a '\', dont skip to highlight esc chars.
|
||||||
|
if (str.find("\\", from) >= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
prev_color = color_regions[in_region].color;
|
prev_color = color_regions[in_region].color;
|
||||||
highlighter_info["color"] = color_regions[c].color;
|
highlighter_info["color"] = color_regions[c].color;
|
||||||
color_map[j] = highlighter_info;
|
color_map[j] = highlighter_info;
|
||||||
@@ -161,21 +172,42 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
|
|||||||
|
|
||||||
/* if we are in one find the end key */
|
/* if we are in one find the end key */
|
||||||
if (in_region != -1) {
|
if (in_region != -1) {
|
||||||
|
Color region_color = color_regions[in_region].color;
|
||||||
|
if (in_node_path && (color_regions[in_region].start_key == "\"" || color_regions[in_region].start_key == "\'")) {
|
||||||
|
region_color = node_path_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
prev_color = region_color;
|
||||||
|
highlighter_info["color"] = region_color;
|
||||||
|
color_map[j] = highlighter_info;
|
||||||
|
|
||||||
/* search the line */
|
/* search the line */
|
||||||
int region_end_index = -1;
|
int region_end_index = -1;
|
||||||
int end_key_length = color_regions[in_region].end_key.length();
|
int end_key_length = color_regions[in_region].end_key.length();
|
||||||
const char32_t *end_key = color_regions[in_region].end_key.get_data();
|
const char32_t *end_key = color_regions[in_region].end_key.get_data();
|
||||||
for (; from < line_length; from++) {
|
for (; from < line_length; from++) {
|
||||||
if (line_length - from < end_key_length) {
|
if (line_length - from < end_key_length) {
|
||||||
|
// Don't break if '\' to highlight esc chars.
|
||||||
|
if (str.find("\\", from) < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_symbol(str[from])) {
|
if (!is_symbol(str[from])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str[from] == '\\') {
|
if (str[from] == '\\') {
|
||||||
|
Dictionary escape_char_highlighter_info;
|
||||||
|
escape_char_highlighter_info["color"] = symbol_color;
|
||||||
|
color_map[from] = escape_char_highlighter_info;
|
||||||
|
|
||||||
from++;
|
from++;
|
||||||
|
|
||||||
|
Dictionary region_continue_highlighter_info;
|
||||||
|
prev_color = region_color;
|
||||||
|
region_continue_highlighter_info["color"] = region_color;
|
||||||
|
color_map[from + 1] = region_continue_highlighter_info;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,10 +224,6 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prev_color = color_regions[in_region].color;
|
|
||||||
highlighter_info["color"] = color_regions[in_region].color;
|
|
||||||
color_map[j] = highlighter_info;
|
|
||||||
|
|
||||||
previous_type = REGION;
|
previous_type = REGION;
|
||||||
previous_text = "";
|
previous_text = "";
|
||||||
previous_column = j;
|
previous_column = j;
|
||||||
@@ -289,6 +317,9 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!in_function_name && in_word && !in_keyword) {
|
if (!in_function_name && in_word && !in_keyword) {
|
||||||
|
if (previous_text == GDScriptTokenizer::get_token_name(GDScriptTokenizer::Token::SIGNAL)) {
|
||||||
|
in_signal_declaration = true;
|
||||||
|
} else {
|
||||||
int k = j;
|
int k = j;
|
||||||
while (k < str.length() && !is_symbol(str[k]) && str[k] != '\t' && str[k] != ' ') {
|
while (k < str.length() && !is_symbol(str[k]) && str[k] != '\t' && str[k] != ' ') {
|
||||||
k++;
|
k++;
|
||||||
@@ -304,6 +335,19 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
|
|||||||
} else if (previous_text == GDScriptTokenizer::get_token_name(GDScriptTokenizer::Token::VAR)) {
|
} else if (previous_text == GDScriptTokenizer::get_token_name(GDScriptTokenizer::Token::VAR)) {
|
||||||
in_variable_declaration = true;
|
in_variable_declaration = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for lambda.
|
||||||
|
if (in_function_name && previous_text == GDScriptTokenizer::get_token_name(GDScriptTokenizer::Token::FUNC)) {
|
||||||
|
k = j - 1;
|
||||||
|
while (k > 0 && (str[k] == '\t' || str[k] == ' ')) {
|
||||||
|
k--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str[k] == ':') {
|
||||||
|
in_lambda = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!in_function_name && !in_member_variable && !in_keyword && !is_number && in_word) {
|
if (!in_function_name && !in_member_variable && !in_keyword && !is_number && in_word) {
|
||||||
@@ -348,7 +392,9 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
|
|||||||
}
|
}
|
||||||
|
|
||||||
in_variable_declaration = false;
|
in_variable_declaration = false;
|
||||||
|
in_signal_declaration = false;
|
||||||
in_function_name = false;
|
in_function_name = false;
|
||||||
|
in_lambda = false;
|
||||||
in_member_variable = false;
|
in_member_variable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -375,11 +421,15 @@ Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting_impl(int p_l
|
|||||||
color = keyword_color;
|
color = keyword_color;
|
||||||
} else if (in_member_variable) {
|
} else if (in_member_variable) {
|
||||||
next_type = MEMBER;
|
next_type = MEMBER;
|
||||||
|
color = member_color;
|
||||||
|
} else if (in_signal_declaration) {
|
||||||
|
next_type = SIGNAL;
|
||||||
|
|
||||||
color = member_color;
|
color = member_color;
|
||||||
} else if (in_function_name) {
|
} else if (in_function_name) {
|
||||||
next_type = FUNCTION;
|
next_type = FUNCTION;
|
||||||
|
|
||||||
if (previous_text == GDScriptTokenizer::get_token_name(GDScriptTokenizer::Token::FUNC)) {
|
if (!in_lambda && previous_text == GDScriptTokenizer::get_token_name(GDScriptTokenizer::Token::FUNC)) {
|
||||||
color = function_definition_color;
|
color = function_definition_color;
|
||||||
} else {
|
} else {
|
||||||
color = function_color;
|
color = function_color;
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ private:
|
|||||||
SYMBOL,
|
SYMBOL,
|
||||||
NUMBER,
|
NUMBER,
|
||||||
FUNCTION,
|
FUNCTION,
|
||||||
|
SIGNAL,
|
||||||
KEYWORD,
|
KEYWORD,
|
||||||
MEMBER,
|
MEMBER,
|
||||||
IDENTIFIER,
|
IDENTIFIER,
|
||||||
|
|||||||
@@ -171,6 +171,8 @@ Dictionary CodeHighlighter::_get_line_syntax_highlighting_impl(int p_line) {
|
|||||||
/* color regions */
|
/* color regions */
|
||||||
if (is_a_symbol || in_region != -1) {
|
if (is_a_symbol || in_region != -1) {
|
||||||
int from = j;
|
int from = j;
|
||||||
|
|
||||||
|
if (in_region == -1) {
|
||||||
for (; from < line_length; from++) {
|
for (; from < line_length; from++) {
|
||||||
if (str[from] == '\\') {
|
if (str[from] == '\\') {
|
||||||
from++;
|
from++;
|
||||||
@@ -178,6 +180,7 @@ Dictionary CodeHighlighter::_get_line_syntax_highlighting_impl(int p_line) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (from != line_length) {
|
if (from != line_length) {
|
||||||
/* check if we are in entering a region */
|
/* check if we are in entering a region */
|
||||||
@@ -208,6 +211,12 @@ Dictionary CodeHighlighter::_get_line_syntax_highlighting_impl(int p_line) {
|
|||||||
|
|
||||||
/* check if it's the whole line */
|
/* check if it's the whole line */
|
||||||
if (end_key_length == 0 || color_regions[c].line_only || from + end_key_length > line_length) {
|
if (end_key_length == 0 || color_regions[c].line_only || from + end_key_length > line_length) {
|
||||||
|
if (from + end_key_length > line_length && (color_regions[in_region].start_key == "\"" || color_regions[in_region].start_key == "\'")) {
|
||||||
|
// If it's key length and there is a '\', dont skip to highlight esc chars.
|
||||||
|
if (str.find("\\", from) >= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
prev_color = color_regions[in_region].color;
|
prev_color = color_regions[in_region].color;
|
||||||
highlighter_info["color"] = color_regions[c].color;
|
highlighter_info["color"] = color_regions[c].color;
|
||||||
color_map[j] = highlighter_info;
|
color_map[j] = highlighter_info;
|
||||||
@@ -227,21 +236,44 @@ Dictionary CodeHighlighter::_get_line_syntax_highlighting_impl(int p_line) {
|
|||||||
|
|
||||||
/* if we are in one find the end key */
|
/* if we are in one find the end key */
|
||||||
if (in_region != -1) {
|
if (in_region != -1) {
|
||||||
|
bool is_string = (color_regions[in_region].start_key == "\"" || color_regions[in_region].start_key == "\'");
|
||||||
|
|
||||||
|
Color region_color = color_regions[in_region].color;
|
||||||
|
prev_color = region_color;
|
||||||
|
highlighter_info["color"] = region_color;
|
||||||
|
color_map[j] = highlighter_info;
|
||||||
|
|
||||||
/* search the line */
|
/* search the line */
|
||||||
int region_end_index = -1;
|
int region_end_index = -1;
|
||||||
int end_key_length = color_regions[in_region].end_key.length();
|
int end_key_length = color_regions[in_region].end_key.length();
|
||||||
const char32_t *end_key = color_regions[in_region].end_key.get_data();
|
const char32_t *end_key = color_regions[in_region].end_key.get_data();
|
||||||
for (; from < line_length; from++) {
|
for (; from < line_length; from++) {
|
||||||
if (line_length - from < end_key_length) {
|
if (line_length - from < end_key_length) {
|
||||||
|
// Don't break if '\' to highlight esc chars.
|
||||||
|
if (!is_string || str.find("\\", from) < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_symbol(str[from])) {
|
if (!is_symbol(str[from])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str[from] == '\\') {
|
if (str[from] == '\\') {
|
||||||
|
if (is_string) {
|
||||||
|
Dictionary escape_char_highlighter_info;
|
||||||
|
escape_char_highlighter_info["color"] = symbol_color;
|
||||||
|
color_map[from] = escape_char_highlighter_info;
|
||||||
|
}
|
||||||
|
|
||||||
from++;
|
from++;
|
||||||
|
|
||||||
|
if (is_string) {
|
||||||
|
Dictionary region_continue_highlighter_info;
|
||||||
|
prev_color = region_color;
|
||||||
|
region_continue_highlighter_info["color"] = region_color;
|
||||||
|
color_map[from + 1] = region_continue_highlighter_info;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,10 +290,6 @@ Dictionary CodeHighlighter::_get_line_syntax_highlighting_impl(int p_line) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prev_color = color_regions[in_region].color;
|
|
||||||
highlighter_info["color"] = color_regions[in_region].color;
|
|
||||||
color_map[j] = highlighter_info;
|
|
||||||
|
|
||||||
j = from + (end_key_length - 1);
|
j = from + (end_key_length - 1);
|
||||||
if (region_end_index == -1) {
|
if (region_end_index == -1) {
|
||||||
color_region_cache[p_line] = in_region;
|
color_region_cache[p_line] = in_region;
|
||||||
|
|||||||
Reference in New Issue
Block a user