refactor: rename ES5 to JavaScript

This commit is contained in:
TopchetoEU 2024-08-30 18:48:30 +03:00
parent a0f0550c81
commit 6767a707ed
Signed by: topchetoeu
GPG Key ID: 6531B8583E5F6ED4
29 changed files with 95 additions and 99 deletions

View File

@ -1,14 +1,10 @@
package me.topchetoeu.jscript.compilation;
import me.topchetoeu.jscript.common.Operation;
import me.topchetoeu.jscript.common.parsing.Location;
public abstract class AssignableStatement extends Statement {
public interface AssignableStatement {
public abstract Statement toAssign(Statement val, Operation operation);
protected AssignableStatement(Location loc) {
super(loc);
}
// private static final Map<String, Operation> operations = Map.ofEntries(
// Map.entry("*=", Operation.MULTIPLY),
// Map.entry("/=", Operation.DIVIDE),

View File

@ -75,7 +75,7 @@ public class CompoundStatement extends Statement {
if (!src.is(i + n, ",")) return ParseRes.failed();
n++;
var res = ES5.parseExpression(src, i + n, 2);
var res = JavaScript.parseExpression(src, i + n, 2);
if (!res.isSuccess()) return res.chainError(src.loc(i + n), "Expected a value after the comma");
n += res.n;
@ -102,7 +102,7 @@ public class CompoundStatement extends Statement {
continue;
}
var res = ES5.parseStatement(src, i + n);
var res = JavaScript.parseStatement(src, i + n);
if (!res.isSuccess()) return res.chainError(src.loc(i + n), "Expected a statement");
n += res.n;

View File

@ -43,7 +43,7 @@ import me.topchetoeu.jscript.compilation.values.operations.TypeofStatement;
import me.topchetoeu.jscript.compilation.values.operations.VariableIndexStatement;
import me.topchetoeu.jscript.runtime.exceptions.SyntaxException;
public class ES5 {
public class JavaScript {
static final Set<String> reserved = Set.of(
"true", "false", "void", "null", "this", "if", "else", "try", "catch",
"finally", "for", "do", "while", "switch", "case", "default", "new",
@ -59,7 +59,7 @@ public class ES5 {
if (!openParen.isSuccess()) return openParen.chainError();
n += openParen.n;
var res = ES5.parseExpression(src, i + n, 0);
var res = JavaScript.parseExpression(src, i + n, 0);
if (!res.isSuccess()) return res.chainError(src.loc(i + n), "Expected an expression in parens");
n += res.n;
@ -74,7 +74,7 @@ public class ES5 {
return ParseRes.first(src, i,
(a, b) -> statement ? ParseRes.failed() : ObjectStatement.parse(a, b),
(a, b) -> statement ? ParseRes.failed() : FunctionStatement.parseFunction(a, b, false),
ES5::parseLiteral,
JavaScript::parseLiteral,
StringStatement::parse,
RegexStatement::parse,
NumberStatement::parse,
@ -82,7 +82,7 @@ public class ES5 {
ChangeStatement::parsePrefixIncrease,
OperationStatement::parsePrefix,
ArrayStatement::parse,
ES5::parseParens,
JavaScript::parseParens,
CallStatement::parseNew,
TypeofStatement::parse,
DiscardStatement::parse,
@ -162,7 +162,7 @@ public class ES5 {
var res = parseExpression(src, i, 0, true);
if (!res.isSuccess()) return res.chainError();
var end = ES5.parseStatementEnd(src, i + res.n);
var end = JavaScript.parseStatementEnd(src, i + res.n);
if (!end.isSuccess()) return ParseRes.error(src.loc(i + res.n), "Expected an end of statement");
return res.addN(end.n);
@ -191,7 +191,7 @@ public class ES5 {
TryStatement::parse,
CompoundStatement::parse,
(s, j) -> FunctionStatement.parseFunction(s, j, true),
ES5::parseExpressionStatement
JavaScript::parseExpressionStatement
);
return res.addN(n);
}
@ -232,7 +232,7 @@ public class ES5 {
}
public static boolean checkVarName(String name) {
return !ES5.reserved.contains(name);
return !JavaScript.reserved.contains(name);
}
public static ParseRes<List<String>> parseParamList(Source src, int i) {
@ -297,6 +297,6 @@ public class ES5 {
}
public static CompileResult compile(Filename filename, String raw) {
return ES5.compile(ES5.parse(filename, raw));
return JavaScript.compile(JavaScript.parse(filename, raw));
}
}

View File

@ -63,7 +63,7 @@ public class VariableDeclareStatement extends Statement {
var res = new ArrayList<Pair>();
var end = ES5.parseStatementEnd(src, i + n);
var end = JavaScript.parseStatementEnd(src, i + n);
if (end.isSuccess()) {
n += end.n;
return ParseRes.res(new VariableDeclareStatement(loc, res), n);
@ -75,7 +75,7 @@ public class VariableDeclareStatement extends Statement {
if (!name.isSuccess()) return name.chainError(nameLoc, "Expected a variable name");
n += name.n;
if (!ES5.checkVarName(name.result)) {
if (!JavaScript.checkVarName(name.result)) {
return ParseRes.error(src.loc(i + n), String.format("Unexpected identifier '%s'", name.result));
}
@ -85,7 +85,7 @@ public class VariableDeclareStatement extends Statement {
if (src.is(i + n, "=")) {
n++;
var valRes = ES5.parseExpression(src, i + n, 2);
var valRes = JavaScript.parseExpression(src, i + n, 2);
if (!valRes.isSuccess()) return valRes.chainError(src.loc(i + n), "Expected a value after '='");
n += valRes.n;
@ -100,7 +100,7 @@ public class VariableDeclareStatement extends Statement {
continue;
}
end = ES5.parseStatementEnd(src, i + n);
end = JavaScript.parseStatementEnd(src, i + n);
if (end.isSuccess()) {
n += end.n;

View File

@ -6,7 +6,7 @@ import me.topchetoeu.jscript.common.parsing.ParseRes;
import me.topchetoeu.jscript.common.parsing.Parsing;
import me.topchetoeu.jscript.common.parsing.Source;
import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.ES5;
import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.compilation.Statement;
public class BreakStatement extends Statement {
@ -29,7 +29,7 @@ public class BreakStatement extends Statement {
if (!Parsing.isIdentifier(src, i + n, "break")) return ParseRes.failed();
n += 5;
var end = ES5.parseStatementEnd(src, i + n);
var end = JavaScript.parseStatementEnd(src, i + n);
if (end.isSuccess()) {
n += end.n;
return ParseRes.res(new BreakStatement(loc, null), n);
@ -39,7 +39,7 @@ public class BreakStatement extends Statement {
if (label.isFailed()) return ParseRes.error(src.loc(i + n), "Expected a label name or an end of statement");
n += label.n;
end = ES5.parseStatementEnd(src, i + n);
end = JavaScript.parseStatementEnd(src, i + n);
if (end.isSuccess()) {
n += end.n;
return ParseRes.res(new BreakStatement(loc, label.result), n);

View File

@ -6,7 +6,7 @@ import me.topchetoeu.jscript.common.parsing.ParseRes;
import me.topchetoeu.jscript.common.parsing.Parsing;
import me.topchetoeu.jscript.common.parsing.Source;
import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.ES5;
import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.compilation.Statement;
public class ContinueStatement extends Statement {
@ -29,7 +29,7 @@ public class ContinueStatement extends Statement {
if (!Parsing.isIdentifier(src, i + n, "continue")) return ParseRes.failed();
n += 8;
var end = ES5.parseStatementEnd(src, i + n);
var end = JavaScript.parseStatementEnd(src, i + n);
if (end.isSuccess()) {
n += end.n;
return ParseRes.res(new ContinueStatement(loc, null), n);
@ -39,7 +39,7 @@ public class ContinueStatement extends Statement {
if (label.isFailed()) return ParseRes.error(src.loc(i + n), "Expected a label name or an end of statement");
n += label.n;
end = ES5.parseStatementEnd(src, i + n);
end = JavaScript.parseStatementEnd(src, i + n);
if (end.isSuccess()) {
n += end.n;
return ParseRes.res(new ContinueStatement(loc, label.result), n);

View File

@ -6,7 +6,7 @@ import me.topchetoeu.jscript.common.parsing.ParseRes;
import me.topchetoeu.jscript.common.parsing.Parsing;
import me.topchetoeu.jscript.common.parsing.Source;
import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.ES5;
import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.compilation.Statement;
public class DebugStatement extends Statement {
@ -26,7 +26,7 @@ public class DebugStatement extends Statement {
if (!Parsing.isIdentifier(src, i + n, "debugger")) return ParseRes.failed();
n += 8;
var end = ES5.parseStatementEnd(src, i + n);
var end = JavaScript.parseStatementEnd(src, i + n);
if (end.isSuccess()) {
n += end.n;
return ParseRes.res(new DebugStatement(loc), n);

View File

@ -6,7 +6,7 @@ import me.topchetoeu.jscript.common.parsing.ParseRes;
import me.topchetoeu.jscript.common.parsing.Parsing;
import me.topchetoeu.jscript.common.parsing.Source;
import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.ES5;
import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.compilation.Statement;
import me.topchetoeu.jscript.compilation.values.VariableStatement;
import me.topchetoeu.jscript.compilation.values.constants.BoolStatement;
@ -32,7 +32,7 @@ public class DeleteStatement extends Statement {
if (!Parsing.isIdentifier(src, i + n, "delete")) return ParseRes.failed();
n += 6;
var valRes = ES5.parseExpression(src, i + n, 15);
var valRes = JavaScript.parseExpression(src, i + n, 15);
if (!valRes.isSuccess()) return valRes.chainError(src.loc(i + n), "Expected a value after 'delete'");
n += valRes.n;

View File

@ -7,7 +7,7 @@ import me.topchetoeu.jscript.common.parsing.ParseRes;
import me.topchetoeu.jscript.common.parsing.Parsing;
import me.topchetoeu.jscript.common.parsing.Source;
import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.ES5;
import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.compilation.Statement;
public class DoWhileStatement extends Statement {
@ -48,7 +48,7 @@ public class DoWhileStatement extends Statement {
if (!Parsing.isIdentifier(src, i + n, "do")) return ParseRes.failed();
n += 2;
var bodyRes = ES5.parseStatement(src, i + n);
var bodyRes = JavaScript.parseStatement(src, i + n);
if (!bodyRes.isSuccess()) return bodyRes.chainError(src.loc(i + n), "Expected a do-while body.");
n += bodyRes.n;
@ -59,7 +59,7 @@ public class DoWhileStatement extends Statement {
if (!src.is(i + n, "(")) return ParseRes.error(src.loc(i + n), "Expected a open paren after 'while'.");
n++;
var condRes = ES5.parseExpression(src, i + n, 0);
var condRes = JavaScript.parseExpression(src, i + n, 0);
if (!condRes.isSuccess()) return condRes.chainError(src.loc(i + n), "Expected a do-while condition.");
n += condRes.n;
n += Parsing.skipEmpty(src, i + n);
@ -67,7 +67,7 @@ public class DoWhileStatement extends Statement {
if (!src.is(i + n, ")")) return ParseRes.error(src.loc(i + n), "Expected a closing paren after do-while condition.");
n++;
var end = ES5.parseStatementEnd(src, i + n);
var end = JavaScript.parseStatementEnd(src, i + n);
if (end.isSuccess()) {
n += end.n;
return ParseRes.res(new DoWhileStatement(loc, labelRes.result, condRes.result, bodyRes.result), n);

View File

@ -8,7 +8,7 @@ import me.topchetoeu.jscript.common.parsing.ParseRes;
import me.topchetoeu.jscript.common.parsing.Parsing;
import me.topchetoeu.jscript.common.parsing.Source;
import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.ES5;
import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.compilation.Statement;
public class ForInStatement extends Statement {
@ -91,7 +91,7 @@ public class ForInStatement extends Statement {
if (!Parsing.isIdentifier(src, i + n, "in")) return ParseRes.error(src.loc(i + n), "Expected 'in' keyword after variable declaration");
n += 2;
var obj = ES5.parseExpression(src, i + n, 0);
var obj = JavaScript.parseExpression(src, i + n, 0);
if (!obj.isSuccess()) return obj.chainError(src.loc(i + n), "Expected a value");
n += obj.n;
n += Parsing.skipEmpty(src, i + n);
@ -99,7 +99,7 @@ public class ForInStatement extends Statement {
if (!src.is(i + n, ")")) return ParseRes.error(src.loc(i + n), "Expected a closing paren");
n++;
var bodyRes = ES5.parseStatement(src, i + n);
var bodyRes = JavaScript.parseStatement(src, i + n);
if (!bodyRes.isSuccess()) return bodyRes.chainError(src.loc(i + n), "Expected a for-in body");
n += bodyRes.n;

View File

@ -7,7 +7,7 @@ import me.topchetoeu.jscript.common.parsing.ParseRes;
import me.topchetoeu.jscript.common.parsing.Parsing;
import me.topchetoeu.jscript.common.parsing.Source;
import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.ES5;
import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.compilation.Statement;
public class ForOfStatement extends Statement {
@ -103,7 +103,7 @@ public class ForOfStatement extends Statement {
if (!Parsing.isIdentifier(src, i + n, "fo")) return ParseRes.error(src.loc(i + n), "Expected 'of' keyword after variable declaration");
n += 2;
var obj = ES5.parseExpression(src, i + n, 0);
var obj = JavaScript.parseExpression(src, i + n, 0);
if (!obj.isSuccess()) return obj.chainError(src.loc(i + n), "Expected a value");
n += obj.n;
n += Parsing.skipEmpty(src, i + n);
@ -111,7 +111,7 @@ public class ForOfStatement extends Statement {
if (!src.is(i + n, ")")) return ParseRes.error(src.loc(i + n), "Expected a closing paren");
n++;
var bodyRes = ES5.parseStatement(src, i + n);
var bodyRes = JavaScript.parseStatement(src, i + n);
if (!bodyRes.isSuccess()) return bodyRes.chainError(src.loc(i + n), "Expected a for-of body");
n += bodyRes.n;

View File

@ -7,7 +7,7 @@ import me.topchetoeu.jscript.common.parsing.ParseRes;
import me.topchetoeu.jscript.common.parsing.Parsing;
import me.topchetoeu.jscript.common.parsing.Source;
import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.ES5;
import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.compilation.Statement;
import me.topchetoeu.jscript.compilation.VariableDeclareStatement;
import me.topchetoeu.jscript.compilation.values.operations.DiscardStatement;
@ -58,7 +58,7 @@ public class ForStatement extends Statement {
private static ParseRes<Statement> parseCondition(Source src, int i) {
var n = Parsing.skipEmpty(src, i);
var res = ES5.parseExpression(src, i + n, 0);
var res = JavaScript.parseExpression(src, i + n, 0);
if (!res.isSuccess()) return res.chainError();
n += res.n;
n += Parsing.skipEmpty(src, i + n);
@ -67,7 +67,7 @@ public class ForStatement extends Statement {
else return ParseRes.res(res.result, n + 1);
}
private static ParseRes<? extends Statement> parseUpdater(Source src, int i) {
return ES5.parseExpression(src, i, 0);
return JavaScript.parseExpression(src, i, 0);
}
public static ParseRes<ForStatement> parse(Source src, int i) {
@ -108,7 +108,7 @@ public class ForStatement extends Statement {
if (!src.is(i + n, ")")) return ParseRes.error(src.loc(i + n), "Expected a close paren after for updater");
n++;
var body = ES5.parseStatement(src, i + n);
var body = JavaScript.parseStatement(src, i + n);
if (!body.isSuccess()) return body.chainError(src.loc(i + n), "Expected a for body.");
n += body.n;

View File

@ -7,7 +7,7 @@ import me.topchetoeu.jscript.common.parsing.ParseRes;
import me.topchetoeu.jscript.common.parsing.Parsing;
import me.topchetoeu.jscript.common.parsing.Source;
import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.ES5;
import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.compilation.Statement;
public class IfStatement extends Statement {
@ -59,7 +59,7 @@ public class IfStatement extends Statement {
var loc = src.loc(i + n);
n++;
var a = ES5.parseExpression(src, i + n, 2);
var a = JavaScript.parseExpression(src, i + n, 2);
if (!a.isSuccess()) return a.chainError(src.loc(i + n), "Expected a value after the ternary operator.");
n += a.n;
n += Parsing.skipEmpty(src, i);
@ -67,7 +67,7 @@ public class IfStatement extends Statement {
if (!src.is(i + n, ":")) return ParseRes.failed();
n++;
var b = ES5.parseExpression(src, i + n, 2);
var b = JavaScript.parseExpression(src, i + n, 2);
if (!b.isSuccess()) return b.chainError(src.loc(i + n), "Expected a second value after the ternary operator.");
n += b.n;
@ -84,7 +84,7 @@ public class IfStatement extends Statement {
if (!src.is(i + n, "(")) return ParseRes.error(src.loc(i + n), "Expected a open paren after 'if'.");
n++;
var condRes = ES5.parseExpression(src, i + n, 0);
var condRes = JavaScript.parseExpression(src, i + n, 0);
if (!condRes.isSuccess()) return condRes.chainError(src.loc(i + n), "Expected an if condition.");
n += condRes.n;
n += Parsing.skipEmpty(src, i + n);
@ -92,7 +92,7 @@ public class IfStatement extends Statement {
if (!src.is(i + n, ")")) return ParseRes.error(src.loc(i + n), "Expected a closing paren after if condition.");
n++;
var res = ES5.parseStatement(src, i + n);
var res = JavaScript.parseStatement(src, i + n);
if (!res.isSuccess()) return res.chainError(src.loc(i + n), "Expected an if body.");
n += res.n;
@ -100,7 +100,7 @@ public class IfStatement extends Statement {
if (!elseKw.isSuccess()) return ParseRes.res(new IfStatement(loc, condRes.result, res.result, null), n);
n += elseKw.n;
var elseRes = ES5.parseStatement(src, i + n);
var elseRes = JavaScript.parseStatement(src, i + n);
if (!elseRes.isSuccess()) return elseRes.chainError(src.loc(i + n), "Expected an else body.");
n += elseRes.n;

View File

@ -6,7 +6,7 @@ import me.topchetoeu.jscript.common.parsing.ParseRes;
import me.topchetoeu.jscript.common.parsing.Parsing;
import me.topchetoeu.jscript.common.parsing.Source;
import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.ES5;
import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.compilation.Statement;
public class ReturnStatement extends Statement {
@ -31,17 +31,17 @@ public class ReturnStatement extends Statement {
if (!Parsing.isIdentifier(src, i + n, "return")) return ParseRes.failed();
n += 6;
var end = ES5.parseStatementEnd(src, i + n);
var end = JavaScript.parseStatementEnd(src, i + n);
if (end.isSuccess()) {
n += end.n;
return ParseRes.res(new ReturnStatement(loc, null), n);
}
var val = ES5.parseExpression(src, i + n, 0);
var val = JavaScript.parseExpression(src, i + n, 0);
if (val.isError()) return val.chainError();
n += val.n;
end = ES5.parseStatementEnd(src, i + n);
end = JavaScript.parseStatementEnd(src, i + n);
if (end.isSuccess()) {
n += end.n;
return ParseRes.res(new ReturnStatement(loc, val.result), n);

View File

@ -12,7 +12,7 @@ import me.topchetoeu.jscript.common.parsing.ParseRes;
import me.topchetoeu.jscript.common.parsing.Parsing;
import me.topchetoeu.jscript.common.parsing.Source;
import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.ES5;
import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.compilation.Statement;
public class SwitchStatement extends Statement {
@ -90,7 +90,7 @@ public class SwitchStatement extends Statement {
if (!Parsing.isIdentifier(src, i + n, "case")) return ParseRes.failed();
n += 4;
var valRes = ES5.parseExpression(src, i + n, 0);
var valRes = JavaScript.parseExpression(src, i + n, 0);
if (!valRes.isSuccess()) return valRes.chainError(src.loc(i + n), "Expected a value after 'case'");
n += valRes.n;
@ -122,7 +122,7 @@ public class SwitchStatement extends Statement {
if (!src.is(i + n, "(")) return ParseRes.error(src.loc(i + n), "Expected a open paren after 'switch'");
n++;
var valRes = ES5.parseExpression(src, i + n, 0);
var valRes = JavaScript.parseExpression(src, i + n, 0);
if (!valRes.isSuccess()) return valRes.chainError(src.loc(i + n), "Expected a switch value");
n += valRes.n;
n += Parsing.skipEmpty(src, i + n);
@ -167,7 +167,7 @@ public class SwitchStatement extends Statement {
}
if (caseRes.isError()) return caseRes.chainError();
var stm = ES5.parseStatement(src, i + n);
var stm = JavaScript.parseStatement(src, i + n);
if (stm.isSuccess()) {
n += stm.n;
statements.add(stm.result);

View File

@ -6,7 +6,7 @@ import me.topchetoeu.jscript.common.parsing.ParseRes;
import me.topchetoeu.jscript.common.parsing.Parsing;
import me.topchetoeu.jscript.common.parsing.Source;
import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.ES5;
import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.compilation.Statement;
public class ThrowStatement extends Statement {
@ -30,17 +30,17 @@ public class ThrowStatement extends Statement {
if (!Parsing.isIdentifier(src, i + n, "throw")) return ParseRes.failed();
n += 5;
var end = ES5.parseStatementEnd(src, i + n);
var end = JavaScript.parseStatementEnd(src, i + n);
if (end.isSuccess()) {
n += end.n;
return ParseRes.res(new ThrowStatement(loc, null), n);
}
var val = ES5.parseExpression(src, i + n, 0);
var val = JavaScript.parseExpression(src, i + n, 0);
if (val.isFailed()) return ParseRes.error(src.loc(i + n), "Expected a value");
n += val.n;
end = ES5.parseStatementEnd(src, i + n);
end = JavaScript.parseStatementEnd(src, i + n);
if (end.isSuccess()) {
n += end.n;
return ParseRes.res(new ThrowStatement(loc, val.result), n);

View File

@ -8,7 +8,7 @@ import me.topchetoeu.jscript.common.parsing.ParseRes;
import me.topchetoeu.jscript.common.parsing.Parsing;
import me.topchetoeu.jscript.common.parsing.Source;
import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.ES5;
import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.compilation.Statement;
public class WhileStatement extends Statement {
@ -83,7 +83,7 @@ public class WhileStatement extends Statement {
if (!src.is(i + n, "(")) return ParseRes.error(src.loc(i + n), "Expected a open paren after 'while'.");
n++;
var condRes = ES5.parseExpression(src, i + n, 0);
var condRes = JavaScript.parseExpression(src, i + n, 0);
if (!condRes.isSuccess()) return condRes.chainError(src.loc(i + n), "Expected a while condition.");
n += condRes.n;
n += Parsing.skipEmpty(src, i + n);
@ -91,7 +91,7 @@ public class WhileStatement extends Statement {
if (!src.is(i + n, ")")) return ParseRes.error(src.loc(i + n), "Expected a closing paren after while condition.");
n++;
var res = ES5.parseStatement(src, i + n);
var res = JavaScript.parseStatement(src, i + n);
if (!res.isSuccess()) return res.chainError(src.loc(i + n), "Expected a while body.");
n += res.n;

View File

@ -8,7 +8,7 @@ import me.topchetoeu.jscript.common.parsing.ParseRes;
import me.topchetoeu.jscript.common.parsing.Parsing;
import me.topchetoeu.jscript.common.parsing.Source;
import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.ES5;
import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.compilation.Statement;
public class ArrayStatement extends Statement {
@ -70,7 +70,7 @@ public class ArrayStatement extends Statement {
}
}
var res = ES5.parseExpression(src, i + n, 2);
var res = JavaScript.parseExpression(src, i + n, 2);
if (!res.isSuccess()) return res.chainError(src.loc(i + n), "Expected an array element.");
n += res.n;
n += Parsing.skipEmpty(src, i + n);

View File

@ -9,7 +9,7 @@ import me.topchetoeu.jscript.common.parsing.Parsing;
import me.topchetoeu.jscript.common.parsing.Source;
import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.CompoundStatement;
import me.topchetoeu.jscript.compilation.ES5;
import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.compilation.Statement;
import me.topchetoeu.jscript.runtime.exceptions.SyntaxException;
@ -133,7 +133,7 @@ public class FunctionStatement extends Statement {
n += nameRes.n;
n += Parsing.skipEmpty(src, i + n);
var args = ES5.parseParamList(src, i + n);
var args = JavaScript.parseParamList(src, i + n);
if (!args.isSuccess()) return args.chainError(src.loc(i + n), "Expected a parameter list");
n += args.n;

View File

@ -11,7 +11,7 @@ import me.topchetoeu.jscript.common.parsing.Parsing;
import me.topchetoeu.jscript.common.parsing.Source;
import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.CompoundStatement;
import me.topchetoeu.jscript.compilation.ES5;
import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.compilation.Statement;
public class ObjectStatement extends Statement {
@ -103,7 +103,7 @@ public class ObjectStatement extends Statement {
if (!name.isSuccess()) return name.chainError(src.loc(i + n), "Expected a property name after '" + access + "'");
n += name.n;
var params = ES5.parseParamList(src, i + n);
var params = JavaScript.parseParamList(src, i + n);
if (!params.isSuccess()) return params.chainError(src.loc(i + n), "Expected an argument list");
n += params.n;
@ -154,7 +154,7 @@ public class ObjectStatement extends Statement {
if (!src.is(i + n, ":")) return ParseRes.error(src.loc(i + n), "Expected a colon");
n++;
var valRes = ES5.parseExpression(src, i + n, 2);
var valRes = JavaScript.parseExpression(src, i + n, 2);
if (!valRes.isSuccess()) return valRes.chainError(src.loc(i + n), "Expected a value in array list");
n += valRes.n;

View File

@ -8,11 +8,11 @@ import me.topchetoeu.jscript.common.parsing.Parsing;
import me.topchetoeu.jscript.common.parsing.Source;
import me.topchetoeu.jscript.compilation.AssignableStatement;
import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.ES5;
import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.compilation.Statement;
import me.topchetoeu.jscript.compilation.values.operations.VariableAssignStatement;
public class VariableStatement extends AssignableStatement {
public class VariableStatement extends Statement implements AssignableStatement {
public final String name;
@Override public boolean pure() { return false; }
@ -42,7 +42,7 @@ public class VariableStatement extends AssignableStatement {
if (!literal.isSuccess()) return literal.chainError();
n += literal.n;
if (!ES5.checkVarName(literal.result)) {
if (!JavaScript.checkVarName(literal.result)) {
if (literal.result.equals("await")) return ParseRes.error(src.loc(i + n), "'await' expressions are not supported.");
if (literal.result.equals("const")) return ParseRes.error(src.loc(i + n), "'const' declarations are not supported.");
if (literal.result.equals("let")) return ParseRes.error(src.loc(i + n), "'let' declarations are not supported.");

View File

@ -11,7 +11,7 @@ import me.topchetoeu.jscript.common.parsing.ParseRes;
import me.topchetoeu.jscript.common.parsing.Parsing;
import me.topchetoeu.jscript.common.parsing.Source;
import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.ES5;
import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.compilation.Statement;
import me.topchetoeu.jscript.compilation.values.ArrayStatement;
import me.topchetoeu.jscript.compilation.values.ObjectStatement;
@ -136,7 +136,7 @@ public class CallStatement extends Statement {
boolean prevArg = false;
while (true) {
var argRes = ES5.parseExpression(src, i + n, 2);
var argRes = JavaScript.parseExpression(src, i + n, 2);
n += argRes.n;
n += Parsing.skipEmpty(src, i + n);
@ -166,7 +166,7 @@ public class CallStatement extends Statement {
if (!Parsing.isIdentifier(src, i + n, "new")) return ParseRes.failed();
n += 3;
var valRes = ES5.parseExpression(src, i + n, 18);
var valRes = JavaScript.parseExpression(src, i + n, 18);
if (!valRes.isSuccess()) return valRes.chainError(src.loc(i + n), "Expected a value after 'new' keyword.");
n += valRes.n;

View File

@ -8,7 +8,7 @@ import me.topchetoeu.jscript.common.parsing.Parsing;
import me.topchetoeu.jscript.common.parsing.Source;
import me.topchetoeu.jscript.compilation.AssignableStatement;
import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.ES5;
import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.compilation.Statement;
import me.topchetoeu.jscript.compilation.values.constants.NumberStatement;
@ -40,7 +40,7 @@ public class ChangeStatement extends Statement {
if (!src.is(i + n, "++")) return ParseRes.failed();
n += 2;
var res = ES5.parseExpression(src, i + n, 15);
var res = JavaScript.parseExpression(src, i + n, 15);
if (!res.isSuccess()) return res.chainError(src.loc(i + n), "Expected assignable value after prefix operator.");
else if (!(res.result instanceof AssignableStatement)) return ParseRes.error(src.loc(i + n), "Expected assignable value after prefix operator.");
@ -53,7 +53,7 @@ public class ChangeStatement extends Statement {
if (!src.is(i + n, "--")) return ParseRes.failed();
n += 2;
var res = ES5.parseExpression(src, i + n, 15);
var res = JavaScript.parseExpression(src, i + n, 15);
if (!res.isSuccess()) return res.chainError(src.loc(i + n), "Expected assignable value after prefix operator.");
else if (!(res.result instanceof AssignableStatement)) return ParseRes.error(src.loc(i + n), "Expected assignable value after prefix operator.");

View File

@ -6,7 +6,7 @@ import me.topchetoeu.jscript.common.parsing.ParseRes;
import me.topchetoeu.jscript.common.parsing.Parsing;
import me.topchetoeu.jscript.common.parsing.Source;
import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.ES5;
import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.compilation.Statement;
public class DiscardStatement extends Statement {
@ -31,7 +31,7 @@ public class DiscardStatement extends Statement {
if (!Parsing.isIdentifier(src, i + n, "void")) return ParseRes.failed();
n += 4;
var valRes = ES5.parseExpression(src, i + n, 14);
var valRes = JavaScript.parseExpression(src, i + n, 14);
if (!valRes.isSuccess()) return valRes.chainError(src.loc(i + n), "Expected a value after 'void' keyword.");
n += valRes.n;

View File

@ -9,11 +9,11 @@ import me.topchetoeu.jscript.common.parsing.Parsing;
import me.topchetoeu.jscript.common.parsing.Source;
import me.topchetoeu.jscript.compilation.AssignableStatement;
import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.ES5;
import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.compilation.Statement;
import me.topchetoeu.jscript.compilation.values.constants.StringStatement;
public class IndexStatement extends AssignableStatement {
public class IndexStatement extends Statement implements AssignableStatement {
public final Statement object;
public final Statement index;
@ -49,7 +49,7 @@ public class IndexStatement extends AssignableStatement {
if (!src.is(i + n, "[")) return ParseRes.failed();
n++;
var valRes = ES5.parseExpression(src, i + n, 0);
var valRes = JavaScript.parseExpression(src, i + n, 0);
if (!valRes.isSuccess()) return valRes.chainError(src.loc(i + n), "Expected a value in index expression");
n += valRes.n;
n += Parsing.skipEmpty(src, i + n);

View File

@ -6,7 +6,7 @@ import me.topchetoeu.jscript.common.parsing.ParseRes;
import me.topchetoeu.jscript.common.parsing.Parsing;
import me.topchetoeu.jscript.common.parsing.Source;
import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.ES5;
import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.compilation.Statement;
public class LazyAndStatement extends Statement {
@ -39,7 +39,7 @@ public class LazyAndStatement extends Statement {
var loc = src.loc(i + n);
n += 2;
var res = ES5.parseExpression(src, i + n, 4);
var res = JavaScript.parseExpression(src, i + n, 4);
if (!res.isSuccess()) return res.chainError(src.loc(i + n), "Expected a value after the '&&' operator.");
n += res.n;

View File

@ -6,7 +6,7 @@ import me.topchetoeu.jscript.common.parsing.ParseRes;
import me.topchetoeu.jscript.common.parsing.Parsing;
import me.topchetoeu.jscript.common.parsing.Source;
import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.ES5;
import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.compilation.Statement;
public class LazyOrStatement extends Statement {
@ -39,7 +39,7 @@ public class LazyOrStatement extends Statement {
var loc = src.loc(i + n);
n += 2;
var res = ES5.parseExpression(src, i + n, 4);
var res = JavaScript.parseExpression(src, i + n, 4);
if (!res.isSuccess()) return res.chainError(src.loc(i + n), "Expected a value after the '||' operator.");
n += res.n;

View File

@ -13,7 +13,7 @@ import me.topchetoeu.jscript.common.parsing.Parsing;
import me.topchetoeu.jscript.common.parsing.Source;
import me.topchetoeu.jscript.compilation.AssignableStatement;
import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.ES5;
import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.compilation.Statement;
public class OperationStatement extends Statement {
@ -33,7 +33,7 @@ public class OperationStatement extends Statement {
@Override public ParseRes<Statement> construct(Source src, int i, Statement prev) {
var loc = src.loc(i);
var other = ES5.parseExpression(src, i, precedence + 1);
var other = JavaScript.parseExpression(src, i, precedence + 1);
if (!other.isSuccess()) return other.chainError(src.loc(i + other.n), String.format("Expected a value after '%s'", token));
return ParseRes.res(new OperationStatement(loc, operation, prev, (Statement)other.result), other.n);
}
@ -56,7 +56,7 @@ public class OperationStatement extends Statement {
if (!(prev instanceof AssignableStatement)) return ParseRes.error(loc, String.format("Expected an assignable expression before '%s'", token));
var other = ES5.parseExpression(src, i, precedence);
var other = JavaScript.parseExpression(src, i, precedence);
if (!other.isSuccess()) return other.chainError(src.loc(i + other.n), String.format("Expected a value after '%s'", token));
return ParseRes.res(((AssignableStatement)prev).toAssign(other.result, operation), other.n);
}
@ -73,7 +73,7 @@ public class OperationStatement extends Statement {
@Override public ParseRes<Statement> construct(Source src, int i, Statement prev) {
var loc = src.loc(i);
var other = ES5.parseExpression(src, i, 5);
var other = JavaScript.parseExpression(src, i, 5);
if (!other.isSuccess()) return other.chainError(src.loc(i + other.n), "Expected a value after '&&'");
return ParseRes.res(new LazyAndStatement(loc, prev, (Statement)other.result), other.n);
}
@ -84,7 +84,7 @@ public class OperationStatement extends Statement {
@Override public ParseRes<Statement> construct(Source src, int i, Statement prev) {
var loc = src.loc(i);
var other = ES5.parseExpression(src, i, 6);
var other = JavaScript.parseExpression(src, i, 6);
if (!other.isSuccess()) return other.chainError(src.loc(i + other.n), "Expected a value after '||'");
return ParseRes.res(new LazyOrStatement(loc, prev, (Statement)other.result), other.n);
}
@ -171,7 +171,7 @@ public class OperationStatement extends Statement {
n++;
var res = ES5.parseExpression(src, i + n, 14);
var res = JavaScript.parseExpression(src, i + n, 14);
if (res.isSuccess()) return ParseRes.res(new OperationStatement(loc, operation, res.result), n + res.n);
else return res.chainError(src.loc(i + n), String.format("Expected a value after the unary operator '%s'.", op));
@ -186,7 +186,7 @@ public class OperationStatement extends Statement {
if (!kw.isSuccess()) return kw.chainError();
n += kw.n;
var valRes = ES5.parseExpression(src, i + n, 10);
var valRes = JavaScript.parseExpression(src, i + n, 10);
if (!valRes.isSuccess()) return valRes.chainError(src.loc(i + n), "Expected a value after 'instanceof'.");
n += valRes.n;
@ -202,7 +202,7 @@ public class OperationStatement extends Statement {
if (!kw.isSuccess()) return kw.chainError();
n += kw.n;
var valRes = ES5.parseExpression(src, i + n, 10);
var valRes = JavaScript.parseExpression(src, i + n, 10);
if (!valRes.isSuccess()) return valRes.chainError(src.loc(i + n), "Expected a value after 'in'.");
n += valRes.n;

View File

@ -6,7 +6,7 @@ import me.topchetoeu.jscript.common.parsing.ParseRes;
import me.topchetoeu.jscript.common.parsing.Parsing;
import me.topchetoeu.jscript.common.parsing.Source;
import me.topchetoeu.jscript.compilation.CompileResult;
import me.topchetoeu.jscript.compilation.ES5;
import me.topchetoeu.jscript.compilation.JavaScript;
import me.topchetoeu.jscript.compilation.Statement;
import me.topchetoeu.jscript.compilation.values.VariableStatement;
@ -42,7 +42,7 @@ public class TypeofStatement extends Statement {
if (!Parsing.isIdentifier(src, i + n, "typeof")) return ParseRes.failed();
n += 6;
var valRes = ES5.parseExpression(src, i + n, 15);
var valRes = JavaScript.parseExpression(src, i + n, 15);
if (!valRes.isSuccess()) return valRes.chainError(src.loc(i + n), "Expected a value after 'typeof' keyword.");
n += valRes.n;