Swap variable and string regex order and update highlight colors to prevent highlighting glitches

This commit is contained in:
Stone_Red
2026-03-04 18:00:08 +01:00
parent f411aa7433
commit 9e9123f58d
+10 -10
View File
@@ -36,19 +36,18 @@ internal partial class SyntaxHighlighter(ReadOnlyCollection<StatementInformation
}
else
{
MatchCollection matches = VariableRegex().Matches(input);
for (int i = 0; i < matches.Count; i++)
{
input = AddColorInformation(input, matches[i].Value, ConsoleColor.Cyan, SearchMode.Contains);
}
matches = StringRegex().Matches(input);
MatchCollection matches = StringRegex().Matches(input);
for (int i = 0; i < matches.Count; i++)
{
input = AddColorInformation(input, matches[i].Value, ConsoleColor.DarkYellow, SearchMode.Contains);
}
matches = VariableRegex().Matches(input);
for (int i = 0; i < matches.Count; i++)
{
input = AddColorInformation(input, matches[i].Value, ConsoleColor.Cyan, SearchMode.Contains);
}
for (int i = 0; i < replacementValues.Length; i++)
{
input = AddColorInformation(input, replacementValues[i], ConsoleColor.Blue, SearchMode.Contains);
@@ -162,14 +161,15 @@ internal partial class SyntaxHighlighter(ReadOnlyCollection<StatementInformation
return result;
}
// This regex matches variables in the format ${variableName}, where variableName consists of alphanumeric characters.
[GeneratedRegex("\\$\\{[a-zA-Z0-9]+\\}")]
private static partial Regex VariableRegex();
// match all double quote pairs
// This regex matches string literals, taking into account escaped quotes and backslashes.
[GeneratedRegex(@"(?<!\\)(?:\\\\{2})*""(?:\\.|[^""\\])*""")]
private static partial Regex StringRegex();
// This regex matches the color information embedded in the string, which is in the format \v{colorIndex}\v{base64EncodedValue}\v.
[GeneratedRegex("(?<=(\\v))(.*)(?=\\v)")]
private static partial Regex StringColorRegex();
}