mirror of
https://github.com/Stone-Red-Code/YesNt-Interpreter.git
synced 2026-09-08 07:56:06 +02:00
Swap variable and string regex order and update highlight colors to prevent highlighting glitches
This commit is contained in:
@@ -36,19 +36,18 @@ internal partial class SyntaxHighlighter(ReadOnlyCollection<StatementInformation
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
MatchCollection matches = StringRegex().Matches(input);
|
||||||
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);
|
|
||||||
for (int i = 0; i < matches.Count; i++)
|
for (int i = 0; i < matches.Count; i++)
|
||||||
{
|
{
|
||||||
input = AddColorInformation(input, matches[i].Value, ConsoleColor.DarkYellow, SearchMode.Contains);
|
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++)
|
for (int i = 0; i < replacementValues.Length; i++)
|
||||||
{
|
{
|
||||||
input = AddColorInformation(input, replacementValues[i], ConsoleColor.Blue, SearchMode.Contains);
|
input = AddColorInformation(input, replacementValues[i], ConsoleColor.Blue, SearchMode.Contains);
|
||||||
@@ -162,14 +161,15 @@ internal partial class SyntaxHighlighter(ReadOnlyCollection<StatementInformation
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This regex matches variables in the format ${variableName}, where variableName consists of alphanumeric characters.
|
||||||
[GeneratedRegex("\\$\\{[a-zA-Z0-9]+\\}")]
|
[GeneratedRegex("\\$\\{[a-zA-Z0-9]+\\}")]
|
||||||
private static partial Regex VariableRegex();
|
private static partial Regex VariableRegex();
|
||||||
|
|
||||||
// match all double quote pairs
|
// This regex matches string literals, taking into account escaped quotes and backslashes.
|
||||||
|
|
||||||
[GeneratedRegex(@"(?<!\\)(?:\\\\{2})*""(?:\\.|[^""\\])*""")]
|
[GeneratedRegex(@"(?<!\\)(?:\\\\{2})*""(?:\\.|[^""\\])*""")]
|
||||||
private static partial Regex StringRegex();
|
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)")]
|
[GeneratedRegex("(?<=(\\v))(.*)(?=\\v)")]
|
||||||
private static partial Regex StringColorRegex();
|
private static partial Regex StringColorRegex();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user