Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse more UnparsedLiterals, but only if they're actually meaningful #4776

Merged
merged 7 commits into from
Jun 30, 2022
29 changes: 20 additions & 9 deletions src/main/java/ch/njol/skript/lang/SkriptParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,15 +369,20 @@ private final <T> Expression<? extends T> parseSingleExpr(final boolean allowUnp
log.printError();
return null;
}
if (allowUnparsedLiteral && types[0] == Object.class) {
if (types[0] == Object.class) {
// Do check if a literal with this name actually exists before returning an UnparsedLiteral
if (!allowUnparsedLiteral || Classes.parseSimple(expr, Object.class, context) == null) {
log.printError();
return null;
}
log.clear();
LogEntry e = log.getError();
final LogEntry e = log.getError();
return (Literal<? extends T>) new UnparsedLiteral(expr, e != null && (error == null || e.quality > error.quality) ? e : error);
}
for (final Class<? extends T> c : types) {
log.clear();
assert c != null;
T t = Classes.parse(expr, c, context);
final T t = Classes.parse(expr, c, context);
if (t != null) {
log.printLog();
return new SimpleLiteral<>(t, false);
Expand Down Expand Up @@ -563,14 +568,20 @@ else if (!hasSingular && hasPlural)
log.printError();
return null;
}
if (allowUnparsedLiteral && vi.classes[0].getC() == Object.class) {
if (vi.classes[0].getC() == Object.class) {
// Do check if a literal with this name actually exists before returning an UnparsedLiteral
if (!allowUnparsedLiteral || Classes.parseSimple(expr, Object.class, context) == null) {
log.printError();
return null;
}
log.clear();
LogEntry e = log.getError();
final LogEntry e = log.getError();
return new UnparsedLiteral(expr, e != null && (error == null || e.quality > error.quality) ? e : error);
}
for (ClassInfo<?> ci : vi.classes) {
for (final ClassInfo<?> ci : vi.classes) {
log.clear();
Object t = Classes.parse(expr, ci.getC(), context);
assert ci.getC() != null;
final Object t = Classes.parse(expr, ci.getC(), context);
if (t != null) {
log.printLog();
return new SimpleLiteral<>(t, false, new UnparsedLiteral(expr));
Expand Down Expand Up @@ -613,7 +624,7 @@ public final <T> Expression<? extends T> parseExpression(final Class<? extends T
final boolean isObject = types.length == 1 && types[0] == Object.class;
final ParseLogHandler log = SkriptLogger.startParseLogHandler();
try {
final Expression<? extends T> r = parseSingleExpr(false, null, types);
final Expression<? extends T> r = parseSingleExpr(true, null, types);
if (r != null) {
log.printLog();
return r;
Expand Down Expand Up @@ -739,7 +750,7 @@ public final Expression<?> parseExpression(final ExprInfo vi) {
final ParseLogHandler log = SkriptLogger.startParseLogHandler();
try {
// Attempt to parse a single expression
final Expression<?> r = parseSingleExpr(false, null, vi);
final Expression<?> r = parseSingleExpr(true, null, vi);
if (r != null) {
log.printLog();
return r;
Expand Down