fix: 词法位置报错 (#53)

Co-authored-by: Huaps <1183155719@qq.com>
Reviewed-on: PostGuard/Canon#53
This commit is contained in:
2024-04-24 11:01:45 +08:00
parent d381f56e1d
commit 447a791793
5 changed files with 15 additions and 42 deletions

View File

@@ -1,4 +1,4 @@
using Canon.Core.Enums;
using Canon.Core.Enums;
namespace Canon.Core.LexicalParser;

View File

@@ -10,7 +10,7 @@ public class Lexer : ILexer
// 记录token
private SemanticToken? _semanticToken;
private readonly StringBuilder _tokenBuilder = new();
private readonly List<SemanticToken> _tokens = [];
private List<SemanticToken> _tokens = [];
// 状态机
private StateType _state = StateType.Start;
@@ -25,6 +25,7 @@ public class Lexer : ILexer
public IEnumerable<SemanticToken> Tokenize(ISourceReader reader)
{
_reader = reader;
_tokens = [];
_state = StateType.Start;
while (_state != StateType.Done)