refactor: 移除 OperatorTokenScanner 中的冗余状态管理

- 删除了未使用的 State 枚举类
- 移除了冗余的 currentState 变量和相关逻辑
- 简化了代码结构,提高了代码可读性
This commit is contained in:
Luke 2025-07-17 15:09:02 +08:00
parent d0e8cee6bd
commit 7f09b0e501

View File

@ -47,10 +47,6 @@ public class OperatorTokenScanner extends AbstractTokenScanner {
char c = ctx.advance();
String lexeme = String.valueOf(c);
TokenType type = TokenType.UNKNOWN;
// 当前状态
State currentState = State.OPERATOR;
switch (c) {
case '=':
if (ctx.match('=')) {
@ -107,22 +103,10 @@ public class OperatorTokenScanner extends AbstractTokenScanner {
break;
default:
currentState = State.UNKNOWN;
break;
}
// 执行完扫描后重置状态为初始状态
if (currentState != State.UNKNOWN) {
currentState = State.START;
}
return new Token(type, lexeme, line, col);
}
// 定义状态枚举
private enum State {
START, // 初始状态
OPERATOR, // 当前字符是运算符的一部分
UNKNOWN // 无法识别的状态
}
}