From 59872e535277f59bd8a25deac6f82248b3c7904a Mon Sep 17 00:00:00 2001 From: pommicket Date: Thu, 12 Jun 2025 15:18:31 -0400 Subject: C# string interpolation, bump version to 2.8.0 --- README.md | 1 + syntax.c | 51 ++++++++++++++++++++++++++++++++++++---- ted.h | 2 +- windows_installer/ted/ted.vdproj | 6 ++--- 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d4550e8..3067d9c 100644 --- a/README.md +++ b/README.md @@ -362,6 +362,7 @@ Then run `make.bat release`. 2.7.6 Fix new LSP bug introduced by 2.7.5 2024 Dec 8 2.7.7 Add prepareRename support, fix IDE hover 2025 Mar 5 2.7.8 Fix occasional crash (bad settings pointer) 2025 Mar 23 +2.8.0 Add syntax highlighting for C#; improvements to other languages 2025 Jun 12 ## License diff --git a/syntax.c b/syntax.c index 82a7ede..9c6f24d 100644 --- a/syntax.c +++ b/syntax.c @@ -79,6 +79,8 @@ enum { SYNTAX_STATE_CSHARP_STRING_RAW = 0x01, SYNTAX_STATE_CSHARP_STRING_VERBATIM = 0x02, SYNTAX_STATE_CSHARP_MULTILINE_COMMENT = 0x04, + SYNTAX_STATE_CSHARP_TEMPLATE_STRING = 0x08, + SYNTAX_STATE_CSHARP_INTERPOLATING = 0x10, }; typedef struct { @@ -2284,8 +2286,10 @@ static void syntax_highlight_gdscript(SyntaxState *state, const char32_t *line, static void syntax_highlight_csharp(SyntaxState *state, const char32_t *line, u32 line_len, SyntaxCharType *char_types) { bool string_is_raw = (*state & SYNTAX_STATE_CSHARP_STRING_RAW) != 0; bool string_is_verbatim = (*state & SYNTAX_STATE_CSHARP_STRING_VERBATIM) != 0; + bool string_is_template = (*state & SYNTAX_STATE_CSHARP_TEMPLATE_STRING) != 0; bool in_multiline_comment = (*state & SYNTAX_STATE_CSHARP_MULTILINE_COMMENT) != 0; - bool in_string = string_is_raw || string_is_verbatim; + bool interpolating = (*state & SYNTAX_STATE_CSHARP_INTERPOLATING) != 0; + bool in_string = (string_is_raw || string_is_verbatim) && !interpolating; bool in_number = false; bool in_preprocessor = false; u32 backslashes = 0; @@ -2332,7 +2336,15 @@ static void syntax_highlight_csharp(SyntaxState *state, const char32_t *line, u3 dealt_with = true; } break; - case '"': { + case '$': + if (line[i+1] == '"') { + string_is_template = true; + if (char_types) char_types[i] = SYNTAX_STRING; + dealt_with = true; + } + break; + case '"': + if (interpolating) break; if (in_string && string_is_raw) { if (i + 2 < line_len && line[i+1] == '"' && line[i+2] == '"') { in_string = false; @@ -2344,6 +2356,7 @@ static void syntax_highlight_csharp(SyntaxState *state, const char32_t *line, u3 } else if (in_string) { if (backslashes % 2 == 0 || string_is_verbatim) { in_string = false; + string_is_raw = string_is_verbatim = false; if (char_types) char_types[i] = SYNTAX_STRING; dealt_with = true; } @@ -2355,7 +2368,33 @@ static void syntax_highlight_csharp(SyntaxState *state, const char32_t *line, u3 i += 2; } } - } break; + break; + case '{': + if (in_string && string_is_template) { + u32 lbraces = 1; + if (char_types) + char_types[i] = SYNTAX_STRING; + for (i++; i < line_len; i++) { + if (line[i] != '{') break; + if (char_types) + char_types[i] = SYNTAX_STRING; + lbraces++; + } + i--; + if (lbraces == 1) { + // string interpolation + interpolating = true; + in_string = false; + dealt_with = true; + } + } + break; + case '}': + if (interpolating) { + interpolating = false; + in_string = true; + } + break; case '\'': if (!in_string) { if (char_types) char_types[i] = SYNTAX_CHARACTER; @@ -2404,7 +2443,7 @@ static void syntax_highlight_csharp(SyntaxState *state, const char32_t *line, u3 char_types[i] = char_types[i+1] = SYNTAX_COMMENT; } i++; - continue; + dealt_with = true; } } break; @@ -2446,9 +2485,11 @@ static void syntax_highlight_csharp(SyntaxState *state, const char32_t *line, u3 } } *state = (SyntaxState)( - (SYNTAX_STATE_CSHARP_STRING_RAW * (in_string && string_is_raw)) + (SYNTAX_STATE_CSHARP_STRING_RAW * ((in_string || interpolating) && string_is_raw)) | (SYNTAX_STATE_CSHARP_STRING_VERBATIM * (in_string && string_is_verbatim)) | (SYNTAX_STATE_CSHARP_MULTILINE_COMMENT * in_multiline_comment) + | (SYNTAX_STATE_CSHARP_TEMPLATE_STRING * ((in_string || interpolating) && string_is_template)) + | (SYNTAX_STATE_CSHARP_INTERPOLATING * interpolating) ); } diff --git a/ted.h b/ted.h index 7f5f139..a8aab74 100644 --- a/ted.h +++ b/ted.h @@ -22,7 +22,7 @@ extern "C" { #include "command.h" /// Version number -#define TED_VERSION "2.7.8" +#define TED_VERSION "2.8.0" /// Maximum path size ted handles. #define TED_PATH_MAX 1024 /// Config filename diff --git a/windows_installer/ted/ted.vdproj b/windows_installer/ted/ted.vdproj index 4a0dc56..9ba4d8c 100644 --- a/windows_installer/ted/ted.vdproj +++ b/windows_installer/ted/ted.vdproj @@ -620,15 +620,15 @@ { "Name" = "8:Microsoft Visual Studio" "ProductName" = "8:ted" - "ProductCode" = "8:{72C2B66B-B357-435B-9F50-BD23829BB5CE}" - "PackageCode" = "8:{E505C206-972B-41DD-9DF5-8D295E73C659}" + "ProductCode" = "8:{3B295C5E-C63E-4212-BC99-2E58429E1304}" + "PackageCode" = "8:{062BC64F-94A7-4DA0-ACAA-E92922554EA4}" "UpgradeCode" = "8:{844F6C2B-DF3B-4A81-9BD5-603401BBA651}" "AspNetVersion" = "8:2.0.50727.0" "RestartWWWService" = "11:FALSE" "RemovePreviousVersions" = "11:TRUE" "DetectNewerInstalledVersion" = "11:FALSE" "InstallAllUsers" = "11:FALSE" - "ProductVersion" = "8:25.03.2400" + "ProductVersion" = "8:25.06.1200" "Manufacturer" = "8:ted" "ARPHELPTELEPHONE" = "8:" "ARPHELPLINK" = "8:" -- cgit v1.2.3