aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/repl/REPL.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-02-14 15:56:22 +0100
committerMartin Odersky <odersky@gmail.com>2016-02-17 18:39:35 +0100
commit4550b524771af0719846eb906795a5ba83106eb9 (patch)
tree39d008ec7e26d341beff0041d219c6f99fa35cda /src/dotty/tools/dotc/repl/REPL.scala
parent37b6df435f1595f8610ec6d5fbe16d079da2eff7 (diff)
downloaddotty-4550b524771af0719846eb906795a5ba83106eb9.tar.gz
dotty-4550b524771af0719846eb906795a5ba83106eb9.tar.bz2
dotty-4550b524771af0719846eb906795a5ba83106eb9.zip
Revisions to REPL
Changes necessary to make basic REPL functionality work. Major refactoing: Code of Interpreter is now in CompilingInterpreter.scala. Interpreter.scala contains just the API.
Diffstat (limited to 'src/dotty/tools/dotc/repl/REPL.scala')
-rw-r--r--src/dotty/tools/dotc/repl/REPL.scala49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/repl/REPL.scala b/src/dotty/tools/dotc/repl/REPL.scala
new file mode 100644
index 000000000..2d6a3c742
--- /dev/null
+++ b/src/dotty/tools/dotc/repl/REPL.scala
@@ -0,0 +1,49 @@
+package dotty.tools
+package dotc
+package repl
+
+import core.Contexts.Context
+import reporting.Reporter
+import java.io.{BufferedReader, File, FileReader, PrintWriter}
+
+/** A compiler which stays resident between runs.
+ * Usage:
+ *
+ * > scala dotty.tools.dotc.Resident <options> <initial files>
+ *
+ * dotc> "more options and files to compile"
+ *
+ * ...
+ *
+ * dotc> :reset // reset all options to the ones passed on the command line
+ *
+ * ...
+ *
+ * dotc> :q // quit
+ */
+class REPL extends Driver {
+
+ /** The default input reader */
+ def input(implicit ctx: Context): InteractiveReader = {
+ val emacsShell = System.getProperty("env.emacs", "") != ""
+ //println("emacsShell="+emacsShell) //debug
+ if (ctx.settings.Xnojline.value || emacsShell) new SimpleReader()
+ else InteractiveReader.createDefault()
+ }
+
+ /** The defult output writer */
+ def output: PrintWriter = new NewLinePrintWriter(new ConsoleWriter, true)
+
+ override def newCompiler(implicit ctx: Context): Compiler =
+ new repl.CompilingInterpreter(output, ctx)
+
+ override def sourcesRequired = false
+
+ override def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Reporter = {
+ if (fileNames.isEmpty)
+ new InterpreterLoop(compiler, input, output).run()
+ else
+ ctx.error(s"don't now what to do with $fileNames%, %")
+ ctx.reporter
+ }
+}