Skip to content

Commit 199a447

Browse files
committed
Simplified coordination between the parser and simulation.
1 parent f1f4fca commit 199a447

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

SqlServerSimulator/Parser/ParserContext.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using SqlServerSimulator.Parser.Tokens;
22
using System.Collections.Frozen;
33
using System.Data.Common;
4+
using System.Diagnostics.CodeAnalysis;
45

56
namespace SqlServerSimulator.Parser;
67

@@ -80,7 +81,7 @@ public void MoveNextOptional()
8081
public Token GetNextRequired()
8182
{
8283
var previous = this.Token;
83-
return MoveNext() ? this.Token! : throw SimulatedSqlException.SyntaxErrorNear(previous);
84+
return MoveNext() ? this.Token : throw SimulatedSqlException.SyntaxErrorNear(previous);
8485
}
8586

8687
/// <summary>
@@ -131,7 +132,8 @@ public void MoveNextRequired()
131132
/// <see cref="index"/> is updated to the position of the next token.
132133
/// </remarks>
133134
/// <returns>True if another token was found, otherwise false.</returns>
134-
private bool MoveNext()
135+
[MemberNotNullWhen(true, nameof(Token))]
136+
public bool MoveNext()
135137
{
136138
while (Tokenizer.NextToken(commandText, ref index) is Token token)
137139
{

SqlServerSimulator/Simulation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ internal IEnumerable<SimulatedStatementOutcome> CreateResultSetsForCommand(Simul
3232
{
3333
var context = new ParserContext(command);
3434

35-
while (context.GetNextOptional() is not null)
35+
while (context.MoveNext())
3636
{
3737
switch (context.Token)
3838
{
@@ -166,7 +166,7 @@ internal IEnumerable<SimulatedStatementOutcome> CreateResultSetsForCommand(Simul
166166
}
167167

168168
throw SimulatedSqlException.SyntaxErrorNear(context);
169-
} // while (tokens.TryMoveNext(out var token))
169+
}
170170
}
171171

172172
private static bool TryParseSet(ParserContext context)

0 commit comments

Comments
 (0)