From 3d275c52c036e0e821bc5a2e8e23875047ab226b Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Sun, 24 Dec 2023 14:30:31 +0200 Subject: [PATCH] refactor: fix code to not result in compile warning --- src/me/topchetoeu/jscript/parsing/ParseRes.java | 3 +++ src/me/topchetoeu/jscript/parsing/Parsing.java | 14 ++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/me/topchetoeu/jscript/parsing/ParseRes.java b/src/me/topchetoeu/jscript/parsing/ParseRes.java index 0d79c03..e69f04e 100644 --- a/src/me/topchetoeu/jscript/parsing/ParseRes.java +++ b/src/me/topchetoeu/jscript/parsing/ParseRes.java @@ -69,6 +69,9 @@ public class ParseRes { @SafeVarargs public static ParseRes any(ParseRes ...parsers) { + return any(List.of(parsers)); + } + public static ParseRes any(List> parsers) { ParseRes best = null; ParseRes error = ParseRes.failed(); diff --git a/src/me/topchetoeu/jscript/parsing/Parsing.java b/src/me/topchetoeu/jscript/parsing/Parsing.java index 8226029..6131677 100644 --- a/src/me/topchetoeu/jscript/parsing/Parsing.java +++ b/src/me/topchetoeu/jscript/parsing/Parsing.java @@ -216,8 +216,10 @@ public class Parsing { currToken.append(c); continue; case CURR_SCIENTIFIC_NOT: - if (c == '-') currStage = CURR_NEG_SCIENTIFIC_NOT; - else if (!isDigit(c)) { + if (c == '-') { + if (currToken.toString().endsWith("e")) currStage = CURR_NEG_SCIENTIFIC_NOT; + } + if (currStage == CURR_SCIENTIFIC_NOT && !isDigit(c)) { i--; start--; break; } @@ -565,7 +567,8 @@ public class Parsing { } private static double parseNumber(Location loc, String value) { var res = parseNumber(false, value); - if (res == null) throw new SyntaxException(loc, "Invalid number format."); + if (res == null) + throw new SyntaxException(loc, "Invalid number format."); else return res; } @@ -1022,9 +1025,8 @@ public class Parsing { return ParseRes.res(res.result, n); } - @SuppressWarnings("all") public static ParseRes parseSimple(Filename filename, List tokens, int i, boolean statement) { - var res = new ArrayList<>(); + var res = new ArrayList>(); if (!statement) { res.add(parseObject(filename, tokens, i)); @@ -1047,7 +1049,7 @@ public class Parsing { parseDelete(filename, tokens, i) )); - return ParseRes.any(res.toArray(ParseRes[]::new)); + return ParseRes.any(res); } public static ParseRes parseVariable(Filename filename, List tokens, int i) {