geforkt von Mirrors/FastAsyncWorldEdit
Generalized the Lexer a bit more and renamed a function in the parser.
Dieser Commit ist enthalten in:
Ursprung
7dfc2a34e5
Commit
c2191f4fc7
@ -21,8 +21,10 @@ package com.sk89q.worldedit.expression.lexer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -74,6 +76,13 @@ public class Lexer {
|
||||
)
|
||||
);
|
||||
|
||||
private static final Set<Character> characterTokens = new HashSet<Character>();
|
||||
static {
|
||||
characterTokens.add(',');
|
||||
characterTokens.add('(');
|
||||
characterTokens.add(')');
|
||||
}
|
||||
|
||||
private static final Pattern numberPattern = Pattern.compile("^([0-9]*(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?)");
|
||||
private static final Pattern identifierPattern = Pattern.compile("^([A-Za-z][0-9A-Za-z_]*)");
|
||||
|
||||
@ -93,14 +102,12 @@ public class Lexer {
|
||||
}
|
||||
|
||||
final char ch = peek();
|
||||
switch (ch) {
|
||||
case ',':
|
||||
case '(':
|
||||
case ')':
|
||||
tokens.add(new CharacterToken(position++, ch));
|
||||
break;
|
||||
|
||||
default:
|
||||
if (characterTokens.contains(ch)) {
|
||||
tokens.add(new CharacterToken(position++, ch));
|
||||
continue;
|
||||
}
|
||||
|
||||
final Matcher numberMatcher = numberPattern.matcher(expression.substring(position));
|
||||
if (numberMatcher.lookingAt()) {
|
||||
String numberPart = numberMatcher.group(1);
|
||||
@ -130,7 +137,6 @@ public class Lexer {
|
||||
|
||||
throw new LexerException(position, "Unknown character '" + ch + "'");
|
||||
}
|
||||
}
|
||||
while (position < expression.length());
|
||||
|
||||
return tokens;
|
||||
|
@ -95,7 +95,7 @@ public class Parser {
|
||||
|
||||
final Token next = peek();
|
||||
if (next.id() == '(') {
|
||||
halfProcessed.add(parseFunction(identifierToken));
|
||||
halfProcessed.add(parseFunctionCall(identifierToken));
|
||||
}
|
||||
else {
|
||||
Invokable variable = variables.get(identifierToken.value);
|
||||
@ -301,9 +301,9 @@ public class Parser {
|
||||
return tokens.get(position);
|
||||
}
|
||||
|
||||
private Identifiable parseFunction(IdentifierToken identifierToken) throws ParserException {
|
||||
private Identifiable parseFunctionCall(IdentifierToken identifierToken) throws ParserException {
|
||||
if (peek().id() != '(') {
|
||||
throw new ParserException(peek().getPosition(), "Unexpected character in parseBracket");
|
||||
throw new ParserException(peek().getPosition(), "Unexpected character in parseFunctionCall");
|
||||
}
|
||||
++position;
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren