first commit
Build AsminVoicechat / prepare-release (push) Successful in 14s
Build AsminVoicechat / build-and-test (17) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (18) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (19) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (20) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (21) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (22) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (23) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (24) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (25) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (26) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (27-ea) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (16) (push) Canceled after 38s
Build AsminVoicechat / prepare-release (push) Successful in 14s
Build AsminVoicechat / build-and-test (17) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (18) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (19) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (20) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (21) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (22) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (23) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (24) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (25) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (26) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (27-ea) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (16) (push) Canceled after 38s
This commit is contained in:
commit
bbccd4a815
454 files changed
+45050
No files matched your search
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package de.maxhenkel.voicechat.commodore.file;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
abstract class AbstractIterator<T>
|
||||
implements Iterator<T> {
|
||||
private State state = State.NOT_READY;
|
||||
private T next;
|
||||
|
||||
protected AbstractIterator() {
|
||||
}
|
||||
|
||||
protected abstract T computeNext() throws Exception;
|
||||
|
||||
protected final T endOfData() {
|
||||
this.state = State.DONE;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean hasNext() {
|
||||
if (this.state == State.FAILED) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
switch (this.state) {
|
||||
case DONE: {
|
||||
return false;
|
||||
}
|
||||
case READY: {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return this.tryToComputeNext();
|
||||
}
|
||||
|
||||
private boolean tryToComputeNext() {
|
||||
this.state = State.FAILED;
|
||||
try {
|
||||
this.next = this.computeNext();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException("Exception whilst computing next value", e);
|
||||
}
|
||||
if (this.state != State.DONE) {
|
||||
this.state = State.READY;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final T next() {
|
||||
if (!this.hasNext()) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
this.state = State.NOT_READY;
|
||||
T result = this.next;
|
||||
this.next = null;
|
||||
return result;
|
||||
}
|
||||
|
||||
public final T peek() {
|
||||
if (!this.hasNext()) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
return this.next;
|
||||
}
|
||||
|
||||
private static enum State {
|
||||
READY,
|
||||
NOT_READY,
|
||||
DONE,
|
||||
FAILED;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* com.mojang.brigadier.arguments.ArgumentType
|
||||
*/
|
||||
package de.maxhenkel.voicechat.commodore.file;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import de.maxhenkel.voicechat.commodore.file.ParseException;
|
||||
import de.maxhenkel.voicechat.commodore.file.TokenStream;
|
||||
|
||||
public interface ArgumentTypeParser {
|
||||
public boolean canParse(String var1, String var2);
|
||||
|
||||
public ArgumentType<?> parse(String var1, String var2, TokenStream var3) throws ParseException;
|
||||
}
|
||||
|
||||
+225
@@ -0,0 +1,225 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* com.mojang.brigadier.arguments.ArgumentType
|
||||
* com.mojang.brigadier.arguments.BoolArgumentType
|
||||
* com.mojang.brigadier.arguments.DoubleArgumentType
|
||||
* com.mojang.brigadier.arguments.FloatArgumentType
|
||||
* com.mojang.brigadier.arguments.IntegerArgumentType
|
||||
* com.mojang.brigadier.arguments.LongArgumentType
|
||||
* com.mojang.brigadier.arguments.StringArgumentType
|
||||
*/
|
||||
package de.maxhenkel.voicechat.commodore.file;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.arguments.BoolArgumentType;
|
||||
import com.mojang.brigadier.arguments.DoubleArgumentType;
|
||||
import com.mojang.brigadier.arguments.FloatArgumentType;
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.arguments.LongArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import de.maxhenkel.voicechat.commodore.file.ArgumentTypeParser;
|
||||
import de.maxhenkel.voicechat.commodore.file.ParseException;
|
||||
import de.maxhenkel.voicechat.commodore.file.Token;
|
||||
import de.maxhenkel.voicechat.commodore.file.TokenStream;
|
||||
|
||||
public class BrigadierArgumentTypeParser
|
||||
implements ArgumentTypeParser {
|
||||
public static final BrigadierArgumentTypeParser INSTANCE = new BrigadierArgumentTypeParser();
|
||||
|
||||
private BrigadierArgumentTypeParser() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canParse(String namespace, String name) {
|
||||
if (!namespace.equals("brigadier")) {
|
||||
return false;
|
||||
}
|
||||
switch (name) {
|
||||
case "bool":
|
||||
case "string":
|
||||
case "integer":
|
||||
case "long":
|
||||
case "float":
|
||||
case "double": {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgumentType<?> parse(String namespace, String name, TokenStream tokens) throws ParseException {
|
||||
switch (name) {
|
||||
case "bool": {
|
||||
return BoolArgumentType.bool();
|
||||
}
|
||||
case "string": {
|
||||
return BrigadierArgumentTypeParser.parseStringArgumentType(tokens);
|
||||
}
|
||||
case "integer": {
|
||||
return BrigadierArgumentTypeParser.parseIntegerArgumentType(tokens);
|
||||
}
|
||||
case "long": {
|
||||
return BrigadierArgumentTypeParser.parseLongArgumentType(tokens);
|
||||
}
|
||||
case "float": {
|
||||
return BrigadierArgumentTypeParser.parseFloatArgumentType(tokens);
|
||||
}
|
||||
case "double": {
|
||||
return BrigadierArgumentTypeParser.parseDoubleArgumentType(tokens);
|
||||
}
|
||||
}
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
private static StringArgumentType parseStringArgumentType(TokenStream tokens) throws ParseException {
|
||||
String stringType;
|
||||
Token token = tokens.next();
|
||||
if (!(token instanceof Token.StringToken)) {
|
||||
throw tokens.createException("Expected string token for string type but got " + token);
|
||||
}
|
||||
switch (stringType = ((Token.StringToken)token).getString()) {
|
||||
case "single_word": {
|
||||
return StringArgumentType.word();
|
||||
}
|
||||
case "quotable_phrase": {
|
||||
return StringArgumentType.string();
|
||||
}
|
||||
case "greedy_phrase": {
|
||||
return StringArgumentType.greedyString();
|
||||
}
|
||||
}
|
||||
throw tokens.createException("Unknown string type: " + stringType);
|
||||
}
|
||||
|
||||
private static IntegerArgumentType parseIntegerArgumentType(TokenStream tokens) throws ParseException {
|
||||
if (tokens.peek() instanceof Token.StringToken) {
|
||||
int min = BrigadierArgumentTypeParser.parseInt(tokens);
|
||||
if (tokens.peek() instanceof Token.StringToken) {
|
||||
int max = BrigadierArgumentTypeParser.parseInt(tokens);
|
||||
return IntegerArgumentType.integer((int)min, (int)max);
|
||||
}
|
||||
return IntegerArgumentType.integer((int)min);
|
||||
}
|
||||
return IntegerArgumentType.integer();
|
||||
}
|
||||
|
||||
private static LongArgumentType parseLongArgumentType(TokenStream tokens) throws ParseException {
|
||||
if (tokens.peek() instanceof Token.StringToken) {
|
||||
long min = BrigadierArgumentTypeParser.parseLong(tokens);
|
||||
if (tokens.peek() instanceof Token.StringToken) {
|
||||
long max = BrigadierArgumentTypeParser.parseLong(tokens);
|
||||
return LongArgumentType.longArg((long)min, (long)max);
|
||||
}
|
||||
return LongArgumentType.longArg((long)min);
|
||||
}
|
||||
return LongArgumentType.longArg();
|
||||
}
|
||||
|
||||
private static FloatArgumentType parseFloatArgumentType(TokenStream tokens) throws ParseException {
|
||||
if (tokens.peek() instanceof Token.StringToken) {
|
||||
float min = BrigadierArgumentTypeParser.parseFloat(tokens);
|
||||
if (tokens.peek() instanceof Token.StringToken) {
|
||||
float max = BrigadierArgumentTypeParser.parseFloat(tokens);
|
||||
return FloatArgumentType.floatArg((float)min, (float)max);
|
||||
}
|
||||
return FloatArgumentType.floatArg((float)min);
|
||||
}
|
||||
return FloatArgumentType.floatArg();
|
||||
}
|
||||
|
||||
private static DoubleArgumentType parseDoubleArgumentType(TokenStream tokens) throws ParseException {
|
||||
if (tokens.peek() instanceof Token.StringToken) {
|
||||
double min = BrigadierArgumentTypeParser.parseDouble(tokens);
|
||||
if (tokens.peek() instanceof Token.StringToken) {
|
||||
double max = BrigadierArgumentTypeParser.parseDouble(tokens);
|
||||
return DoubleArgumentType.doubleArg((double)min, (double)max);
|
||||
}
|
||||
return DoubleArgumentType.doubleArg((double)min);
|
||||
}
|
||||
return DoubleArgumentType.doubleArg();
|
||||
}
|
||||
|
||||
private static int parseInt(TokenStream tokens) throws ParseException {
|
||||
Token token = tokens.next();
|
||||
if (!(token instanceof Token.StringToken)) {
|
||||
throw tokens.createException("Expected string token for integer but got " + token);
|
||||
}
|
||||
String value = ((Token.StringToken)token).getString();
|
||||
if (value.equals("min")) {
|
||||
return Integer.MIN_VALUE;
|
||||
}
|
||||
if (value.equals("max")) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
throw tokens.createException("Expected int but got " + value, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static long parseLong(TokenStream tokens) throws ParseException {
|
||||
Token token = tokens.next();
|
||||
if (!(token instanceof Token.StringToken)) {
|
||||
throw tokens.createException("Expected string token for long but got " + token);
|
||||
}
|
||||
String value = ((Token.StringToken)token).getString();
|
||||
if (value.equals("min")) {
|
||||
return Long.MIN_VALUE;
|
||||
}
|
||||
if (value.equals("max")) {
|
||||
return Long.MAX_VALUE;
|
||||
}
|
||||
try {
|
||||
return Long.parseLong(value);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
throw tokens.createException("Expected long but got " + value, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static float parseFloat(TokenStream tokens) throws ParseException {
|
||||
Token token = tokens.next();
|
||||
if (!(token instanceof Token.StringToken)) {
|
||||
throw tokens.createException("Expected string token for float but got " + token);
|
||||
}
|
||||
String value = ((Token.StringToken)token).getString();
|
||||
if (value.equals("min")) {
|
||||
return Float.MIN_VALUE;
|
||||
}
|
||||
if (value.equals("max")) {
|
||||
return Float.MAX_VALUE;
|
||||
}
|
||||
try {
|
||||
return Float.parseFloat(value);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
throw tokens.createException("Expected float but got " + value, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static double parseDouble(TokenStream tokens) throws ParseException {
|
||||
Token token = tokens.next();
|
||||
if (!(token instanceof Token.StringToken)) {
|
||||
throw tokens.createException("Expected string token for double but got " + token);
|
||||
}
|
||||
String value = ((Token.StringToken)token).getString();
|
||||
if (value.equals("min")) {
|
||||
return Double.MIN_VALUE;
|
||||
}
|
||||
if (value.equals("max")) {
|
||||
return Double.MAX_VALUE;
|
||||
}
|
||||
try {
|
||||
return Double.parseDouble(value);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
throw tokens.createException("Expected double but got " + value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* com.mojang.brigadier.tree.LiteralCommandNode
|
||||
*/
|
||||
package de.maxhenkel.voicechat.commodore.file;
|
||||
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import de.maxhenkel.voicechat.commodore.file.ArgumentTypeParser;
|
||||
import de.maxhenkel.voicechat.commodore.file.BrigadierArgumentTypeParser;
|
||||
import de.maxhenkel.voicechat.commodore.file.Lexer;
|
||||
import de.maxhenkel.voicechat.commodore.file.ParseException;
|
||||
import de.maxhenkel.voicechat.commodore.file.Parser;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CommodoreFileReader {
|
||||
public static final CommodoreFileReader INSTANCE = CommodoreFileReader.builder().withArgumentTypeParser(BrigadierArgumentTypeParser.INSTANCE).build();
|
||||
private final List<ArgumentTypeParser> argumentTypeParsers;
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
CommodoreFileReader(List<ArgumentTypeParser> argumentTypeParsers) {
|
||||
this.argumentTypeParsers = Collections.unmodifiableList(argumentTypeParsers);
|
||||
}
|
||||
|
||||
public <S> LiteralCommandNode<S> parse(Reader reader) throws IOException {
|
||||
try {
|
||||
return new Parser(new Lexer(reader), this.argumentTypeParsers).parse();
|
||||
}
|
||||
catch (ParseException e) {
|
||||
if (e.getCause() instanceof IOException) {
|
||||
throw (IOException)e.getCause();
|
||||
}
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public <S> LiteralCommandNode<S> parse(InputStream inputStream) throws IOException {
|
||||
try (InputStreamReader reader = new InputStreamReader(inputStream);){
|
||||
LiteralCommandNode<S> literalCommandNode = this.parse(reader);
|
||||
return literalCommandNode;
|
||||
}
|
||||
}
|
||||
|
||||
public <S> LiteralCommandNode<S> parse(Path path) throws IOException {
|
||||
try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8);){
|
||||
LiteralCommandNode<S> literalCommandNode = this.parse(reader);
|
||||
return literalCommandNode;
|
||||
}
|
||||
}
|
||||
|
||||
public <S> LiteralCommandNode<S> parse(File file) throws IOException {
|
||||
return this.parse(file.toPath());
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private final List<ArgumentTypeParser> argumentTypeParsers = new ArrayList<ArgumentTypeParser>();
|
||||
|
||||
Builder() {
|
||||
}
|
||||
|
||||
public Builder withArgumentTypeParser(ArgumentTypeParser argumentTypeParser) {
|
||||
Objects.requireNonNull(argumentTypeParser, "argumentTypeParser");
|
||||
this.argumentTypeParsers.add(argumentTypeParser);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommodoreFileReader build() {
|
||||
return new CommodoreFileReader(new ArrayList<ArgumentTypeParser>(this.argumentTypeParsers));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package de.maxhenkel.voicechat.commodore.file;
|
||||
|
||||
import de.maxhenkel.voicechat.commodore.file.AbstractIterator;
|
||||
import de.maxhenkel.voicechat.commodore.file.ParseException;
|
||||
import de.maxhenkel.voicechat.commodore.file.Token;
|
||||
import de.maxhenkel.voicechat.commodore.file.TokenStream;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StreamTokenizer;
|
||||
|
||||
class Lexer
|
||||
extends AbstractIterator<Token>
|
||||
implements TokenStream {
|
||||
private final StreamTokenizer tokenizer;
|
||||
private boolean end = false;
|
||||
|
||||
Lexer(Reader reader) {
|
||||
this.tokenizer = new StreamTokenizer(reader);
|
||||
this.tokenizer.resetSyntax();
|
||||
this.tokenizer.wordChars(33, 126);
|
||||
this.tokenizer.quoteChar(34);
|
||||
this.tokenizer.whitespaceChars(0, 32);
|
||||
"{};".chars().forEach(this.tokenizer::ordinaryChar);
|
||||
this.tokenizer.slashSlashComments(true);
|
||||
this.tokenizer.slashStarComments(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Token computeNext() throws ParseException {
|
||||
if (this.end) {
|
||||
return (Token)this.endOfData();
|
||||
}
|
||||
try {
|
||||
int token = this.tokenizer.nextToken();
|
||||
switch (token) {
|
||||
case -1: {
|
||||
this.end = true;
|
||||
return Token.ConstantToken.EOF;
|
||||
}
|
||||
case -3: {
|
||||
return new Token.StringToken(this.tokenizer.sval);
|
||||
}
|
||||
case 123: {
|
||||
return Token.ConstantToken.OPEN_BRACKET;
|
||||
}
|
||||
case 125: {
|
||||
return Token.ConstantToken.CLOSE_BRACKET;
|
||||
}
|
||||
case 59: {
|
||||
return Token.ConstantToken.SEMICOLON;
|
||||
}
|
||||
}
|
||||
throw this.createException("Unknown token: " + (char)token + "(" + token + ")");
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw this.createException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParseException createException(String message) {
|
||||
return new ParseException(message, this.tokenizer.lineno());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParseException createException(Throwable cause) {
|
||||
return new ParseException(cause, this.tokenizer.lineno());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParseException createException(String message, Throwable cause) {
|
||||
return new ParseException(message, cause, this.tokenizer.lineno());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package de.maxhenkel.voicechat.commodore.file;
|
||||
|
||||
public final class ParseException
|
||||
extends Exception {
|
||||
ParseException(String message, int currentLine) {
|
||||
super(message + " (at line " + currentLine + ")");
|
||||
}
|
||||
|
||||
ParseException(Throwable cause, int currentLine) {
|
||||
super("At line " + currentLine, cause);
|
||||
}
|
||||
|
||||
ParseException(String message, Throwable cause, int currentLine) {
|
||||
super(message + " (at line " + currentLine + ")", cause);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* com.mojang.brigadier.arguments.ArgumentType
|
||||
* com.mojang.brigadier.builder.LiteralArgumentBuilder
|
||||
* com.mojang.brigadier.builder.RequiredArgumentBuilder
|
||||
* com.mojang.brigadier.tree.CommandNode
|
||||
* com.mojang.brigadier.tree.LiteralCommandNode
|
||||
*/
|
||||
package de.maxhenkel.voicechat.commodore.file;
|
||||
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import de.maxhenkel.voicechat.commodore.file.ArgumentTypeParser;
|
||||
import de.maxhenkel.voicechat.commodore.file.Lexer;
|
||||
import de.maxhenkel.voicechat.commodore.file.ParseException;
|
||||
import de.maxhenkel.voicechat.commodore.file.Token;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
class Parser<S> {
|
||||
private final Lexer lexer;
|
||||
private final Collection<ArgumentTypeParser> argumentTypeParsers;
|
||||
|
||||
Parser(Lexer lexer, Collection<ArgumentTypeParser> argumentTypeParsers) {
|
||||
this.lexer = lexer;
|
||||
this.argumentTypeParsers = argumentTypeParsers;
|
||||
}
|
||||
|
||||
LiteralCommandNode<S> parse() throws ParseException {
|
||||
CommandNode<S> node = this.parseNode();
|
||||
if (!(node instanceof LiteralCommandNode)) {
|
||||
throw this.lexer.createException("Root command node is not a literal command node");
|
||||
}
|
||||
if (this.lexer.peek() != Token.ConstantToken.EOF) {
|
||||
throw this.lexer.createException("Expected end of file but got " + this.lexer.peek());
|
||||
}
|
||||
return (LiteralCommandNode)node;
|
||||
}
|
||||
|
||||
private CommandNode<S> parseNode() throws ParseException {
|
||||
Token token = (Token)this.lexer.next();
|
||||
if (!(token instanceof Token.StringToken)) {
|
||||
throw this.lexer.createException("Expected string token for node name but got " + token);
|
||||
}
|
||||
String name = ((Token.StringToken)token).getString();
|
||||
Object node = this.lexer.peek() instanceof Token.StringToken ? RequiredArgumentBuilder.argument((String)name, this.parseArgumentType()) : LiteralArgumentBuilder.literal((String)name);
|
||||
if (this.lexer.peek() == Token.ConstantToken.OPEN_BRACKET) {
|
||||
this.lexer.next();
|
||||
while (this.lexer.peek() != Token.ConstantToken.CLOSE_BRACKET) {
|
||||
CommandNode<S> child = this.parseNode();
|
||||
node.then(child);
|
||||
}
|
||||
this.lexer.next();
|
||||
} else {
|
||||
if (this.lexer.peek() != Token.ConstantToken.SEMICOLON) {
|
||||
throw this.lexer.createException("Node definition not ended with semicolon, got " + this.lexer.peek());
|
||||
}
|
||||
this.lexer.next();
|
||||
}
|
||||
return node.build();
|
||||
}
|
||||
|
||||
private ArgumentType<?> parseArgumentType() throws ParseException {
|
||||
Token token = (Token)this.lexer.next();
|
||||
if (!(token instanceof Token.StringToken)) {
|
||||
throw this.lexer.createException("Expected string token for argument type but got " + token);
|
||||
}
|
||||
String argumentType = ((Token.StringToken)token).getString();
|
||||
Object[] key = argumentType.split(":");
|
||||
if (key.length != 2) {
|
||||
throw this.lexer.createException("Invalid key for argument type: " + Arrays.toString(key));
|
||||
}
|
||||
for (ArgumentTypeParser parser : this.argumentTypeParsers) {
|
||||
if (!parser.canParse((String)key[0], (String)key[1])) continue;
|
||||
return parser.parse((String)key[0], (String)key[1], this.lexer);
|
||||
}
|
||||
throw this.lexer.createException("Unable to parse argument type: " + argumentType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package de.maxhenkel.voicechat.commodore.file;
|
||||
|
||||
public interface Token {
|
||||
|
||||
public static final class StringToken
|
||||
implements Token {
|
||||
private final String string;
|
||||
|
||||
StringToken(String string) {
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
return this.string;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum ConstantToken implements Token
|
||||
{
|
||||
OPEN_BRACKET,
|
||||
CLOSE_BRACKET,
|
||||
SEMICOLON,
|
||||
EOF;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package de.maxhenkel.voicechat.commodore.file;
|
||||
|
||||
import de.maxhenkel.voicechat.commodore.file.ParseException;
|
||||
import de.maxhenkel.voicechat.commodore.file.Token;
|
||||
|
||||
public interface TokenStream {
|
||||
public boolean hasNext();
|
||||
|
||||
public Token next();
|
||||
|
||||
public Token peek();
|
||||
|
||||
public ParseException createException(String var1);
|
||||
|
||||
public ParseException createException(Throwable var1);
|
||||
|
||||
public ParseException createException(String var1, Throwable var2);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user