...
This commit is contained in:
@@ -14,10 +14,10 @@ public static class Parser
|
||||
{
|
||||
private static string _namespace = null!;
|
||||
private static List<Diagnostic> _diagnostics = [];
|
||||
private static List<Token> _tokens = [];
|
||||
private static IEnumerable<Token> _tokens = [];
|
||||
private static int _index;
|
||||
|
||||
public static DiagnosticsResult<CompilationUnit?> ParseFile(List<Token> tokens)
|
||||
public static CompilationUnit? ParseFile(IEnumerable<Token> tokens, out IEnumerable<Diagnostic> diagnostics)
|
||||
{
|
||||
_tokens = tokens;
|
||||
_namespace = null!;
|
||||
@@ -33,7 +33,8 @@ public static class Parser
|
||||
catch (ParseException ex)
|
||||
{
|
||||
_diagnostics.Add(ex.Diagnostic);
|
||||
return new DiagnosticsResult<CompilationUnit?>(_diagnostics, null);
|
||||
diagnostics = _diagnostics;
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
@@ -46,7 +47,8 @@ public static class Parser
|
||||
definitions.Add(definition);
|
||||
}
|
||||
|
||||
return new DiagnosticsResult<CompilationUnit?>(_diagnostics, new CompilationUnit(_namespace, definitions));
|
||||
diagnostics = _diagnostics;
|
||||
return new CompilationUnit(_namespace, definitions);
|
||||
}
|
||||
catch (ParseException ex)
|
||||
{
|
||||
@@ -54,7 +56,8 @@ public static class Parser
|
||||
RecoverToNextDefinition();
|
||||
}
|
||||
|
||||
return new DiagnosticsResult<CompilationUnit?>(_diagnostics, null);
|
||||
diagnostics = _diagnostics;
|
||||
return null;
|
||||
}
|
||||
|
||||
private static DefinitionNode ParseDefinition()
|
||||
@@ -63,7 +66,7 @@ public static class Parser
|
||||
List<ModifierToken> modifiers = [];
|
||||
|
||||
List<string> documentationParts = [];
|
||||
while (_index < _tokens.Count && _tokens[_index] is DocumentationToken commentToken)
|
||||
while (_index < _tokens.Count() && _tokens.ElementAt(_index) is DocumentationToken commentToken)
|
||||
{
|
||||
documentationParts.Add(commentToken.Documentation);
|
||||
_index++;
|
||||
@@ -898,14 +901,14 @@ public static class Parser
|
||||
private static Optional<Token> Peek(int offset = 0)
|
||||
{
|
||||
var peekIndex = _index + offset;
|
||||
while (peekIndex < _tokens.Count && _tokens[peekIndex] is DocumentationToken)
|
||||
while (peekIndex < _tokens.Count() && _tokens.ElementAt(peekIndex) is DocumentationToken)
|
||||
{
|
||||
peekIndex++;
|
||||
}
|
||||
|
||||
if (peekIndex < _tokens.Count)
|
||||
if (peekIndex < _tokens.Count())
|
||||
{
|
||||
return _tokens[peekIndex];
|
||||
return _tokens.ElementAt(peekIndex);
|
||||
}
|
||||
|
||||
return Optional<Token>.Empty();
|
||||
@@ -913,7 +916,7 @@ public static class Parser
|
||||
|
||||
private static void Next()
|
||||
{
|
||||
while (_index < _tokens.Count && _tokens[_index] is DocumentationToken)
|
||||
while (_index < _tokens.Count() && _tokens.ElementAt(_index) is DocumentationToken)
|
||||
{
|
||||
_index++;
|
||||
}
|
||||
@@ -921,9 +924,9 @@ public static class Parser
|
||||
_index++;
|
||||
}
|
||||
|
||||
private static IReadOnlyList<Token> GetTokensForNode(int startIndex)
|
||||
private static IEnumerable<Token> GetTokensForNode(int startIndex)
|
||||
{
|
||||
return _tokens[startIndex..Math.Min(_index, _tokens.Count - 1)];
|
||||
return _tokens.Skip(startIndex).Take(Math.Min(_index, _tokens.Count() - 1) - startIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user