Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-25 18:40:05 +01:00
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.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
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 numberPattern = Pattern.compile("^([0-9]*(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?)");
|
||||||
private static final Pattern identifierPattern = Pattern.compile("^([A-Za-z][0-9A-Za-z_]*)");
|
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();
|
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));
|
final Matcher numberMatcher = numberPattern.matcher(expression.substring(position));
|
||||||
if (numberMatcher.lookingAt()) {
|
if (numberMatcher.lookingAt()) {
|
||||||
String numberPart = numberMatcher.group(1);
|
String numberPart = numberMatcher.group(1);
|
||||||
@ -130,7 +137,6 @@ public class Lexer {
|
|||||||
|
|
||||||
throw new LexerException(position, "Unknown character '" + ch + "'");
|
throw new LexerException(position, "Unknown character '" + ch + "'");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
while (position < expression.length());
|
while (position < expression.length());
|
||||||
|
|
||||||
return tokens;
|
return tokens;
|
||||||
|
@ -95,7 +95,7 @@ public class Parser {
|
|||||||
|
|
||||||
final Token next = peek();
|
final Token next = peek();
|
||||||
if (next.id() == '(') {
|
if (next.id() == '(') {
|
||||||
halfProcessed.add(parseFunction(identifierToken));
|
halfProcessed.add(parseFunctionCall(identifierToken));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Invokable variable = variables.get(identifierToken.value);
|
Invokable variable = variables.get(identifierToken.value);
|
||||||
@ -301,9 +301,9 @@ public class Parser {
|
|||||||
return tokens.get(position);
|
return tokens.get(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Identifiable parseFunction(IdentifierToken identifierToken) throws ParserException {
|
private Identifiable parseFunctionCall(IdentifierToken identifierToken) throws ParserException {
|
||||||
if (peek().id() != '(') {
|
if (peek().id() != '(') {
|
||||||
throw new ParserException(peek().getPosition(), "Unexpected character in parseBracket");
|
throw new ParserException(peek().getPosition(), "Unexpected character in parseFunctionCall");
|
||||||
}
|
}
|
||||||
++position;
|
++position;
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren