style: TokenStream.isAtEnd 返回值符合文档说明

This commit is contained in:
zhangxun 2025-06-28 10:20:11 +08:00
parent 50654fac6d
commit 22c7ec46f8
3 changed files with 5 additions and 5 deletions

View File

@ -120,7 +120,7 @@ public class TokenStream {
* @return 若当前位置 Token EOF则返回 true否则 false
*/
public boolean isAtEnd() {
return peek().getType() != TokenType.EOF;
return peek().getType() == TokenType.EOF;
}

View File

@ -17,7 +17,7 @@ public record ParserEngine(ParserContext ctx) {
List<String> errs = new ArrayList<>();
TokenStream ts = ctx.getTokens();
while (ts.isAtEnd()) {
while (!ts.isAtEnd()) {
// 跳过空行
if (ts.peek().getType() == TokenType.NEWLINE) {
ts.next();
@ -46,7 +46,7 @@ public record ParserEngine(ParserContext ctx) {
* 错误同步跳到下一行或下一个已注册顶层关键字
*/
private void synchronize(TokenStream ts) {
while (ts.isAtEnd()) {
while (!ts.isAtEnd()) {
if (ts.peek().getType() == TokenType.NEWLINE) {
ts.next();
break;
@ -57,7 +57,7 @@ public record ParserEngine(ParserContext ctx) {
ts.next();
}
// 连续空行全部吃掉
while (ts.isAtEnd() && ts.peek().getType() == TokenType.NEWLINE) {
while (!ts.isAtEnd() && ts.peek().getType() == TokenType.NEWLINE) {
ts.next();
}
}

View File

@ -92,7 +92,7 @@ public class PrattExpressionParser implements ExpressionParser {
ExpressionNode left = prefix.parse(ctx, token);
while (ctx.getTokens().isAtEnd()
while (!ctx.getTokens().isAtEnd()
&& prec.ordinal() < nextPrecedence(ctx)) {
String lex = ctx.getTokens().peek().getLexeme();
InfixParselet infix = infixes.get(lex);