diff options
| author | jantuomi <jans.tuomi@gmail.com> | 2016-08-01 12:40:38 +0300 |
|---|---|---|
| committer | jantuomi <jans.tuomi@gmail.com> | 2016-08-01 12:40:38 +0300 |
| commit | 7fe8ef9ca40cabf54dd0d43a10bf7227efbae9b4 (patch) | |
| tree | 1fa902a481f09d6ea230c0fac942c256c75e1ed0 /src/main/com/jantuomi/tunkki/repl | |
| parent | 20a3fb57ae9ee1e70a2d57169742d481eac82fe9 (diff) | |
Add multiline input to REPL
Fix bug where REPL input is echoed back
Fix bug where an exclamation point would cause a JLine event exception
Input can now be continued on the next line with a '\' character at the end of the line. The character will be disregarded as whitespace in the parser.
Resolves #13
Diffstat (limited to 'src/main/com/jantuomi/tunkki/repl')
| -rw-r--r-- | src/main/com/jantuomi/tunkki/repl/Repl.java | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/src/main/com/jantuomi/tunkki/repl/Repl.java b/src/main/com/jantuomi/tunkki/repl/Repl.java index 817d746..3b63b6e 100644 --- a/src/main/com/jantuomi/tunkki/repl/Repl.java +++ b/src/main/com/jantuomi/tunkki/repl/Repl.java @@ -1,6 +1,7 @@ package com.jantuomi.tunkki.repl; import com.jantuomi.tunkki.Tunkki; +import com.jantuomi.tunkki.core.parser.datatype.IntegerDatatype; import com.jantuomi.tunkki.exception.TunkkiError; import jline.console.*; @@ -23,17 +24,33 @@ public class Repl { ConsoleReader reader = new ConsoleReader(); reader.setBellEnabled(false); + reader.setExpandEvents(false); String line; + String command = ""; PrintWriter out = new PrintWriter(System.out); - - while ((line = readLine(reader, "")) != null) { - try { - tunkki.run(line); + boolean isMultilineInput = false; + while (true) { + if (isMultilineInput) { + line = readLine(reader, "... "); + } else { + line = readLine(reader, "tunkki> "); } - catch (TunkkiError ex) { - ex.printStackTrace(); - Thread.sleep(50); + + if (line.endsWith("\\")) { + isMultilineInput = true; + command += line.substring(0, line.length() - 1) + " "; + } else { + try { + isMultilineInput = false; + command += line; + tunkki.run(command); + } catch (TunkkiError ex) { + ex.printStackTrace(); + Thread.sleep(50); + } finally { + command = ""; + } } out.flush(); @@ -42,11 +59,13 @@ public class Repl { private String readLine(ConsoleReader reader, String promptMessage) throws IOException { - String line = reader.readLine(promptMessage + "\ntunkki> "); + System.out.print(promptMessage); + String line = reader.readLine(); return line.trim(); } private void showWelcomeText() { System.out.println(String.format("tunkki REPL version %s", tunkki.versionString())); + System.out.println("Copyright: Jan Tuomi 2016"); } } |
