Prevented overwriting built-in constants.

This commit is contained in:
TomyLobo 2011-11-22 17:44:51 +01:00
parent 5ef9df7feb
commit efc2209c0f

View File

@ -26,7 +26,6 @@ import java.util.Map;
import com.sk89q.worldedit.expression.lexer.Lexer; import com.sk89q.worldedit.expression.lexer.Lexer;
import com.sk89q.worldedit.expression.lexer.tokens.Token; import com.sk89q.worldedit.expression.lexer.tokens.Token;
import com.sk89q.worldedit.expression.parser.Parser; import com.sk89q.worldedit.expression.parser.Parser;
import com.sk89q.worldedit.expression.parser.ParserException;
import com.sk89q.worldedit.expression.runtime.Constant; import com.sk89q.worldedit.expression.runtime.Constant;
import com.sk89q.worldedit.expression.runtime.EvaluationException; import com.sk89q.worldedit.expression.runtime.EvaluationException;
import com.sk89q.worldedit.expression.runtime.RValue; import com.sk89q.worldedit.expression.runtime.RValue;
@ -69,13 +68,18 @@ public class Expression {
this(Lexer.tokenize(expression), variableNames); this(Lexer.tokenize(expression), variableNames);
} }
private Expression(List<Token> tokens, String... variableNames) throws ParserException { private Expression(List<Token> tokens, String... variableNames) throws ExpressionException {
this.variableNames = variableNames; this.variableNames = variableNames;
variables.put("e", new Constant(-1, Math.E)); variables.put("e", new Constant(-1, Math.E));
variables.put("pi", new Constant(-1, Math.PI)); variables.put("pi", new Constant(-1, Math.PI));
variables.put("true", new Constant(-1, 1)); variables.put("true", new Constant(-1, 1));
variables.put("false", new Constant(-1, 0)); variables.put("false", new Constant(-1, 0));
for (String variableName : variableNames) { for (String variableName : variableNames) {
if (variables.containsKey(variableName)) {
throw new ExpressionException(-1, "Tried to overwrite identifier '" + variableName + "'");
}
variables.put(variableName, new Variable(0)); variables.put(variableName, new Variable(0));
} }