Fix statement recovery infinite loop

This commit is contained in:
nub31
2025-05-25 02:28:15 +02:00
parent 29d4a78034
commit ae14398904
2 changed files with 12 additions and 20 deletions

View File

@@ -1,17 +1,12 @@
import c
// Test
// Test2
// Test3
// Test4
/// # Documentation
/// ## Documentation subtitle
global func main(args: []string) {
i = 0
printf("%d\n", args.count)
while i < args.count {
// Test
printf("%s\n", args[i])
i = i + 1
}
i: string = "test"
}

View File

@@ -82,20 +82,17 @@ public class Parser
ExpectSymbol(Symbol.OpenParen);
if (!TryExpectSymbol(Symbol.CloseParen))
while (!TryExpectSymbol(Symbol.CloseParen))
{
while (!TryExpectSymbol(Symbol.CloseParen))
{
parameters.Add(ParseFuncParameter());
parameters.Add(ParseFuncParameter());
if (!TryExpectSymbol(Symbol.Comma) && Peek().TryGetValue(out var token) && token is not SymbolToken { Symbol: Symbol.CloseParen })
{
_diagnostics.Add(Diagnostic
.Warning("Missing comma between function parameters")
.WithHelp("Add a ',' to separate parameters")
.At(token)
.Build());
}
if (!TryExpectSymbol(Symbol.Comma) && Peek().TryGetValue(out var token) && token is not SymbolToken { Symbol: Symbol.CloseParen })
{
_diagnostics.Add(Diagnostic
.Warning("Missing comma between function parameters")
.WithHelp("Add a ',' to separate parameters")
.At(token)
.Build());
}
}
@@ -529,7 +526,7 @@ public class Parser
var startIndex = _index;
ExpectSymbol(Symbol.OpenBrace);
List<StatementNode> statements = [];
while (!TryExpectSymbol(Symbol.CloseBrace))
while (Peek().HasValue && !TryExpectSymbol(Symbol.CloseBrace))
{
try
{