repl: better command parsing
This commit is contained in:
@@ -25,8 +25,8 @@ import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
|||||||
import org.jetbrains.jet.utils.ExceptionUtils;
|
import org.jetbrains.jet.utils.ExceptionUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -136,7 +136,8 @@ public class ReplFromTerminal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean oneCommand(@NotNull String command) throws Exception {
|
private boolean oneCommand(@NotNull String command) throws Exception {
|
||||||
if (command.equals("help")) {
|
List<String> split = splitCommand(command);
|
||||||
|
if (split.size() >= 1 && command.equals("help")) {
|
||||||
System.out.println("This is Kotlin REPL help");
|
System.out.println("This is Kotlin REPL help");
|
||||||
System.out.println("Available commands are:");
|
System.out.println("Available commands are:");
|
||||||
System.out.println(":help show this help");
|
System.out.println(":help show this help");
|
||||||
@@ -145,15 +146,15 @@ public class ReplFromTerminal {
|
|||||||
System.out.println(":load <file> load script from specified file");
|
System.out.println(":load <file> load script from specified file");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (command.equals("dump bytecode")) {
|
else if (split.size() >= 2 && split.get(0).equals("dump") && split.get(1).equals("bytecode")) {
|
||||||
getReplInterpreter().dumpClasses(new PrintWriter(System.out));
|
getReplInterpreter().dumpClasses(new PrintWriter(System.out));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (command.equals("quit")) {
|
else if (split.size() >= 1 && split.get(0).equals("quit")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (command.startsWith("load ")) {
|
else if (split.size() >= 2 && split.get(0).equals("load")) {
|
||||||
String fileName = command.substring("load ".length());
|
String fileName = split.get(1);
|
||||||
String scriptText = FileUtil.loadFile(new File(fileName));
|
String scriptText = FileUtil.loadFile(new File(fileName));
|
||||||
eval(scriptText);
|
eval(scriptText);
|
||||||
return true;
|
return true;
|
||||||
@@ -165,6 +166,10 @@ public class ReplFromTerminal {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<String> splitCommand(@NotNull String command) {
|
||||||
|
return Arrays.asList(command.split(" "));
|
||||||
|
}
|
||||||
|
|
||||||
public static void run(@NotNull Disposable disposable, @NotNull CompilerDependencies compilerDependencies) {
|
public static void run(@NotNull Disposable disposable, @NotNull CompilerDependencies compilerDependencies) {
|
||||||
new ReplFromTerminal(disposable, compilerDependencies).doRun();
|
new ReplFromTerminal(disposable, compilerDependencies).doRun();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user