mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-01 19:06:41 +00:00
Renamed Assignable to LValue and Invokable to RValue
This commit is contained in:
@ -32,7 +32,7 @@ import com.sk89q.worldedit.expression.lexer.tokens.OperatorToken;
|
||||
import com.sk89q.worldedit.expression.lexer.tokens.Token;
|
||||
import com.sk89q.worldedit.expression.runtime.Constant;
|
||||
import com.sk89q.worldedit.expression.runtime.Functions;
|
||||
import com.sk89q.worldedit.expression.runtime.Invokable;
|
||||
import com.sk89q.worldedit.expression.runtime.RValue;
|
||||
|
||||
public class Parser {
|
||||
private final class NullToken extends Token {
|
||||
@ -51,19 +51,19 @@ public class Parser {
|
||||
|
||||
private final List<Token> tokens;
|
||||
private int position = 0;
|
||||
private Map<String, Invokable> variables;
|
||||
private Map<String, RValue> variables;
|
||||
|
||||
private Parser(List<Token> tokens, Map<String, Invokable> variables) {
|
||||
private Parser(List<Token> tokens, Map<String, RValue> variables) {
|
||||
this.tokens = tokens;
|
||||
this.variables = variables;
|
||||
}
|
||||
|
||||
public static final Invokable parse(List<Token> tokens, Map<String, Invokable> variables) throws ParserException {
|
||||
public static final RValue parse(List<Token> tokens, Map<String, RValue> variables) throws ParserException {
|
||||
return new Parser(tokens, variables).parse();
|
||||
}
|
||||
|
||||
private Invokable parse() throws ParserException {
|
||||
final Invokable ret = parseInternal(true);
|
||||
private RValue parse() throws ParserException {
|
||||
final RValue ret = parseInternal(true);
|
||||
if (position < tokens.size()) {
|
||||
final Token token = peek();
|
||||
throw new ParserException(token.getPosition(), "Extra token at the end of the input: " + token);
|
||||
@ -71,7 +71,7 @@ public class Parser {
|
||||
return ret;
|
||||
}
|
||||
|
||||
private final Invokable parseInternal(boolean isStatement) throws ParserException {
|
||||
private final RValue parseInternal(boolean isStatement) throws ParserException {
|
||||
LinkedList<Identifiable> halfProcessed = new LinkedList<Identifiable>();
|
||||
|
||||
// process brackets, numbers, functions, variables and detect prefix operators
|
||||
@ -95,7 +95,7 @@ public class Parser {
|
||||
halfProcessed.add(parseFunctionCall(identifierToken));
|
||||
}
|
||||
else {
|
||||
Invokable variable = variables.get(identifierToken.value);
|
||||
RValue variable = variables.get(identifierToken.value);
|
||||
if (variable == null) {
|
||||
throw new ParserException(current.getPosition(), "Variable '" + identifierToken.value + "' not found");
|
||||
}
|
||||
@ -167,7 +167,7 @@ public class Parser {
|
||||
return Functions.getFunction(identifierToken.getPosition(), identifierToken.value);
|
||||
}
|
||||
|
||||
List<Invokable> args = new ArrayList<Invokable>();
|
||||
List<RValue> args = new ArrayList<RValue>();
|
||||
|
||||
loop: while (true) {
|
||||
args.add(parseInternal(false));
|
||||
@ -187,20 +187,20 @@ public class Parser {
|
||||
}
|
||||
}
|
||||
|
||||
return Functions.getFunction(identifierToken.getPosition(), identifierToken.value, args.toArray(new Invokable[args.size()]));
|
||||
return Functions.getFunction(identifierToken.getPosition(), identifierToken.value, args.toArray(new RValue[args.size()]));
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
throw new ParserException(identifierToken.getPosition(), "Function not found", e);
|
||||
}
|
||||
}
|
||||
|
||||
private final Invokable parseBracket() throws ParserException {
|
||||
private final RValue parseBracket() throws ParserException {
|
||||
if (peek().id() != '(') {
|
||||
throw new ParserException(peek().getPosition(), "Unexpected character in parseBracket");
|
||||
}
|
||||
++position;
|
||||
|
||||
final Invokable ret = parseInternal(false);
|
||||
final RValue ret = parseInternal(false);
|
||||
|
||||
if (peek().id() != ')') {
|
||||
throw new ParserException(peek().getPosition(), "Unmatched opening bracket");
|
||||
@ -210,13 +210,13 @@ public class Parser {
|
||||
return ret;
|
||||
}
|
||||
|
||||
private final Invokable parseBlock() throws ParserException {
|
||||
private final RValue parseBlock() throws ParserException {
|
||||
if (peek().id() != '{') {
|
||||
throw new ParserException(peek().getPosition(), "Unexpected character in parseBlock");
|
||||
}
|
||||
++position;
|
||||
|
||||
final Invokable ret = parseInternal(true);
|
||||
final RValue ret = parseInternal(true);
|
||||
|
||||
if (peek().id() != '}') {
|
||||
throw new ParserException(peek().getPosition(), "Unmatched opening brace");
|
||||
|
@ -9,7 +9,7 @@ import java.util.Map;
|
||||
import com.sk89q.worldedit.expression.Identifiable;
|
||||
import com.sk89q.worldedit.expression.lexer.tokens.OperatorToken;
|
||||
import com.sk89q.worldedit.expression.lexer.tokens.Token;
|
||||
import com.sk89q.worldedit.expression.runtime.Invokable;
|
||||
import com.sk89q.worldedit.expression.runtime.RValue;
|
||||
import com.sk89q.worldedit.expression.runtime.Operators;
|
||||
import com.sk89q.worldedit.expression.runtime.Sequence;
|
||||
|
||||
@ -121,7 +121,7 @@ public final class ParserProcessors {
|
||||
}
|
||||
}
|
||||
|
||||
static Invokable processStatement(LinkedList<Identifiable> input) throws ParserException {
|
||||
static RValue processStatement(LinkedList<Identifiable> input) throws ParserException {
|
||||
LinkedList<Identifiable> lhs = new LinkedList<Identifiable>();
|
||||
LinkedList<Identifiable> rhs = new LinkedList<Identifiable>();
|
||||
boolean semicolonFound = false;
|
||||
@ -153,18 +153,18 @@ public final class ParserProcessors {
|
||||
else {
|
||||
assert(semicolonFound);
|
||||
|
||||
Invokable lhsInvokable = processExpression(lhs);
|
||||
Invokable rhsInvokable = processStatement(rhs);
|
||||
RValue lhsInvokable = processExpression(lhs);
|
||||
RValue rhsInvokable = processStatement(rhs);
|
||||
|
||||
return new Sequence(lhsInvokable.getPosition(), lhsInvokable, rhsInvokable);
|
||||
}
|
||||
}
|
||||
|
||||
static Invokable processExpression(LinkedList<Identifiable> input) throws ParserException {
|
||||
static RValue processExpression(LinkedList<Identifiable> input) throws ParserException {
|
||||
return processBinaryOpsRA(input, binaryOpMapsRA.length - 1);
|
||||
}
|
||||
|
||||
private static Invokable processBinaryOpsLA(LinkedList<Identifiable> input, int level) throws ParserException {
|
||||
private static RValue processBinaryOpsLA(LinkedList<Identifiable> input, int level) throws ParserException {
|
||||
if (level < 0) {
|
||||
return processUnaryOps(input);
|
||||
}
|
||||
@ -194,10 +194,10 @@ public final class ParserProcessors {
|
||||
}
|
||||
}
|
||||
|
||||
Invokable rhsInvokable = processBinaryOpsLA(rhs, level - 1);
|
||||
RValue rhsInvokable = processBinaryOpsLA(rhs, level - 1);
|
||||
if (operator == null) return rhsInvokable;
|
||||
|
||||
Invokable lhsInvokable = processBinaryOpsLA(lhs, level);
|
||||
RValue lhsInvokable = processBinaryOpsLA(lhs, level);
|
||||
|
||||
try {
|
||||
return Operators.getOperator(input.get(0).getPosition(), operator, lhsInvokable, rhsInvokable);
|
||||
@ -208,7 +208,7 @@ public final class ParserProcessors {
|
||||
}
|
||||
}
|
||||
|
||||
private static Invokable processBinaryOpsRA(LinkedList<Identifiable> input, int level) throws ParserException {
|
||||
private static RValue processBinaryOpsRA(LinkedList<Identifiable> input, int level) throws ParserException {
|
||||
if (level < 0) {
|
||||
return processTernaryOps(input);
|
||||
}
|
||||
@ -237,10 +237,10 @@ public final class ParserProcessors {
|
||||
}
|
||||
}
|
||||
|
||||
Invokable lhsInvokable = processBinaryOpsRA(lhs, level - 1);
|
||||
RValue lhsInvokable = processBinaryOpsRA(lhs, level - 1);
|
||||
if (operator == null) return lhsInvokable;
|
||||
|
||||
Invokable rhsInvokable = processBinaryOpsRA(rhs, level);
|
||||
RValue rhsInvokable = processBinaryOpsRA(rhs, level);
|
||||
|
||||
try {
|
||||
return Operators.getOperator(input.get(0).getPosition(), operator, lhsInvokable, rhsInvokable);
|
||||
@ -251,16 +251,16 @@ public final class ParserProcessors {
|
||||
}
|
||||
}
|
||||
|
||||
private static Invokable processTernaryOps(LinkedList<Identifiable> input) throws ParserException {
|
||||
private static RValue processTernaryOps(LinkedList<Identifiable> input) throws ParserException {
|
||||
return processBinaryOpsLA(input, binaryOpMapsLA.length - 1);
|
||||
}
|
||||
|
||||
private static Invokable processUnaryOps(LinkedList<Identifiable> input) throws ParserException {
|
||||
private static RValue processUnaryOps(LinkedList<Identifiable> input) throws ParserException {
|
||||
if (input.isEmpty()) {
|
||||
throw new ParserException(-1, "Expression missing.");
|
||||
}
|
||||
|
||||
Invokable ret = (Invokable) input.removeLast();
|
||||
RValue ret = (RValue) input.removeLast();
|
||||
while (!input.isEmpty()) {
|
||||
final Identifiable last = input.removeLast();
|
||||
final int lastPosition = last.getPosition();
|
||||
@ -284,7 +284,7 @@ public final class ParserProcessors {
|
||||
if (last instanceof Token) {
|
||||
throw new ParserException(lastPosition, "Extra token found in expression: " + last);
|
||||
}
|
||||
else if (last instanceof Invokable) {
|
||||
else if (last instanceof RValue) {
|
||||
throw new ParserException(lastPosition, "Extra expression found: " + last);
|
||||
}
|
||||
else {
|
||||
|
Reference in New Issue
Block a user