From b79cacadaae8a64a1a229d592266308dde68428b Mon Sep 17 00:00:00 2001 From: dubiousconst282 <87553666+dubiousconst282@users.noreply.github.com> Date: Thu, 7 Nov 2024 00:27:27 -0300 Subject: [PATCH 1/2] fix: Infinite loop in repl highlighting --- Source/Silverfly.Repl/ReplPromptCallbacks.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Source/Silverfly.Repl/ReplPromptCallbacks.cs b/Source/Silverfly.Repl/ReplPromptCallbacks.cs index 498eaa2..6151b1e 100644 --- a/Source/Silverfly.Repl/ReplPromptCallbacks.cs +++ b/Source/Silverfly.Repl/ReplPromptCallbacks.cs @@ -21,7 +21,7 @@ protected override Task> HighlightCallbackAsync( var spans = GetKeywordSpans(text, keywords) .Concat(brackets) - //.Concat(GetNumberSpans(text)) + .Concat(GetNumberSpans(text)) .Concat(GetStringsSpans(text)) .ToList(); @@ -121,13 +121,17 @@ private static IEnumerable GetNumberSpans(string text) { int startIndex = offset; - while (char.IsDigit(text[offset])) + while (offset < text.Length && char.IsDigit(text[offset])) { offset++; } - yield return new FormatSpan(startIndex, offset, ToAnsi(MessageFormatter.Theme.Number)); + if (startIndex == 0 || !char.IsLetter(text[startIndex - 1])) + { + yield return new FormatSpan(startIndex, offset, ToAnsi(MessageFormatter.Theme.Number)); + } } + offset++; } } } From 4b2c014038b6f83397157d725ef568b7770bb1f1 Mon Sep 17 00:00:00 2001 From: dubiousconst282 <87553666+dubiousconst282@users.noreply.github.com> Date: Thu, 7 Nov 2024 00:28:37 -0300 Subject: [PATCH 2/2] fix: Check for EOF while skipping single line comment --- .../Comments/MultiLineCommentIgnoreMatcher.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Source/Silverfly/Lexing/IgnoreMatcher/Comments/MultiLineCommentIgnoreMatcher.cs b/Source/Silverfly/Lexing/IgnoreMatcher/Comments/MultiLineCommentIgnoreMatcher.cs index c0ddf09..cd6e27b 100644 --- a/Source/Silverfly/Lexing/IgnoreMatcher/Comments/MultiLineCommentIgnoreMatcher.cs +++ b/Source/Silverfly/Lexing/IgnoreMatcher/Comments/MultiLineCommentIgnoreMatcher.cs @@ -29,11 +29,14 @@ public void Advance(Lexer lexer) { lexer.Advance(start.Name.Length); - while (!lexer.IsMatch(end)) + while (lexer.IsNotAtEnd()) { + if (lexer.IsMatch(end)) + { + lexer.Advance(end.Name.Length); + break; + } lexer.Advance(); } - - lexer.Advance(end.Name.Length); } }