Skip to content

Commit 1702343

Browse files
authored
Merge pull request #59 from dubiousconst282/fix-infloop
fix: Infinite loop in repl highlighting, single-line comment skipping
2 parents f3e71ce + 4b2c014 commit 1702343

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

Source/Silverfly.Repl/ReplPromptCallbacks.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected override Task<IReadOnlyCollection<FormatSpan>> HighlightCallbackAsync(
2121

2222
var spans = GetKeywordSpans(text, keywords)
2323
.Concat(brackets)
24-
//.Concat(GetNumberSpans(text))
24+
.Concat(GetNumberSpans(text))
2525
.Concat(GetStringsSpans(text))
2626
.ToList();
2727

@@ -121,13 +121,17 @@ private static IEnumerable<FormatSpan> GetNumberSpans(string text)
121121
{
122122
int startIndex = offset;
123123

124-
while (char.IsDigit(text[offset]))
124+
while (offset < text.Length && char.IsDigit(text[offset]))
125125
{
126126
offset++;
127127
}
128128

129-
yield return new FormatSpan(startIndex, offset, ToAnsi(MessageFormatter.Theme.Number));
129+
if (startIndex == 0 || !char.IsLetter(text[startIndex - 1]))
130+
{
131+
yield return new FormatSpan(startIndex, offset, ToAnsi(MessageFormatter.Theme.Number));
132+
}
130133
}
134+
offset++;
131135
}
132136
}
133137
}

Source/Silverfly/Lexing/IgnoreMatcher/Comments/MultiLineCommentIgnoreMatcher.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ public void Advance(Lexer lexer)
2929
{
3030
lexer.Advance(start.Name.Length);
3131

32-
while (!lexer.IsMatch(end))
32+
while (lexer.IsNotAtEnd())
3333
{
34+
if (lexer.IsMatch(end))
35+
{
36+
lexer.Advance(end.Name.Length);
37+
break;
38+
}
3439
lexer.Advance();
3540
}
36-
37-
lexer.Advance(end.Name.Length);
3841
}
3942
}

0 commit comments

Comments
 (0)