style: TokenStream.isAtEnd 返回值符合文档说明
This commit is contained in:
parent
50654fac6d
commit
22c7ec46f8
@ -120,7 +120,7 @@ public class TokenStream {
|
|||||||
* @return 若当前位置 Token 为 EOF,则返回 true,否则 false
|
* @return 若当前位置 Token 为 EOF,则返回 true,否则 false
|
||||||
*/
|
*/
|
||||||
public boolean isAtEnd() {
|
public boolean isAtEnd() {
|
||||||
return peek().getType() != TokenType.EOF;
|
return peek().getType() == TokenType.EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -17,7 +17,7 @@ public record ParserEngine(ParserContext ctx) {
|
|||||||
List<String> errs = new ArrayList<>();
|
List<String> errs = new ArrayList<>();
|
||||||
TokenStream ts = ctx.getTokens();
|
TokenStream ts = ctx.getTokens();
|
||||||
|
|
||||||
while (ts.isAtEnd()) {
|
while (!ts.isAtEnd()) {
|
||||||
// 跳过空行
|
// 跳过空行
|
||||||
if (ts.peek().getType() == TokenType.NEWLINE) {
|
if (ts.peek().getType() == TokenType.NEWLINE) {
|
||||||
ts.next();
|
ts.next();
|
||||||
@ -46,7 +46,7 @@ public record ParserEngine(ParserContext ctx) {
|
|||||||
* 错误同步:跳到下一行或下一个已注册顶层关键字
|
* 错误同步:跳到下一行或下一个已注册顶层关键字
|
||||||
*/
|
*/
|
||||||
private void synchronize(TokenStream ts) {
|
private void synchronize(TokenStream ts) {
|
||||||
while (ts.isAtEnd()) {
|
while (!ts.isAtEnd()) {
|
||||||
if (ts.peek().getType() == TokenType.NEWLINE) {
|
if (ts.peek().getType() == TokenType.NEWLINE) {
|
||||||
ts.next();
|
ts.next();
|
||||||
break;
|
break;
|
||||||
@ -57,7 +57,7 @@ public record ParserEngine(ParserContext ctx) {
|
|||||||
ts.next();
|
ts.next();
|
||||||
}
|
}
|
||||||
// 连续空行全部吃掉
|
// 连续空行全部吃掉
|
||||||
while (ts.isAtEnd() && ts.peek().getType() == TokenType.NEWLINE) {
|
while (!ts.isAtEnd() && ts.peek().getType() == TokenType.NEWLINE) {
|
||||||
ts.next();
|
ts.next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -92,7 +92,7 @@ public class PrattExpressionParser implements ExpressionParser {
|
|||||||
|
|
||||||
ExpressionNode left = prefix.parse(ctx, token);
|
ExpressionNode left = prefix.parse(ctx, token);
|
||||||
|
|
||||||
while (ctx.getTokens().isAtEnd()
|
while (!ctx.getTokens().isAtEnd()
|
||||||
&& prec.ordinal() < nextPrecedence(ctx)) {
|
&& prec.ordinal() < nextPrecedence(ctx)) {
|
||||||
String lex = ctx.getTokens().peek().getLexeme();
|
String lex = ctx.getTokens().peek().getLexeme();
|
||||||
InfixParselet infix = infixes.get(lex);
|
InfixParselet infix = infixes.get(lex);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user