Skip to content

Commit

Permalink
Merge pull request #59 from dubiousconst282/fix-infloop
Browse files Browse the repository at this point in the history
fix: Infinite loop in repl highlighting, single-line comment skipping
  • Loading branch information
furesoft authored Nov 7, 2024
2 parents f3e71ce + 4b2c014 commit 1702343
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
10 changes: 7 additions & 3 deletions Source/Silverfly.Repl/ReplPromptCallbacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected override Task<IReadOnlyCollection<FormatSpan>> HighlightCallbackAsync(

var spans = GetKeywordSpans(text, keywords)
.Concat(brackets)
//.Concat(GetNumberSpans(text))
.Concat(GetNumberSpans(text))
.Concat(GetStringsSpans(text))
.ToList();

Expand Down Expand Up @@ -121,13 +121,17 @@ private static IEnumerable<FormatSpan> 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++;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 1702343

Please sign in to comment.