[jlox] Match error messages to official impl
.... For easier automated testing
This commit is contained in:
@@ -338,6 +338,6 @@ public class Interpreter implements Expr.Visitor<Object>, Stmt.Visitor<Void> {
|
||||
|
||||
private void checkNumberOperands(Token operator, Object left, Object right) {
|
||||
if (left instanceof Double && right instanceof Double) return;
|
||||
throw new RuntimeError(operator, "Operands must be numbers");
|
||||
throw new RuntimeError(operator, "Operands must be numbers.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public class Lox {
|
||||
private static boolean hadRuntimeError = false;
|
||||
|
||||
private static void report(int line, String where, String message) {
|
||||
System.err.printf("[line %d] Error %s: %s%n", line, where, message);
|
||||
System.err.printf("[line %d] Error%s: %s%n", line, where, message);
|
||||
hadError = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,6 @@ public class LoxFunction implements LoxCallable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "<fn " + declaration.name().lexeme() + " >";
|
||||
return "<fn " + declaration.name().lexeme() + ">";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,6 @@ public class LoxInstance {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "<" + clazz.name + " instance>";
|
||||
return clazz.name + " instance";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ public class Parser {
|
||||
params.add(consume(IDENTIFIER, "Expect parameter name."));
|
||||
} while (match(COMMA));
|
||||
}
|
||||
consume(RIGHT_PAREN, "Expect ')' after parameters");
|
||||
consume(RIGHT_PAREN, "Expect ')' after parameters.");
|
||||
|
||||
consume(LEFT_BRACE, "Expect '{' before %s body.".formatted(kind.toString().toLowerCase()));
|
||||
List<Stmt> body = blockStatement();
|
||||
@@ -382,7 +382,7 @@ public class Parser {
|
||||
} while (match(COMMA));
|
||||
}
|
||||
|
||||
Token paren = consume(RIGHT_PAREN, "Expect ')' after arguments");
|
||||
Token paren = consume(RIGHT_PAREN, "Expect ')' after arguments.");
|
||||
return new Expr.Call(callee, paren, arguments);
|
||||
}
|
||||
|
||||
@@ -397,7 +397,7 @@ public class Parser {
|
||||
|
||||
if (match(SUPER)) {
|
||||
Token keyword = previous();
|
||||
consume(DOT, "Expect ',' after 'super'.");
|
||||
consume(DOT, "Expect '.' after 'super'.");
|
||||
Token method = consume(IDENTIFIER, "Expect superclass method name.");
|
||||
return new Expr.Super(keyword, method);
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ public class Resolver implements Expr.Visitor<Void>, Stmt.Visitor<Void> {
|
||||
@Override
|
||||
public Void visitReturnStmt(Stmt.Return stmt) {
|
||||
if (currentFunction == FunctionType.NONE) {
|
||||
Lox.error(stmt.keyword(), "Can't return fom top-level code.");
|
||||
Lox.error(stmt.keyword(), "Can't return from top-level code.");
|
||||
}
|
||||
|
||||
if (stmt.value() != null) {
|
||||
@@ -242,7 +242,7 @@ public class Resolver implements Expr.Visitor<Void>, Stmt.Visitor<Void> {
|
||||
if (currentClass == ClassType.NONE) {
|
||||
Lox.error(expr.keyword(), "Can't use 'super' outside of a class.");
|
||||
} else if (currentClass != ClassType.SUBCLASS) {
|
||||
Lox.error(expr.keyword(), "Can't use 'super' in a class with no subclass.");
|
||||
Lox.error(expr.keyword(), "Can't use 'super' in a class with no superclass.");
|
||||
}
|
||||
resolveLocal(expr, expr.keyword());
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user