|
1 | | -using System.Collections.Frozen; |
| 1 | +using SqlServerSimulator.Parser.Tokens; |
| 2 | +using System.Collections.Frozen; |
2 | 3 | using System.Data.Common; |
3 | 4 |
|
4 | 5 | namespace SqlServerSimulator.Parser; |
@@ -35,10 +36,29 @@ public ParserContext(SimulatedDbCommand command) |
35 | 36 | #if DEBUG |
36 | 37 | this.tokens = new TokenArrayEnumerator(command.CommandText); |
37 | 38 | #else |
38 | | - this.tokens = Tokenizer.Tokenize(command.CommandText).GetEnumerator(); |
| 39 | + this.tokens = TokenizerIterator(command.CommandText).GetEnumerator(); |
39 | 40 | #endif |
40 | 41 | } |
41 | 42 |
|
| 43 | + /// <summary> |
| 44 | + /// Converts the redesigned tokenizer to a traditional enumerable for compatibility with the existing logic. |
| 45 | + /// This should be phased out eventually. |
| 46 | + /// </summary> |
| 47 | + static IEnumerable<Token> TokenizerIterator(string? commandText) |
| 48 | + { |
| 49 | + if (string.IsNullOrEmpty(commandText)) |
| 50 | + throw new InvalidOperationException("ExecuteReader: CommandText property has not been initialized"); |
| 51 | + |
| 52 | + var index = -1; |
| 53 | + while (Tokenizer.NextToken(commandText, ref index) is Token token) |
| 54 | + { |
| 55 | + if (token is Whitespace) |
| 56 | + continue; |
| 57 | + |
| 58 | + yield return token; |
| 59 | + } |
| 60 | + } |
| 61 | + |
42 | 62 | public Simulation Simulation => Command.simulation; |
43 | 63 |
|
44 | 64 | /// <summary> |
@@ -167,10 +187,10 @@ public void Dispose() |
167 | 187 | private sealed class TokenArrayEnumerator(string? command) : IEnumerator<Token> |
168 | 188 | { |
169 | 189 | /// <summary> |
170 | | - /// Retains the full results of <see cref="Tokenizer.Tokenize(string?)"/>. |
| 190 | + /// Retains the full results of tokenization. |
171 | 191 | /// This is less efficient than streaming the results, but enables this class's debugging-friendly <see cref="ToString"/>. |
172 | 192 | /// </summary> |
173 | | - private readonly Token[] source = [.. Tokenizer.Tokenize(command)]; |
| 193 | + private readonly Token[] source = [.. TokenizerIterator(command)]; |
174 | 194 |
|
175 | 195 | public int Index { get; private set; } = -1; |
176 | 196 |
|
|
0 commit comments