diff options
author | paltherr <paltherr@epfl.ch> | 2005-02-18 17:57:29 +0000 |
---|---|---|
committer | paltherr <paltherr@epfl.ch> | 2005-02-18 17:57:29 +0000 |
commit | 008f8f063c505e690314992ccdf00ecbd88691b1 (patch) | |
tree | cb5cd4bb0ba2b7d200a35b4387ded2157af9b6d4 | |
parent | 9b8b0e477e358893f0df7ef8af696817ea6c49fc (diff) | |
download | scala-008f8f063c505e690314992ccdf00ecbd88691b1.tar.gz scala-008f8f063c505e690314992ccdf00ecbd88691b1.tar.bz2 scala-008f8f063c505e690314992ccdf00ecbd88691b1.zip |
- Changed behaviour of ":use" to execute comman...
- Changed behaviour of ":use" to execute commands in read files
-rw-r--r-- | sources/scala/tools/scalai/Interpreter.java | 8 | ||||
-rw-r--r-- | sources/scala/tools/scalai/InterpreterShell.java | 38 |
2 files changed, 43 insertions, 3 deletions
diff --git a/sources/scala/tools/scalai/Interpreter.java b/sources/scala/tools/scalai/Interpreter.java index 669793fa78..6a6895272a 100644 --- a/sources/scala/tools/scalai/Interpreter.java +++ b/sources/scala/tools/scalai/Interpreter.java @@ -70,9 +70,15 @@ public class Interpreter { } public EvaluatorResult interpret(String input, boolean interactive) { + return interpret("<console>", input, interactive); + } + + public EvaluatorResult interpret(String file, String input, + boolean interactive) + { if (input.trim().length() == 0) return EvaluatorResult.Void; return interpret( - global.compile("<console>", input + ";", interactive), + global.compile(file, input + ";", interactive), interactive); } diff --git a/sources/scala/tools/scalai/InterpreterShell.java b/sources/scala/tools/scalai/InterpreterShell.java index e57830b1e0..8bd4bb40b3 100644 --- a/sources/scala/tools/scalai/InterpreterShell.java +++ b/sources/scala/tools/scalai/InterpreterShell.java @@ -8,6 +8,7 @@ package scala.tools.scalai; +import java.io.FileReader; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.PushbackReader; @@ -193,8 +194,7 @@ public class InterpreterShell { case USE: if (args.length != 0) ufiles = args; - eval(ufiles); - return true; + return exec(ufiles); case GC: System.gc(); @@ -220,6 +220,36 @@ public class InterpreterShell { } } + public boolean exec(String[] files) { + for (int i = 0; i < files.length; i++) { + String file = files[i]; + StringBuffer blank = new StringBuffer(); + StringBuffer input = new StringBuffer(); + try { + BufferedReader reader = + new BufferedReader(new FileReader(file)); + while (true) { + String line = reader.readLine(); + if (line == null || line.trim().startsWith(":")) { + String code = input.toString(); + if (code.trim().length() > 0) eval(file, code); + if (line == null) break; + if (!exec(line.trim())) return false; + blank.append('\n'); + input.setLength(0); + input.append(blank); + } else { + blank.append('\n'); + input.append(line).append('\n'); + } + } + } catch (IOException exception) { + error(exception.getMessage()); + } + } + return true; + } + //######################################################################## // Public Methods - interpretation @@ -239,6 +269,10 @@ public class InterpreterShell { show(interpreter.interpret(input, true), true); } + public void eval(String file, String input) { + show(interpreter.interpret(file, input, true), true); + } + public void eval(String[] files) { show(interpreter.interpret(files, true), true); } |